aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoachim Strömbergson <joachim@secworks.se>2014-04-01 09:47:34 +0200
committerJoachim Strömbergson <joachim@secworks.se>2014-04-01 09:47:34 +0200
commit077cfbc902c18fae72c79090a5ad5924fe6a2a1a (patch)
tree4e575d9298e241f00ee0ba5cef8dea5384110920 /src
parented0edb437fe02c44e555ab8396e53fd081d72a15 (diff)
Update of the Python model to support NIST dual block message test as well as a test case with a huge message.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/model/python/sha1.py57
1 files changed, 52 insertions, 5 deletions
diff --git a/src/model/python/sha1.py b/src/model/python/sha1.py
index 4cb74bd..9bae18a 100755
--- a/src/model/python/sha1.py
+++ b/src/model/python/sha1.py
@@ -10,7 +10,7 @@
#
#
# Author: Joachim Strömbergson
-# (c) 2014 SUNET
+# (c) 2014, SUNET
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
@@ -186,13 +186,14 @@ def compare_digests(digest, expected):
# If executed tests the ChaCha class using known test vectors.
#-------------------------------------------------------------------
def main():
- print("Testing the SHA-256 Python model.")
- print("---------------------------------")
+ print("Testing the SHA-1 Python model.")
+ print("-------------------------------")
print
- my_sha1 = SHA1(verbose=1);
+ my_sha1 = SHA1(verbose=0);
# TC1: NIST testcase with message "abc"
+ print("TC1: Single block NIST test case.")
TC1_block = [0x61626380, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
@@ -200,12 +201,58 @@ def main():
TC1_expected = [0xa9993e36, 0x4706816a, 0xba3e2571,
0x7850c26c, 0x9cd0d89d]
-
my_sha1.init()
my_sha1.next(TC1_block)
my_digest = my_sha1.get_digest()
compare_digests(my_digest, TC1_expected)
+ print("")
+
+
+ # TC2: NIST testcase with message two block message.
+ print("TC2: Dual block NIST test case.")
+ TC2_1_block = [0x61626364, 0x62636465, 0x63646566, 0x64656667,
+ 0x65666768, 0x66676869, 0x6768696A, 0x68696A6B,
+ 0x696A6B6C, 0x6A6B6C6D, 0x6B6C6D6E, 0x6C6D6E6F,
+ 0x6D6E6F70, 0x6E6F7071, 0x80000000, 0x00000000]
+
+
+ TC2_2_block = [0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x000001C0]
+
+ TC2_1_expected = [0xF4286818, 0xC37B27AE, 0x0408F581,
+ 0x84677148, 0x4A566572]
+
+ TC2_2_expected = [0x84983E44, 0x1C3BD26E, 0xBAAE4AA1,
+ 0xF95129E5, 0xE54670F1]
+
+ my_sha1.init()
+ my_sha1.next(TC2_1_block)
+ my_digest = my_sha1.get_digest()
+ compare_digests(my_digest, TC2_1_expected)
+ my_sha1.next(TC2_2_block)
+ my_digest = my_sha1.get_digest()
+ compare_digests(my_digest, TC2_2_expected)
+ print("")
+
+ # TC3: Huge message with n blocks
+ n = 10000
+ print("TC3: Huge message with %d blocks test case." % n)
+ TC3_block = [0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f,
+ 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f,
+ 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f,
+ 0xaa55aa55, 0xdeadbeef, 0x55aa55aa, 0xf00ff00f]
+
+ TC3_expected = [0xea2ebc79, 0x35516705, 0xde1e1467,
+ 0x31e55587, 0xa0038725]
+
+ my_sha1.init()
+ for i in range(n):
+ my_sha1.next(TC3_block)
+ my_digest = my_sha1.get_digest()
+ compare_digests(my_digest, TC3_expected)
#-------------------------------------------------------------------