comparison src/encauth/gcm/gcm_test.c @ 381:999a5eb4ed10 libtomcrypt-dropbear

propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28) to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:39:21 +0000
parents d5faf4814ddb
children
comparison
equal deleted inserted replaced
281:997e6f7dc01e 381:999a5eb4ed10
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 11
12 /** 12 /**
13 @file gcm_test.c 13 @file gcm_test.c
14 GCM implementation, testing, by Tom St Denis 14 GCM implementation, testing, by Tom St Denis
27 return CRYPT_NOP; 27 return CRYPT_NOP;
28 #else 28 #else
29 static const struct { 29 static const struct {
30 unsigned char K[32]; 30 unsigned char K[32];
31 int keylen; 31 int keylen;
32 unsigned char P[64]; 32 unsigned char P[128];
33 unsigned long ptlen; 33 unsigned long ptlen;
34 unsigned char A[64]; 34 unsigned char A[128];
35 unsigned long alen; 35 unsigned long alen;
36 unsigned char IV[64]; 36 unsigned char IV[128];
37 unsigned long IVlen; 37 unsigned long IVlen;
38 unsigned char C[64]; 38 unsigned char C[128];
39 unsigned char T[16]; 39 unsigned char T[16];
40 } tests[] = { 40 } tests[] = {
41 41
42 /* test case #1 */ 42 /* test case #1 */
43 { 43 {
273 0x4c, 0x34, 0xae, 0xe5, }, 273 0x4c, 0x34, 0xae, 0xe5, },
274 274
275 /* TAG */ 275 /* TAG */
276 { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, 276 { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
277 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, } 277 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, }
278 },
279
280 /* test case #46 from BG (catches the LTC bug of v1.15) */
281 {
282 /* key */
283 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
285 16,
286
287 /* PT */
288 { 0xa2, 0xaa, 0xb3, 0xad, 0x8b, 0x17, 0xac, 0xdd,
289 0xa2, 0x88, 0x42, 0x6c, 0xd7, 0xc4, 0x29, 0xb7,
290 0xca, 0x86, 0xb7, 0xac, 0xa0, 0x58, 0x09, 0xc7,
291 0x0c, 0xe8, 0x2d, 0xb2, 0x57, 0x11, 0xcb, 0x53,
292 0x02, 0xeb, 0x27, 0x43, 0xb0, 0x36, 0xf3, 0xd7,
293 0x50, 0xd6, 0xcf, 0x0d, 0xc0, 0xac, 0xb9, 0x29,
294 0x50, 0xd5, 0x46, 0xdb, 0x30, 0x8f, 0x93, 0xb4,
295 0xff, 0x24, 0x4a, 0xfa, 0x9d, 0xc7, 0x2b, 0xcd,
296 0x75, 0x8d, 0x2c },
297 67,
298
299 /* ADATA */
300 { 0x68, 0x8e, 0x1a, 0xa9, 0x84, 0xde, 0x92, 0x6d,
301 0xc7, 0xb4, 0xc4, 0x7f, 0x44 },
302 13,
303
304 /* IV */
305 { 0xb7, 0x21, 0x38, 0xb5, 0xa0, 0x5f, 0xf5, 0x07,
306 0x0e, 0x8c, 0xd9, 0x41, 0x83, 0xf7, 0x61, 0xd8 },
307 16,
308
309 /* CT */
310 { 0xcb, 0xc8, 0xd2, 0xf1, 0x54, 0x81, 0xa4, 0xcc,
311 0x7d, 0xd1, 0xe1, 0x9a, 0xaa, 0x83, 0xde, 0x56,
312 0x78, 0x48, 0x3e, 0xc3, 0x59, 0xae, 0x7d, 0xec,
313 0x2a, 0xb8, 0xd5, 0x34, 0xe0, 0x90, 0x6f, 0x4b,
314 0x46, 0x63, 0xfa, 0xff, 0x58, 0xa8, 0xb2, 0xd7,
315 0x33, 0xb8, 0x45, 0xee, 0xf7, 0xc9, 0xb3, 0x31,
316 0xe9, 0xe1, 0x0e, 0xb2, 0x61, 0x2c, 0x99, 0x5f,
317 0xeb, 0x1a, 0xc1, 0x5a, 0x62, 0x86, 0xcc, 0xe8,
318 0xb2, 0x97, 0xa8 },
319
320 /* TAG */
321 { 0x8d, 0x2d, 0x2a, 0x93, 0x72, 0x62, 0x6f, 0x6b,
322 0xee, 0x85, 0x80, 0x27, 0x6a, 0x63, 0x66, 0xbf }
278 } 323 }
279 324
280 /* rest of test cases are the same except AES key size changes... ignored... */ 325 /* rest of test cases are the same except AES key size changes... ignored... */
281 }; 326 };
282 int idx, err; 327 int idx, err;
283 unsigned long x, y; 328 unsigned long x, y;
284 unsigned char out[2][64], T[2][16]; 329 unsigned char out[2][128], T[2][16];
285 330
286 /* find aes */ 331 /* find aes */
287 idx = find_cipher("aes"); 332 idx = find_cipher("aes");
288 if (idx == -1) { 333 if (idx == -1) {
289 idx = find_cipher("rijndael"); 334 idx = find_cipher("rijndael");
300 (unsigned char*)tests[x].P, tests[x].ptlen, 345 (unsigned char*)tests[x].P, tests[x].ptlen,
301 out[0], T[0], &y, GCM_ENCRYPT)) != CRYPT_OK) { 346 out[0], T[0], &y, GCM_ENCRYPT)) != CRYPT_OK) {
302 return err; 347 return err;
303 } 348 }
304 349
305 if (memcmp(out[0], tests[x].C, tests[x].ptlen)) { 350 if (XMEMCMP(out[0], tests[x].C, tests[x].ptlen)) {
306 #if 0 351 #if 0
307 printf("\nCiphertext wrong %lu\n", x); 352 printf("\nCiphertext wrong %lu\n", x);
308 for (y = 0; y < tests[x].ptlen; y++) { 353 for (y = 0; y < tests[x].ptlen; y++) {
309 printf("%02x", out[0][y] & 255); 354 printf("%02x", out[0][y] & 255);
310 } 355 }
311 printf("\n"); 356 printf("\n");
312 #endif 357 #endif
313 return CRYPT_FAIL_TESTVECTOR; 358 return CRYPT_FAIL_TESTVECTOR;
314 } 359 }
315 360
316 if (memcmp(T[0], tests[x].T, 16)) { 361 if (XMEMCMP(T[0], tests[x].T, 16)) {
317 #if 0 362 #if 0
318 printf("\nTag on plaintext wrong %lu\n", x); 363 printf("\nTag on plaintext wrong %lu\n", x);
319 for (y = 0; y < 16; y++) { 364 for (y = 0; y < 16; y++) {
320 printf("%02x", T[0][y] & 255); 365 printf("%02x", T[0][y] & 255);
321 } 366 }
331 out[1], tests[x].ptlen, 376 out[1], tests[x].ptlen,
332 out[0], T[1], &y, GCM_DECRYPT)) != CRYPT_OK) { 377 out[0], T[1], &y, GCM_DECRYPT)) != CRYPT_OK) {
333 return err; 378 return err;
334 } 379 }
335 380
336 if (memcmp(out[1], tests[x].P, tests[x].ptlen)) { 381 if (XMEMCMP(out[1], tests[x].P, tests[x].ptlen)) {
337 #if 0 382 #if 0
338 printf("\nplaintext wrong %lu\n", x); 383 printf("\nplaintext wrong %lu\n", x);
339 for (y = 0; y < tests[x].ptlen; y++) { 384 for (y = 0; y < tests[x].ptlen; y++) {
340 printf("%02x", out[0][y] & 255); 385 printf("%02x", out[0][y] & 255);
341 } 386 }
342 printf("\n"); 387 printf("\n");
343 #endif 388 #endif
344 return CRYPT_FAIL_TESTVECTOR; 389 return CRYPT_FAIL_TESTVECTOR;
345 } 390 }
346 391
347 if (memcmp(T[1], tests[x].T, 16)) { 392 if (XMEMCMP(T[1], tests[x].T, 16)) {
348 #if 0 393 #if 0
349 printf("\nTag on ciphertext wrong %lu\n", x); 394 printf("\nTag on ciphertext wrong %lu\n", x);
350 for (y = 0; y < 16; y++) { 395 for (y = 0; y < 16; y++) {
351 printf("%02x", T[1][y] & 255); 396 printf("%02x", T[1][y] & 255);
352 } 397 }
362 407
363 #endif 408 #endif
364 409
365 410
366 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_test.c,v $ */ 411 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_test.c,v $ */
367 /* $Revision: 1.15 $ */ 412 /* $Revision: 1.20 $ */
368 /* $Date: 2005/05/05 14:35:58 $ */ 413 /* $Date: 2006/12/03 17:25:44 $ */