11 extern void sshfwd_close(struct ssh_channel
*c
);
12 extern int sshfwd_write(struct ssh_channel
*c
, char *, int);
13 extern void sshfwd_unthrottle(struct ssh_channel
*c
, int bufsize
);
19 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
22 #define SSH_CIPHER_IDEA 1
23 #define SSH_CIPHER_DES 2
24 #define SSH_CIPHER_3DES 3
25 #define SSH_CIPHER_BLOWFISH 6
33 #ifndef BIGNUM_INTERNAL
41 unsigned long exponent
;
42 unsigned char *modulus
;
46 Bignum private_exponent
;
58 int makekey(unsigned char *data
, int len
, struct RSAKey
*result
,
59 unsigned char **keystr
, int order
);
60 int makeprivate(unsigned char *data
, int len
, struct RSAKey
*result
);
61 int rsaencrypt(unsigned char *data
, int length
, struct RSAKey
*key
);
62 Bignum
rsadecrypt(Bignum input
, struct RSAKey
*key
);
63 void rsasign(unsigned char *data
, int length
, struct RSAKey
*key
);
64 void rsasanitise(struct RSAKey
*key
);
65 int rsastr_len(struct RSAKey
*key
);
66 void rsastr_fmt(char *str
, struct RSAKey
*key
);
67 void rsa_fingerprint(char *str
, int len
, struct RSAKey
*key
);
68 int rsa_verify(struct RSAKey
*key
);
69 unsigned char *rsa_public_blob(struct RSAKey
*key
, int *len
);
70 int rsa_public_blob_len(void *data
, int maxlen
);
71 void freersakey(struct RSAKey
*key
);
73 typedef unsigned int word32
;
74 typedef unsigned int uint32
;
76 unsigned long crc32_compute(const void *s
, size_t len
);
77 unsigned long crc32_update(unsigned long crc_input
, const void *s
, size_t len
);
79 /* SSH CRC compensation attack detector */
80 void *crcda_make_context(void);
81 void crcda_free_context(void *handle
);
82 int detect_attack(void *handle
, unsigned char *buf
, uint32 len
,
86 * SSH2 RSA key exchange functions
89 void *ssh_rsakex_newkey(char *data
, int len
);
90 void ssh_rsakex_freekey(void *key
);
91 int ssh_rsakex_klen(void *key
);
92 void ssh_rsakex_encrypt(const struct ssh_hash
*h
, unsigned char *in
, int inlen
,
93 unsigned char *out
, int outlen
,
105 unsigned char block
[64];
111 void MD5Init(struct MD5Context
*context
);
112 void MD5Update(struct MD5Context
*context
, unsigned char const *buf
,
114 void MD5Final(unsigned char digest
[16], struct MD5Context
*context
);
115 void MD5Simple(void const *p
, unsigned len
, unsigned char output
[16]);
117 void *hmacmd5_make_context(void);
118 void hmacmd5_free_context(void *handle
);
119 void hmacmd5_key(void *handle
, void const *key
, int len
);
120 void hmacmd5_do_hmac(void *handle
, unsigned char const *blk
, int len
,
121 unsigned char *hmac
);
125 unsigned char block
[64];
129 void SHA_Init(SHA_State
* s
);
130 void SHA_Bytes(SHA_State
* s
, void *p
, int len
);
131 void SHA_Final(SHA_State
* s
, unsigned char *output
);
132 void SHA_Simple(void *p
, int len
, unsigned char *output
);
134 void hmac_sha1_simple(void *key
, int keylen
, void *data
, int datalen
,
135 unsigned char *output
);
138 unsigned char block
[64];
142 void SHA256_Init(SHA256_State
* s
);
143 void SHA256_Bytes(SHA256_State
* s
, const void *p
, int len
);
144 void SHA256_Final(SHA256_State
* s
, unsigned char *output
);
145 void SHA256_Simple(const void *p
, int len
, unsigned char *output
);
149 unsigned char block
[128];
153 void SHA512_Init(SHA512_State
* s
);
154 void SHA512_Bytes(SHA512_State
* s
, const void *p
, int len
);
155 void SHA512_Final(SHA512_State
* s
, unsigned char *output
);
156 void SHA512_Simple(const void *p
, int len
, unsigned char *output
);
159 void *(*make_context
)(void);
160 void (*free_context
)(void *);
161 void (*sesskey
) (void *, unsigned char *key
); /* for SSH-1 */
162 void (*encrypt
) (void *, unsigned char *blk
, int len
);
163 void (*decrypt
) (void *, unsigned char *blk
, int len
);
169 void *(*make_context
)(void);
170 void (*free_context
)(void *);
171 void (*setiv
) (void *, unsigned char *key
); /* for SSH-2 */
172 void (*setkey
) (void *, unsigned char *key
);/* for SSH-2 */
173 void (*encrypt
) (void *, unsigned char *blk
, int len
);
174 void (*decrypt
) (void *, unsigned char *blk
, int len
);
179 #define SSH_CIPHER_IS_CBC 1
183 struct ssh2_ciphers
{
185 const struct ssh2_cipher
*const *list
;
189 void *(*make_context
)(void);
190 void (*free_context
)(void *);
191 void (*setkey
) (void *, unsigned char *key
);
192 void (*generate
) (void *, unsigned char *blk
, int len
, unsigned long seq
);
193 int (*verify
) (void *, unsigned char *blk
, int len
, unsigned long seq
);
200 void *(*init
)(void); /* also allocates context */
201 void (*bytes
)(void *, void *, int);
202 void (*final
)(void *, unsigned char *); /* also frees context */
203 int hlen
; /* output length in bytes */
208 char *name
, *groupname
;
209 enum { KEXTYPE_DH
, KEXTYPE_RSA
} main_type
;
211 const unsigned char *pdata
, *gdata
; /* NULL means group exchange */
213 const struct ssh_hash
*hash
;
218 const struct ssh_kex
*const *list
;
222 void *(*newkey
) (char *data
, int len
);
223 void (*freekey
) (void *key
);
224 char *(*fmtkey
) (void *key
);
225 unsigned char *(*public_blob
) (void *key
, int *len
);
226 unsigned char *(*private_blob
) (void *key
, int *len
);
227 void *(*createkey
) (unsigned char *pub_blob
, int pub_len
,
228 unsigned char *priv_blob
, int priv_len
);
229 void *(*openssh_createkey
) (unsigned char **blob
, int *len
);
230 int (*openssh_fmtkey
) (void *key
, unsigned char *blob
, int len
);
231 int (*pubkey_bits
) (void *blob
, int len
);
232 char *(*fingerprint
) (void *key
);
233 int (*verifysig
) (void *key
, char *sig
, int siglen
,
234 char *data
, int datalen
);
235 unsigned char *(*sign
) (void *key
, char *data
, int datalen
,
238 char *keytype
; /* for host key cache */
241 struct ssh_compress
{
243 void *(*compress_init
) (void);
244 void (*compress_cleanup
) (void *);
245 int (*compress
) (void *, unsigned char *block
, int len
,
246 unsigned char **outblock
, int *outlen
);
247 void *(*decompress_init
) (void);
248 void (*decompress_cleanup
) (void *);
249 int (*decompress
) (void *, unsigned char *block
, int len
,
250 unsigned char **outblock
, int *outlen
);
251 int (*disable_compression
) (void *);
255 struct ssh2_userkey
{
256 const struct ssh_signkey
*alg
; /* the key algorithm */
257 void *data
; /* the key data */
258 char *comment
; /* the key comment */
261 /* The maximum length of any hash algorithm used in kex. (bytes) */
262 #define SSH2_KEX_MAX_HASH_LEN (32) /* SHA-256 */
264 extern const struct ssh_cipher ssh_3des
;
265 extern const struct ssh_cipher ssh_des
;
266 extern const struct ssh_cipher ssh_blowfish_ssh1
;
267 extern const struct ssh2_ciphers ssh2_3des
;
268 extern const struct ssh2_ciphers ssh2_des
;
269 extern const struct ssh2_ciphers ssh2_aes
;
270 extern const struct ssh2_ciphers ssh2_blowfish
;
271 extern const struct ssh2_ciphers ssh2_arcfour
;
272 extern const struct ssh_hash ssh_sha1
;
273 extern const struct ssh_hash ssh_sha256
;
274 extern const struct ssh_kexes ssh_diffiehellman_group1
;
275 extern const struct ssh_kexes ssh_diffiehellman_group14
;
276 extern const struct ssh_kexes ssh_diffiehellman_gex
;
277 extern const struct ssh_kexes ssh_rsa_kex
;
278 extern const struct ssh_signkey ssh_dss
;
279 extern const struct ssh_signkey ssh_rsa
;
280 extern const struct ssh_mac ssh_hmac_md5
;
281 extern const struct ssh_mac ssh_hmac_sha1
;
282 extern const struct ssh_mac ssh_hmac_sha1_buggy
;
283 extern const struct ssh_mac ssh_hmac_sha1_96
;
284 extern const struct ssh_mac ssh_hmac_sha1_96_buggy
;
288 * PuTTY version number formatted as an SSH version string.
290 extern char sshver
[];
293 * Gross hack: pscp will try to start SFTP but fall back to scp1 if
294 * that fails. This variable is the means by which scp.c can reach
295 * into the SSH code and find out which one it got.
297 extern int ssh_fallback_cmd(void *handle
);
300 void SHATransform(word32
* digest
, word32
* data
);
303 int random_byte(void);
304 void random_add_noise(void *noise
, int length
);
305 void random_add_heavynoise(void *noise
, int length
);
307 void logevent(void *, const char *);
309 /* Allocate and register a new channel for port forwarding */
310 void *new_sock_channel(void *handle
, Socket s
);
311 void ssh_send_port_open(void *channel
, char *hostname
, int port
, char *org
);
313 /* Exports from portfwd.c */
314 extern const char *pfd_newconnect(Socket
* s
, char *hostname
, int port
,
315 void *c
, const Config
*cfg
,
317 /* desthost == NULL indicates dynamic (SOCKS) port forwarding */
318 extern const char *pfd_addforward(char *desthost
, int destport
, char *srcaddr
,
319 int port
, void *backhandle
,
320 const Config
*cfg
, void **sockdata
,
322 extern void pfd_close(Socket s
);
323 extern void pfd_terminate(void *sockdata
);
324 extern int pfd_send(Socket s
, char *data
, int len
);
325 extern void pfd_confirm(Socket s
);
326 extern void pfd_unthrottle(Socket s
);
327 extern void pfd_override_throttle(Socket s
, int enable
);
329 /* Exports from x11fwd.c */
330 extern const char *x11_init(Socket
*, char *, void *, void *, const char *,
331 int, const Config
*);
332 extern void x11_close(Socket
);
333 extern int x11_send(Socket
, char *, int);
334 extern void *x11_invent_auth(char *, int, char *, int, int);
335 extern void x11_free_auth(void *);
336 extern void x11_unthrottle(Socket s
);
337 extern void x11_override_throttle(Socket s
, int enable
);
338 extern int x11_get_screen_number(char *display
);
339 void x11_get_real_auth(void *authv
, char *display
);
340 char *x11_display(const char *display
);
342 /* Platform-dependent X11 functions */
343 extern void platform_get_x11_auth(char *display
, int *proto
,
344 unsigned char *data
, int *datalen
);
345 extern const char platform_x11_best_transport
[];
346 /* best X11 hostname for this platform if none specified */
347 SockAddr
platform_get_x11_unix_address(int displaynum
, char **canonicalname
);
348 /* make up a SockAddr naming the address for displaynum */
349 char *platform_get_x_display(void);
350 /* allocated local X display string, if any */
352 Bignum
copybn(Bignum b
);
353 Bignum
bn_power_2(int n
);
354 void bn_restore_invariant(Bignum b
);
355 Bignum
bignum_from_long(unsigned long n
);
356 void freebn(Bignum b
);
357 Bignum
modpow(Bignum base
, Bignum exp
, Bignum mod
);
358 Bignum
modmul(Bignum a
, Bignum b
, Bignum mod
);
359 void decbn(Bignum n
);
360 extern Bignum Zero
, One
;
361 Bignum
bignum_from_bytes(const unsigned char *data
, int nbytes
);
362 int ssh1_read_bignum(const unsigned char *data
, int len
, Bignum
* result
);
363 int bignum_bitcount(Bignum bn
);
364 int ssh1_bignum_length(Bignum bn
);
365 int ssh2_bignum_length(Bignum bn
);
366 int bignum_byte(Bignum bn
, int i
);
367 int bignum_bit(Bignum bn
, int i
);
368 void bignum_set_bit(Bignum bn
, int i
, int value
);
369 int ssh1_write_bignum(void *data
, Bignum bn
);
370 Bignum
biggcd(Bignum a
, Bignum b
);
371 unsigned short bignum_mod_short(Bignum number
, unsigned short modulus
);
372 Bignum
bignum_add_long(Bignum number
, unsigned long addend
);
373 Bignum
bigmul(Bignum a
, Bignum b
);
374 Bignum
bigmuladd(Bignum a
, Bignum b
, Bignum addend
);
375 Bignum
bigdiv(Bignum a
, Bignum b
);
376 Bignum
bigmod(Bignum a
, Bignum b
);
377 Bignum
modinv(Bignum number
, Bignum modulus
);
378 Bignum
bignum_bitmask(Bignum number
);
379 Bignum
bignum_rshift(Bignum number
, int shift
);
380 int bignum_cmp(Bignum a
, Bignum b
);
381 char *bignum_decimal(Bignum x
);
384 void diagbn(char *prefix
, Bignum md
);
387 void *dh_setup_group(const struct ssh_kex
*kex
);
388 void *dh_setup_gex(Bignum pval
, Bignum gval
);
389 void dh_cleanup(void *);
390 Bignum
dh_create_e(void *, int nbits
);
391 Bignum
dh_find_K(void *, Bignum f
);
393 int loadrsakey(const Filename
*filename
, struct RSAKey
*key
,
394 char *passphrase
, const char **errorstr
);
395 int rsakey_encrypted(const Filename
*filename
, char **comment
);
396 int rsakey_pubblob(const Filename
*filename
, void **blob
, int *bloblen
,
397 char **commentptr
, const char **errorstr
);
399 int saversakey(const Filename
*filename
, struct RSAKey
*key
, char *passphrase
);
401 extern int base64_decode_atom(char *atom
, unsigned char *out
);
402 extern int base64_lines(int datalen
);
403 extern void base64_encode_atom(unsigned char *data
, int n
, char *out
);
404 extern void base64_encode(FILE *fp
, unsigned char *data
, int datalen
, int cpl
);
406 /* ssh2_load_userkey can return this as an error */
407 extern struct ssh2_userkey ssh2_wrong_passphrase
;
408 #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
410 int ssh2_userkey_encrypted(const Filename
*filename
, char **comment
);
411 struct ssh2_userkey
*ssh2_load_userkey(const Filename
*filename
,
412 char *passphrase
, const char **errorstr
);
413 unsigned char *ssh2_userkey_loadpub(const Filename
*filename
, char **algorithm
,
414 int *pub_blob_len
, char **commentptr
,
415 const char **errorstr
);
416 int ssh2_save_userkey(const Filename
*filename
, struct ssh2_userkey
*key
,
418 const struct ssh_signkey
*find_pubkey_alg(const char *name
);
421 SSH_KEYTYPE_UNOPENABLE
,
423 SSH_KEYTYPE_SSH1
, SSH_KEYTYPE_SSH2
,
424 SSH_KEYTYPE_OPENSSH
, SSH_KEYTYPE_SSHCOM
426 int key_type(const Filename
*filename
);
427 char *key_type_to_str(int type
);
429 int import_possible(int type
);
430 int import_target_type(int type
);
431 int import_encrypted(const Filename
*filename
, int type
, char **comment
);
432 int import_ssh1(const Filename
*filename
, int type
,
433 struct RSAKey
*key
, char *passphrase
, const char **errmsg_p
);
434 struct ssh2_userkey
*import_ssh2(const Filename
*filename
, int type
,
435 char *passphrase
, const char **errmsg_p
);
436 int export_ssh1(const Filename
*filename
, int type
,
437 struct RSAKey
*key
, char *passphrase
);
438 int export_ssh2(const Filename
*filename
, int type
,
439 struct ssh2_userkey
*key
, char *passphrase
);
441 void des3_decrypt_pubkey(unsigned char *key
, unsigned char *blk
, int len
);
442 void des3_encrypt_pubkey(unsigned char *key
, unsigned char *blk
, int len
);
443 void des3_decrypt_pubkey_ossh(unsigned char *key
, unsigned char *iv
,
444 unsigned char *blk
, int len
);
445 void des3_encrypt_pubkey_ossh(unsigned char *key
, unsigned char *iv
,
446 unsigned char *blk
, int len
);
447 void aes256_encrypt_pubkey(unsigned char *key
, unsigned char *blk
,
449 void aes256_decrypt_pubkey(unsigned char *key
, unsigned char *blk
,
452 void des_encrypt_xdmauth(unsigned char *key
, unsigned char *blk
, int len
);
453 void des_decrypt_xdmauth(unsigned char *key
, unsigned char *blk
, int len
);
456 * For progress updates in the key generation utility.
458 #define PROGFN_INITIALISE 1
459 #define PROGFN_LIN_PHASE 2
460 #define PROGFN_EXP_PHASE 3
461 #define PROGFN_PHASE_EXTENT 4
462 #define PROGFN_READY 5
463 #define PROGFN_PROGRESS 6
464 typedef void (*progfn_t
) (void *param
, int action
, int phase
, int progress
);
466 int rsa_generate(struct RSAKey
*key
, int bits
, progfn_t pfn
,
468 int dsa_generate(struct dss_key
*key
, int bits
, progfn_t pfn
,
470 Bignum
primegen(int bits
, int modulus
, int residue
, Bignum factor
,
471 int phase
, progfn_t pfn
, void *pfnparam
);
477 void *zlib_compress_init(void);
478 void zlib_compress_cleanup(void *);
479 void *zlib_decompress_init(void);
480 void zlib_decompress_cleanup(void *);
481 int zlib_compress_block(void *, unsigned char *block
, int len
,
482 unsigned char **outblock
, int *outlen
);
483 int zlib_decompress_block(void *, unsigned char *block
, int len
,
484 unsigned char **outblock
, int *outlen
);
487 * SSH-1 agent messages.
489 #define SSH1_AGENTC_REQUEST_RSA_IDENTITIES 1
490 #define SSH1_AGENT_RSA_IDENTITIES_ANSWER 2
491 #define SSH1_AGENTC_RSA_CHALLENGE 3
492 #define SSH1_AGENT_RSA_RESPONSE 4
493 #define SSH1_AGENTC_ADD_RSA_IDENTITY 7
494 #define SSH1_AGENTC_REMOVE_RSA_IDENTITY 8
495 #define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
498 * Messages common to SSH-1 and OpenSSH's SSH-2.
500 #define SSH_AGENT_FAILURE 5
501 #define SSH_AGENT_SUCCESS 6
504 * OpenSSH's SSH-2 agent messages.
506 #define SSH2_AGENTC_REQUEST_IDENTITIES 11
507 #define SSH2_AGENT_IDENTITIES_ANSWER 12
508 #define SSH2_AGENTC_SIGN_REQUEST 13
509 #define SSH2_AGENT_SIGN_RESPONSE 14
510 #define SSH2_AGENTC_ADD_IDENTITY 17
511 #define SSH2_AGENTC_REMOVE_IDENTITY 18
512 #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
515 * Need this to warn about support for the original SSH-2 keyfile
518 void old_keyfile_warning(void);