sl@0: Test suite from http://csrc.nist.gov/cryptval/shs.html sl@0: sl@0: Sample Vectors for SHA-1 Testing sl@0: sl@0: This file describes tests and vectors that can be used in verifying the correctness of sl@0: an SHA-1 implementation. However, use of these vectors does not take the place of validation sl@0: obtained through the Cryptographic Module Validation Program. sl@0: sl@0: There are three areas of the Secure Hash Standard for which test vectors are supplied: sl@0: short messages of varying length, selected long messages, and pseudorandomly generated messages. sl@0: Since it is possible for an implementation to correctly handle the hashing of byte-oriented sl@0: messages (and not messages of a non-byte length), the SHS tests each come in two flavors. For sl@0: both byte oriented and bit oriented messages, the message lengths are given in bits. sl@0: sl@0: Type I Test: Messages of Varying Length sl@0: sl@0: An implementation of the SHS must be able to correctly generate message digests for sl@0: messages of arbitrary length. This functionality can be tested by supplying the implementation sl@0: with 1025 pseudorandomly generated messages with lengths from 0 to 1024 bits (for an implementation sl@0: that only hashes byte-oriented data correctly, 129 messages of length 0, 8, 16, 24,...,1024 bits sl@0: will be supplied). sl@0: sl@0: Type II Test: Selected Long Messages sl@0: sl@0: Additional testing of an implementation can be performed by testing that the implementation sl@0: can correctly generate digests for longer messages. A list of 100 messages, each of length > 1024, sl@0: is supplied. These can be used to verify the hashing of longer message lengths. For bit oriented sl@0: testing the messages are from 1025 to 103425 bits long (length=1025+i*1024, where 0<=i<100). For sl@0: byte oriented testing the messages are from 1032 to 103432 (length=1032+i*1024, where 0<=i<100). sl@0: sl@0: Type III Test: Pseudorandomly Generated Messages sl@0: sl@0: This test determines whether the implementation can compute message digests for messages sl@0: that are generated using a given seed. A sequence of 100 message digests is generated using this sl@0: seed. The digests are generated according to the following pseudocode: sl@0: sl@0: procedure MonteCarlo(string SEED) sl@0: { sl@0: integer i, j, a; sl@0: string M; sl@0: sl@0: M := SEED; sl@0: for j = 0 to 99 do { sl@0: for i = 1 to 50000 do { sl@0: for a = 1 to (j/4*8 + 24) do M := M || ’0’; /*‘0' is the binary zero bit. */ sl@0: M := M || i; /* Here, the value for ‘i’ is expressed as a 32-bit word sl@0: and concatenated with ‘M’. The first bit sl@0: concatenated with ‘M’ is the most significant bit of sl@0: this 32-bit word. */ sl@0: M := SHA(M); sl@0: } sl@0: print(M); sl@0: } sl@0: } sl@0: sl@0: NOTE: In the above procedure, || denotes concatenation. Also, M || i denotes appending the 32-bit sl@0: word representing the value ‘i’, as defined in section 2 of the SHS. Within the procedure, M is a string sl@0: of variable length. The initial length of 416 bits ensures that the length of M never exceeds 512 bits sl@0: during execution of the above procedure, and it ensures that messages will be of a byte length. Each sl@0: element printed should be 160 bits in length. sl@0: sl@0: sl@0: File formats: sl@0: sl@0: There are two files included for each test type (bit-oriented and byte-oriented). One file contains sl@0: the messages and the other file contains the hashes. sl@0: sl@0: The message files provided use "compact strings" to store the message values. Compact strings are sl@0: used to represented the messages in a compact form. A compact string has the form sl@0: z || b || n(1) || n(2) || ... || n(z) sl@0: 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: representing a positive number. The length of the compact string is given by the summation of the n(i). sl@0: sl@0: The compact string is interpreted as the representation of the bit string consisting of b repeated n(1) times, sl@0: followed by 1-b repeated n(2) times, followed by b repeated n(3) times, and so on. sl@0: sl@0: Example: sl@0: M = 5 1 7 13 5 1 2 sl@0: where z = 5 and b = 1. Then the compact string M represents the bit string sl@0: 1111111000000000000011111011 sl@0: where 1 is repeated 7 times, 0 is repeated 13 times, 1 is repeated 5 times, sl@0: 0 is repeated 1 time, and 1 is repeated 2 times. sl@0: