I want to run the SHA2 and SHA3 NIST algorithm test vectors provided in the zip files at the bottom of this page: http://csrc.nist.gov/groups/STM/cavp/secure-hashing.html#sha-2
I don't quite understand how the test vectors are encoded. For example, if I run the SHA2-256 algorithm on an empty string as so:
import hashlib
sha2_256_test_str = b""
sha2_standard = hashlib.sha256(sha2_256_test_str).hexdigest()
I obtain the hash:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Which is correct. However, if I look at the first test vector in the NIST zip file it says that:
# CAVS 11.0
# "SHA-256 ShortMsg" information
# SHA-256 tests are configured for BYTE oriented implementations
# Generated on Tue Mar 15 08:23:38 2011
[L = 32]
Len = 0
Msg = 00
MD = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
This would seem to indicate to me that for a message of "00", I should receive the hash above. However, this is the hash I obtain for an empty string. So for instance, the way that I interpret to run this test vector in Python is:
import hashlib
sha2_256_test_str = b"00"
sha2_standard = hashlib.sha256(sha2_256_test_str).hexdigest()
But this gives the hash
f1534392279bddbf9d43dde8701cb5be14b82f76ec6607bf8d6ad557f60f304e
What key point am I missing here? How would I be able to convert the messages in the NIST zip files to a message for my Python script?
Len = 1
andMsg = 00
. The hash they give isn't obtained for that message nor for anything obvious. How can I interpret these vectors more generally? $\endgroup$Len=1
is asking for. If your implementation can only hash byte strings, then you'll want to look at the 'byte oriented' test vectors. $\endgroup$