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