SSH 2 support, phase 1, debugging. Currently does Diffie-Hellman and gets
[u/mdw/putty] / ssh.h
1 #include <string.h>
2
3 /*
4 * Useful thing.
5 */
6 #ifndef lenof
7 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
8 #endif
9
10 #define SSH_CIPHER_IDEA 1
11 #define SSH_CIPHER_DES 2
12 #define SSH_CIPHER_3DES 3
13 #define SSH_CIPHER_BLOWFISH 6
14
15 #ifdef MSCRYPTOAPI
16 #define APIEXTRA 8
17 #else
18 #define APIEXTRA 0
19 #endif
20
21 struct RSAKey {
22 int bits;
23 int bytes;
24 #ifdef MSCRYPTOAPI
25 unsigned long exponent;
26 unsigned char *modulus;
27 #else
28 void *modulus;
29 void *exponent;
30 #endif
31 };
32
33 int makekey(unsigned char *data, struct RSAKey *result,
34 unsigned char **keystr);
35 void rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
36 int rsastr_len(struct RSAKey *key);
37 void rsastr_fmt(char *str, struct RSAKey *key);
38
39 typedef unsigned int word32;
40 typedef unsigned int uint32;
41
42 unsigned long crc32(const void *s, size_t len);
43
44 typedef struct {
45 uint32 h[4];
46 } MD5_Core_State;
47
48 struct MD5Context {
49 #ifdef MSCRYPTOAPI
50 unsigned long hHash;
51 #else
52 MD5_Core_State core;
53 unsigned char block[64];
54 int blkused;
55 uint32 lenhi, lenlo;
56 #endif
57 };
58
59 void MD5Init(struct MD5Context *context);
60 void MD5Update(struct MD5Context *context, unsigned char const *buf,
61 unsigned len);
62 void MD5Final(unsigned char digest[16], struct MD5Context *context);
63
64 typedef struct {
65 uint32 h[5];
66 unsigned char block[64];
67 int blkused;
68 uint32 lenhi, lenlo;
69 } SHA_State;
70
71 void SHA_Init(SHA_State *s);
72 void SHA_Bytes(SHA_State *s, void *p, int len);
73 void SHA_Final(SHA_State *s, unsigned char *output);
74
75 struct ssh_cipher {
76 void (*sesskey)(unsigned char *key);
77 void (*encrypt)(unsigned char *blk, int len);
78 void (*decrypt)(unsigned char *blk, int len);
79 char *name;
80 int blksize;
81 };
82
83 struct ssh_mac {
84 void (*sesskey)(unsigned char *key, int len);
85 void (*generate)(unsigned char *blk, int len, unsigned long seq);
86 int (*verify)(unsigned char *blk, int len, unsigned long seq);
87 char *name;
88 int len;
89 };
90
91 struct ssh_kex {
92 char *name;
93 };
94
95 struct ssh_hostkey {
96 char *name;
97 };
98
99 struct ssh_compress {
100 char *name;
101 };
102
103 #ifndef MSCRYPTOAPI
104 void SHATransform(word32 *digest, word32 *data);
105 #endif
106
107 int random_byte(void);
108 void random_add_noise(void *noise, int length);
109
110 void logevent (char *);
111
112 /*
113 * A Bignum is stored as a sequence of `unsigned short' words. The
114 * first tells how many remain; the remaining ones are digits, LS
115 * first.
116 */
117 typedef unsigned short *Bignum;
118
119 Bignum newbn(int length);
120 void freebn(Bignum b);
121 void modpow(Bignum base, Bignum exp, Bignum mod, Bignum result);
122
123 Bignum dh_create_e(void);
124 Bignum dh_find_K(Bignum f);