comparison libtomcrypt/src/mac/hmac/hmac_test.c @ 1435:f849a5ca2efc

update to libtomcrypt 1.17 (with Dropbear changes)
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 17:50:50 +0800
parents 0cbe8f6dbf9e
children 6dba84798cd5
comparison
equal deleted inserted replaced
1434:27b9ddb06b09 1435:f849a5ca2efc
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.com 9 * Tom St Denis, [email protected], http://libtom.org
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file hmac_test.c 14 @file hmac_test.c
15 HMAC support, self-test, Tom St Denis/Dobes Vandermeer 15 LTC_HMAC support, self-test, Tom St Denis/Dobes Vandermeer
16 */ 16 */
17 17
18 #ifdef LTC_HMAC 18 #ifdef LTC_HMAC
19 19
20 #define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize 20 #define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
21 21
22 /* 22 /*
23 TEST CASES SOURCE: 23 TEST CASES SOURCE:
24 24
25 Network Working Group P. Cheng 25 Network Working Group P. Cheng
26 Request for Comments: 2202 IBM 26 Request for Comments: 2202 IBM
27 Category: Informational R. Glenn 27 Category: Informational R. Glenn
28 NIST 28 NIST
29 September 1997 29 September 1997
30 Test Cases for HMAC-MD5 and HMAC-SHA-1 30 Test Cases for LTC_HMAC-LTC_MD5 and LTC_HMAC-LTC_SHA-1
31 */ 31 */
32 32
33 /** 33 /**
34 HMAC self-test 34 LTC_HMAC self-test
35 @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled. 35 @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
36 */ 36 */
37 int hmac_test(void) 37 int hmac_test(void)
38 { 38 {
39 #ifndef LTC_TEST 39 #ifndef LTC_TEST
50 unsigned char data[128]; 50 unsigned char data[128];
51 unsigned long datalen; 51 unsigned long datalen;
52 unsigned char digest[MAXBLOCKSIZE]; 52 unsigned char digest[MAXBLOCKSIZE];
53 } cases[] = { 53 } cases[] = {
54 /* 54 /*
55 3. Test Cases for HMAC-SHA-1 55 3. Test Cases for LTC_HMAC-LTC_SHA-1
56 56
57 test_case = 1 57 test_case = 1
58 key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c 58 key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
59 key_len = 20 59 key_len = 20
60 data = "Hi Ther 20 60 data = "Hi Ther 20
116 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73, 116 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73,
117 {0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 117 {0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d,
118 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} }, 118 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} },
119 119
120 /* 120 /*
121 2. Test Cases for HMAC-MD5 121 2. Test Cases for LTC_HMAC-LTC_MD5
122 122
123 test_case = 1 123 test_case = 1
124 key = 0x0b 0b 0b 0b 124 key = 0x0b 0b 0b 0b
125 0b 0b 0b 0b 125 0b 0b 0b 0b
126 0b 0b 0b 0b 126 0b 0b 0b 0b
270 if (hash == -1) continue; 270 if (hash == -1) continue;
271 ++tested; 271 ++tested;
272 outlen = sizeof(digest); 272 outlen = sizeof(digest);
273 if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) { 273 if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) {
274 #if 0 274 #if 0
275 printf("HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err)); 275 printf("LTC_HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
276 #endif 276 #endif
277 return err; 277 return err;
278 } 278 }
279 279
280 if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) { 280 if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) {
281 failed++; 281 failed++;
282 #if 0 282 #if 0
283 unsigned int j; 283 unsigned int j;
284 printf("\nHMAC-%s test #%d:\n", cases[i].algo, cases[i].num); 284 printf("\nLTC_HMAC-%s test #%d:\n", cases[i].algo, cases[i].num);
285 printf( "Result: 0x"); 285 printf( "Result: 0x");
286 for(j=0; j < hash_descriptor[hash].hashsize; j++) { 286 for(j=0; j < hash_descriptor[hash].hashsize; j++) {
287 printf("%2x ", digest[j]); 287 printf("%2x ", digest[j]);
288 } 288 }
289 printf("\nCorrect: 0x"); 289 printf("\nCorrect: 0x");
292 } 292 }
293 printf("\n"); 293 printf("\n");
294 return CRYPT_ERROR; 294 return CRYPT_ERROR;
295 #endif 295 #endif
296 } else { 296 } else {
297 /* printf("HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */ 297 /* printf("LTC_HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */
298 } 298 }
299 } 299 }
300 300
301 if (failed != 0) { 301 if (failed != 0) {
302 return CRYPT_FAIL_TESTVECTOR; 302 return CRYPT_FAIL_TESTVECTOR;
309 } 309 }
310 310
311 #endif 311 #endif
312 312
313 313
314 /* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_test.c,v $ */ 314 /* $Source$ */
315 /* $Revision: 1.7 $ */ 315 /* $Revision$ */
316 /* $Date: 2006/11/03 00:39:49 $ */ 316 /* $Date$ */