Commit | Line | Data |
6bc89f92 |
1 | # Test Vectors for HMAC-SHA-256/384/512 |
2 | # |
3 | # Vectors and script courtesy of Adam Woodbury, The MITRE Corporation |
4 | |
5 | use Test; |
6 | use strict; |
7 | use integer; |
8 | use Digest::SHA qw(hmac_sha256_hex hmac_sha384_hex hmac_sha512_hex); |
9 | |
41c686de |
10 | BEGIN { |
77d2a621 |
11 | if ($ENV{PERL_CORE}) { |
12 | chdir 't' if -d 't'; |
13 | @INC = '../lib'; |
14 | } |
41c686de |
15 | } |
16 | |
6bc89f92 |
17 | BEGIN { plan tests => 21 } |
18 | |
19 | # Use RFC 2202 data/key values for 512-bit blocks |
20 | |
21 | my @vecs_bs512 = ( |
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 | |
31 | my @keys_bs512 = ( |
32 | chr(0x0b) x 20, |
33 | "Jefe", |
34 | chr(0xaa) x 20, |
35 | "", |
36 | chr(0x0c) x 20, |
37 | chr(0xaa) x 80, |
38 | chr(0xaa) x 80 |
39 | ); |
40 | |
41 | # Lengthen final RFC 2202 data/key values for 1024-bit blocks |
42 | |
43 | my @vecs_bs1024 = ( |
44 | "Hi There", |
45 | "what do ya want for nothing?", |
46 | chr(0xdd) x 50, |
47 | chr(0xcd) x 50, |
48 | "Test With Truncation", |
49 | "Test Using Larger Than Block-Size Key - Hash Key First", |
50 | "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data. The Larger Block-Sizes Make For Much Longer Test Vectors" |
51 | ); |
52 | |
53 | my @keys_bs1024 = ( |
54 | chr(0x0b) x 20, |
55 | "Jefe", |
56 | chr(0xaa) x 20, |
57 | "", |
58 | chr(0x0c) x 20, |
59 | chr(0xaa) x 200, |
60 | chr(0xaa) x 200 |
61 | ); |
62 | |
63 | my @hmac256rsp = ( |
64 | "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7", |
65 | "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", |
66 | "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe", |
67 | "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b", |
68 | "a3b6167473100ee06e0c796c2955552bfa6f7c0a6a8aef8b93f860aab0cd20c5", |
69 | "6953025ed96f0c09f80a96f78e6538dbe2e7b820e3dd970e7ddd39091b32352f", |
70 | "6355ac22e890d0a3c8481a5ca4825bc884d3e7a1ff98a2fc2ac7d8e064c3b2e6" |
71 | ); |
72 | |
73 | my @hmac384rsp = ( |
74 | "afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6", |
75 | "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649", |
76 | "88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27", |
77 | "3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb", |
78 | "3abf34c3503b2a23a46efc619baef897f4c8e42c934ce55ccbae9740fcbc1af4ca62269e2a37cd88ba926341efe4aeea", |
79 | "ec629fe0dc1fab504fc1c89572d6573cf15c3a4b5b69d53f0c13849561a6c13e153af48d2538ce056a3fe10d69da16c3", |
80 | "07109d2c6c2fdcac39c3a8b5f36fc9a69e029d3d8647cc3e4ddb77888418c5c09d807942e5f96d17ee9fd46aed64b7f2" |
81 | ); |
82 | |
83 | my @hmac512rsp = ( |
84 | "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854", |
85 | "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737", |
86 | "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb", |
87 | "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd", |
88 | "415fad6271580a531d4179bc891d87a650188707922a4fbb36663a1eb16da008711c5b50ddd0fc235084eb9d3364a1454fb2ef67cd1d29fe6773068ea266e96b", |
89 | "9dc6330f4c966b62b735d565343cb77413deccdf42a92d9ef5e4e2ae33f6c924bbc8e34c47111bc069482d4dbcfee148419a6547f2d01500e8160b39cc2e4ae8", |
90 | "396ed3a17cef82cddbd987ea66a5dd1f38b68167df31f049463b85fa10b531d0e90d1052f8c9c7cda263468ec3f980a8fec06213c2944c92a0ac95a2d8ade76d" |
91 | ); |
92 | |
93 | my $i = 0x01; |
94 | $keys_bs512[3] .= chr($i++) while (length($keys_bs512[3]) < 25); |
95 | $i = 0x01; |
96 | $keys_bs1024[3] .= chr($i++) while (length($keys_bs1024[3]) < 25); |
97 | |
98 | for ($i = 0; $i < @vecs_bs512; $i++) { |
99 | ok( |
100 | hmac_sha256_hex($vecs_bs512[$i], $keys_bs512[$i]), |
101 | $hmac256rsp[$i] |
102 | ); |
103 | } |
104 | |
105 | my $skip = hmac_sha384_hex("", "") ? 0 : 1; |
106 | |
107 | for ($i = 0; $i < @vecs_bs1024; $i++) { |
108 | skip( |
109 | $skip, |
110 | hmac_sha384_hex($vecs_bs1024[$i], $keys_bs1024[$i]), |
111 | $hmac384rsp[$i] |
112 | ); |
113 | } |
114 | |
115 | for ($i = 0; $i < @vecs_bs1024; $i++) { |
116 | skip( |
117 | $skip, |
118 | hmac_sha512_hex($vecs_bs1024[$i], $keys_bs1024[$i]), |
119 | $hmac512rsp[$i] |
120 | ); |
121 | } |