Implement the Montgomery technique for speeding up modular
[u/mdw/putty] / ssh.h
CommitLineData
df3c4460 1#include <stdio.h>
37508af4 2#include <string.h>
3
dcbde236 4#include "puttymem.h"
8def70c3 5#include "tree234.h"
d74d141c 6#include "network.h"
5c72ca61 7#include "int64.h"
9a30e26b 8#include "misc.h"
dcbde236 9
2871113a 10struct ssh_channel;
11
5471d09a 12extern void sshfwd_close(struct ssh_channel *c);
13extern int sshfwd_write(struct ssh_channel *c, char *, int);
14extern void sshfwd_unthrottle(struct ssh_channel *c, int bufsize);
15
e5574168 16/*
17 * Useful thing.
18 */
19#ifndef lenof
20#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
21#endif
22
bea1ef5f 23#define SSH_CIPHER_IDEA 1
9697bfd2 24#define SSH_CIPHER_DES 2
bea1ef5f 25#define SSH_CIPHER_3DES 3
26#define SSH_CIPHER_BLOWFISH 6
27
e5574168 28#ifdef MSCRYPTOAPI
29#define APIEXTRA 8
30#else
31#define APIEXTRA 0
32#endif
33
3709bfe9 34#ifndef BIGNUM_INTERNAL
35typedef void *Bignum;
36#endif
7cca0d81 37
374330e2 38struct RSAKey {
39 int bits;
40 int bytes;
8f203108 41#ifdef MSCRYPTOAPI
42 unsigned long exponent;
43 unsigned char *modulus;
44#else
7cca0d81 45 Bignum modulus;
46 Bignum exponent;
47 Bignum private_exponent;
9400cf6f 48 Bignum p;
49 Bignum q;
50 Bignum iqmp;
65a22376 51#endif
52 char *comment;
9400cf6f 53};
54
5c72ca61 55struct dss_key {
56 Bignum p, q, g, y, x;
57};
58
0016d70b 59int makekey(unsigned char *data, int len, struct RSAKey *result,
7cca0d81 60 unsigned char **keystr, int order);
0016d70b 61int makeprivate(unsigned char *data, int len, struct RSAKey *result);
62int rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
7cca0d81 63Bignum rsadecrypt(Bignum input, struct RSAKey *key);
64void rsasign(unsigned char *data, int length, struct RSAKey *key);
65void rsasanitise(struct RSAKey *key);
374330e2 66int rsastr_len(struct RSAKey *key);
67void rsastr_fmt(char *str, struct RSAKey *key);
1c2a93c4 68void rsa_fingerprint(char *str, int len, struct RSAKey *key);
014970c8 69int rsa_verify(struct RSAKey *key);
3f2d010c 70unsigned char *rsa_public_blob(struct RSAKey *key, int *len);
0016d70b 71int rsa_public_blob_len(void *data, int maxlen);
5c58ad2d 72void freersakey(struct RSAKey *key);
374330e2 73
b3d375b2 74#ifndef PUTTY_UINT32_DEFINED
75/* This makes assumptions about the int type. */
374330e2 76typedef unsigned int uint32;
b3d375b2 77#define PUTTY_UINT32_DEFINED
78#endif
79typedef uint32 word32;
374330e2 80
71bedafe 81unsigned long crc32_compute(const void *s, size_t len);
9a3a93a5 82unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
83
84/* SSH CRC compensation attack detector */
0183b242 85void *crcda_make_context(void);
86void crcda_free_context(void *handle);
87int detect_attack(void *handle, unsigned char *buf, uint32 len,
88 unsigned char *IV);
374330e2 89
fae1a71b 90/*
91 * SSH2 RSA key exchange functions
92 */
93struct ssh_hash;
94void *ssh_rsakex_newkey(char *data, int len);
95void ssh_rsakex_freekey(void *key);
96int ssh_rsakex_klen(void *key);
97void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen,
98 unsigned char *out, int outlen,
99 void *key);
100
48672163 101typedef struct {
102 uint32 h[4];
103} MD5_Core_State;
104
374330e2 105struct MD5Context {
8f203108 106#ifdef MSCRYPTOAPI
107 unsigned long hHash;
108#else
48672163 109 MD5_Core_State core;
bb093ca7 110 unsigned char block[64];
48672163 111 int blkused;
112 uint32 lenhi, lenlo;
8f203108 113#endif
374330e2 114};
115
116void MD5Init(struct MD5Context *context);
117void MD5Update(struct MD5Context *context, unsigned char const *buf,
32874aea 118 unsigned len);
374330e2 119void MD5Final(unsigned char digest[16], struct MD5Context *context);
f33ba69e 120void MD5Simple(void const *p, unsigned len, unsigned char output[16]);
121
122void *hmacmd5_make_context(void);
123void hmacmd5_free_context(void *handle);
447f7a7b 124void hmacmd5_key(void *handle, void const *key, int len);
f33ba69e 125void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
126 unsigned char *hmac);
374330e2 127
e5574168 128typedef struct {
129 uint32 h[5];
130 unsigned char block[64];
131 int blkused;
132 uint32 lenhi, lenlo;
133} SHA_State;
32874aea 134void SHA_Init(SHA_State * s);
135void SHA_Bytes(SHA_State * s, void *p, int len);
136void SHA_Final(SHA_State * s, unsigned char *output);
7cca0d81 137void SHA_Simple(void *p, int len, unsigned char *output);
e5574168 138
5c72ca61 139void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
140 unsigned char *output);
062e5811 141typedef struct {
142 uint32 h[8];
143 unsigned char block[64];
144 int blkused;
145 uint32 lenhi, lenlo;
146} SHA256_State;
147void SHA256_Init(SHA256_State * s);
148void SHA256_Bytes(SHA256_State * s, const void *p, int len);
149void SHA256_Final(SHA256_State * s, unsigned char *output);
150void SHA256_Simple(const void *p, int len, unsigned char *output);
5c72ca61 151
152typedef struct {
153 uint64 h[8];
154 unsigned char block[128];
155 int blkused;
156 uint32 len[4];
157} SHA512_State;
158void SHA512_Init(SHA512_State * s);
159void SHA512_Bytes(SHA512_State * s, const void *p, int len);
160void SHA512_Final(SHA512_State * s, unsigned char *output);
161void SHA512_Simple(const void *p, int len, unsigned char *output);
162
374330e2 163struct ssh_cipher {
371e569c 164 void *(*make_context)(void);
165 void (*free_context)(void *);
2e85c969 166 void (*sesskey) (void *, unsigned char *key); /* for SSH-1 */
371e569c 167 void (*encrypt) (void *, unsigned char *blk, int len);
168 void (*decrypt) (void *, unsigned char *blk, int len);
0a3f1d48 169 int blksize;
371e569c 170 char *text_name;
0a3f1d48 171};
172
173struct ssh2_cipher {
371e569c 174 void *(*make_context)(void);
175 void (*free_context)(void *);
2e85c969 176 void (*setiv) (void *, unsigned char *key); /* for SSH-2 */
177 void (*setkey) (void *, unsigned char *key);/* for SSH-2 */
371e569c 178 void (*encrypt) (void *, unsigned char *blk, int len);
179 void (*decrypt) (void *, unsigned char *blk, int len);
e5574168 180 char *name;
181 int blksize;
d2a0e0be 182 int keylen;
97ab28d7 183 unsigned int flags;
184#define SSH_CIPHER_IS_CBC 1
371e569c 185 char *text_name;
e5574168 186};
187
0a3f1d48 188struct ssh2_ciphers {
189 int nciphers;
65a22376 190 const struct ssh2_cipher *const *list;
0a3f1d48 191};
192
e5574168 193struct ssh_mac {
e0e1a00d 194 void *(*make_context)(void);
195 void (*free_context)(void *);
196 void (*setkey) (void *, unsigned char *key);
9916cc1e 197 /* whole-packet operations */
e0e1a00d 198 void (*generate) (void *, unsigned char *blk, int len, unsigned long seq);
199 int (*verify) (void *, unsigned char *blk, int len, unsigned long seq);
9916cc1e 200 /* partial-packet operations */
201 void (*start) (void *);
202 void (*bytes) (void *, unsigned char const *, int);
203 void (*genresult) (void *, unsigned char *);
204 int (*verresult) (void *, unsigned char const *);
e5574168 205 char *name;
206 int len;
6c135243 207 char *text_name;
e5574168 208};
209
b672f405 210struct ssh_hash {
211 void *(*init)(void); /* also allocates context */
212 void (*bytes)(void *, void *, int);
213 void (*final)(void *, unsigned char *); /* also frees context */
214 int hlen; /* output length in bytes */
c6daaa1a 215 char *text_name;
b672f405 216};
217
e5574168 218struct ssh_kex {
d1aaf71d 219 char *name, *groupname;
fae1a71b 220 enum { KEXTYPE_DH, KEXTYPE_RSA } main_type;
221 /* For DH */
222 const unsigned char *pdata, *gdata; /* NULL means group exchange */
d1aaf71d 223 int plen, glen;
b672f405 224 const struct ssh_hash *hash;
e5574168 225};
226
34557659 227struct ssh_kexes {
228 int nkexes;
229 const struct ssh_kex *const *list;
230};
231
e055a386 232struct ssh_signkey {
32874aea 233 void *(*newkey) (char *data, int len);
234 void (*freekey) (void *key);
235 char *(*fmtkey) (void *key);
236 unsigned char *(*public_blob) (void *key, int *len);
237 unsigned char *(*private_blob) (void *key, int *len);
238 void *(*createkey) (unsigned char *pub_blob, int pub_len,
239 unsigned char *priv_blob, int priv_len);
240 void *(*openssh_createkey) (unsigned char **blob, int *len);
241 int (*openssh_fmtkey) (void *key, unsigned char *blob, int len);
47a6b94c 242 int (*pubkey_bits) (void *blob, int len);
32874aea 243 char *(*fingerprint) (void *key);
244 int (*verifysig) (void *key, char *sig, int siglen,
245 char *data, int datalen);
246 unsigned char *(*sign) (void *key, char *data, int datalen,
247 int *siglen);
e5574168 248 char *name;
32874aea 249 char *keytype; /* for host key cache */
e5574168 250};
251
252struct ssh_compress {
253 char *name;
5366aed8 254 void *(*compress_init) (void);
255 void (*compress_cleanup) (void *);
256 int (*compress) (void *, unsigned char *block, int len,
32874aea 257 unsigned char **outblock, int *outlen);
5366aed8 258 void *(*decompress_init) (void);
259 void (*decompress_cleanup) (void *);
260 int (*decompress) (void *, unsigned char *block, int len,
32874aea 261 unsigned char **outblock, int *outlen);
5366aed8 262 int (*disable_compression) (void *);
263 char *text_name;
374330e2 264};
265
65a22376 266struct ssh2_userkey {
267 const struct ssh_signkey *alg; /* the key algorithm */
268 void *data; /* the key data */
269 char *comment; /* the key comment */
270};
271
754c0df9 272/* The maximum length of any hash algorithm used in kex. (bytes) */
273#define SSH2_KEX_MAX_HASH_LEN (32) /* SHA-256 */
274
65a22376 275extern const struct ssh_cipher ssh_3des;
276extern const struct ssh_cipher ssh_des;
277extern const struct ssh_cipher ssh_blowfish_ssh1;
278extern const struct ssh2_ciphers ssh2_3des;
0d7c43a6 279extern const struct ssh2_ciphers ssh2_des;
65a22376 280extern const struct ssh2_ciphers ssh2_aes;
281extern const struct ssh2_ciphers ssh2_blowfish;
a2add208 282extern const struct ssh2_ciphers ssh2_arcfour;
b672f405 283extern const struct ssh_hash ssh_sha1;
062e5811 284extern const struct ssh_hash ssh_sha256;
34557659 285extern const struct ssh_kexes ssh_diffiehellman_group1;
286extern const struct ssh_kexes ssh_diffiehellman_group14;
287extern const struct ssh_kexes ssh_diffiehellman_gex;
fae1a71b 288extern const struct ssh_kexes ssh_rsa_kex;
65a22376 289extern const struct ssh_signkey ssh_dss;
290extern const struct ssh_signkey ssh_rsa;
1993f323 291extern const struct ssh_mac ssh_hmac_md5;
292extern const struct ssh_mac ssh_hmac_sha1;
293extern const struct ssh_mac ssh_hmac_sha1_buggy;
6668a75e 294extern const struct ssh_mac ssh_hmac_sha1_96;
295extern const struct ssh_mac ssh_hmac_sha1_96_buggy;
1993f323 296
06e09f43 297void *aes_make_context(void);
298void aes_free_context(void *handle);
299void aes128_key(void *handle, unsigned char *key);
300void aes192_key(void *handle, unsigned char *key);
301void aes256_key(void *handle, unsigned char *key);
302void aes_iv(void *handle, unsigned char *iv);
303void aes_ssh2_encrypt_blk(void *handle, unsigned char *blk, int len);
304void aes_ssh2_decrypt_blk(void *handle, unsigned char *blk, int len);
65a22376 305
900a4ee6 306/*
307 * PuTTY version number formatted as an SSH version string.
308 */
309extern char sshver[];
310
fd5e5847 311/*
312 * Gross hack: pscp will try to start SFTP but fall back to scp1 if
313 * that fails. This variable is the means by which scp.c can reach
314 * into the SSH code and find out which one it got.
315 */
51470298 316extern int ssh_fallback_cmd(void *handle);
fd5e5847 317
8f203108 318#ifndef MSCRYPTOAPI
32874aea 319void SHATransform(word32 * digest, word32 * data);
8f203108 320#endif
374330e2 321
322int random_byte(void);
323void random_add_noise(void *noise, int length);
6e522441 324void random_add_heavynoise(void *noise, int length);
c5e9c988 325
cbe2d68f 326void logevent(void *, const char *);
51470298 327
328/* Allocate and register a new channel for port forwarding */
329void *new_sock_channel(void *handle, Socket s);
6b78788a 330void ssh_send_port_open(void *channel, char *hostname, int port, char *org);
e5574168 331
322d09a8 332/* Exports from portfwd.c */
cbe2d68f 333extern const char *pfd_newconnect(Socket * s, char *hostname, int port,
05581745 334 void *c, const Config *cfg,
335 int addressfamily);
820ebe3b 336/* desthost == NULL indicates dynamic (SOCKS) port forwarding */
cbe2d68f 337extern const char *pfd_addforward(char *desthost, int destport, char *srcaddr,
338 int port, void *backhandle,
05581745 339 const Config *cfg, void **sockdata,
340 int address_family);
322d09a8 341extern void pfd_close(Socket s);
fda2feb1 342extern void pfd_terminate(void *sockdata);
322d09a8 343extern int pfd_send(Socket s, char *data, int len);
344extern void pfd_confirm(Socket s);
345extern void pfd_unthrottle(Socket s);
346extern void pfd_override_throttle(Socket s, int enable);
347
348/* Exports from x11fwd.c */
8def70c3 349enum {
350 X11_TRANS_IPV4 = 0, X11_TRANS_IPV6 = 6, X11_TRANS_UNIX = 256
351};
352struct X11Display {
353 /* Broken-down components of the display name itself */
354 int unixdomain;
355 char *hostname;
356 int displaynum;
357 int screennum;
358 /* OSX sometimes replaces all the above with a full Unix-socket pathname */
359 char *unixsocketpath;
360
361 /* PuTTY networking SockAddr to connect to the display, and associated
362 * gubbins */
363 SockAddr addr;
364 int port;
365 char *realhost;
366
367 /* Auth details we invented for the virtual display on the SSH server. */
368 int remoteauthproto;
369 unsigned char *remoteauthdata;
370 int remoteauthdatalen;
371 char *remoteauthprotoname;
372 char *remoteauthdatastring;
373
374 /* Our local auth details for talking to the real X display. */
375 int localauthproto;
376 unsigned char *localauthdata;
377 int localauthdatalen;
378
379 /*
380 * Used inside x11fwd.c to remember recently seen
381 * XDM-AUTHORIZATION-1 strings, to avoid replay attacks.
382 */
383 tree234 *xdmseen;
384};
385/*
386 * x11_setup_display() parses the display variable and fills in an
387 * X11Display structure. Some remote auth details are invented;
388 * the supplied authtype parameter configures the preferred
389 * authorisation protocol to use at the remote end. The local auth
390 * details are looked up by calling platform_get_x11_auth.
391 */
392extern struct X11Display *x11_setup_display(char *display, int authtype,
393 const Config *);
394void x11_free_display(struct X11Display *disp);
395extern const char *x11_init(Socket *, struct X11Display *, void *,
396 const char *, int, const Config *);
322d09a8 397extern void x11_close(Socket);
398extern int x11_send(Socket, char *, int);
322d09a8 399extern void x11_unthrottle(Socket s);
400extern void x11_override_throttle(Socket s, int enable);
fc0f17db 401char *x11_display(const char *display);
fc0f17db 402/* Platform-dependent X11 functions */
8def70c3 403extern void platform_get_x11_auth(struct X11Display *display,
404 const Config *);
405 /* examine a mostly-filled-in X11Display and fill in localauth* */
406extern const int platform_uses_x11_unix_by_default;
407 /* choose default X transport in the absence of a specified one */
408SockAddr platform_get_x11_unix_address(const char *path, int displaynum);
409 /* make up a SockAddr naming the address for displaynum */
46ed7b64 410char *platform_get_x_display(void);
8def70c3 411 /* allocated local X display string, if any */
412/* Callbacks in x11.c usable _by_ platform X11 functions */
413/*
414 * This function does the job of platform_get_x11_auth, provided
415 * it is told where to find a normally formatted .Xauthority file:
416 * it opens that file, parses it to find an auth record which
417 * matches the display details in "display", and fills in the
418 * localauth fields.
419 *
420 * It is expected that most implementations of
421 * platform_get_x11_auth() will work by finding their system's
422 * .Xauthority file, adjusting the display details if necessary
423 * for local oddities like Unix-domain socket transport, and
424 * calling this function to do the rest of the work.
425 */
426void x11_get_auth_from_authfile(struct X11Display *display,
427 const char *authfilename);
9bee6826 428
7cca0d81 429Bignum copybn(Bignum b);
3709bfe9 430Bignum bn_power_2(int n);
431void bn_restore_invariant(Bignum b);
5c72ca61 432Bignum bignum_from_long(unsigned long n);
e5574168 433void freebn(Bignum b);
59600f67 434Bignum modpow(Bignum base, Bignum exp, Bignum mod);
435Bignum modmul(Bignum a, Bignum b, Bignum mod);
7cca0d81 436void decbn(Bignum n);
437extern Bignum Zero, One;
27cd7fc2 438Bignum bignum_from_bytes(const unsigned char *data, int nbytes);
0016d70b 439int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result);
ddecd643 440int bignum_bitcount(Bignum bn);
5c58ad2d 441int ssh1_bignum_length(Bignum bn);
260f3dec 442int ssh2_bignum_length(Bignum bn);
5c58ad2d 443int bignum_byte(Bignum bn, int i);
9400cf6f 444int bignum_bit(Bignum bn, int i);
445void bignum_set_bit(Bignum bn, int i, int value);
5c58ad2d 446int ssh1_write_bignum(void *data, Bignum bn);
9400cf6f 447Bignum biggcd(Bignum a, Bignum b);
448unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
449Bignum bignum_add_long(Bignum number, unsigned long addend);
450Bignum bigmul(Bignum a, Bignum b);
5c72ca61 451Bignum bigmuladd(Bignum a, Bignum b, Bignum addend);
452Bignum bigdiv(Bignum a, Bignum b);
453Bignum bigmod(Bignum a, Bignum b);
9400cf6f 454Bignum modinv(Bignum number, Bignum modulus);
3709bfe9 455Bignum bignum_bitmask(Bignum number);
9400cf6f 456Bignum bignum_rshift(Bignum number, int shift);
8c3cd914 457int bignum_cmp(Bignum a, Bignum b);
6e522441 458char *bignum_decimal(Bignum x);
e5574168 459
a3412f52 460#ifdef DEBUG
461void diagbn(char *prefix, Bignum md);
462#endif
463
d1aaf71d 464void *dh_setup_group(const struct ssh_kex *kex);
465void *dh_setup_gex(Bignum pval, Bignum gval);
27cd7fc2 466void dh_cleanup(void *);
467Bignum dh_create_e(void *, int nbits);
468Bignum dh_find_K(void *, Bignum f);
7cca0d81 469
9a30e26b 470int loadrsakey(const Filename *filename, struct RSAKey *key,
222d54dc 471 char *passphrase, const char **errorstr);
9a30e26b 472int rsakey_encrypted(const Filename *filename, char **comment);
222d54dc 473int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen,
4bcf919e 474 char **commentptr, const char **errorstr);
7cca0d81 475
9a30e26b 476int saversakey(const Filename *filename, struct RSAKey *key, char *passphrase);
65a22376 477
df3c4460 478extern int base64_decode_atom(char *atom, unsigned char *out);
479extern int base64_lines(int datalen);
480extern void base64_encode_atom(unsigned char *data, int n, char *out);
481extern void base64_encode(FILE *fp, unsigned char *data, int datalen, int cpl);
65a22376 482
483/* ssh2_load_userkey can return this as an error */
484extern struct ssh2_userkey ssh2_wrong_passphrase;
485#define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
486
9a30e26b 487int ssh2_userkey_encrypted(const Filename *filename, char **comment);
488struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
222d54dc 489 char *passphrase, const char **errorstr);
8a9977e5 490unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
491 int *pub_blob_len, char **commentptr,
492 const char **errorstr);
9a30e26b 493int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
32874aea 494 char *passphrase);
47a6b94c 495const struct ssh_signkey *find_pubkey_alg(const char *name);
65a22376 496
231ee168 497enum {
498 SSH_KEYTYPE_UNOPENABLE,
499 SSH_KEYTYPE_UNKNOWN,
500 SSH_KEYTYPE_SSH1, SSH_KEYTYPE_SSH2,
501 SSH_KEYTYPE_OPENSSH, SSH_KEYTYPE_SSHCOM
502};
9a30e26b 503int key_type(const Filename *filename);
231ee168 504char *key_type_to_str(int type);
6e522441 505
9dda6459 506int import_possible(int type);
507int import_target_type(int type);
9a30e26b 508int import_encrypted(const Filename *filename, int type, char **comment);
509int import_ssh1(const Filename *filename, int type,
1e87cce5 510 struct RSAKey *key, char *passphrase, const char **errmsg_p);
9a30e26b 511struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
1e87cce5 512 char *passphrase, const char **errmsg_p);
9a30e26b 513int export_ssh1(const Filename *filename, int type,
514 struct RSAKey *key, char *passphrase);
515int export_ssh2(const Filename *filename, int type,
4801c01c 516 struct ssh2_userkey *key, char *passphrase);
9dda6459 517
65a22376 518void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
519void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
9dda6459 520void des3_decrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
521 unsigned char *blk, int len);
522void des3_encrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
523 unsigned char *blk, int len);
32874aea 524void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk,
525 int len);
526void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk,
527 int len);
9400cf6f 528
2f92b717 529void des_encrypt_xdmauth(unsigned char *key, unsigned char *blk, int len);
b3ebaa28 530void des_decrypt_xdmauth(unsigned char *key, unsigned char *blk, int len);
2f92b717 531
9400cf6f 532/*
533 * For progress updates in the key generation utility.
534 */
7c7f6893 535#define PROGFN_INITIALISE 1
536#define PROGFN_LIN_PHASE 2
537#define PROGFN_EXP_PHASE 3
538#define PROGFN_PHASE_EXTENT 4
539#define PROGFN_READY 5
540#define PROGFN_PROGRESS 6
5c72ca61 541typedef void (*progfn_t) (void *param, int action, int phase, int progress);
9400cf6f 542
32874aea 543int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn,
544 void *pfnparam);
5c72ca61 545int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
546 void *pfnparam);
547Bignum primegen(int bits, int modulus, int residue, Bignum factor,
548 int phase, progfn_t pfn, void *pfnparam);
4ba9b64b 549
d74d141c 550
4ba9b64b 551/*
552 * zlib compression.
553 */
5366aed8 554void *zlib_compress_init(void);
555void zlib_compress_cleanup(void *);
556void *zlib_decompress_init(void);
557void zlib_decompress_cleanup(void *);
558int zlib_compress_block(void *, unsigned char *block, int len,
4ba9b64b 559 unsigned char **outblock, int *outlen);
5366aed8 560int zlib_decompress_block(void *, unsigned char *block, int len,
4ba9b64b 561 unsigned char **outblock, int *outlen);
1983e559 562
563/*
2e85c969 564 * SSH-1 agent messages.
1983e559 565 */
566#define SSH1_AGENTC_REQUEST_RSA_IDENTITIES 1
567#define SSH1_AGENT_RSA_IDENTITIES_ANSWER 2
568#define SSH1_AGENTC_RSA_CHALLENGE 3
569#define SSH1_AGENT_RSA_RESPONSE 4
570#define SSH1_AGENTC_ADD_RSA_IDENTITY 7
571#define SSH1_AGENTC_REMOVE_RSA_IDENTITY 8
32874aea 572#define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
1983e559 573
574/*
2e85c969 575 * Messages common to SSH-1 and OpenSSH's SSH-2.
1983e559 576 */
577#define SSH_AGENT_FAILURE 5
578#define SSH_AGENT_SUCCESS 6
579
580/*
2e85c969 581 * OpenSSH's SSH-2 agent messages.
1983e559 582 */
583#define SSH2_AGENTC_REQUEST_IDENTITIES 11
584#define SSH2_AGENT_IDENTITIES_ANSWER 12
585#define SSH2_AGENTC_SIGN_REQUEST 13
586#define SSH2_AGENT_SIGN_RESPONSE 14
587#define SSH2_AGENTC_ADD_IDENTITY 17
588#define SSH2_AGENTC_REMOVE_IDENTITY 18
589#define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
7bedb13c 590
591/*
2e85c969 592 * Need this to warn about support for the original SSH-2 keyfile
7bedb13c 593 * format.
594 */
595void old_keyfile_warning(void);