aboutsummaryrefslogtreecommitdiff
path: root/src/sw
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw')
-rwxr-xr-xsrc/sw/entropy_tester.py78
1 files changed, 51 insertions, 27 deletions
diff --git a/src/sw/entropy_tester.py b/src/sw/entropy_tester.py
index 6a5ff0b..fcc993d 100755
--- a/src/sw/entropy_tester.py
+++ b/src/sw/entropy_tester.py
@@ -16,37 +16,37 @@
# NIST KAT document:
# http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA_All.pdf
#
-#
+#
# Authors: Joachim Strömbergson, Paul Selkirk
# Copyright (c) 2014, SUNET
-#
-# Redistribution and use in source and binary forms, with or
-# without modification, are permitted provided that the following
-# conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#=======================================================================
-
+
#-------------------------------------------------------------------
# Python module imports.
#-------------------------------------------------------------------
@@ -195,7 +195,7 @@ class I2C:
def __del__(self):
if (self.file):
self.file.close()
-
+
# write a command to the i2c device
def write(self, buf):
if DEBUG:
@@ -635,6 +635,28 @@ def TC10(i2c):
print "TC10-4: Double block message test for SHA-512."
tc10(i2c, MODE_SHA_512, SHA512_DOUBLE_DIGEST)
+ tc_wait_valid(i2c, SHA1_ADDR_PREFIX)
+
+
+
+# Avalanche entropy tests
+
+AVALANCHE_ADDR_PREFIX = 0x20
+
+def avalanche_read(i2c, addr, data):
+ tc_read(i2c, AVALANCHE_ADDR_PREFIX, addr, data)
+
+def avalanche_write(i2c, addr, data):
+ tc_write(i2c, AVALANCHE_ADDR_PREFIX, addr, data)
+
+
+# TC11 Read name and version from SHA-1 core.
+def TC11(i2c):
+ print "TC1: Reading name, type and version words from SHA-1 core."
+
+ avalanche_read(i2c, ADDR_NAME0, 0x73686131) # "sha1"
+ avalanche_read(i2c, ADDR_NAME1, 0x20202020) # " "
+ avalanche_read(i2c, ADDR_VERSION, 0x302e3530) # "0.50"
#----------------------------------------------------------------
# main
@@ -642,11 +664,13 @@ def TC10(i2c):
if __name__ == '__main__':
import argparse
- all_tests = [ TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 ]
+ # all_tests = [ TC1, TC2, TC3, TC4, TC5, TC6, TC7, TC8, TC9, TC10 ]
sha1_tests = all_tests[0:3]
sha256_tests = all_tests[3:7]
sha512_tests = all_tests[7:]
+ all_tests = [TC11]
+
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true',
help='add debugging/trace information')