1999-01-08 16:10:19 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-09-05 18:28:17 +04:00
|
|
|
/*
|
|
|
|
* Useful thing.
|
|
|
|
*/
|
|
|
|
#ifndef lenof
|
|
|
|
#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
|
|
|
|
#endif
|
|
|
|
|
1999-07-06 23:42:57 +04:00
|
|
|
#define SSH_CIPHER_IDEA 1
|
1999-10-25 12:59:40 +04:00
|
|
|
#define SSH_CIPHER_DES 2
|
1999-07-06 23:42:57 +04:00
|
|
|
#define SSH_CIPHER_3DES 3
|
|
|
|
#define SSH_CIPHER_BLOWFISH 6
|
|
|
|
|
2000-09-05 18:28:17 +04:00
|
|
|
#ifdef MSCRYPTOAPI
|
|
|
|
#define APIEXTRA 8
|
|
|
|
#else
|
|
|
|
#define APIEXTRA 0
|
|
|
|
#endif
|
|
|
|
|
2000-09-07 20:33:49 +04:00
|
|
|
/*
|
|
|
|
* A Bignum is stored as a sequence of `unsigned short' words. The
|
|
|
|
* first tells how many remain; the remaining ones are digits, LS
|
|
|
|
* first.
|
|
|
|
*/
|
|
|
|
typedef unsigned short *Bignum;
|
|
|
|
|
1999-01-08 16:02:13 +03:00
|
|
|
struct RSAKey {
|
|
|
|
int bits;
|
|
|
|
int bytes;
|
2000-03-24 12:45:49 +03:00
|
|
|
#ifdef MSCRYPTOAPI
|
|
|
|
unsigned long exponent;
|
|
|
|
unsigned char *modulus;
|
|
|
|
#else
|
2000-09-07 20:33:49 +04:00
|
|
|
Bignum modulus;
|
|
|
|
Bignum exponent;
|
|
|
|
Bignum private_exponent;
|
2000-03-24 12:45:49 +03:00
|
|
|
#endif
|
2000-09-14 19:02:50 +04:00
|
|
|
char *comment;
|
1999-01-08 16:02:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int makekey(unsigned char *data, struct RSAKey *result,
|
2000-09-07 20:33:49 +04:00
|
|
|
unsigned char **keystr, int order);
|
|
|
|
int makeprivate(unsigned char *data, struct RSAKey *result);
|
1999-01-08 16:02:13 +03:00
|
|
|
void rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
|
2000-09-07 20:33:49 +04:00
|
|
|
Bignum rsadecrypt(Bignum input, struct RSAKey *key);
|
|
|
|
void rsasign(unsigned char *data, int length, struct RSAKey *key);
|
|
|
|
void rsasanitise(struct RSAKey *key);
|
1999-01-08 16:02:13 +03:00
|
|
|
int rsastr_len(struct RSAKey *key);
|
|
|
|
void rsastr_fmt(char *str, struct RSAKey *key);
|
2000-09-14 19:02:50 +04:00
|
|
|
void freersakey(struct RSAKey *key);
|
1999-01-08 16:02:13 +03:00
|
|
|
|
|
|
|
typedef unsigned int word32;
|
|
|
|
typedef unsigned int uint32;
|
|
|
|
|
2000-03-08 19:13:32 +03:00
|
|
|
unsigned long crc32(const void *s, size_t len);
|
1999-01-08 16:02:13 +03:00
|
|
|
|
2000-04-04 18:47:22 +04:00
|
|
|
typedef struct {
|
|
|
|
uint32 h[4];
|
|
|
|
} MD5_Core_State;
|
|
|
|
|
1999-01-08 16:02:13 +03:00
|
|
|
struct MD5Context {
|
2000-03-24 12:45:49 +03:00
|
|
|
#ifdef MSCRYPTOAPI
|
|
|
|
unsigned long hHash;
|
|
|
|
#else
|
2000-04-04 18:47:22 +04:00
|
|
|
MD5_Core_State core;
|
2000-04-04 18:51:17 +04:00
|
|
|
unsigned char block[64];
|
2000-04-04 18:47:22 +04:00
|
|
|
int blkused;
|
|
|
|
uint32 lenhi, lenlo;
|
2000-03-24 12:45:49 +03:00
|
|
|
#endif
|
1999-01-08 16:02:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void MD5Init(struct MD5Context *context);
|
|
|
|
void MD5Update(struct MD5Context *context, unsigned char const *buf,
|
|
|
|
unsigned len);
|
|
|
|
void MD5Final(unsigned char digest[16], struct MD5Context *context);
|
|
|
|
|
2000-09-05 18:28:17 +04:00
|
|
|
typedef struct {
|
|
|
|
uint32 h[5];
|
|
|
|
unsigned char block[64];
|
|
|
|
int blkused;
|
|
|
|
uint32 lenhi, lenlo;
|
|
|
|
} SHA_State;
|
|
|
|
|
|
|
|
void SHA_Init(SHA_State *s);
|
|
|
|
void SHA_Bytes(SHA_State *s, void *p, int len);
|
|
|
|
void SHA_Final(SHA_State *s, unsigned char *output);
|
2000-09-07 20:33:49 +04:00
|
|
|
void SHA_Simple(void *p, int len, unsigned char *output);
|
2000-09-05 18:28:17 +04:00
|
|
|
|
1999-01-08 16:02:13 +03:00
|
|
|
struct ssh_cipher {
|
2000-09-05 20:23:36 +04:00
|
|
|
void (*sesskey)(unsigned char *key); /* for ssh 1 */
|
|
|
|
void (*setcsiv)(unsigned char *key); /* for ssh 2 */
|
|
|
|
void (*setcskey)(unsigned char *key); /* for ssh 2 */
|
|
|
|
void (*setsciv)(unsigned char *key); /* for ssh 2 */
|
|
|
|
void (*setsckey)(unsigned char *key); /* for ssh 2 */
|
1999-01-08 16:02:13 +03:00
|
|
|
void (*encrypt)(unsigned char *blk, int len);
|
|
|
|
void (*decrypt)(unsigned char *blk, int len);
|
2000-09-05 18:28:17 +04:00
|
|
|
char *name;
|
|
|
|
int blksize;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ssh_mac {
|
2000-09-05 20:23:36 +04:00
|
|
|
void (*setcskey)(unsigned char *key);
|
|
|
|
void (*setsckey)(unsigned char *key);
|
2000-09-05 18:28:17 +04:00
|
|
|
void (*generate)(unsigned char *blk, int len, unsigned long seq);
|
|
|
|
int (*verify)(unsigned char *blk, int len, unsigned long seq);
|
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ssh_kex {
|
2000-09-07 20:33:49 +04:00
|
|
|
/*
|
|
|
|
* Plugging in another KEX algorithm requires structural chaos,
|
|
|
|
* so it's hard to abstract them into nice little structures
|
|
|
|
* like this. Hence, for the moment, this is just a
|
|
|
|
* placeholder. I claim justification in the fact that OpenSSH
|
|
|
|
* does this too :-)
|
|
|
|
*/
|
2000-09-05 18:28:17 +04:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ssh_hostkey {
|
2000-09-07 20:33:49 +04:00
|
|
|
void (*setkey)(char *data, int len);
|
|
|
|
char *(*fmtkey)(void);
|
|
|
|
int (*verifysig)(char *sig, int siglen, char *data, int datalen);
|
2000-09-05 18:28:17 +04:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ssh_compress {
|
|
|
|
char *name;
|
1999-01-08 16:02:13 +03:00
|
|
|
};
|
|
|
|
|
2000-03-24 12:45:49 +03:00
|
|
|
#ifndef MSCRYPTOAPI
|
1999-01-08 16:02:13 +03:00
|
|
|
void SHATransform(word32 *digest, word32 *data);
|
2000-03-24 12:45:49 +03:00
|
|
|
#endif
|
1999-01-08 16:02:13 +03:00
|
|
|
|
|
|
|
int random_byte(void);
|
|
|
|
void random_add_noise(void *noise, int length);
|
1999-11-09 14:10:04 +03:00
|
|
|
|
|
|
|
void logevent (char *);
|
2000-09-05 18:28:17 +04:00
|
|
|
|
|
|
|
Bignum newbn(int length);
|
2000-09-07 20:33:49 +04:00
|
|
|
Bignum copybn(Bignum b);
|
2000-09-05 18:28:17 +04:00
|
|
|
void freebn(Bignum b);
|
|
|
|
void modpow(Bignum base, Bignum exp, Bignum mod, Bignum result);
|
2000-09-07 20:33:49 +04:00
|
|
|
void modmul(Bignum a, Bignum b, Bignum mod, Bignum result);
|
|
|
|
void decbn(Bignum n);
|
|
|
|
extern Bignum Zero, One;
|
|
|
|
int ssh1_read_bignum(unsigned char *data, Bignum *result);
|
2000-09-14 19:02:50 +04:00
|
|
|
int ssh1_bignum_bitcount(Bignum bn);
|
|
|
|
int ssh1_bignum_length(Bignum bn);
|
|
|
|
int bignum_byte(Bignum bn, int i);
|
|
|
|
int ssh1_write_bignum(void *data, Bignum bn);
|
2000-09-05 18:28:17 +04:00
|
|
|
|
|
|
|
Bignum dh_create_e(void);
|
|
|
|
Bignum dh_find_K(Bignum f);
|
2000-09-07 20:33:49 +04:00
|
|
|
|
|
|
|
int loadrsakey(char *filename, struct RSAKey *key, char *passphrase);
|
2000-09-25 14:14:53 +04:00
|
|
|
int rsakey_encrypted(char *filename, char **comment);
|
2000-09-07 20:33:49 +04:00
|
|
|
|
|
|
|
void des3_decrypt_pubkey(unsigned char *key,
|
2000-09-14 19:02:50 +04:00
|
|
|
unsigned char *blk, int len);
|