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