From e303dece38db2916d787fa068a2eeaa445ae6e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Fri, 6 Apr 2018 09:39:16 +0200 Subject: Finally implemented SHA-512-224 digest properly. Added test case for SHA-512-224 with double block message. Test ok. --- src/model/python/sha512.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/model/python/sha512.py b/src/model/python/sha512.py index bfeea54..ad5b1fb 100755 --- a/src/model/python/sha512.py +++ b/src/model/python/sha512.py @@ -150,7 +150,9 @@ class SHA512(): def get_digest(self): if self.mode == 'MODE_SHA_512_224': - return self.H[0:3] # FIX THIS! + d = self.H[0:4] + d[3] = d[3] & 0xffffffff00000000 + return d elif self.mode == 'MODE_SHA_512_256': return self.H[0:4] @@ -314,6 +316,15 @@ def double_block_tests(): 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000380] + print("Test case for SHA-512-224.") + TC256_expected = [0x23fec5bb94d60b23, 0x308192640b0c4533, 0x35d664734fe40e72, 0x68674af900000000] + my_sha512 = SHA512(mode = 'MODE_SHA_512_224', verbose = 0) + my_sha512.init() + my_sha512.next(TC_BLOCK1) + my_sha512.next(TC_BLOCK2) + my_digest = my_sha512.get_digest() + compare_digests(my_digest, TC256_expected) + print("Test case for SHA-512-256.") TC256_expected = [0x3928e184fb8690f8, 0x40da3988121d31be, 0x65cb9d3ef83ee614, 0x6feac861e19b563a] my_sha512 = SHA512(mode = 'MODE_SHA_512_256', verbose = 0) -- cgit v1.2.3