Commit | Line | Data |
6bc89f92 |
1 | # HMAC-SHA-256 test vectors from draft-ietf-ipsec-ciph-sha-256-01.txt |
2 | |
3 | use Test; |
4 | use strict; |
5 | use integer; |
6 | use Digest::SHA qw(hmac_sha256_hex); |
7 | |
41c686de |
8 | BEGIN { |
77d2a621 |
9 | if ($ENV{PERL_CORE}) { |
10 | chdir 't' if -d 't'; |
11 | @INC = '../lib'; |
12 | } |
41c686de |
13 | } |
14 | |
6bc89f92 |
15 | my(@data); |
16 | |
77d2a621 |
17 | BEGIN { |
6bc89f92 |
18 | @data = ( |
19 | "abc", |
20 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
21 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
22 | "Hi There", |
23 | "what do ya want for nothing?", |
24 | chr(0xdd) x 50, |
25 | chr(0xcd) x 50, |
26 | "Test With Truncation", |
27 | "Test Using Larger Than Block-Size Key - Hash Key First", |
28 | "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" |
29 | ); |
30 | plan tests => scalar(@data); |
31 | } |
32 | |
33 | my $k1 = pack("H*", "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); |
34 | my $k2 = pack("H*", "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425"); |
35 | |
36 | my @key = ( |
37 | $k1, |
38 | $k1, |
39 | $k1, |
40 | chr(0x0b) x 32, |
41 | "Jefe", |
42 | chr(0xaa) x 32, |
43 | $k2, |
44 | chr(0x0c) x 32, |
45 | chr(0xaa) x 80, |
46 | chr(0xaa) x 80 |
47 | ); |
48 | |
49 | my @hmac256rsp = ( |
50 | "a21b1f5d4cf4f73a4dd939750f7a066a7f98cc131cb16a6692759021cfab8181", |
51 | "104fdc1257328f08184ba73131c53caee698e36119421149ea8c712456697d30", |
52 | "470305fc7e40fe34d3eeb3e773d95aab73acf0fd060447a5eb4595bf33a9d1a3", |
53 | "198a607eb44bfbc69903a0f1cf2bbdc5ba0aa3f3d9ae3c1c7a3b1696a0b68cf7", |
54 | "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", |
55 | "cdcb1220d1ecccea91e53aba3092f962e549fe6ce9ed7fdc43191fbde45c30b0", |
56 | "d4633c17f6fb8d744c66dee0f8f074556ec4af55ef07998541468eb49bd2e917", |
57 | "7546af01841fc09b1ab9c3749a5f1c17d4f589668a587b2700a9c97c1193cf42", |
58 | "6953025ed96f0c09f80a96f78e6538dbe2e7b820e3dd970e7ddd39091b32352f", |
59 | "6355ac22e890d0a3c8481a5ca4825bc884d3e7a1ff98a2fc2ac7d8e064c3b2e6" |
60 | ); |
61 | |
62 | # do the first one by hand to test multi-argument data feed |
63 | |
64 | ok(hmac_sha256_hex("a", "b", "c", $k1), $hmac256rsp[0]); |
65 | |
66 | for (my $i = 1; $i < @data; $i++) { |
67 | ok( |
68 | hmac_sha256_hex($data[$i], $key[$i]), |
69 | $hmac256rsp[$i] |
70 | ); |
71 | } |