9 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
12 #define SSH_CIPHER_IDEA 1
13 #define SSH_CIPHER_DES 2
14 #define SSH_CIPHER_3DES 3
15 #define SSH_CIPHER_BLOWFISH 6
24 * A Bignum is stored as a sequence of `unsigned short' words. The
25 * first tells how many remain; the remaining ones are digits, LS
28 typedef unsigned short *Bignum;
34 unsigned long exponent;
35 unsigned char *modulus;
39 Bignum private_exponent;
50 int makekey(unsigned char *data, struct RSAKey *result,
51 unsigned char **keystr, int order);
52 int makeprivate(unsigned char *data, struct RSAKey *result);
53 void rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
54 Bignum rsadecrypt(Bignum input, struct RSAKey *key);
55 void rsasign(unsigned char *data, int length, struct RSAKey *key);
56 void rsasanitise(struct RSAKey *key);
57 int rsastr_len(struct RSAKey *key);
58 void rsastr_fmt(char *str, struct RSAKey *key);
59 void rsa_fingerprint(char *str, int len, struct RSAKey *key);
60 void freersakey(struct RSAKey *key);
62 typedef unsigned int word32;
63 typedef unsigned int uint32;
65 unsigned long crc32(const void *s, size_t len);
76 unsigned char block[64];
82 void MD5Init(struct MD5Context *context);
83 void MD5Update(struct MD5Context *context, unsigned char const *buf,
85 void MD5Final(unsigned char digest[16], struct MD5Context *context);
89 unsigned char block[64];
94 void SHA_Init(SHA_State *s);
95 void SHA_Bytes(SHA_State *s, void *p, int len);
96 void SHA_Final(SHA_State *s, unsigned char *output);
97 void SHA_Simple(void *p, int len, unsigned char *output);
100 void (*sesskey)(unsigned char *key); /* for ssh 1 */
101 void (*setcsiv)(unsigned char *key); /* for ssh 2 */
102 void (*setcskey)(unsigned char *key); /* for ssh 2 */
103 void (*setsciv)(unsigned char *key); /* for ssh 2 */
104 void (*setsckey)(unsigned char *key); /* for ssh 2 */
105 void (*encrypt)(unsigned char *blk, int len);
106 void (*decrypt)(unsigned char *blk, int len);
112 void (*setcskey)(unsigned char *key);
113 void (*setsckey)(unsigned char *key);
114 void (*generate)(unsigned char *blk, int len, unsigned long seq);
115 int (*verify)(unsigned char *blk, int len, unsigned long seq);
122 * Plugging in another KEX algorithm requires structural chaos,
123 * so it's hard to abstract them into nice little structures
124 * like this. Hence, for the moment, this is just a
125 * placeholder. I claim justification in the fact that OpenSSH
132 void *(*newkey)(char *data, int len);
133 void (*freekey)(void *key);
134 char *(*fmtkey)(void *key);
135 char *(*fingerprint)(void *key);
136 int (*verifysig)(void *key, char *sig, int siglen,
137 char *data, int datalen);
138 int (*sign)(void *key, char *sig, int siglen,
139 char *data, int datalen);
141 char *keytype; /* for host key cache */
144 struct ssh_compress {
146 void (*compress_init)(void);
147 int (*compress)(unsigned char *block, int len,
148 unsigned char **outblock, int *outlen);
149 void (*decompress_init)(void);
150 int (*decompress)(unsigned char *block, int len,
151 unsigned char **outblock, int *outlen);
155 void SHATransform(word32 *digest, word32 *data);
158 int random_byte(void);
159 void random_add_noise(void *noise, int length);
160 void random_add_heavynoise(void *noise, int length);
162 void logevent (char *);
164 Bignum newbn(int length);
165 Bignum copybn(Bignum b);
166 Bignum bignum_from_short(unsigned short n);
167 void freebn(Bignum b);
168 Bignum modpow(Bignum base, Bignum exp, Bignum mod);
169 Bignum modmul(Bignum a, Bignum b, Bignum mod);
170 void decbn(Bignum n);
171 extern Bignum Zero, One;
172 int ssh1_read_bignum(unsigned char *data, Bignum *result);
173 int ssh1_bignum_bitcount(Bignum bn);
174 int ssh1_bignum_length(Bignum bn);
175 int bignum_byte(Bignum bn, int i);
176 int bignum_bit(Bignum bn, int i);
177 void bignum_set_bit(Bignum bn, int i, int value);
178 int ssh1_write_bignum(void *data, Bignum bn);
179 Bignum biggcd(Bignum a, Bignum b);
180 unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
181 Bignum bignum_add_long(Bignum number, unsigned long addend);
182 Bignum bigmul(Bignum a, Bignum b);
183 Bignum modinv(Bignum number, Bignum modulus);
184 Bignum bignum_rshift(Bignum number, int shift);
185 int bignum_cmp(Bignum a, Bignum b);
186 char *bignum_decimal(Bignum x);
188 Bignum dh_create_e(void);
189 Bignum dh_find_K(Bignum f);
191 int loadrsakey(char *filename, struct RSAKey *key, struct RSAAux *aux,
193 int rsakey_encrypted(char *filename, char **comment);
195 int saversakey(char *filename, struct RSAKey *key, struct RSAAux *aux,
198 void des3_decrypt_pubkey(unsigned char *key,
199 unsigned char *blk, int len);
200 void des3_encrypt_pubkey(unsigned char *key,
201 unsigned char *blk, int len);
204 * For progress updates in the key generation utility.
206 typedef void (*progfn_t)(void *param, int phase, int progress);
208 int rsa_generate(struct RSAKey *key, struct RSAAux *aux, int bits,
209 progfn_t pfn, void *pfnparam);
210 Bignum primegen(int bits, int modulus, int residue,
211 int phase, progfn_t pfn, void *pfnparam);
216 void zlib_compress_init(void);
217 void zlib_decompress_init(void);
218 int zlib_compress_block(unsigned char *block, int len,
219 unsigned char **outblock, int *outlen);
220 int zlib_decompress_block(unsigned char *block, int len,
221 unsigned char **outblock, int *outlen);