Mercurial > dropbear
comparison mycrypt_cipher.h @ 0:d7da3b1e1540 libtomcrypt
put back the 0.95 makefile which was inadvertently merged over
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:21:40 +0000 |
parents | |
children | 6362d3854bb4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7da3b1e1540 |
---|---|
1 /* ---- SYMMETRIC KEY STUFF ----- | |
2 * | |
3 * We put each of the ciphers scheduled keys in their own structs then we put all of | |
4 * the key formats in one union. This makes the function prototypes easier to use. | |
5 */ | |
6 #ifdef BLOWFISH | |
7 struct blowfish_key { | |
8 ulong32 S[4][256]; | |
9 ulong32 K[18]; | |
10 }; | |
11 #endif | |
12 | |
13 #ifdef RC5 | |
14 struct rc5_key { | |
15 int rounds; | |
16 ulong32 K[50]; | |
17 }; | |
18 #endif | |
19 | |
20 #ifdef RC6 | |
21 struct rc6_key { | |
22 ulong32 K[44]; | |
23 }; | |
24 #endif | |
25 | |
26 #ifdef SAFERP | |
27 struct saferp_key { | |
28 unsigned char K[33][16]; | |
29 long rounds; | |
30 }; | |
31 #endif | |
32 | |
33 #ifdef RIJNDAEL | |
34 struct rijndael_key { | |
35 ulong32 eK[64], dK[64]; | |
36 int Nr; | |
37 }; | |
38 #endif | |
39 | |
40 #ifdef XTEA | |
41 struct xtea_key { | |
42 unsigned long A[32], B[32]; | |
43 }; | |
44 #endif | |
45 | |
46 #ifdef TWOFISH | |
47 #ifndef TWOFISH_SMALL | |
48 struct twofish_key { | |
49 ulong32 S[4][256], K[40]; | |
50 }; | |
51 #else | |
52 struct twofish_key { | |
53 ulong32 K[40]; | |
54 unsigned char S[32], start; | |
55 }; | |
56 #endif | |
57 #endif | |
58 | |
59 #ifdef SAFER | |
60 #define SAFER_K64_DEFAULT_NOF_ROUNDS 6 | |
61 #define SAFER_K128_DEFAULT_NOF_ROUNDS 10 | |
62 #define SAFER_SK64_DEFAULT_NOF_ROUNDS 8 | |
63 #define SAFER_SK128_DEFAULT_NOF_ROUNDS 10 | |
64 #define SAFER_MAX_NOF_ROUNDS 13 | |
65 #define SAFER_BLOCK_LEN 8 | |
66 #define SAFER_KEY_LEN (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS)) | |
67 typedef unsigned char safer_block_t[SAFER_BLOCK_LEN]; | |
68 typedef unsigned char safer_key_t[SAFER_KEY_LEN]; | |
69 struct safer_key { safer_key_t key; }; | |
70 #endif | |
71 | |
72 #ifdef RC2 | |
73 struct rc2_key { unsigned xkey[64]; }; | |
74 #endif | |
75 | |
76 #ifdef DES | |
77 struct des_key { | |
78 ulong32 ek[32], dk[32]; | |
79 }; | |
80 | |
81 struct des3_key { | |
82 ulong32 ek[3][32], dk[3][32]; | |
83 }; | |
84 #endif | |
85 | |
86 #ifdef CAST5 | |
87 struct cast5_key { | |
88 ulong32 K[32], keylen; | |
89 }; | |
90 #endif | |
91 | |
92 #ifdef NOEKEON | |
93 struct noekeon_key { | |
94 ulong32 K[4], dK[4]; | |
95 }; | |
96 #endif | |
97 | |
98 #ifdef SKIPJACK | |
99 struct skipjack_key { | |
100 unsigned char key[10]; | |
101 }; | |
102 #endif | |
103 | |
104 typedef union Symmetric_key { | |
105 #ifdef DES | |
106 struct des_key des; | |
107 struct des3_key des3; | |
108 #endif | |
109 #ifdef RC2 | |
110 struct rc2_key rc2; | |
111 #endif | |
112 #ifdef SAFER | |
113 struct safer_key safer; | |
114 #endif | |
115 #ifdef TWOFISH | |
116 struct twofish_key twofish; | |
117 #endif | |
118 #ifdef BLOWFISH | |
119 struct blowfish_key blowfish; | |
120 #endif | |
121 #ifdef RC5 | |
122 struct rc5_key rc5; | |
123 #endif | |
124 #ifdef RC6 | |
125 struct rc6_key rc6; | |
126 #endif | |
127 #ifdef SAFERP | |
128 struct saferp_key saferp; | |
129 #endif | |
130 #ifdef RIJNDAEL | |
131 struct rijndael_key rijndael; | |
132 #endif | |
133 #ifdef XTEA | |
134 struct xtea_key xtea; | |
135 #endif | |
136 #ifdef CAST5 | |
137 struct cast5_key cast5; | |
138 #endif | |
139 #ifdef NOEKEON | |
140 struct noekeon_key noekeon; | |
141 #endif | |
142 #ifdef SKIPJACK | |
143 struct skipjack_key skipjack; | |
144 #endif | |
145 } symmetric_key; | |
146 | |
147 /* A block cipher ECB structure */ | |
148 typedef struct { | |
149 int cipher, blocklen; | |
150 symmetric_key key; | |
151 } symmetric_ECB; | |
152 | |
153 /* A block cipher CFB structure */ | |
154 typedef struct { | |
155 int cipher, blocklen, padlen; | |
156 unsigned char IV[MAXBLOCKSIZE], pad[MAXBLOCKSIZE]; | |
157 symmetric_key key; | |
158 } symmetric_CFB; | |
159 | |
160 /* A block cipher OFB structure */ | |
161 typedef struct { | |
162 int cipher, blocklen, padlen; | |
163 unsigned char IV[MAXBLOCKSIZE]; | |
164 symmetric_key key; | |
165 } symmetric_OFB; | |
166 | |
167 /* A block cipher CBC structure */ | |
168 typedef struct Symmetric_CBC { | |
169 int cipher, blocklen; | |
170 unsigned char IV[MAXBLOCKSIZE]; | |
171 symmetric_key key; | |
172 } symmetric_CBC; | |
173 | |
174 /* A block cipher CTR structure */ | |
175 typedef struct Symmetric_CTR { | |
176 int cipher, blocklen, padlen, mode; | |
177 unsigned char ctr[MAXBLOCKSIZE], pad[MAXBLOCKSIZE]; | |
178 symmetric_key key; | |
179 } symmetric_CTR; | |
180 | |
181 /* cipher descriptor table, last entry has "name == NULL" to mark the end of table */ | |
182 extern struct _cipher_descriptor { | |
183 char *name; | |
184 unsigned char ID; | |
185 int min_key_length, max_key_length, block_length, default_rounds; | |
186 int (*setup)(const unsigned char *key, int keylength, int num_rounds, symmetric_key *skey); | |
187 void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
188 void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
189 int (*test)(void); | |
190 int (*keysize)(int *desired_keysize); | |
191 } cipher_descriptor[]; | |
192 | |
193 #ifdef BLOWFISH | |
194 extern int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
195 extern void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
196 extern void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
197 extern int blowfish_test(void); | |
198 extern int blowfish_keysize(int *desired_keysize); | |
199 extern const struct _cipher_descriptor blowfish_desc; | |
200 #endif | |
201 | |
202 #ifdef RC5 | |
203 extern int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
204 extern void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
205 extern void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
206 extern int rc5_test(void); | |
207 extern int rc5_keysize(int *desired_keysize); | |
208 extern const struct _cipher_descriptor rc5_desc; | |
209 #endif | |
210 | |
211 #ifdef RC6 | |
212 extern int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
213 extern void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
214 extern void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
215 extern int rc6_test(void); | |
216 extern int rc6_keysize(int *desired_keysize); | |
217 extern const struct _cipher_descriptor rc6_desc; | |
218 #endif | |
219 | |
220 #ifdef RC2 | |
221 extern int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
222 extern void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
223 extern void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
224 extern int rc2_test(void); | |
225 extern int rc2_keysize(int *desired_keysize); | |
226 extern const struct _cipher_descriptor rc2_desc; | |
227 #endif | |
228 | |
229 #ifdef SAFERP | |
230 extern int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
231 extern void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
232 extern void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
233 extern int saferp_test(void); | |
234 extern int saferp_keysize(int *desired_keysize); | |
235 extern const struct _cipher_descriptor saferp_desc; | |
236 #endif | |
237 | |
238 #ifdef SAFER | |
239 extern int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
240 extern int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
241 extern int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
242 extern int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
243 extern void safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
244 extern void safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
245 | |
246 extern int safer_k64_test(void); | |
247 extern int safer_sk64_test(void); | |
248 extern int safer_sk128_test(void); | |
249 | |
250 extern int safer_64_keysize(int *desired_keysize); | |
251 extern int safer_128_keysize(int *desired_keysize); | |
252 extern const struct _cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc; | |
253 #endif | |
254 | |
255 #ifdef RIJNDAEL | |
256 | |
257 /* make aes an alias */ | |
258 #define aes_setup rijndael_setup | |
259 #define aes_ecb_encrypt rijndael_ecb_encrypt | |
260 #define aes_ecb_decrypt rijndael_ecb_decrypt | |
261 #define aes_test rijndael_test | |
262 #define aes_keysize rijndael_keysize | |
263 | |
264 extern int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
265 extern void rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
266 extern void rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
267 extern int rijndael_test(void); | |
268 extern int rijndael_keysize(int *desired_keysize); | |
269 extern const struct _cipher_descriptor rijndael_desc, aes_desc; | |
270 #endif | |
271 | |
272 #ifdef XTEA | |
273 extern int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
274 extern void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
275 extern void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
276 extern int xtea_test(void); | |
277 extern int xtea_keysize(int *desired_keysize); | |
278 extern const struct _cipher_descriptor xtea_desc; | |
279 #endif | |
280 | |
281 #ifdef TWOFISH | |
282 extern int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
283 extern void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
284 extern void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
285 extern int twofish_test(void); | |
286 extern int twofish_keysize(int *desired_keysize); | |
287 extern const struct _cipher_descriptor twofish_desc; | |
288 #endif | |
289 | |
290 #ifdef DES | |
291 extern int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
292 extern void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
293 extern void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
294 extern int des_test(void); | |
295 extern int des_keysize(int *desired_keysize); | |
296 | |
297 extern int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
298 extern void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
299 extern void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
300 extern int des3_test(void); | |
301 extern int des3_keysize(int *desired_keysize); | |
302 | |
303 extern const struct _cipher_descriptor des_desc, des3_desc; | |
304 #endif | |
305 | |
306 #ifdef CAST5 | |
307 extern int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
308 extern void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
309 extern void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
310 extern int cast5_test(void); | |
311 extern int cast5_keysize(int *desired_keysize); | |
312 extern const struct _cipher_descriptor cast5_desc; | |
313 #endif | |
314 | |
315 #ifdef NOEKEON | |
316 extern int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
317 extern void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
318 extern void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
319 extern int noekeon_test(void); | |
320 extern int noekeon_keysize(int *desired_keysize); | |
321 extern const struct _cipher_descriptor noekeon_desc; | |
322 #endif | |
323 | |
324 #ifdef SKIPJACK | |
325 extern int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
326 extern void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key); | |
327 extern void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key); | |
328 extern int skipjack_test(void); | |
329 extern int skipjack_keysize(int *desired_keysize); | |
330 extern const struct _cipher_descriptor skipjack_desc; | |
331 #endif | |
332 | |
333 #ifdef ECB | |
334 extern int ecb_start(int cipher, const unsigned char *key, | |
335 int keylen, int num_rounds, symmetric_ECB *ecb); | |
336 extern int ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ECB *ecb); | |
337 extern int ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ECB *ecb); | |
338 #endif | |
339 | |
340 #ifdef CFB | |
341 extern int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, | |
342 int keylen, int num_rounds, symmetric_CFB *cfb); | |
343 extern int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb); | |
344 extern int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb); | |
345 #endif | |
346 | |
347 #ifdef OFB | |
348 extern int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, | |
349 int keylen, int num_rounds, symmetric_OFB *ofb); | |
350 extern int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb); | |
351 extern int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb); | |
352 #endif | |
353 | |
354 #ifdef CBC | |
355 extern int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key, | |
356 int keylen, int num_rounds, symmetric_CBC *cbc); | |
357 extern int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc); | |
358 extern int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc); | |
359 #endif | |
360 | |
361 #ifdef CTR | |
362 extern int ctr_start(int cipher, const unsigned char *IV, const unsigned char *key, | |
363 int keylen, int num_rounds, symmetric_CTR *ctr); | |
364 extern int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr); | |
365 extern int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr); | |
366 #endif | |
367 | |
368 | |
369 | |
370 extern int find_cipher(const char *name); | |
371 extern int find_cipher_any(const char *name, int blocklen, int keylen); | |
372 extern int find_cipher_id(unsigned char ID); | |
373 | |
374 extern int register_cipher(const struct _cipher_descriptor *cipher); | |
375 extern int unregister_cipher(const struct _cipher_descriptor *cipher); | |
376 | |
377 extern int cipher_is_valid(int idx); | |
378 |