aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2014-12-13 13:38:50 -0500
committerRob Austein <sra@hactrn.net>2014-12-13 13:38:50 -0500
commit95009f48e05d06fb77a9127731d7f5f2de489055 (patch)
tree6db2ce5af8ec1ac7a70291fd37164d5fafa83166 /tests
parent1b88a31f228b4b0eddc23b31d71fb1e5ca6abe66 (diff)
Add code to use Cryptech TRNG in place of Cryptlib's default entropy
sources. This may need further attention, particularly once we start working with buses other than the current I2C kludge.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_trng.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_trng.py b/tests/test_trng.py
new file mode 100644
index 0000000..5207eda
--- /dev/null
+++ b/tests/test_trng.py
@@ -0,0 +1,48 @@
+# Trivial test of cryptech trng and noise cores via cryptlib python interface.
+# Might upgrade to Python's unittest framework eventually.
+
+import atexit
+import os
+
+print "[Loading cryptlib]"
+from cryptlib_py import *
+
+if os.getenv("SET_GDB_BREAKPOINTS"):
+ print "[Sending SIGINT to self to throw to gdb]"
+ os.kill(os.getpid(), 2)
+ print "[Continuing]"
+
+print "[Initializing cryptlib]"
+cryptInit()
+atexit.register(cryptEnd)
+
+print "[Opening device]"
+dev = cryptDeviceOpen(CRYPT_UNUSED, CRYPT_DEVICE_HARDWARE, None)
+atexit.register(cryptDeviceClose, dev)
+
+use_dev_context = False
+
+def generate_key(i):
+ label = "RSA-%04d" % i
+ print "[Generating key %s]" % label
+ ctx = None
+ try:
+ if use_dev_context:
+ ctx = cryptDeviceCreateContext(dev, CRYPT_ALGO_RSA)
+ else:
+ ctx = cryptCreateContext(CRYPT_UNUSED, CRYPT_ALGO_RSA)
+ ctx.CTXINFO_LABEL = label
+ ctx.CTXINFO_KEYSIZE = 2048 / 8
+ cryptGenerateKey(ctx)
+ finally:
+ if ctx is not None:
+ cryptDestroyContext(ctx)
+
+have_i2c = os.path.exists("/dev/i2c-2")
+
+if not have_i2c:
+ print
+ print "[I2C device not found, so testing software only, no hardware cores tested]"
+
+for i in xrange(100):
+ generate_key(i)