comparison libtomcrypt/src/mac/hmac/hmac_test.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
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 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file hmac_test.c 12 @file hmac_test.c
15 LTC_HMAC support, self-test, Tom St Denis/Dobes Vandermeer 13 HMAC support, self-test, Tom St Denis/Dobes Vandermeer/Steffen Jaeckel
16 */ 14 */
17 15
18 #ifdef LTC_HMAC 16 #ifdef LTC_HMAC
19 17
20 #define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize 18 #define LTC_HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
25 Network Working Group P. Cheng 23 Network Working Group P. Cheng
26 Request for Comments: 2202 IBM 24 Request for Comments: 2202 IBM
27 Category: Informational R. Glenn 25 Category: Informational R. Glenn
28 NIST 26 NIST
29 September 1997 27 September 1997
30 Test Cases for LTC_HMAC-LTC_MD5 and LTC_HMAC-LTC_SHA-1 28
29 Test Cases for HMAC-MD5 and HMAC-SHA-1
30
31 *******************************************************************************
32
33 Network Working Group J. Kapp
34 Request for Comments: 2286 Reaper Technologies
35 Category: Informational February 1998
36
37 Test Cases for HMAC-RIPEMD160 and HMAC-RIPEMD128
38
39 *******************************************************************************
40
41 Network Working Group M. Nystrom
42 Request for Comments: 4231 RSA Security
43 Category: Standards Track December 2005
44
45 Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256,
46 HMAC-SHA-384, and HMAC-SHA-512
31 */ 47 */
32 48
33 /** 49 /**
34 LTC_HMAC self-test 50 HMAC self-test
35 @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled. 51 @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
36 */ 52 */
37 int hmac_test(void) 53 int hmac_test(void)
38 { 54 {
39 #ifndef LTC_TEST 55 #ifndef LTC_TEST
40 return CRYPT_NOP; 56 return CRYPT_NOP;
41 #else 57 #else
42 unsigned char digest[MAXBLOCKSIZE]; 58 unsigned char digest[MAXBLOCKSIZE];
43 int i; 59 int i;
44 60
61 static const unsigned char hmac_test_case_keys[][136] = {
62 { /* 1 */
63 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
64 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
65 0x0b, 0x0b, 0x0b, 0x0b
66 },
67 #ifdef LTC_TEST_EXT
68 { /* 2 */
69 0x4a, 0x65, 0x66, 0x65
70 },
71 { /* 4 */
72 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
73 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
74 0x15, 0x16, 0x17, 0x18, 0x19
75 },
76 { /* 5 */
77 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
78 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
79 0x0c, 0x0c, 0x0c, 0x0c
80 },
81 { /* 3, 6, 7 */
82 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
83 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
84 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
85 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
86 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
87
88 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
89 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
90 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
91 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
92 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
93
94 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
95 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
96 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
97 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
98 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
99
100 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
101 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa
102 }
103 #endif /* LTC_TEST_EXT */
104 };
105
106
107 static const unsigned char hmac_test_case_data[][153] = {
108 {
109 "Hi There"
110 },
111 #ifdef LTC_TEST_EXT
112 {
113 "what do ya want for nothing?"
114 },
115 {
116 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
117 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
118 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
119 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
120 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
121 },
122 {
123 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
124 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
125 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
126 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
127 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd
128 },
129 {
130 "Test With Truncation"
131 },
132 {
133 "Test Using Larger Than Block-Size Key - Hash Key First"
134 },
135 {
136 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
137 },
138 {
139 "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm."
140 }
141 #endif /* LTC_TEST_EXT */
142 };
143
45 static const struct hmac_test_case { 144 static const struct hmac_test_case {
46 int num; 145 const char *num;
47 char *algo; 146 const char *algo;
48 unsigned char key[128]; 147 const unsigned char *key;
49 unsigned long keylen; 148 unsigned long keylen;
50 unsigned char data[128]; 149 const unsigned char *data;
51 unsigned long datalen; 150 unsigned long datalen;
52 unsigned char digest[MAXBLOCKSIZE]; 151 unsigned char digest[MAXBLOCKSIZE];
53 } cases[] = { 152 } cases[] = {
54 /* 153 /*
55 3. Test Cases for LTC_HMAC-LTC_SHA-1 154 RFC 2202 3. Test Cases for HMAC-SHA-1
56
57 test_case = 1
58 key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
59 key_len = 20
60 data = "Hi Ther 20
61 digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04
62 digest-96 = 0x4c1a03424b55e07fe7f27be1
63 */ 155 */
64 { 5, "sha1", 156 { "rfc2202 3.1", "sha1",
65 {0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 157 hmac_test_case_keys[0], 20,
66 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 158 hmac_test_case_data[0], 8,
67 0x0c, 0x0c, 0x0c, 0x0c}, 20, 159 {0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64,
68 "Test With Truncation", 20, 160 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
161 0xf1, 0x46, 0xbe, 0x00} },
162
163 #ifdef LTC_TEST_EXT
164 { "rfc2202 3.2", "sha1",
165 hmac_test_case_keys[1], 4,
166 hmac_test_case_data[1], 28,
167 {0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2,
168 0xd2, 0x74, 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c,
169 0x25, 0x9a, 0x7c, 0x79} },
170
171 { "rfc2202 3.3", "sha1",
172 hmac_test_case_keys[4], 20,
173 hmac_test_case_data[2], 50,
174 {0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd,
175 0x91, 0xa3, 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f,
176 0x63, 0xf1, 0x75, 0xd3} },
177
178 { "rfc2202 3.4", "sha1",
179 hmac_test_case_keys[2], 25,
180 hmac_test_case_data[3], 50,
181 {0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6,
182 0xbc, 0x84, 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c,
183 0x2d, 0x72, 0x35, 0xda} },
184
185 { "rfc2202 3.5", "sha1",
186 hmac_test_case_keys[3], 20,
187 hmac_test_case_data[4], 20,
69 {0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, 188 {0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2,
70 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04} }, 189 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04} },
71 190
72 /* 191 { "rfc2202 3.6", "sha1",
73 test_case = 6 192 hmac_test_case_keys[4], 80,
74 key = 0xaa repeated 80 times 193 hmac_test_case_data[5], 54,
75 key_len = 80
76 data = "Test Using Larger Than Block-Size Key - Hash Key First"
77 data_len = 54
78 digest = 0xaa4ae5e15272d00e95705637ce8a3b55ed402112
79 */
80 { 6, "sha1",
81 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
82 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
83 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
84 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
85 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
86 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
87 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
88 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
89 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
90 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 80,
91 "Test Using Larger Than Block-Size Key - Hash Key First", 54,
92 {0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 194 {0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e,
93 0x95, 0x70, 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 195 0x95, 0x70, 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55,
94 0xed, 0x40, 0x21, 0x12} }, 196 0xed, 0x40, 0x21, 0x12} },
95 197
96 /* 198 { "rfc2202 3.7", "sha1",
97 test_case = 7 199 hmac_test_case_keys[4], 80,
98 key = 0xaa repeated 80 times 200 hmac_test_case_data[6], 73,
99 key_len = 80
100 data = "Test Using Larger Than Block-Size Key and Larger
101 Than One Block-Size Data"
102 data_len = 73
103 digest = 0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91
104 */
105 { 7, "sha1",
106 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
107 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
108 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
109 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
110 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
111 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
112 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
113 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
114 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
115 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 80,
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, 201 {0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d,
118 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} }, 202 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} },
203 #endif /* LTC_TEST_EXT */
119 204
120 /* 205 /*
121 2. Test Cases for LTC_HMAC-LTC_MD5 206 RFC 2202 2. Test Cases for HMAC-MD5
122
123 test_case = 1
124 key = 0x0b 0b 0b 0b
125 0b 0b 0b 0b
126 0b 0b 0b 0b
127 0b 0b 0b 0b
128 key_len = 16
129 data = "Hi There"
130 data_len = 8
131 digest = 0x92 94 72 7a
132 36 38 bb 1c
133 13 f4 8e f8
134 15 8b fc 9d
135 */ 207 */
136 { 1, "md5", 208 { "rfc2202 2.1", "md5",
137 {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 209 hmac_test_case_keys[0], 16,
138 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 16, 210 hmac_test_case_data[0], 8,
139 "Hi There", 8, 211 {0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
140 {0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
141 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d} }, 212 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d} },
142 /* 213
143 test_case = 2 214 #ifdef LTC_TEST_EXT
144 key = "Jefe" 215 { "rfc2202 2.2", "md5",
145 key_len = 4 216 hmac_test_case_keys[1], 4,
146 data = "what do ya want for nothing?" 217 hmac_test_case_data[1], 28,
147 data_len = 28 218 {0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
148 digest = 0x750c783e6ab0b503eaa86e310a5db738
149 */
150 { 2, "md5",
151 "Jefe", 4,
152 "what do ya want for nothing?", 28,
153 {0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
154 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38} }, 219 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38} },
155 220
156 /* 221 { "rfc2202 2.3", "md5",
157 test_case = 3 222 hmac_test_case_keys[4], 16,
158 key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 223 hmac_test_case_data[2], 50,
159 key_len 16
160 data = 0xdd repeated 50 times
161 data_len = 50
162 digest = 0x56be34521d144c88dbb8c733f0e8b3f6
163 */
164 { 3, "md5",
165 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
166 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 16,
167 {0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
168 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
169 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
170 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
171 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd}, 50,
172 {0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 224 {0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
173 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6} }, 225 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6} },
226
227 { "rfc2202 2.4", "md5",
228 hmac_test_case_keys[2], 25,
229 hmac_test_case_data[3], 50,
230 {0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
231 0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79} },
232
233 { "rfc2202 2.5", "md5",
234 hmac_test_case_keys[3], 16,
235 hmac_test_case_data[4], 20,
236 {0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00,
237 0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c} },
238
239 { "rfc2202 2.6", "md5",
240 hmac_test_case_keys[4], 80,
241 hmac_test_case_data[5], 54,
242 {0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f,
243 0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd} },
244
245 { "rfc2202 2.7", "md5",
246 hmac_test_case_keys[4], 80,
247 hmac_test_case_data[6], 73,
248 {0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
249 0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e} },
250 #endif /* LTC_TEST_EXT */
251
174 /* 252 /*
175 253 RFC 2286 2. Test Cases for HMAC-RIPEMD160
176 test_case = 4
177 key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819
178 key_len 25
179 data = 0xcd repeated 50 times
180 data_len = 50
181 digest = 0x697eaf0aca3a3aea3a75164746ffaa79
182 */ 254 */
183 { 4, "md5", 255 { "rfc2286 2.1", "rmd160",
184 {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 256 hmac_test_case_keys[0], 20,
185 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 257 hmac_test_case_data[0], 8,
186 0x15, 0x16, 0x17, 0x18, 0x19}, 25, 258 {0x24, 0xcb, 0x4b, 0xd6, 0x7d, 0x20, 0xfc, 0x1a,
187 {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 259 0x5d, 0x2e, 0xd7, 0x73, 0x2d, 0xcc, 0x39, 0x37,
188 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 260 0x7f, 0x0a, 0x56, 0x68} },
189 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 261
190 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 262 #ifdef LTC_TEST_EXT
191 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd}, 50, 263 { "rfc2286 2.2", "rmd160",
192 {0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea, 264 hmac_test_case_keys[1], 4,
193 0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79} }, 265 hmac_test_case_data[1], 28,
194 266 {0xdd, 0xa6, 0xc0, 0x21, 0x3a, 0x48, 0x5a, 0x9e,
267 0x24, 0xf4, 0x74, 0x20, 0x64, 0xa7, 0xf0, 0x33,
268 0xb4, 0x3c, 0x40, 0x69} },
269
270 { "rfc2286 2.3", "rmd160",
271 hmac_test_case_keys[4], 20,
272 hmac_test_case_data[2], 50,
273 {0xb0, 0xb1, 0x05, 0x36, 0x0d, 0xe7, 0x59, 0x96,
274 0x0a, 0xb4, 0xf3, 0x52, 0x98, 0xe1, 0x16, 0xe2,
275 0x95, 0xd8, 0xe7, 0xc1} },
276
277 { "rfc2286 2.4", "rmd160",
278 hmac_test_case_keys[2], 25,
279 hmac_test_case_data[3], 50,
280 {0xd5, 0xca, 0x86, 0x2f, 0x4d, 0x21, 0xd5, 0xe6,
281 0x10, 0xe1, 0x8b, 0x4c, 0xf1, 0xbe, 0xb9, 0x7a,
282 0x43, 0x65, 0xec, 0xf4} },
283
284 { "rfc2286 2.5", "rmd160",
285 hmac_test_case_keys[3], 20,
286 hmac_test_case_data[4], 20,
287 {0x76, 0x19, 0x69, 0x39, 0x78, 0xf9, 0x1d, 0x90,
288 0x53, 0x9a, 0xe7, 0x86, 0x50, 0x0f, 0xf3, 0xd8,
289 0xe0, 0x51, 0x8e, 0x39} },
290
291 { "rfc2286 2.6", "rmd160",
292 hmac_test_case_keys[4], 80,
293 hmac_test_case_data[5], 54,
294 {0x64, 0x66, 0xca, 0x07, 0xac, 0x5e, 0xac, 0x29,
295 0xe1, 0xbd, 0x52, 0x3e, 0x5a, 0xda, 0x76, 0x05,
296 0xb7, 0x91, 0xfd, 0x8b} },
297
298 { "rfc2286 2.7", "rmd160",
299 hmac_test_case_keys[4], 80,
300 hmac_test_case_data[6], 73,
301 {0x69, 0xea, 0x60, 0x79, 0x8d, 0x71, 0x61, 0x6c,
302 0xce, 0x5f, 0xd0, 0x87, 0x1e, 0x23, 0x75, 0x4c,
303 0xd7, 0x5d, 0x5a, 0x0a} },
304 #endif /* LTC_TEST_EXT */
195 305
196 /* 306 /*
197 307 RFC 2286 3. Test Cases for HMAC-RIPEMD128
198 test_case = 5
199 key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
200 key_len = 16
201 data = "Test With Truncation"
202 data_len = 20
203 digest = 0x56461ef2342edc00f9bab995690efd4c
204 digest-96 0x56461ef2342edc00f9bab995
205 */ 308 */
206 { 5, "md5", 309 { "rfc2286 3.1", "rmd128",
207 {0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 310 hmac_test_case_keys[0], 16,
208 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}, 16, 311 hmac_test_case_data[0], 8,
209 "Test With Truncation", 20, 312 {0xfb, 0xf6, 0x1f, 0x94, 0x92, 0xaa, 0x4b, 0xbf,
210 {0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 313 0x81, 0xc1, 0x72, 0xe8, 0x4e, 0x07, 0x34, 0xdb} },
211 0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c} }, 314
315 #ifdef LTC_TEST_EXT
316 { "rfc2286 3.2", "rmd128",
317 hmac_test_case_keys[1], 4,
318 hmac_test_case_data[1], 28,
319 {0x87, 0x5f, 0x82, 0x88, 0x62, 0xb6, 0xb3, 0x34,
320 0xb4, 0x27, 0xc5, 0x5f, 0x9f, 0x7f, 0xf0, 0x9b} },
321
322 { "rfc2286 3.3", "rmd128",
323 hmac_test_case_keys[4], 16,
324 hmac_test_case_data[2], 50,
325 {0x09, 0xf0, 0xb2, 0x84, 0x6d, 0x2f, 0x54, 0x3d,
326 0xa3, 0x63, 0xcb, 0xec, 0x8d, 0x62, 0xa3, 0x8d} },
327
328 { "rfc2286 3.4", "rmd128",
329 hmac_test_case_keys[2], 25,
330 hmac_test_case_data[3], 50,
331 {0xbd, 0xbb, 0xd7, 0xcf, 0x03, 0xe4, 0x4b, 0x5a,
332 0xa6, 0x0a, 0xf8, 0x15, 0xbe, 0x4d, 0x22, 0x94} },
333
334 { "rfc2286 3.5", "rmd128",
335 hmac_test_case_keys[3], 16,
336 hmac_test_case_data[4], 20,
337 {0xe7, 0x98, 0x08, 0xf2, 0x4b, 0x25, 0xfd, 0x03,
338 0x1c, 0x15, 0x5f, 0x0d, 0x55, 0x1d, 0x9a, 0x3a} },
339
340 { "rfc2286 3.6", "rmd128",
341 hmac_test_case_keys[4], 80,
342 hmac_test_case_data[5], 54,
343 {0xdc, 0x73, 0x29, 0x28, 0xde, 0x98, 0x10, 0x4a,
344 0x1f, 0x59, 0xd3, 0x73, 0xc1, 0x50, 0xac, 0xbb} },
345
346 { "rfc2286 3.7", "rmd128",
347 hmac_test_case_keys[4], 80,
348 hmac_test_case_data[6], 73,
349 {0x5c, 0x6b, 0xec, 0x96, 0x79, 0x3e, 0x16, 0xd4,
350 0x06, 0x90, 0xc2, 0x37, 0x63, 0x5f, 0x30, 0xc5} },
351 #endif /* LTC_TEST_EXT */
212 352
213 /* 353 /*
214 354 RFC 4231 4. Test Vectors
215 test_case = 6 355 Ch. 4.6 with truncated output left out to simplify tests
216 key = 0xaa repeated 80 times
217 key_len = 80
218 data = "Test Using Larger Than Block-Size Key - Hash
219 Key First"
220 data_len = 54
221 digest = 0x6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd
222 */ 356 */
223 { 6, "md5", 357 { "rfc4231 4.2", "sha224",
224 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 358 hmac_test_case_keys[0], 20,
225 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 359 hmac_test_case_data[0], 8,
226 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 360 {0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
227 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 361 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
228 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 362 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
229 363 0x53, 0x68, 0x4b, 0x22} },
230 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 364
231 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 365 #ifdef LTC_TEST_EXT
232 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 366 { "rfc4231 4.3", "sha224",
233 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 367 hmac_test_case_keys[1], 4,
234 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 80, 368 hmac_test_case_data[1], 28,
235 "Test Using Larger Than Block-Size Key - Hash Key First", 54, 369 {0xa3, 0x0e, 0x01, 0x09, 0x8b, 0xc6, 0xdb, 0xbf,
236 {0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 370 0x45, 0x69, 0x0f, 0x3a, 0x7e, 0x9e, 0x6d, 0x0f,
237 0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd} }, 371 0x8b, 0xbe, 0xa2, 0xa3, 0x9e, 0x61, 0x48, 0x00,
238 372 0x8f, 0xd0, 0x5e, 0x44} },
239 /* 373
240 374 { "rfc4231 4.4", "sha224",
241 test_case = 7 375 hmac_test_case_keys[4], 20,
242 key = 0xaa repeated 80 times 376 hmac_test_case_data[2], 50,
243 key_len = 80 377 {0x7f, 0xb3, 0xcb, 0x35, 0x88, 0xc6, 0xc1, 0xf6,
244 data = "Test Using Larger Than Block-Size Key and Larger 378 0xff, 0xa9, 0x69, 0x4d, 0x7d, 0x6a, 0xd2, 0x64,
245 Than One Block-Size Data" 379 0x93, 0x65, 0xb0, 0xc1, 0xf6, 0x5d, 0x69, 0xd1,
246 data_len = 73 380 0xec, 0x83, 0x33, 0xea} },
247 digest = 0x6f630fad67cda0ee1fb1f562db3aa53e 381
248 */ 382 { "rfc4231 4.5", "sha224",
249 { 7, "md5", 383 hmac_test_case_keys[2], 25,
250 {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 384 hmac_test_case_data[3], 50,
251 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 385 {0x6c, 0x11, 0x50, 0x68, 0x74, 0x01, 0x3c, 0xac,
252 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 386 0x6a, 0x2a, 0xbc, 0x1b, 0xb3, 0x82, 0x62, 0x7c,
253 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 387 0xec, 0x6a, 0x90, 0xd8, 0x6e, 0xfc, 0x01, 0x2d,
254 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 388 0xe7, 0xaf, 0xec, 0x5a} },
255 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 389
256 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 390 { "rfc4231 4.7", "sha224",
257 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 391 hmac_test_case_keys[4], 131,
258 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 392 hmac_test_case_data[5], 54,
259 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 80, 393 {0x95, 0xe9, 0xa0, 0xdb, 0x96, 0x20, 0x95, 0xad,
260 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", 73, 394 0xae, 0xbe, 0x9b, 0x2d, 0x6f, 0x0d, 0xbc, 0xe2,
261 {0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 395 0xd4, 0x99, 0xf1, 0x12, 0xf2, 0xd2, 0xb7, 0x27,
262 0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e} } 396 0x3f, 0xa6, 0x87, 0x0e} },
397
398 { "rfc4231 4.8", "sha224",
399 hmac_test_case_keys[4], 131,
400 hmac_test_case_data[7], 152,
401 {0x3a, 0x85, 0x41, 0x66, 0xac, 0x5d, 0x9f, 0x02,
402 0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd,
403 0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9,
404 0xf6, 0xf5, 0x65, 0xd1} },
405 #endif /* LTC_TEST_EXT */
406
407 { "rfc4231 4.2", "sha256",
408 hmac_test_case_keys[0], 20,
409 hmac_test_case_data[0], 8,
410 {0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
411 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
412 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
413 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7} },
414
415 #ifdef LTC_TEST_EXT
416 { "rfc4231 4.3", "sha256",
417 hmac_test_case_keys[1], 4,
418 hmac_test_case_data[1], 28,
419 {0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
420 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
421 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
422 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43} },
423
424 { "rfc4231 4.4", "sha256",
425 hmac_test_case_keys[4], 20,
426 hmac_test_case_data[2], 50,
427 {0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46,
428 0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7,
429 0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22,
430 0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, 0x65, 0xfe} },
431
432 { "rfc4231 4.5", "sha256",
433 hmac_test_case_keys[2], 25,
434 hmac_test_case_data[3], 50,
435 {0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e,
436 0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a,
437 0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07,
438 0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, 0x66, 0x5b} },
439
440 { "rfc4231 4.7", "sha256",
441 hmac_test_case_keys[4], 131,
442 hmac_test_case_data[5], 54,
443 {0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f,
444 0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f,
445 0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14,
446 0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, 0x7f, 0x54} },
447
448 { "rfc4231 4.8", "sha256",
449 hmac_test_case_keys[4], 131,
450 hmac_test_case_data[7], 152,
451 {0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb,
452 0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44,
453 0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93,
454 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2} },
455 #endif /* LTC_TEST_EXT */
456
457 { "rfc4231 4.2", "sha384",
458 hmac_test_case_keys[0], 20,
459 hmac_test_case_data[0], 8,
460 {0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
461 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
462 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
463 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
464 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
465 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6} },
466
467 #ifdef LTC_TEST_EXT
468 { "rfc4231 4.3", "sha384",
469 hmac_test_case_keys[1], 4,
470 hmac_test_case_data[1], 28,
471 {0xaf, 0x45, 0xd2, 0xe3, 0x76, 0x48, 0x40, 0x31,
472 0x61, 0x7f, 0x78, 0xd2, 0xb5, 0x8a, 0x6b, 0x1b,
473 0x9c, 0x7e, 0xf4, 0x64, 0xf5, 0xa0, 0x1b, 0x47,
474 0xe4, 0x2e, 0xc3, 0x73, 0x63, 0x22, 0x44, 0x5e,
475 0x8e, 0x22, 0x40, 0xca, 0x5e, 0x69, 0xe2, 0xc7,
476 0x8b, 0x32, 0x39, 0xec, 0xfa, 0xb2, 0x16, 0x49} },
477
478 { "rfc4231 4.4", "sha384",
479 hmac_test_case_keys[4], 20,
480 hmac_test_case_data[2], 50,
481 {0x88, 0x06, 0x26, 0x08, 0xd3, 0xe6, 0xad, 0x8a,
482 0x0a, 0xa2, 0xac, 0xe0, 0x14, 0xc8, 0xa8, 0x6f,
483 0x0a, 0xa6, 0x35, 0xd9, 0x47, 0xac, 0x9f, 0xeb,
484 0xe8, 0x3e, 0xf4, 0xe5, 0x59, 0x66, 0x14, 0x4b,
485 0x2a, 0x5a, 0xb3, 0x9d, 0xc1, 0x38, 0x14, 0xb9,
486 0x4e, 0x3a, 0xb6, 0xe1, 0x01, 0xa3, 0x4f, 0x27} },
487
488 { "rfc4231 4.5", "sha384",
489 hmac_test_case_keys[2], 25,
490 hmac_test_case_data[3], 50,
491 {0x3e, 0x8a, 0x69, 0xb7, 0x78, 0x3c, 0x25, 0x85,
492 0x19, 0x33, 0xab, 0x62, 0x90, 0xaf, 0x6c, 0xa7,
493 0x7a, 0x99, 0x81, 0x48, 0x08, 0x50, 0x00, 0x9c,
494 0xc5, 0x57, 0x7c, 0x6e, 0x1f, 0x57, 0x3b, 0x4e,
495 0x68, 0x01, 0xdd, 0x23, 0xc4, 0xa7, 0xd6, 0x79,
496 0xcc, 0xf8, 0xa3, 0x86, 0xc6, 0x74, 0xcf, 0xfb} },
497
498 { "rfc4231 4.7", "sha384",
499 hmac_test_case_keys[4], 131,
500 hmac_test_case_data[5], 54,
501 {0x4e, 0xce, 0x08, 0x44, 0x85, 0x81, 0x3e, 0x90,
502 0x88, 0xd2, 0xc6, 0x3a, 0x04, 0x1b, 0xc5, 0xb4,
503 0x4f, 0x9e, 0xf1, 0x01, 0x2a, 0x2b, 0x58, 0x8f,
504 0x3c, 0xd1, 0x1f, 0x05, 0x03, 0x3a, 0xc4, 0xc6,
505 0x0c, 0x2e, 0xf6, 0xab, 0x40, 0x30, 0xfe, 0x82,
506 0x96, 0x24, 0x8d, 0xf1, 0x63, 0xf4, 0x49, 0x52} },
507
508 { "rfc4231 4.8", "sha384",
509 hmac_test_case_keys[4], 131,
510 hmac_test_case_data[7], 152,
511 {0x66, 0x17, 0x17, 0x8e, 0x94, 0x1f, 0x02, 0x0d,
512 0x35, 0x1e, 0x2f, 0x25, 0x4e, 0x8f, 0xd3, 0x2c,
513 0x60, 0x24, 0x20, 0xfe, 0xb0, 0xb8, 0xfb, 0x9a,
514 0xdc, 0xce, 0xbb, 0x82, 0x46, 0x1e, 0x99, 0xc5,
515 0xa6, 0x78, 0xcc, 0x31, 0xe7, 0x99, 0x17, 0x6d,
516 0x38, 0x60, 0xe6, 0x11, 0x0c, 0x46, 0x52, 0x3e} },
517 #endif /* LTC_TEST_EXT */
518
519 { "rfc4231 4.2", "sha512",
520 hmac_test_case_keys[0], 20,
521 hmac_test_case_data[0], 8,
522 {0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
523 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
524 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
525 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
526 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
527 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
528 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
529 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54} },
530
531 #ifdef LTC_TEST_EXT
532 { "rfc4231 4.3", "sha512",
533 hmac_test_case_keys[1], 4,
534 hmac_test_case_data[1], 28,
535 {0x16, 0x4b, 0x7a, 0x7b, 0xfc, 0xf8, 0x19, 0xe2,
536 0xe3, 0x95, 0xfb, 0xe7, 0x3b, 0x56, 0xe0, 0xa3,
537 0x87, 0xbd, 0x64, 0x22, 0x2e, 0x83, 0x1f, 0xd6,
538 0x10, 0x27, 0x0c, 0xd7, 0xea, 0x25, 0x05, 0x54,
539 0x97, 0x58, 0xbf, 0x75, 0xc0, 0x5a, 0x99, 0x4a,
540 0x6d, 0x03, 0x4f, 0x65, 0xf8, 0xf0, 0xe6, 0xfd,
541 0xca, 0xea, 0xb1, 0xa3, 0x4d, 0x4a, 0x6b, 0x4b,
542 0x63, 0x6e, 0x07, 0x0a, 0x38, 0xbc, 0xe7, 0x37} },
543
544 { "rfc4231 4.4", "sha512",
545 hmac_test_case_keys[4], 20,
546 hmac_test_case_data[2], 50,
547 {0xfa, 0x73, 0xb0, 0x08, 0x9d, 0x56, 0xa2, 0x84,
548 0xef, 0xb0, 0xf0, 0x75, 0x6c, 0x89, 0x0b, 0xe9,
549 0xb1, 0xb5, 0xdb, 0xdd, 0x8e, 0xe8, 0x1a, 0x36,
550 0x55, 0xf8, 0x3e, 0x33, 0xb2, 0x27, 0x9d, 0x39,
551 0xbf, 0x3e, 0x84, 0x82, 0x79, 0xa7, 0x22, 0xc8,
552 0x06, 0xb4, 0x85, 0xa4, 0x7e, 0x67, 0xc8, 0x07,
553 0xb9, 0x46, 0xa3, 0x37, 0xbe, 0xe8, 0x94, 0x26,
554 0x74, 0x27, 0x88, 0x59, 0xe1, 0x32, 0x92, 0xfb} },
555
556 { "rfc4231 4.5", "sha512",
557 hmac_test_case_keys[2], 25,
558 hmac_test_case_data[3], 50,
559 {0xb0, 0xba, 0x46, 0x56, 0x37, 0x45, 0x8c, 0x69,
560 0x90, 0xe5, 0xa8, 0xc5, 0xf6, 0x1d, 0x4a, 0xf7,
561 0xe5, 0x76, 0xd9, 0x7f, 0xf9, 0x4b, 0x87, 0x2d,
562 0xe7, 0x6f, 0x80, 0x50, 0x36, 0x1e, 0xe3, 0xdb,
563 0xa9, 0x1c, 0xa5, 0xc1, 0x1a, 0xa2, 0x5e, 0xb4,
564 0xd6, 0x79, 0x27, 0x5c, 0xc5, 0x78, 0x80, 0x63,
565 0xa5, 0xf1, 0x97, 0x41, 0x12, 0x0c, 0x4f, 0x2d,
566 0xe2, 0xad, 0xeb, 0xeb, 0x10, 0xa2, 0x98, 0xdd} },
567
568 { "rfc4231 4.7", "sha512",
569 hmac_test_case_keys[4], 131,
570 hmac_test_case_data[5], 54,
571 {0x80, 0xb2, 0x42, 0x63, 0xc7, 0xc1, 0xa3, 0xeb,
572 0xb7, 0x14, 0x93, 0xc1, 0xdd, 0x7b, 0xe8, 0xb4,
573 0x9b, 0x46, 0xd1, 0xf4, 0x1b, 0x4a, 0xee, 0xc1,
574 0x12, 0x1b, 0x01, 0x37, 0x83, 0xf8, 0xf3, 0x52,
575 0x6b, 0x56, 0xd0, 0x37, 0xe0, 0x5f, 0x25, 0x98,
576 0xbd, 0x0f, 0xd2, 0x21, 0x5d, 0x6a, 0x1e, 0x52,
577 0x95, 0xe6, 0x4f, 0x73, 0xf6, 0x3f, 0x0a, 0xec,
578 0x8b, 0x91, 0x5a, 0x98, 0x5d, 0x78, 0x65, 0x98} },
579
580 { "rfc4231 4.8", "sha512",
581 hmac_test_case_keys[4], 131,
582 hmac_test_case_data[7], 152,
583 {0xe3, 0x7b, 0x6a, 0x77, 0x5d, 0xc8, 0x7d, 0xba,
584 0xa4, 0xdf, 0xa9, 0xf9, 0x6e, 0x5e, 0x3f, 0xfd,
585 0xde, 0xbd, 0x71, 0xf8, 0x86, 0x72, 0x89, 0x86,
586 0x5d, 0xf5, 0xa3, 0x2d, 0x20, 0xcd, 0xc9, 0x44,
587 0xb6, 0x02, 0x2c, 0xac, 0x3c, 0x49, 0x82, 0xb1,
588 0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15,
589 0x13, 0x46, 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60,
590 0x65, 0xc9, 0x74, 0x40, 0xfa, 0x8c, 0x6a, 0x58} },
591 #endif /* LTC_TEST_EXT */
592
263 }; 593 };
264 594
265 unsigned long outlen; 595 unsigned long outlen;
266 int err; 596 int err;
267 int tested=0,failed=0; 597 int tested=0,failed=0;
269 int hash = find_hash(cases[i].algo); 599 int hash = find_hash(cases[i].algo);
270 if (hash == -1) continue; 600 if (hash == -1) continue;
271 ++tested; 601 ++tested;
272 outlen = sizeof(digest); 602 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) { 603 if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) {
274 #if 0 604 #ifdef LTC_TEST_DBG
275 printf("LTC_HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err)); 605 printf("HMAC-%s test %s, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
276 #endif 606 #endif
277 return err; 607 return err;
278 } 608 }
279 609
280 if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0) { 610 if(compare_testvector(digest, outlen, cases[i].digest, (size_t)hash_descriptor[hash].hashsize, cases[i].num, i)) {
281 failed++; 611 failed++;
282 #if 0
283 unsigned int j;
284 printf("\nLTC_HMAC-%s test #%d:\n", cases[i].algo, cases[i].num);
285 printf( "Result: 0x");
286 for(j=0; j < hash_descriptor[hash].hashsize; j++) {
287 printf("%2x ", digest[j]);
288 }
289 printf("\nCorrect: 0x");
290 for(j=0; j < hash_descriptor[hash].hashsize; j++) {
291 printf("%2x ", cases[i].digest[j]);
292 }
293 printf("\n");
294 return CRYPT_ERROR;
295 #endif
296 } else {
297 /* printf("LTC_HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */
298 } 612 }
299 } 613 }
300 614
301 if (failed != 0) { 615 if (failed != 0) {
302 return CRYPT_FAIL_TESTVECTOR; 616 return CRYPT_FAIL_TESTVECTOR;
309 } 623 }
310 624
311 #endif 625 #endif
312 626
313 627
314 /* $Source$ */ 628 /* ref: $Format:%D$ */
315 /* $Revision$ */ 629 /* git commit: $Format:%H$ */
316 /* $Date$ */ 630 /* commit time: $Format:%ai$ */