sl@0
|
1 |
Test suite from http://csrc.nist.gov/cryptval/shs.html
|
sl@0
|
2 |
|
sl@0
|
3 |
Sample Vectors for SHA-1 Testing
|
sl@0
|
4 |
|
sl@0
|
5 |
This file describes tests and vectors that can be used in verifying the correctness of
|
sl@0
|
6 |
an SHA-1 implementation. However, use of these vectors does not take the place of validation
|
sl@0
|
7 |
obtained through the Cryptographic Module Validation Program.
|
sl@0
|
8 |
|
sl@0
|
9 |
There are three areas of the Secure Hash Standard for which test vectors are supplied:
|
sl@0
|
10 |
short messages of varying length, selected long messages, and pseudorandomly generated messages.
|
sl@0
|
11 |
Since it is possible for an implementation to correctly handle the hashing of byte-oriented
|
sl@0
|
12 |
messages (and not messages of a non-byte length), the SHS tests each come in two flavors. For
|
sl@0
|
13 |
both byte oriented and bit oriented messages, the message lengths are given in bits.
|
sl@0
|
14 |
|
sl@0
|
15 |
Type I Test: Messages of Varying Length
|
sl@0
|
16 |
|
sl@0
|
17 |
An implementation of the SHS must be able to correctly generate message digests for
|
sl@0
|
18 |
messages of arbitrary length. This functionality can be tested by supplying the implementation
|
sl@0
|
19 |
with 1025 pseudorandomly generated messages with lengths from 0 to 1024 bits (for an implementation
|
sl@0
|
20 |
that only hashes byte-oriented data correctly, 129 messages of length 0, 8, 16, 24,...,1024 bits
|
sl@0
|
21 |
will be supplied).
|
sl@0
|
22 |
|
sl@0
|
23 |
Type II Test: Selected Long Messages
|
sl@0
|
24 |
|
sl@0
|
25 |
Additional testing of an implementation can be performed by testing that the implementation
|
sl@0
|
26 |
can correctly generate digests for longer messages. A list of 100 messages, each of length > 1024,
|
sl@0
|
27 |
is supplied. These can be used to verify the hashing of longer message lengths. For bit oriented
|
sl@0
|
28 |
testing the messages are from 1025 to 103425 bits long (length=1025+i*1024, where 0<=i<100). For
|
sl@0
|
29 |
byte oriented testing the messages are from 1032 to 103432 (length=1032+i*1024, where 0<=i<100).
|
sl@0
|
30 |
|
sl@0
|
31 |
Type III Test: Pseudorandomly Generated Messages
|
sl@0
|
32 |
|
sl@0
|
33 |
This test determines whether the implementation can compute message digests for messages
|
sl@0
|
34 |
that are generated using a given seed. A sequence of 100 message digests is generated using this
|
sl@0
|
35 |
seed. The digests are generated according to the following pseudocode:
|
sl@0
|
36 |
|
sl@0
|
37 |
procedure MonteCarlo(string SEED)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
integer i, j, a;
|
sl@0
|
40 |
string M;
|
sl@0
|
41 |
|
sl@0
|
42 |
M := SEED;
|
sl@0
|
43 |
for j = 0 to 99 do {
|
sl@0
|
44 |
for i = 1 to 50000 do {
|
sl@0
|
45 |
for a = 1 to (j/4*8 + 24) do M := M || ’0’; /*‘0' is the binary zero bit. */
|
sl@0
|
46 |
M := M || i; /* Here, the value for ‘i’ is expressed as a 32-bit word
|
sl@0
|
47 |
and concatenated with ‘M’. The first bit
|
sl@0
|
48 |
concatenated with ‘M’ is the most significant bit of
|
sl@0
|
49 |
this 32-bit word. */
|
sl@0
|
50 |
M := SHA(M);
|
sl@0
|
51 |
}
|
sl@0
|
52 |
print(M);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
NOTE: In the above procedure, || denotes concatenation. Also, M || i denotes appending the 32-bit
|
sl@0
|
57 |
word representing the value ‘i’, as defined in section 2 of the SHS. Within the procedure, M is a string
|
sl@0
|
58 |
of variable length. The initial length of 416 bits ensures that the length of M never exceeds 512 bits
|
sl@0
|
59 |
during execution of the above procedure, and it ensures that messages will be of a byte length. Each
|
sl@0
|
60 |
element printed should be 160 bits in length.
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
File formats:
|
sl@0
|
64 |
|
sl@0
|
65 |
There are two files included for each test type (bit-oriented and byte-oriented). One file contains
|
sl@0
|
66 |
the messages and the other file contains the hashes.
|
sl@0
|
67 |
|
sl@0
|
68 |
The message files provided use "compact strings" to store the message values. Compact strings are
|
sl@0
|
69 |
used to represented the messages in a compact form. A compact string has the form
|
sl@0
|
70 |
z || b || n(1) || n(2) || ... || n(z)
|
sl@0
|
71 |
where z>=0 that represents the number of n, b is either 0 or 1, and each n(i) is a decimal integer
|
sl@0
|
72 |
representing a positive number. The length of the compact string is given by the summation of the n(i).
|
sl@0
|
73 |
|
sl@0
|
74 |
The compact string is interpreted as the representation of the bit string consisting of b repeated n(1) times,
|
sl@0
|
75 |
followed by 1-b repeated n(2) times, followed by b repeated n(3) times, and so on.
|
sl@0
|
76 |
|
sl@0
|
77 |
Example:
|
sl@0
|
78 |
M = 5 1 7 13 5 1 2
|
sl@0
|
79 |
where z = 5 and b = 1. Then the compact string M represents the bit string
|
sl@0
|
80 |
1111111000000000000011111011
|
sl@0
|
81 |
where 1 is repeated 7 times, 0 is repeated 13 times, 1 is repeated 5 times,
|
sl@0
|
82 |
0 is repeated 1 time, and 1 is repeated 2 times.
|
sl@0
|
83 |
|