hmac-test.c 31.6 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
#include "testutils.h"
#include "hmac.h"

Niels Möller's avatar
Niels Möller committed
4
/* KEY and MSG are supposed to expand to length, data */ 
5
6
7
8
9
10
11
#define HMAC_TEST(alg, length, key, msg, mac) do {		\
  hmac_##alg##_set_key(&alg, key);				\
  hmac_##alg##_update(&alg, msg);				\
  digest[length] = 17;						\
  hmac_##alg##_digest(&alg, length, digest);			\
  ASSERT(MEMEQ (length, digest, mac));				\
  ASSERT(digest[length] == 17);					\
Niels Möller's avatar
Niels Möller committed
12
13
} while (0)

Niels Möller's avatar
Niels Möller committed
14
15
16
17
18
int
test_main(void)
{
  struct hmac_md5_ctx md5;
  struct hmac_sha1_ctx sha1;
19
  struct hmac_ripemd160_ctx ripemd160;
20
  struct hmac_sha224_ctx sha224;
Niels Möller's avatar
Niels Möller committed
21
  struct hmac_sha256_ctx sha256;
22
  struct hmac_sha384_ctx sha384;
23
  struct hmac_sha512_ctx sha512;
Niels Möller's avatar
Niels Möller committed
24

25
  /* sha512's digests are longest */
26
  uint8_t digest[SHA512_DIGEST_SIZE+1];
Niels Möller's avatar
Niels Möller committed
27
28

  memset(digest, 0, sizeof(digest));
29

Niels Möller's avatar
Niels Möller committed
30
  /* Test vectors for md5, from RFC-2202 */
31
32

  /* md5 - 1 */
Niels Möller's avatar
Niels Möller committed
33
34
35
36
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
	    LDATA("Hi There"),
	    H("9294727a3638bb1c 13f48ef8158bfc9d"));
Niels Möller's avatar
Niels Möller committed
37
38


39
  /* md5 - 2 */
Niels Möller's avatar
Niels Möller committed
40
41
42
43
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("750c783e6ab0b503 eaa86e310a5db738"));	    
Niels Möller's avatar
Niels Möller committed
44

45
  /* md5 - 3 */
Niels Möller's avatar
Niels Möller committed
46
47
48
49
50
51
52
53
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    HL("dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddd"),
	    H("56be34521d144c88 dbb8c733f0e8b3f6"));
  
54
  /* md5 - 4 */
Niels Möller's avatar
Niels Möller committed
55
56
57
58
59
60
61
62
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10" 
	       "1112131415161718 19"),
	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("697eaf0aca3a3aea 3a75164746ffaa79"));
Niels Möller's avatar
Niels Möller committed
63

64
  /* md5 - 5 */
65
66
67
68
  HMAC_TEST(md5, 12,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("56461ef2342edc00 f9bab995"));
Niels Möller's avatar
Niels Möller committed
69

70
  /* md5 - 6 */
Niels Möller's avatar
Niels Möller committed
71
72
73
74
75
76
77
78
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("6b1ab7fe4bd7bf8f 0b62e6ce61b9d0cd"));
Niels Möller's avatar
Niels Möller committed
79

80
  /* md5 - 7 */
Niels Möller's avatar
Niels Möller committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key and Larger "
		  "Than One Block-Size Data"),
	    H("6f630fad67cda0ee 1fb1f562db3aa53e"));

  /* Additional test vectors, from Daniel Kahn Gillmor */
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA(""),
	    H("e84db42a188813f30a15e611d64c7869"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("a"),
	    H("123662062e67c2aab371cc49db0df134"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("38"),
	    H("0a46cc10a49d4b7025c040c597bf5d76"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abc"),
	    H("d1f4d89f0e8b2b6ed0623c99ec298310"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("message digest"),
	    H("1627207b9bed5009a4f6e9ca8d2ca01e"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("922aae6ab3b3a29202e21ce5f916ae9a"));

  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("ede9cb83679ba82d88fbeae865b3f8fc"));

  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
	    H("939dd45512ee3a594b6654f6b8de27f7"));
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204

  /* Test vectors for ripemd160, from
     http://homes.esat.kuleuven.be/~bosselae/ripemd160.html */
  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA(""),
	    H("cf387677bfda8483e63b57e06c3b5ecd8b7fc055"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("a"),
	    H("0d351d71b78e36dbb7391c810a0d2b6240ddbafc"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("abc"),
	    H("f7ef288cb1bbcc6160d76507e0a3bbf712fb67d6"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("message digest"),
	    H("f83662cc8d339c227e600fcd636c57d2571b1c34"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("843d1c4eb880ac8ac0c9c95696507957d0155ddb"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
	    H("60f5ef198a2dd5745545c1f0c47aa3fb5776f881"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("00112233445566778899aabbccddeeff01234567"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("e49c136a9e5627e0681b808a3b97e6a6e661ae79"));

  /* Other key */
  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA(""),
	    H("fe69a66c7423eea9c8fa2eff8d9dafb4f17a62f5"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("a"),
	    H("85743e899bc82dbfa36faaa7a25b7cfd372432cd"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("abc"),
	    H("6e4afd501fa6b4a1823ca3b10bd9aa0ba97ba182"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("message digest"),
	    H("2e066e624badb76a184c8f90fba053330e650e92"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("07e942aa4e3cd7c04dedc1d46e2e8cc4c741b3d9"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
	    H("b6582318ddcfb67a53a67d676b8ad869aded629a"));

  HMAC_TEST(ripemd160, RIPEMD160_DIGEST_SIZE,
	    HL("0123456789abcdeffedcba987654321000112233"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("f1be3ee877703140d34f97ea1ab3a07c141333e2"));

205
206
207
  /* Test vectors for sha1, from RFC-2202 */

  /* sha1 - 1 */
Niels Möller's avatar
Niels Möller committed
208
209
210
211
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b 0b0b0b0b"),
	    LDATA("Hi There"),
	    H("b617318655057264 e28bc0b6fb378c8e f146be00"));
212
213

  /* sha1 - 2 */
Niels Möller's avatar
Niels Möller committed
214
215
216
217
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("effcdf6ae5eb2fa2 d27416d5f184df9c 259a7c79"));
218
219

  /* sha1 - 3 */
Niels Möller's avatar
Niels Möller committed
220
221
222
223
224
225
226
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaa"),
	    HL("dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddd"),
	    H("125d7342b9ac11cd 91a39af48aa17b4f 63f175d3"));
227

228
  /* sha1 - 4 */
Niels Möller's avatar
Niels Möller committed
229
230
231
232
233
234
235
236
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10" 
	       "1112131415161718 19"),
	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("4c9007f4026250c6 bc8414f9bf50c86c 2d7235da"));
237
238

  /* sha1 - 5 */
239
240
241
242
  HMAC_TEST(sha1, 12,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("4c1a03424b55e07f e7f27be1"));
243
244

  /* sha1 - 6 */
Niels Möller's avatar
Niels Möller committed
245
246
247
248
249
250
251
252
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("aa4ae5e15272d00e 95705637ce8a3b55 ed402112"));
253
254

  /* sha1 - 7 */
Niels Möller's avatar
Niels Möller committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  HMAC_TEST(sha1, SHA1_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key and Larger "
		  "Than One Block-Size Data"),
	    H("e8e99d0f45237d78 6d6bbaa7965c7808 bbff1a91"));

  /* Additional test vectors, from Daniel Kahn Gillmor */
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA(""),
	    H("e84db42a188813f30a15e611d64c7869"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("a"),
	    H("123662062e67c2aab371cc49db0df134"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("38"),
	    H("0a46cc10a49d4b7025c040c597bf5d76"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abc"),
	    H("d1f4d89f0e8b2b6ed0623c99ec298310"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("message digest"),
	    H("1627207b9bed5009a4f6e9ca8d2ca01e"));
  
  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("922aae6ab3b3a29202e21ce5f916ae9a"));

  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("ede9cb83679ba82d88fbeae865b3f8fc"));

  HMAC_TEST(md5, MD5_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
	    H("939dd45512ee3a594b6654f6b8de27f7"));
305

306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
  /* Test vectors for sha224, from RFC 4231 */
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b"),
	    LDATA("Hi There"),
	    H("896fb1128abbdf196832107cd49df33f"
	      "47b4b1169912ba4f53684b22"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("a30e01098bc6dbbf45690f3a7e9e6d0f"
	      "8bbea2a39e6148008fd05e44"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaa"),
	    HL("dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddd"),
	    H("7fb3cb3588c6c1f6ffa9694d7d6ad264"
	      "9365b0c1f65d69d1ec8333ea"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    HL("0102030405060708090a0b0c0d0e0f10"
	       "111213141516171819"),
	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("6c11506874013cac6a2abc1bb382627c"
	      "ec6a90d86efc012de7afec5a"));

  HMAC_TEST(sha224, 16,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("0e2aea68a90c8d37c988bcdb9fca6fa8"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("95e9a0db962095adaebe9b2d6f0dbce2"
	      "d499f112f2d2b7273fa6870e"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("This is a test using a larger than block-size ke"
		  "y and a larger than block-size data. The key nee"
		  "ds to be hashed before being used by the HMAC al"
		  "gorithm."),
	    H("3a854166ac5d9f023f54d517d0b39dbd"
	      "946770db9c2b95c9f6f565d1"));

  /* Additional test vectors, from Daniel Kahn Gillmor */
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA(""),
	    H("d12a49ae38177ffeaa548b2148bb5238"
	      "60849772d9391e675b103d89"));
  
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("a"),
	    H("b04ff8522f904f553970bfa8ad3f0086"
	      "bce1e8580affd8a12c94e31a"));
  
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("38"),
	    H("afcfb5511f710334f9350f57faec3c08"
	      "764b4bd126a6840f4347f116"));
  
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abc"),
	    H("9df9907af127900c909376893565c6cf"
	      "2d7db244fdc4277da1e0b679"));
  
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("message digest"),
	    H("254ebf6b8ddd7a3271b3d9aca1699b0c"
	      "0bfb7df61e8a114922c88d27"));
  
  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("6ec5bffba5880c3234a6cf257816e4d5"
	      "35ab178a7f12929769e378fb"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("5f768179dbb29ca722875d0f461a2e2f"
	      "597d0210340a84df1a8e9c63"));

  HMAC_TEST(sha224, SHA224_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
	    H("c7667b0d7e56b2b4f6fcc1d8da9e22da"
	      "a1556f44c47132a87303c6a2"));

  /* Test vectors for sha256, from RFC 4231 */
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b"),
	    LDATA("Hi There"),
	    H("b0344c61d8db38535ca8afceaf0bf12b"
	      "881dc200c9833da726e9376c2e32cff7"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("5bdcc146bf60754e6a042426089575c7"
	      "5a003f089d2739839dec58b964ec3843"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaa"),
	    HL("dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddd"),
	    H("773ea91e36800e46854db8ebd09181a7"
	      "2959098b3ef8c122d9635514ced565fe"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0102030405060708090a0b0c0d0e0f10"
	       "111213141516171819"),
	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("82558a389a443c0ea4cc819899f2083a"
	      "85f0faa3e578f8077a2e3ff46729665b"));

  HMAC_TEST(sha256, 16,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("a3b6167473100ee06e0c796c2955552b"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("60e431591ee0b67f0d8a26aacbf5b77f"
	      "8e0bc6213728c5140546040f0ee37f54"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("This is a test using a larger than block-size ke"
		  "y and a larger than block-size data. The key nee"
		  "ds to be hashed before being used by the HMAC al"
		  "gorithm."),
	    H("9b09ffa71b942fcb27635fbcd5b0e944"
	      "bfdc63644f0713938a7f51535c3a35e2"));

  /* Additional test vectors for sha256, from
     draft-ietf-ipsec-ciph-sha-256-01.txt */
497
498

  /* Test Case #1: HMAC-SHA-256 with 3-byte input and 32-byte key */
499
500
501
502
503
504
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10"
	       "1112131415161718 191a1b1c1d1e1f20"),
	    LDATA("abc"),
	    H("a21b1f5d4cf4f73a 4dd939750f7a066a"
		 "7f98cc131cb16a66 92759021cfab8181"));
505
506

  /* Test Case #2: HMAC-SHA-256 with 56-byte input and 32-byte key */
507
508
509
510
511
512
513
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10"
	       "1112131415161718 191a1b1c1d1e1f20"),
	    LDATA("abcdbcdecdefdefgefghfghighijhijk"
		  "ijkljklmklmnlmnomnopnopq"),
	    H("104fdc1257328f08 184ba73131c53cae"
		 "e698e36119421149 ea8c712456697d30"));
514
515
516

  /* Test Case #3: HMAC-SHA-256 with 112-byte (multi-block) input
     and 32-byte key */
517
518
519
520
521
522
523
524
525
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10"
	       "1112131415161718 191a1b1c1d1e1f20"),
	    LDATA("abcdbcdecdefdefgefghfghighijhijk"
		  "ijkljklmklmnlmnomnopnopqabcdbcde"
		  "cdefdefgefghfghighijhijkijkljklm"
		  "klmnlmnomnopnopq"),
	    H("470305fc7e40fe34 d3eeb3e773d95aab"
	      "73acf0fd060447a5 eb4595bf33a9d1a3"));
526
527

  /* Test Case #4:  HMAC-SHA-256 with 8-byte input and 32-byte key */
528
529
530
531
532
533
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"
	       "0b0b0b0b0b0b0b0b 0b0b0b0b0b0b0b0b"),
	    LDATA("Hi There"),
	    H("198a607eb44bfbc6 9903a0f1cf2bbdc5"
	      "ba0aa3f3d9ae3c1c 7a3b1696a0b68cf7"));
534
535

  /* Test Case #6: HMAC-SHA-256 with 50-byte input and 32-byte key */
536
537
538
539
540
541
542
543
544
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    HL("dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddddddddddddddd dddddddddddddddd"
	       "dddd"),
	    H("cdcb1220d1ecccea 91e53aba3092f962"
	      "e549fe6ce9ed7fdc 43191fbde45c30b0"));
545
546

  /* Test Case #7: HMAC-SHA-256 with 50-byte input and 37-byte key */
547
548
549
550
551
552
553
554
555
556
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("0102030405060708 090a0b0c0d0e0f10"
	       "1112131415161718 191a1b1c1d1e1f20"
	       "2122232425"),
	    HL("cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcd cdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("d4633c17f6fb8d74 4c66dee0f8f07455"
	      "6ec4af55ef079985 41468eb49bd2e917"));
557
558

  /* Test Case #8: HMAC-SHA-256 with 20-byte input and 32-byte key */
559
560
561
562
563
  HMAC_TEST(sha256, 16,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"
	       "0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("7546af01841fc09b 1ab9c3749a5f1c17"));
564
565

  /* Test Case #9: HMAC-SHA-256 with 54-byte input and 80-byte key */
566
567
568
569
570
571
572
573
574
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("6953025ed96f0c09 f80a96f78e6538db"
	      "e2e7b820e3dd970e 7ddd39091b32352f"));
575
576
577

  /* Test Case #10: HMAC-SHA-256 with 73-byte (multi-block) input
     and 80-byte key */
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"),
	    H("6355ac22e890d0a3 c8481a5ca4825bc8"
	      "84d3e7a1ff98a2fc 2ac7d8e064c3b2e6"));

  /* Additional test vectors, from Daniel Kahn Gillmor */
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA(""),
	    H("5c780648c90d121c50091c3a0c3afc1f"
	      "4ab847528005d99d9821ad3f341b651a"));
  
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("a"),
	    H("6142364c0646b0cfe426866f21d613e0"
	      "55a136a7d9b45d85685e080a09cec463"));
  
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("38"),
	    H("e49aa7839977e130ad87b63da9d4eb7b"
	      "263cd5a27c54a7604b6044eb35901171"));
  
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abc"),
	    H("e5ef49f545c7af933a9d18c7c562bc91"
	      "08583fd5cf00d9e0db351d6d8f8e41bc"));
  
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("message digest"),
	    H("373b04877180fea27a41a8fb8f88201c"
	      "a6268411ee3c80b01a424483eb9156e1"));
  
  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("eb5945d56eefbdb41602946ea6448d53"
	      "86b08d7d801a87f439fab52f8bb9736e"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("3798f363c57afa6edaffe39016ca7bad"
	      "efd1e670afb0e3987194307dec3197db"));

  HMAC_TEST(sha256, SHA256_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
	    H("c89a7039a62985ff813fe4509b918a43"
	      "6d7b1ffd8778e2c24dec464849fb6128"));

  /* Test vectors for sha384, from RFC 4231 */
  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b"),
	    LDATA("Hi There"),
	    H("afd03944d84895626b0825f4ab46907f"
	      "15f9dadbe4101ec682aa034c7cebc59c"
	      "faea9ea9076ede7f4af152e8b2fa9cb6"));

  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("af45d2e376484031617f78d2b58a6b1b"
	      "9c7ef464f5a01b47e42ec3736322445e"
	      "8e2240ca5e69e2c78b3239ecfab21649"));

  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaa"),
	    HL("dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddd"),
	    H("88062608d3e6ad8a0aa2ace014c8a86f"
	      "0aa635d947ac9febe83ef4e55966144b"
	      "2a5ab39dc13814b94e3ab6e101a34f27"));

  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    HL("0102030405060708090a0b0c0d0e0f10"
	       "111213141516171819"),
	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("3e8a69b7783c25851933ab6290af6ca7"
	      "7a9981480850009cc5577c6e1f573b4e"
	      "6801dd23c4a7d679ccf8a386c674cffb"));

  HMAC_TEST(sha384, 16,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("3abf34c3503b2a23a46efc619baef897"));

  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("4ece084485813e9088d2c63a041bc5b4"
	      "4f9ef1012a2b588f3cd11f05033ac4c6"
	      "0c2ef6ab4030fe8296248df163f44952"));

  HMAC_TEST(sha384, SHA384_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("This is a test using a larger than block-size ke"
		  "y and a larger than block-size data. The key nee"
		  "ds to be hashed before being used by the HMAC al"
		  "gorithm."),
	    H("6617178e941f020d351e2f254e8fd32c"
	      "602420feb0b8fb9adccebb82461e99c5"
	      "a678cc31e799176d3860e6110c46523e"));

  /* Test vectors for sha512, from RFC 4231 */
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b"),
	    LDATA("Hi There"),
	    H("87aa7cdea5ef619d4ff0b4241a1d6cb0"
	      "2379f4e2ce4ec2787ad0b30545e17cde"
	      "daa833b7d6b8a702038b274eaea3f4e4"
	      "be9d914eeb61f1702e696c203a126854"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("Jefe"),
	    LDATA("what do ya want for nothing?"),
	    H("164b7a7bfcf819e2e395fbe73b56e0a3"
	      "87bd64222e831fd610270cd7ea250554"
	      "9758bf75c05a994a6d034f65f8f0e6fd"
	      "caeab1a34d4a6b4b636e070a38bce737"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaa"),
	    HL("dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddd"),
	    H("fa73b0089d56a284efb0f0756c890be9"
	      "b1b5dbdd8ee81a3655f83e33b2279d39"
	      "bf3e848279a722c806b485a47e67c807"
	      "b946a337bee8942674278859e13292fb"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("0102030405060708090a0b0c0d0e0f10"
	       "111213141516171819"),
	    HL("cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
	       "cdcd"),
	    H("b0ba465637458c6990e5a8c5f61d4af7"
	      "e576d97ff94b872de76f8050361ee3db"
	      "a91ca5c11aa25eb4d679275cc5788063"
	      "a5f19741120c4f2de2adebeb10a298dd"));

  HMAC_TEST(sha512, 16,
	    HL("0c0c0c0c0c0c0c0c 0c0c0c0c0c0c0c0c 0c0c0c0c"),
	    LDATA("Test With Truncation"),
	    H("415fad6271580a531d4179bc891d87a6"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("Test Using Larger Than Block-Size Key - Hash Key First"),
	    H("80b24263c7c1a3ebb71493c1dd7be8b4"
	      "9b46d1f41b4aeec1121b013783f8f352"
	      "6b56d037e05f2598bd0fd2215d6a1e52"
	      "95e64f73f63f0aec8b915a985d786598"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaa"),
	    LDATA("This is a test using a larger than block-size ke"
		  "y and a larger than block-size data. The key nee"
		  "ds to be hashed before being used by the HMAC al"
		  "gorithm."),
	    H("e37b6a775dc87dbaa4dfa9f96e5e3ffd"
	      "debd71f8867289865df5a32d20cdc944"
	      "b6022cac3c4982b10d5eeb55c3e4de15"
	      "134676fb6de0446065c97440fa8c6a58"));

  /* Additional test vectors, from Daniel Kahn Gillmor */
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA(""),
	    H("34316413c2d6940572d0bbbf099d529d"
	      "148b424533cf562bc1b365f530e21a31"
	      "799fc51cef78060cc6f448a8e5d780c2"
	      "6cdf20d4c3e6f27fe5ef576bbd05e855"));
  
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("a"),
	    H("cf1948507378bc3ab58cb6ec87f4d456"
	      "b90d3298395c29873f1ded1e111b50fe"
	      "c336ed24684bf19716efc309212f37aa"
	      "715cfb9ecccf3af13691ded167b4b336"));
  
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("38"),
	    H("b8201784216ce01b83cdd282616c6e89"
	      "644c6dfd1269ed8580bbc39b92add364"
	      "c2b2a2018cffb1915e8625e473b67d0f"
	      "e54a50e475dfa0e2b1a97bac1383792c"));
  
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abc"),
	    H("f097ee08b8c44e847a384f9fd645e35e"
	      "4816baa9791ba39d3dc611210500b044"
	      "873ee296bf1047dc06daa201a5767192"
	      "5b73b4ea59c60114881c8287d0699c83"));
  
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("message digest"),
	    H("921a441a884b83c76a8526da8e60d60d"
	      "17ded4eee5c29375e0d93717669a4c3e"
	      "eba7473e95f7c1a2a85afc24a0adbc4d"
	      "6c2bdd6ca6cab8b18d19f82d4a6c51bc"));
  
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("abcdefghijklmnopqrstuvwxyz"),
	    H("640054c96f35815095617d0a8c956066"
	      "1a6ff46bfb39110333b2c52c8866abfb"
	      "59d9152c9b0948c1ed65c3fd72a8fb82"
	      "190acc8830770afe5b0c5b6414c75a77"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
	    H("835a4f5b3750b4c1fccfa88da2f746a4"
	      "900160c9f18964309bb736c13b59491b"
	      "8e32d37b724cc5aebb0f554c6338a3b5"
	      "94c4ba26862b2dadb59b7ede1d08d53e"));

  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("monkey monkey monkey monkey"),
	    LDATA("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
	    H("fdf83dc879e3476c8e8aceff2bf6fece"
	      "2e4f39c7e1a167845465bb549dfa5ffe"
	      "997e6c7cf3720eae51ed2b00ad2a8225"
	      "375092290edfa9d48ec7e4bc8e276088"));

  /* Additional test vectors, from
     draft-kelly-ipsec-ciph-sha2-01.txt */
862
863

  /* Test case AUTH512-1: */
864
865
866
867
868
869
870
871
872
873
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"
	       "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"),
	    LDATA("Hi There"),
	    H("637edc6e01dce7e6742a99451aae82df"
	      "23da3e92439e590e43e761b33e910fb8"
	      "ac2878ebd5803f6f0b61dbce5e251ff8"
	      "789a4722c1be65aea45fd464e89f8f5b"));
874
875

  /* Test case AUTH512-2: */
876
877
878
879
880
881
882
883
884
885
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    LDATA("JefeJefeJefeJefe"
		  "JefeJefeJefeJefe"
		  "JefeJefeJefeJefe"
		  "JefeJefeJefeJefe"),	    
	    LDATA("what do ya want for nothing?"),
	    H("cb370917ae8a7ce28cfd1d8f4705d614"
	      "1c173b2a9362c15df235dfb251b15454"
	      "6aa334ae9fb9afc2184932d8695e397b"
	      "fa0ffb93466cfcceaae38c833b7dba38"));
886
887

  /* Test case AUTH512-3: */
888
889
890
891
892
893
894
895
896
897
898
899
900
  HMAC_TEST(sha512, SHA512_DIGEST_SIZE,
	    HL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
	    HL("dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddddddddddddddddddddddddddddddd"
	       "dddd"),
	    H("2ee7acd783624ca9398710f3ee05ae41"
	      "b9f9b0510c87e49e586cc9bf961733d8"
	      "623c7b55cebefccf02d5581acc1c9d5f"
	      "b1ff68a1de45509fbe4da9a433922655"));
901
902

  /* Test case AUTH512-3 from same document seems broken. */
Niels Möller's avatar
Niels Möller committed
903
  
Niels Möller's avatar
Niels Möller committed
904
905
  SUCCESS();
}