1 # Test Vectors for HMAC-SHA-256/384/512
3 # Vectors and initial script courtesy of Adam Woodbury, The MITRE Corporation
10 $MODULE = ($ENV{PERL_CORE} || -e "SHA.pm") ? "Digest::SHA" : "Digest::SHA::PurePerl";
11 eval "require $MODULE" || die $@;
12 $MODULE->import(qw(hmac_sha256_hex hmac_sha384_hex hmac_sha512_hex));
16 if ($ENV{PERL_CORE}) {
22 my @plex = map { eval } <DATA>;
24 my $numtests = scalar(@plex) / 3;
25 print "1..$numtests\n";
27 # Use RFC 2202 data/key values for 512-bit blocks
29 my @data_bs512 = splice(@plex, 0, 7);
30 my @keys_bs512 = splice(@plex, 0, 7);
31 my @hmac256rsp = splice(@plex, 0, 7);
33 # Lengthen final RFC 2202 data/key values for 1024-bit blocks
35 my @data_bs1024 = splice(@plex, 0, 7);
36 my @keys_bs1024 = splice(@plex, 0, 7);
37 my @hmac384rsp = splice(@plex, 0, 7);
39 my @dat2_bs1024 = splice(@plex, 0, 7);
40 my @key2_bs1024 = splice(@plex, 0, 7);
41 my @hmac512rsp = splice(@plex, 0, 7);
47 hmac_sha256_hex(shift @data_bs512, shift @keys_bs512)
49 print "ok ", $testnum++, "\n";
52 my $skip = hmac_sha384_hex("", "") ? 0 : 1;
54 while (@data_bs1024) {
56 print "ok ", $testnum++,
57 $skip ? " # skip: no 64 bit" : "", "\n";
62 hmac_sha384_hex(shift @data_bs1024, shift @keys_bs1024)
64 print "ok ", $testnum++, "\n";
67 while (@dat2_bs1024) {
69 print "ok ", $testnum++,
70 $skip ? " # skip: no 64 bit" : "", "\n";
75 hmac_sha512_hex(shift @dat2_bs1024, shift @key2_bs1024)
77 print "ok ", $testnum++, "\n";
82 "what do ya want for nothing?"
85 "Test With Truncation"
86 "Test Using Larger Than Block-Size Key - Hash Key First"
87 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"
91 join("", map { chr } (1 .. 25))
95 "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"
96 "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"
97 "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe"
98 "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b"
99 "a3b6167473100ee06e0c796c2955552bfa6f7c0a6a8aef8b93f860aab0cd20c5"
100 "6953025ed96f0c09f80a96f78e6538dbe2e7b820e3dd970e7ddd39091b32352f"
101 "6355ac22e890d0a3c8481a5ca4825bc884d3e7a1ff98a2fc2ac7d8e064c3b2e6"
103 "what do ya want for nothing?"
106 "Test With Truncation"
107 "Test Using Larger Than Block-Size Key - Hash Key First"
108 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data. The Larger Block-Sizes Make For Much Longer Test Vectors"
112 join("", map { chr } (1 .. 25))
116 "afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6"
117 "af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649"
118 "88062608d3e6ad8a0aa2ace014c8a86f0aa635d947ac9febe83ef4e55966144b2a5ab39dc13814b94e3ab6e101a34f27"
119 "3e8a69b7783c25851933ab6290af6ca77a9981480850009cc5577c6e1f573b4e6801dd23c4a7d679ccf8a386c674cffb"
120 "3abf34c3503b2a23a46efc619baef897f4c8e42c934ce55ccbae9740fcbc1af4ca62269e2a37cd88ba926341efe4aeea"
121 "ec629fe0dc1fab504fc1c89572d6573cf15c3a4b5b69d53f0c13849561a6c13e153af48d2538ce056a3fe10d69da16c3"
122 "07109d2c6c2fdcac39c3a8b5f36fc9a69e029d3d8647cc3e4ddb77888418c5c09d807942e5f96d17ee9fd46aed64b7f2"
124 "what do ya want for nothing?"
127 "Test With Truncation"
128 "Test Using Larger Than Block-Size Key - Hash Key First"
129 "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data. The Larger Block-Sizes Make For Much Longer Test Vectors"
133 join("", map { chr } (1 .. 25))
137 "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854"
138 "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"
139 "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb"
140 "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd"
141 "415fad6271580a531d4179bc891d87a650188707922a4fbb36663a1eb16da008711c5b50ddd0fc235084eb9d3364a1454fb2ef67cd1d29fe6773068ea266e96b"
142 "9dc6330f4c966b62b735d565343cb77413deccdf42a92d9ef5e4e2ae33f6c924bbc8e34c47111bc069482d4dbcfee148419a6547f2d01500e8160b39cc2e4ae8"
143 "396ed3a17cef82cddbd987ea66a5dd1f38b68167df31f049463b85fa10b531d0e90d1052f8c9c7cda263468ec3f980a8fec06213c2944c92a0ac95a2d8ade76d"