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