Mercurial > dropbear
annotate demos/tv_gen.c @ 192:9cc34777b479 libtomcrypt
propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 9ba8f01f44320e9cb9f19881105ae84f84a43ea9)
to branch 'au.asn.ucc.matt.dropbear.ltc' (head dbf51c569bc34956ad948e4cc87a0eeb2170b768)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 08 May 2005 06:36:47 +0000 |
parents | 1c15b283127b |
children | 39d5d58461d6 |
rev | line source |
---|---|
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
1 #include <tomcrypt.h> |
3 | 2 |
3 void reg_algs(void) | |
4 { | |
143 | 5 int err; |
6 | |
3 | 7 #ifdef RIJNDAEL |
8 register_cipher (&aes_desc); | |
9 #endif | |
10 #ifdef BLOWFISH | |
11 register_cipher (&blowfish_desc); | |
12 #endif | |
13 #ifdef XTEA | |
14 register_cipher (&xtea_desc); | |
15 #endif | |
16 #ifdef RC5 | |
17 register_cipher (&rc5_desc); | |
18 #endif | |
19 #ifdef RC6 | |
20 register_cipher (&rc6_desc); | |
21 #endif | |
22 #ifdef SAFERP | |
23 register_cipher (&saferp_desc); | |
24 #endif | |
25 #ifdef TWOFISH | |
26 register_cipher (&twofish_desc); | |
27 #endif | |
28 #ifdef SAFER | |
29 register_cipher (&safer_k64_desc); | |
30 register_cipher (&safer_sk64_desc); | |
31 register_cipher (&safer_k128_desc); | |
32 register_cipher (&safer_sk128_desc); | |
33 #endif | |
34 #ifdef RC2 | |
35 register_cipher (&rc2_desc); | |
36 #endif | |
37 #ifdef DES | |
38 register_cipher (&des_desc); | |
39 register_cipher (&des3_desc); | |
40 #endif | |
41 #ifdef CAST5 | |
42 register_cipher (&cast5_desc); | |
43 #endif | |
44 #ifdef NOEKEON | |
45 register_cipher (&noekeon_desc); | |
46 #endif | |
47 #ifdef SKIPJACK | |
48 register_cipher (&skipjack_desc); | |
49 #endif | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
50 #ifdef ANUBIS |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
51 register_cipher (&anubis_desc); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
52 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
53 #ifdef KHAZAD |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
54 register_cipher (&khazad_desc); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
55 #endif |
3 | 56 |
57 #ifdef TIGER | |
58 register_hash (&tiger_desc); | |
59 #endif | |
60 #ifdef MD2 | |
61 register_hash (&md2_desc); | |
62 #endif | |
63 #ifdef MD4 | |
64 register_hash (&md4_desc); | |
65 #endif | |
66 #ifdef MD5 | |
67 register_hash (&md5_desc); | |
68 #endif | |
69 #ifdef SHA1 | |
70 register_hash (&sha1_desc); | |
71 #endif | |
72 #ifdef SHA224 | |
73 register_hash (&sha224_desc); | |
74 #endif | |
75 #ifdef SHA256 | |
76 register_hash (&sha256_desc); | |
77 #endif | |
78 #ifdef SHA384 | |
79 register_hash (&sha384_desc); | |
80 #endif | |
81 #ifdef SHA512 | |
82 register_hash (&sha512_desc); | |
83 #endif | |
84 #ifdef RIPEMD128 | |
85 register_hash (&rmd128_desc); | |
86 #endif | |
87 #ifdef RIPEMD160 | |
88 register_hash (&rmd160_desc); | |
89 #endif | |
90 #ifdef WHIRLPOOL | |
91 register_hash (&whirlpool_desc); | |
92 #endif | |
143 | 93 #ifdef CHC_HASH |
94 register_hash(&chc_desc); | |
95 if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) { | |
96 printf("chc_register error: %s\n", error_to_string(err)); | |
97 exit(EXIT_FAILURE); | |
98 } | |
99 #endif | |
100 | |
3 | 101 } |
102 | |
103 void hash_gen(void) | |
104 { | |
143 | 105 unsigned char md[MAXBLOCKSIZE], *buf; |
3 | 106 unsigned long outlen, x, y, z; |
107 FILE *out; | |
143 | 108 int err; |
3 | 109 |
110 out = fopen("hash_tv.txt", "w"); | |
143 | 111 if (out == NULL) { |
112 perror("can't open hash_tv"); | |
113 } | |
3 | 114 |
115 fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n"); | |
116 for (x = 0; hash_descriptor[x].name != NULL; x++) { | |
143 | 117 buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1); |
118 if (buf == NULL) { | |
119 perror("can't alloc mem"); | |
120 exit(EXIT_FAILURE); | |
121 } | |
3 | 122 fprintf(out, "Hash: %s\n", hash_descriptor[x].name); |
123 for (y = 0; y <= (hash_descriptor[x].blocksize * 2); y++) { | |
124 for (z = 0; z < y; z++) { | |
125 buf[z] = (unsigned char)(z & 255); | |
126 } | |
127 outlen = sizeof(md); | |
143 | 128 if ((err = hash_memory(x, buf, y, md, &outlen)) != CRYPT_OK) { |
129 printf("hash_memory error: %s\n", error_to_string(err)); | |
130 exit(EXIT_FAILURE); | |
131 } | |
3 | 132 fprintf(out, "%3lu: ", y); |
133 for (z = 0; z < outlen; z++) { | |
134 fprintf(out, "%02X", md[z]); | |
135 } | |
136 fprintf(out, "\n"); | |
137 } | |
138 fprintf(out, "\n"); | |
143 | 139 XFREE(buf); |
3 | 140 } |
141 fclose(out); | |
142 } | |
143 | |
144 void cipher_gen(void) | |
145 { | |
143 | 146 unsigned char *key, pt[MAXBLOCKSIZE]; |
3 | 147 unsigned long x, y, z, w; |
143 | 148 int err, kl, lastkl; |
3 | 149 FILE *out; |
150 symmetric_key skey; | |
151 | |
152 out = fopen("cipher_tv.txt", "w"); | |
153 | |
154 fprintf(out, | |
155 "Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n" | |
156 "The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n"); | |
157 | |
158 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
159 fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name); | |
160 | |
161 /* three modes, smallest, medium, large keys */ | |
162 lastkl = 10000; | |
163 for (y = 0; y < 3; y++) { | |
164 switch (y) { | |
165 case 0: kl = cipher_descriptor[x].min_key_length; break; | |
166 case 1: kl = (cipher_descriptor[x].min_key_length + cipher_descriptor[x].max_key_length)/2; break; | |
167 case 2: kl = cipher_descriptor[x].max_key_length; break; | |
168 } | |
143 | 169 if ((err = cipher_descriptor[x].keysize(&kl)) != CRYPT_OK) { |
170 printf("keysize error: %s\n", error_to_string(err)); | |
171 exit(EXIT_FAILURE); | |
172 } | |
3 | 173 if (kl == lastkl) break; |
174 lastkl = kl; | |
175 fprintf(out, "Key Size: %d bytes\n", kl); | |
176 | |
143 | 177 key = XMALLOC(kl); |
178 if (key == NULL) { | |
179 perror("can't malloc memory"); | |
180 exit(EXIT_FAILURE); | |
181 } | |
182 | |
3 | 183 for (z = 0; (int)z < kl; z++) { |
184 key[z] = (unsigned char)z; | |
185 } | |
143 | 186 if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) { |
187 printf("setup error: %s\n", error_to_string(err)); | |
188 exit(EXIT_FAILURE); | |
189 } | |
3 | 190 |
191 for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) { | |
192 pt[z] = (unsigned char)z; | |
193 } | |
194 for (w = 0; w < 50; w++) { | |
195 cipher_descriptor[x].ecb_encrypt(pt, pt, &skey); | |
196 fprintf(out, "%2lu: ", w); | |
197 for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) { | |
198 fprintf(out, "%02X", pt[z]); | |
199 } | |
200 fprintf(out, "\n"); | |
201 | |
202 /* reschedule a new key */ | |
203 for (z = 0; z < (unsigned long)kl; z++) { | |
204 key[z] = pt[z % cipher_descriptor[x].block_length]; | |
205 } | |
143 | 206 if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) { |
207 printf("cipher setup2 error: %s\n", error_to_string(err)); | |
208 exit(EXIT_FAILURE); | |
209 } | |
3 | 210 } |
211 fprintf(out, "\n"); | |
143 | 212 XFREE(key); |
3 | 213 } |
214 fprintf(out, "\n"); | |
215 } | |
216 fclose(out); | |
217 } | |
218 | |
219 void hmac_gen(void) | |
220 { | |
143 | 221 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input; |
222 int x, y, z, err; | |
3 | 223 FILE *out; |
224 unsigned long len; | |
225 | |
226 out = fopen("hmac_tv.txt", "w"); | |
227 | |
228 fprintf(out, | |
229 "HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are HMACed. The initial key is\n" | |
230 "of the same format (the same length as the HASH output size). The HMAC key in step N+1 is the HMAC output of\n" | |
231 "step N.\n\n"); | |
232 | |
233 for (x = 0; hash_descriptor[x].name != NULL; x++) { | |
234 fprintf(out, "HMAC-%s\n", hash_descriptor[x].name); | |
235 | |
236 /* initial key */ | |
237 for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) { | |
238 key[y] = (y&255); | |
239 } | |
143 | 240 |
241 input = XMALLOC(hash_descriptor[x].blocksize * 2 + 1); | |
242 if (input == NULL) { | |
243 perror("Can't malloc memory"); | |
244 exit(EXIT_FAILURE); | |
245 } | |
3 | 246 |
247 for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) { | |
248 for (z = 0; z < y; z++) { | |
249 input[z] = (unsigned char)(z & 255); | |
250 } | |
251 len = sizeof(output); | |
252 if ((err = hmac_memory(x, key, hash_descriptor[x].hashsize, input, y, output, &len)) != CRYPT_OK) { | |
253 printf("Error hmacing: %s\n", error_to_string(err)); | |
254 exit(EXIT_FAILURE); | |
255 } | |
256 fprintf(out, "%3d: ", y); | |
257 for (z = 0; z <(int) len; z++) { | |
258 fprintf(out, "%02X", output[z]); | |
259 } | |
260 fprintf(out, "\n"); | |
261 | |
262 /* forward the key */ | |
263 memcpy(key, output, hash_descriptor[x].hashsize); | |
264 } | |
143 | 265 XFREE(input); |
3 | 266 fprintf(out, "\n"); |
267 } | |
268 fclose(out); | |
269 } | |
270 | |
271 void omac_gen(void) | |
272 { | |
273 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; | |
274 int err, x, y, z, kl; | |
275 FILE *out; | |
276 unsigned long len; | |
277 | |
278 out = fopen("omac_tv.txt", "w"); | |
279 | |
280 fprintf(out, | |
281 "OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n" | |
282 "of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n" | |
283 "step N (repeated as required to fill the array).\n\n"); | |
284 | |
285 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
286 kl = cipher_descriptor[x].block_length; | |
287 | |
288 /* skip ciphers which do not have 64 or 128 bit block sizes */ | |
289 if (kl != 8 && kl != 16) continue; | |
290 | |
291 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { | |
292 kl = cipher_descriptor[x].max_key_length; | |
293 } | |
294 fprintf(out, "OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl); | |
295 | |
296 /* initial key/block */ | |
297 for (y = 0; y < kl; y++) { | |
298 key[y] = (y & 255); | |
299 } | |
300 | |
301 for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) { | |
302 for (z = 0; z < y; z++) { | |
303 input[z] = (unsigned char)(z & 255); | |
304 } | |
305 len = sizeof(output); | |
306 if ((err = omac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) { | |
307 printf("Error omacing: %s\n", error_to_string(err)); | |
308 exit(EXIT_FAILURE); | |
309 } | |
310 fprintf(out, "%3d: ", y); | |
311 for (z = 0; z <(int)len; z++) { | |
312 fprintf(out, "%02X", output[z]); | |
313 } | |
314 fprintf(out, "\n"); | |
315 | |
316 /* forward the key */ | |
317 for (z = 0; z < kl; z++) { | |
318 key[z] = output[z % len]; | |
319 } | |
320 } | |
321 fprintf(out, "\n"); | |
322 } | |
323 fclose(out); | |
324 } | |
325 | |
326 void pmac_gen(void) | |
327 { | |
328 unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; | |
329 int err, x, y, z, kl; | |
330 FILE *out; | |
331 unsigned long len; | |
332 | |
333 out = fopen("pmac_tv.txt", "w"); | |
334 | |
335 fprintf(out, | |
336 "PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n" | |
337 "of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n" | |
338 "step N (repeated as required to fill the array).\n\n"); | |
339 | |
340 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
341 kl = cipher_descriptor[x].block_length; | |
342 | |
343 /* skip ciphers which do not have 64 or 128 bit block sizes */ | |
344 if (kl != 8 && kl != 16) continue; | |
345 | |
346 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { | |
347 kl = cipher_descriptor[x].max_key_length; | |
348 } | |
349 fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl); | |
350 | |
351 /* initial key/block */ | |
352 for (y = 0; y < kl; y++) { | |
353 key[y] = (y & 255); | |
354 } | |
355 | |
356 for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) { | |
357 for (z = 0; z < y; z++) { | |
358 input[z] = (unsigned char)(z & 255); | |
359 } | |
360 len = sizeof(output); | |
361 if ((err = pmac_memory(x, key, kl, input, y, output, &len)) != CRYPT_OK) { | |
362 printf("Error omacing: %s\n", error_to_string(err)); | |
363 exit(EXIT_FAILURE); | |
364 } | |
365 fprintf(out, "%3d: ", y); | |
366 for (z = 0; z <(int)len; z++) { | |
367 fprintf(out, "%02X", output[z]); | |
368 } | |
369 fprintf(out, "\n"); | |
370 | |
371 /* forward the key */ | |
372 for (z = 0; z < kl; z++) { | |
373 key[z] = output[z % len]; | |
374 } | |
375 } | |
376 fprintf(out, "\n"); | |
377 } | |
378 fclose(out); | |
379 } | |
380 | |
381 void eax_gen(void) | |
382 { | |
383 int err, kl, x, y1, z; | |
384 FILE *out; | |
385 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2], | |
386 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; | |
387 unsigned long len; | |
388 | |
389 out = fopen("eax_tv.txt", "w"); | |
390 fprintf(out, "EAX Test Vectors. Uses the 00010203...NN-1 pattern for header/nonce/plaintext/key. The outputs\n" | |
391 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n" | |
392 "step repeated sufficiently.\n\n"); | |
393 | |
394 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
395 kl = cipher_descriptor[x].block_length; | |
396 | |
397 /* skip ciphers which do not have 64 or 128 bit block sizes */ | |
398 if (kl != 8 && kl != 16) continue; | |
399 | |
400 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { | |
401 kl = cipher_descriptor[x].max_key_length; | |
402 } | |
403 fprintf(out, "EAX-%s (%d byte key)\n", cipher_descriptor[x].name, kl); | |
404 | |
405 /* the key */ | |
406 for (z = 0; z < kl; z++) { | |
407 key[z] = (z & 255); | |
408 } | |
409 | |
410 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ | |
411 for (z = 0; z < y1; z++) { | |
412 plaintext[z] = (unsigned char)(z & 255); | |
413 nonce[z] = (unsigned char)(z & 255); | |
414 header[z] = (unsigned char)(z & 255); | |
415 } | |
416 len = sizeof(tag); | |
417 if ((err = eax_encrypt_authenticate_memory(x, key, kl, nonce, y1, header, y1, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) { | |
418 printf("Error EAX'ing: %s\n", error_to_string(err)); | |
419 exit(EXIT_FAILURE); | |
420 } | |
421 fprintf(out, "%3d: ", y1); | |
422 for (z = 0; z < y1; z++) { | |
423 fprintf(out, "%02X", plaintext[z]); | |
424 } | |
425 fprintf(out, ", "); | |
426 for (z = 0; z <(int)len; z++) { | |
427 fprintf(out, "%02X", tag[z]); | |
428 } | |
429 fprintf(out, "\n"); | |
430 | |
431 /* forward the key */ | |
432 for (z = 0; z < kl; z++) { | |
433 key[z] = tag[z % len]; | |
434 } | |
435 } | |
436 fprintf(out, "\n"); | |
437 } | |
438 fclose(out); | |
439 } | |
440 | |
441 void ocb_gen(void) | |
442 { | |
443 int err, kl, x, y1, z; | |
444 FILE *out; | |
445 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], | |
446 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; | |
447 unsigned long len; | |
448 | |
449 out = fopen("ocb_tv.txt", "w"); | |
450 fprintf(out, "OCB Test Vectors. Uses the 00010203...NN-1 pattern for nonce/plaintext/key. The outputs\n" | |
451 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n" | |
452 "step repeated sufficiently. The nonce is fixed throughout.\n\n"); | |
453 | |
454 for (x = 0; cipher_descriptor[x].name != NULL; x++) { | |
455 kl = cipher_descriptor[x].block_length; | |
456 | |
457 /* skip ciphers which do not have 64 or 128 bit block sizes */ | |
458 if (kl != 8 && kl != 16) continue; | |
459 | |
460 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { | |
461 kl = cipher_descriptor[x].max_key_length; | |
462 } | |
463 fprintf(out, "OCB-%s (%d byte key)\n", cipher_descriptor[x].name, kl); | |
464 | |
465 /* the key */ | |
466 for (z = 0; z < kl; z++) { | |
467 key[z] = (z & 255); | |
468 } | |
469 | |
470 /* fixed nonce */ | |
471 for (z = 0; z < cipher_descriptor[x].block_length; z++) { | |
472 nonce[z] = z; | |
473 } | |
474 | |
475 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ | |
476 for (z = 0; z < y1; z++) { | |
477 plaintext[z] = (unsigned char)(z & 255); | |
478 } | |
479 len = sizeof(tag); | |
480 if ((err = ocb_encrypt_authenticate_memory(x, key, kl, nonce, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) { | |
481 printf("Error OCB'ing: %s\n", error_to_string(err)); | |
482 exit(EXIT_FAILURE); | |
483 } | |
484 fprintf(out, "%3d: ", y1); | |
485 for (z = 0; z < y1; z++) { | |
486 fprintf(out, "%02X", plaintext[z]); | |
487 } | |
488 fprintf(out, ", "); | |
489 for (z = 0; z <(int)len; z++) { | |
490 fprintf(out, "%02X", tag[z]); | |
491 } | |
492 fprintf(out, "\n"); | |
493 | |
494 /* forward the key */ | |
495 for (z = 0; z < kl; z++) { | |
496 key[z] = tag[z % len]; | |
497 } | |
498 } | |
499 fprintf(out, "\n"); | |
500 } | |
501 fclose(out); | |
502 } | |
503 | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
504 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
505 void ccm_gen(void) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
506 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
507 int err, kl, x, y1, z; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
508 FILE *out; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
509 unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
510 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
511 unsigned long len; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
512 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
513 out = fopen("ccm_tv.txt", "w"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
514 fprintf(out, "CCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n" |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
515 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n" |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
516 "step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
517 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
518 for (x = 0; cipher_descriptor[x].name != NULL; x++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
519 kl = cipher_descriptor[x].block_length; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
520 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
521 /* skip ciphers which do not have 128 bit block sizes */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
522 if (kl != 16) continue; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
523 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
524 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
525 kl = cipher_descriptor[x].max_key_length; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
526 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
527 fprintf(out, "CCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
528 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
529 /* the key */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
530 for (z = 0; z < kl; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
531 key[z] = (z & 255); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
532 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
533 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
534 /* fixed nonce */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
535 for (z = 0; z < cipher_descriptor[x].block_length; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
536 nonce[z] = z; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
537 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
538 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
539 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
540 for (z = 0; z < y1; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
541 plaintext[z] = (unsigned char)(z & 255); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
542 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
543 len = sizeof(tag); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
544 if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
545 printf("Error CCM'ing: %s\n", error_to_string(err)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
546 exit(EXIT_FAILURE); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
547 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
548 fprintf(out, "%3d: ", y1); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
549 for (z = 0; z < y1; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
550 fprintf(out, "%02X", plaintext[z]); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
551 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
552 fprintf(out, ", "); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
553 for (z = 0; z <(int)len; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
554 fprintf(out, "%02X", tag[z]); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
555 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
556 fprintf(out, "\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
557 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
558 /* forward the key */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
559 for (z = 0; z < kl; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
560 key[z] = tag[z % len]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
561 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
562 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
563 fprintf(out, "\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
564 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
565 fclose(out); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
566 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
567 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
568 void gcm_gen(void) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
569 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
570 int err, kl, x, y1, z; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
571 FILE *out; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
572 unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
573 unsigned long len; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
574 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
575 out = fopen("gcm_tv.txt", "w"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
576 fprintf(out, "GCM Test Vectors. Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key. The outputs\n" |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
577 "are of the form ciphertext,tag for a given NN. The key for step N>1 is the tag of the previous\n" |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
578 "step repeated sufficiently. The nonce is fixed throughout at 13 bytes 000102...\n\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
579 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
580 for (x = 0; cipher_descriptor[x].name != NULL; x++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
581 kl = cipher_descriptor[x].block_length; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
582 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
583 /* skip ciphers which do not have 128 bit block sizes */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
584 if (kl != 16) continue; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
585 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
586 if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
587 kl = cipher_descriptor[x].max_key_length; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
588 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
589 fprintf(out, "GCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
590 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
591 /* the key */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
592 for (z = 0; z < kl; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
593 key[z] = (z & 255); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
594 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
595 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
596 for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
597 for (z = 0; z < y1; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
598 plaintext[z] = (unsigned char)(z & 255); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
599 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
600 len = sizeof(tag); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
601 if ((err = gcm_memory(x, key, kl, plaintext, y1, plaintext, y1, plaintext, y1, plaintext, tag, &len, GCM_ENCRYPT)) != CRYPT_OK) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
602 printf("Error GCM'ing: %s\n", error_to_string(err)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
603 exit(EXIT_FAILURE); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
604 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
605 fprintf(out, "%3d: ", y1); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
606 for (z = 0; z < y1; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
607 fprintf(out, "%02X", plaintext[z]); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
608 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
609 fprintf(out, ", "); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
610 for (z = 0; z <(int)len; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
611 fprintf(out, "%02X", tag[z]); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
612 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
613 fprintf(out, "\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
614 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
615 /* forward the key */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
616 for (z = 0; z < kl; z++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
617 key[z] = tag[z % len]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
618 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
619 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
620 fprintf(out, "\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
621 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
622 fclose(out); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
623 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
624 |
3 | 625 void base64_gen(void) |
626 { | |
627 FILE *out; | |
628 unsigned char dst[256], src[32]; | |
629 unsigned long x, y, len; | |
630 | |
631 out = fopen("base64_tv.txt", "w"); | |
632 fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n"); | |
633 for (x = 0; x <= 32; x++) { | |
634 for (y = 0; y < x; y++) { | |
635 src[y] = y; | |
636 } | |
637 len = sizeof(dst); | |
638 base64_encode(src, x, dst, &len); | |
639 fprintf(out, "%2lu: %s\n", x, dst); | |
640 } | |
641 fclose(out); | |
642 } | |
643 | |
644 int main(void) | |
645 { | |
646 reg_algs(); | |
647 printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); | |
648 printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); | |
649 printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); | |
650 printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); | |
651 printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); | |
652 printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); | |
653 printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
654 printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
143
diff
changeset
|
655 printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); |
3 | 656 printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); |
657 return 0; | |
658 } | |
659 | |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 |