1# Test against long bitwise vectors from Jim Gillogly and Francois Grieu 2 3use strict; 4use Digest::SHA; 5 6# SHA-1 Test Vectors 7# 8# In the following we use the notation bitstring#n to mean a bitstring 9# repeated n (in decimal) times, and we use | for concatenation. 10# Therefore 110#3|1 is 1101101101. 11# 12# Here is a set near 2^32 bits to test the roll-over in the length 13# field from one to two 32-bit words: 14# 15# 110#1431655764|11 1eef5a18 969255a3 b1793a2a 955c7ec2 8cd221a5 16# 110#1431655765| 7a1045b9 14672afa ce8d90e6 d19b3a6a da3cb879 17# 110#1431655765|1 d5e09777 a94f1ea9 240874c4 8d9fecb6 b634256b 18# 110#1431655765|11 eb256904 3c3014e5 1b2862ae 6eb5fb4e 0b851d99 19# 20# 011#1431655764|01 4CB0C4EF 69143D5B F34FC35F 1D4B19F6 ECCAE0F2 21# 011#1431655765 47D92F91 1FC7BB74 DE00ADFC 4E981A81 05556D52 22# 011#1431655765|0 A3D7438C 589B0B93 2AA91CC2 446F06DF 9ABC73F0 23# 011#1431655765|01 3EEE3E1E 28DEDE2C A444D68D A5675B2F AAAB3203 24 25my @vec110 = ( # 110 rep 1431655764 26 "11", "1eef5a18969255a3b1793a2a955c7ec28cd221a5", 27 "110", "7a1045b914672aface8d90e6d19b3a6ada3cb879", 28 "1101", "d5e09777a94f1ea9240874c48d9fecb6b634256b", 29 "11011", "eb2569043c3014e51b2862ae6eb5fb4e0b851d99" 30); 31 32my @vec011 = ( # 011 rep 1431655764 33 "01", "4cb0c4ef69143d5bf34fc35f1d4b19f6eccae0f2", 34 "011", "47d92f911fc7bb74de00adfc4e981a8105556d52", 35 "0110", "a3d7438c589b0b932aa91cc2446f06df9abc73f0", 36 "01101", "3eee3e1e28dede2ca444d68da5675b2faaab3203" 37); 38 39my($STATE110, $STATE011) = ('', ''); 40for (1 .. 8) { my $line = <DATA>; $STATE110 .= $line } 41for (1 .. 8) { my $line = <DATA>; $STATE011 .= $line } 42 43my $testnum = 1; 44print "1..", scalar(@vec110)/2 + scalar(@vec011)/2, "\n"; 45 46my $state110 = Digest::SHA->putstate($STATE110); 47while (@vec110) { 48 my $state = $state110->clone; 49 $state->add_bits(shift @vec110); 50 print "not " unless $state->hexdigest eq (shift @vec110); 51 print "ok ", $testnum++, "\n"; 52} 53 54my $state011 = Digest::SHA->putstate($STATE011); 55while (@vec011) { 56 my $state = $state011->clone; 57 $state->add_bits(shift @vec011); 58 print "not " unless $state->hexdigest eq (shift @vec011); 59 print "ok ", $testnum++, "\n"; 60} 61 62__DATA__ 63alg:1 64H:dfc51a14:87b4a4b7:ecf19acd:8cbbe40e:03a435f8:00000000:00000000:00000000 65block:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d 66blockcnt:508 67lenhh:0 68lenhl:0 69lenlh:0 70lenll:4294967292 71alg:1 72H:7950cbe2:86a45aa0:91ff7dff:29015b42:3912e764:00000000:00000000:00000000 73block:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6:db:6d:b6 74blockcnt:508 75lenhh:0 76lenhl:0 77lenlh:0 78lenll:4294967292 79