Header file for 2-3-4 tree routines
[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
7cca0d81 21/*
22 * A Bignum is stored as a sequence of `unsigned short' words. The
23 * first tells how many remain; the remaining ones are digits, LS
24 * first.
25 */
26typedef unsigned short *Bignum;
27
374330e2 28struct RSAKey {
29 int bits;
30 int bytes;
8f203108 31#ifdef MSCRYPTOAPI
32 unsigned long exponent;
33 unsigned char *modulus;
34#else
7cca0d81 35 Bignum modulus;
36 Bignum exponent;
37 Bignum private_exponent;
8f203108 38#endif
374330e2 39};
40
41int makekey(unsigned char *data, struct RSAKey *result,
7cca0d81 42 unsigned char **keystr, int order);
43int makeprivate(unsigned char *data, struct RSAKey *result);
374330e2 44void rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
7cca0d81 45Bignum rsadecrypt(Bignum input, struct RSAKey *key);
46void rsasign(unsigned char *data, int length, struct RSAKey *key);
47void rsasanitise(struct RSAKey *key);
374330e2 48int rsastr_len(struct RSAKey *key);
49void rsastr_fmt(char *str, struct RSAKey *key);
50
51typedef unsigned int word32;
52typedef unsigned int uint32;
53
8160fbfc 54unsigned long crc32(const void *s, size_t len);
374330e2 55
48672163 56typedef struct {
57 uint32 h[4];
58} MD5_Core_State;
59
374330e2 60struct MD5Context {
8f203108 61#ifdef MSCRYPTOAPI
62 unsigned long hHash;
63#else
48672163 64 MD5_Core_State core;
bb093ca7 65 unsigned char block[64];
48672163 66 int blkused;
67 uint32 lenhi, lenlo;
8f203108 68#endif
374330e2 69};
70
71void MD5Init(struct MD5Context *context);
72void MD5Update(struct MD5Context *context, unsigned char const *buf,
73 unsigned len);
74void MD5Final(unsigned char digest[16], struct MD5Context *context);
75
e5574168 76typedef struct {
77 uint32 h[5];
78 unsigned char block[64];
79 int blkused;
80 uint32 lenhi, lenlo;
81} SHA_State;
82
83void SHA_Init(SHA_State *s);
84void SHA_Bytes(SHA_State *s, void *p, int len);
85void SHA_Final(SHA_State *s, unsigned char *output);
7cca0d81 86void SHA_Simple(void *p, int len, unsigned char *output);
e5574168 87
374330e2 88struct ssh_cipher {
d39f364a 89 void (*sesskey)(unsigned char *key); /* for ssh 1 */
90 void (*setcsiv)(unsigned char *key); /* for ssh 2 */
91 void (*setcskey)(unsigned char *key); /* for ssh 2 */
92 void (*setsciv)(unsigned char *key); /* for ssh 2 */
93 void (*setsckey)(unsigned char *key); /* for ssh 2 */
374330e2 94 void (*encrypt)(unsigned char *blk, int len);
95 void (*decrypt)(unsigned char *blk, int len);
e5574168 96 char *name;
97 int blksize;
98};
99
100struct ssh_mac {
d39f364a 101 void (*setcskey)(unsigned char *key);
102 void (*setsckey)(unsigned char *key);
e5574168 103 void (*generate)(unsigned char *blk, int len, unsigned long seq);
104 int (*verify)(unsigned char *blk, int len, unsigned long seq);
105 char *name;
106 int len;
107};
108
109struct ssh_kex {
7cca0d81 110 /*
111 * Plugging in another KEX algorithm requires structural chaos,
112 * so it's hard to abstract them into nice little structures
113 * like this. Hence, for the moment, this is just a
114 * placeholder. I claim justification in the fact that OpenSSH
115 * does this too :-)
116 */
e5574168 117 char *name;
118};
119
120struct ssh_hostkey {
7cca0d81 121 void (*setkey)(char *data, int len);
122 char *(*fmtkey)(void);
123 int (*verifysig)(char *sig, int siglen, char *data, int datalen);
e5574168 124 char *name;
125};
126
127struct ssh_compress {
128 char *name;
374330e2 129};
130
8f203108 131#ifndef MSCRYPTOAPI
374330e2 132void SHATransform(word32 *digest, word32 *data);
8f203108 133#endif
374330e2 134
135int random_byte(void);
136void random_add_noise(void *noise, int length);
c5e9c988 137
138void logevent (char *);
e5574168 139
e5574168 140Bignum newbn(int length);
7cca0d81 141Bignum copybn(Bignum b);
e5574168 142void freebn(Bignum b);
143void modpow(Bignum base, Bignum exp, Bignum mod, Bignum result);
7cca0d81 144void modmul(Bignum a, Bignum b, Bignum mod, Bignum result);
145void decbn(Bignum n);
146extern Bignum Zero, One;
147int ssh1_read_bignum(unsigned char *data, Bignum *result);
e5574168 148
149Bignum dh_create_e(void);
150Bignum dh_find_K(Bignum f);
7cca0d81 151
152int loadrsakey(char *filename, struct RSAKey *key, char *passphrase);
153int rsakey_encrypted(char *filename);
154
155void des3_decrypt_pubkey(unsigned char *key,
156 unsigned char *blk, int len);