Commit | Line | Data |
6bc89f92 |
1 | # Test against short bitwise vectors from Jim Gillogly and Francois Grieu |
2 | # |
3 | # http://www.chiark.greenend.org.uk/pipermail/ukcrypto/1999-February/003538.html |
4 | |
5 | use Test; |
6 | use strict; |
7 | use integer; |
8 | use Digest::SHA; |
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 | # SHA-1 Test Vectors |
18 | # |
19 | # In the following we use the notation bitstring#n to mean a bitstring |
20 | # repeated n (in decimal) times, and we use | for concatenation. |
21 | # Therefore 110#3|1 is 1101101101. |
22 | # |
23 | # 110#148|11 : CE7387AE 577337BE 54EA94F8 2C842E8B E76BC3E1 |
24 | # 110#149 : DE244F06 3142CB2F 4C903B7F 7660577F 9E0D8791 |
25 | # 110#149|1 : A3D29824 27AE39C8 920CA5F4 99D6C2BD 71EBF03C |
26 | # 110#149|11 : 351AAB58 FF93CF12 AF7D5A58 4CFC8F7D 81023D10 |
27 | # |
28 | # 110#170 : 99638692 1E480D4E 2955E727 5DF3522C E8F5AB6E |
29 | # 110#170|1 : BB5F4AD4 8913F51B 157EB985 A5C2034B 8243B01B |
30 | # 110#170|11 : 9E92C554 2237B957 BA2244E8 141FDB66 DEC730A5 |
31 | # 110#171 : 2103E454 DA4491F4 E32DD425 A3341DC9 C2A90848 |
32 | # |
33 | # 011#490 : B4B18049 DE405027 528CD9E7 4B2EC540 D4E6F06B |
34 | # 011#490|0 : 34C63356 B3087427 20AB9669 14EB0FC9 26E4294B |
35 | # 011#490|01 : 75FACE18 02B9F84F 326368AB 06E73E05 02E9EA34 |
36 | # 011#491 : 7C2C3D62 F6AEC28D 94CDF93F 02E739E7 490698A1 |
37 | # |
38 | |
39 | my(@vec); |
40 | |
77d2a621 |
41 | BEGIN { |
6bc89f92 |
42 | @vec = ( |
43 | "110",148,"11","ce7387ae577337be54ea94f82c842e8be76bc3e1", |
44 | "110",149,"","de244f063142cb2f4c903b7f7660577f9e0d8791", |
45 | "110",149,"1","a3d2982427ae39c8920ca5f499d6c2bd71ebf03c", |
46 | "110",149,"11","351aab58ff93cf12af7d5a584cfc8f7d81023d10", |
47 | "110",170,"","996386921e480d4e2955e7275df3522ce8f5ab6e", |
48 | "110",170,"1","bb5f4ad48913f51b157eb985a5c2034b8243b01b", |
49 | "110",170,"11","9e92c5542237b957ba2244e8141fdb66dec730a5", |
50 | "110",171,"","2103e454da4491f4e32dd425a3341dc9c2a90848", |
51 | "011",490,"","b4b18049de405027528cd9e74b2ec540d4e6f06b", |
52 | "011",490,"0","34c63356b308742720ab966914eb0fc926e4294b", |
53 | "011",490,"01","75face1802b9f84f326368ab06e73e0502e9ea34", |
54 | "011",491,"","7c2c3d62f6aec28d94cdf93f02e739e7490698a1", |
55 | ); |
56 | plan tests => scalar(@vec) / 4; |
57 | } |
58 | |
59 | my $bitstr; |
60 | my $bitcnt; |
61 | my $ctx = Digest::SHA->new(1); |
62 | |
63 | for (my $i = 0; $i < @vec/4; $i++) { |
64 | $bitstr = ($vec[4*$i] x $vec[4*$i+1]) . $vec[4*$i+2]; |
65 | $bitcnt = length($bitstr); |
66 | $bitstr = pack("B*", $bitstr); |
67 | ok($ctx->add_bits($bitstr, $bitcnt)->hexdigest, $vec[4*$i+3]); |
68 | } |