[Cryptech-Commits] [core/hash/sha512] branch clock_speed updated: Added testcases for other SHA-512 versions per FIPS 180-4.
git at cryptech.is
git at cryptech.is
Fri Apr 6 07:28:04 UTC 2018
This is an automated email from the git hooks/post-receive script.
joachim at secworks.se pushed a commit to branch clock_speed
in repository core/hash/sha512.
The following commit(s) were added to refs/heads/clock_speed by this push:
new 32c0bfd Added testcases for other SHA-512 versions per FIPS 180-4.
32c0bfd is described below
commit 32c0bfd6e1e144cbcee60f2375582fabdf7b4833
Author: Joachim Strömbergson <joachim at secworks.se>
AuthorDate: Fri Apr 6 09:27:38 2018 +0200
Added testcases for other SHA-512 versions per FIPS 180-4.
---
src/model/python/sha512.py | 82 ++++++++++++++++++++++++++++------------------
1 file changed, 51 insertions(+), 31 deletions(-)
diff --git a/src/model/python/sha512.py b/src/model/python/sha512.py
index f09c99d..bfeea54 100755
--- a/src/model/python/sha512.py
+++ b/src/model/python/sha512.py
@@ -59,7 +59,7 @@ MAX_64BIT = 0xffffffffffffffff
class SHA512():
def __init__(self, mode = 'MODE_SHA_512', verbose = 0):
assert mode in ['MODE_SHA_512_224', 'MODE_SHA_512_256',
- 'MODE_SHA_384', 'MODE_SHA_512']
+ 'MODE_SHA_512_384', 'MODE_SHA_512']
self.mode = mode
self.verbose = verbose
self.mode
@@ -120,7 +120,7 @@ class SHA512():
0x96283ee2a88effe3, 0xbe5e1e2553863992,
0x2b0199fc2c85b8aa, 0x0eb72ddc81c52ca2]
- elif self.mode == 'MODE_SHA_384':
+ elif self.mode == 'MODE_SHA_512_384':
self.H = [0xcbbb9d5dc1059ed8, 0x629a292a367cd507,
0x9159015a3070dd17, 0x152fecd8f70e5939,
0x67332667ffc00b31, 0x8eb44a8768581511,
@@ -155,7 +155,7 @@ class SHA512():
elif self.mode == 'MODE_SHA_512_256':
return self.H[0:4]
- elif self.mode == 'MODE_SHA_384':
+ elif self.mode == 'MODE_SHA_512_384':
return self.H[0:6]
elif self.mode == 'MODE_SHA_512':
@@ -302,27 +302,46 @@ def compare_digests(digest, expected):
# NIST tests with dual block messages.
#-------------------------------------------------------------------
def double_block_tests():
- TC_BLOCK1 = [0x6162636465666768, 0x6263646566676869, 0x636465666768696A, 0x6465666768696A6B,
- 0x65666768696A6B6C, 0x666768696A6B6C6D, 0x6768696A6B6C6D6E, 0x68696A6B6C6D6E6F,
- 0x696A6B6C6D6E6F70, 0x6A6B6C6D6E6F7071, 0x6B6C6D6E6F707172, 0x6C6D6E6F70717273,
- 0x6D6E6F7071727374, 0x6E6F707172737475, 0x8000000000000000, 0x0000000000000000]
+ print("Running double block message tests.")
+
+ TC_BLOCK1 = [0x6162636465666768, 0x6263646566676869, 0x636465666768696a, 0x6465666768696a6b,
+ 0x65666768696a6b6c, 0x666768696a6b6c6d, 0x6768696a6b6c6d6e, 0x68696a6b6c6d6e6f,
+ 0x696a6b6c6d6e6f70, 0x6a6b6c6d6e6f7071, 0x6b6c6d6e6f707172, 0x6c6d6e6f70717273,
+ 0x6d6e6f7071727374, 0x6e6f707172737475, 0x8000000000000000, 0x0000000000000000]
TC_BLOCK2 = [0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000380]
- print("Running double block message tests.")
- print()
+ print("Test case for SHA-512-256.")
+ TC256_expected = [0x3928e184fb8690f8, 0x40da3988121d31be, 0x65cb9d3ef83ee614, 0x6feac861e19b563a]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512_256', 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)
- my_sha512 = SHA512(mode = 'MODE_SHA_512', verbose=1)
- TC1_expected = [0x8E959B75DAE313DA, 0x8CF4F72814FC143F, 0x8F7779C6EB9F7FA1, 0x7299AEADB6889018,
- 0x501D289E4900F7E4, 0x331B99DEC4B5433A, 0xC7D329EEB6DD2654, 0x5E96E55B874BE909]
+ print("Test case for SHA-512-384.")
+ TC384_expected = [0x09330c33f71147e8, 0x3d192fc782cd1b47, 0x53111b173b3b05d2, 0x2fa08086e3b0f712,
+ 0xfcc7c71a557e2db9, 0x66c3e9fa91746039]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512_384', 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, TC1_expected)
+ compare_digests(my_digest, TC384_expected)
+
+ print("Test case for SHA-512.")
+ TC512_expected = [0x8e959b75dae313da, 0x8cf4f72814fc143f, 0x8f7779c6eb9f7fa1, 0x7299aeadb6889018,
+ 0x501d289e4900f7e4, 0x331b99dec4b5433a, 0xc7d329eeb6dd2654, 0x5e96e55b874be909]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512', 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, TC512_expected)
#-------------------------------------------------------------------
@@ -333,46 +352,47 @@ def double_block_tests():
#-------------------------------------------------------------------
def single_block_tests():
print("Running single block message tests.")
- print()
TC1_block = [0x6162638000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000018]
-
- my_sha512 = SHA512(mode = 'MODE_SHA_512', verbose=1)
- TC1_expected = [0xDDAF35A193617ABA, 0xCC417349AE204131, 0x12E6FA4E89A97EA2, 0x0A9EEEE64B55D39A,
- 0x2192992A274FC1A8, 0x36BA3C23A3FEEBBD, 0x454D4423643CE80E, 0x2A9AC94FA54CA49F]
+ print("Test case for SHA-512-224.")
+ TC2_expected = [0x4634270f707b6a54, 0xdaae7530460842e2, 0x0e37ed265ceee9a4, 0x3e8924aa00000000]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512_224', verbose = 0)
my_sha512.init()
my_sha512.next(TC1_block)
my_digest = my_sha512.get_digest()
- compare_digests(my_digest, TC1_expected)
-
+ compare_digests(my_digest, TC2_expected)
- my_sha512 = SHA512(mode = 'MODE_SHA_512_224', verbose=1)
- TC2_expected = [0x4634270F707B6A54, 0xDAAE7530460842E2, 0x0E37ED265CEEE9A4, 0x3E8924AA00000000]
+ print("Test case for SHA-512-256.")
+ TC3_expected = [0x53048e2681941ef9, 0x9b2e29b76b4c7dab, 0xe4c2d0c634fc6d46, 0xe0e2f13107e7af23]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512_256', verbose = 0)
my_sha512.init()
my_sha512.next(TC1_block)
my_digest = my_sha512.get_digest()
- compare_digests(my_digest, TC2_expected)
+ compare_digests(my_digest, TC3_expected)
- my_sha512 = SHA512(mode = 'MODE_SHA_512_256', verbose=1)
- TC3_expected = [0x53048E2681941EF9, 0x9B2E29B76B4C7DAB, 0xE4C2D0C634FC6D46, 0xE0E2F13107E7AF23]
+ print("Test case for SHA-512-384.")
+ TC4_expected = [0xcb00753f45a35e8b, 0xb5a03d699ac65007, 0x272c32ab0eded163, 0x1a8b605a43ff5bed,
+ 0x8086072ba1e7cc23, 0x58baeca134c825a7]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512_384', verbose = 0)
my_sha512.init()
my_sha512.next(TC1_block)
my_digest = my_sha512.get_digest()
- compare_digests(my_digest, TC3_expected)
-
+ compare_digests(my_digest, TC4_expected)
- my_sha512 = SHA512(mode = 'MODE_SHA_384', verbose=1)
- TC4_expected = [0xCB00753F45A35E8B, 0xB5A03D699AC65007, 0x272C32AB0EDED163, 0x1A8B605A43FF5BED,
- 0x8086072BA1E7CC23, 0x58BAECA134C825A7]
+ print("Test case for SHA-512.")
+ TC1_expected = [0xddaf35a193617aba, 0xcc417349ae204131, 0x12e6fa4e89a97ea2, 0x0a9eeee64b55d39a,
+ 0x2192992a274fc1a8, 0x36ba3c23a3feebbd, 0x454d4423643ce80e, 0x2a9ac94fa54ca49f]
+ my_sha512 = SHA512(mode = 'MODE_SHA_512', verbose = 0)
my_sha512.init()
my_sha512.next(TC1_block)
my_digest = my_sha512.get_digest()
- compare_digests(my_digest, TC4_expected)
+ compare_digests(my_digest, TC1_expected)
+ print()
#-------------------------------------------------------------------
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Commits
mailing list