ssh.h 21 KB

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