aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-03-01 17:08:26 -0500
committerRob Austein <sra@hactrn.net>2017-03-01 17:08:26 -0500
commit314a6d2d6fd3ab0c1cc70146acccaa03e6dfe06d (patch)
treef429482f269b1a94a95d7da53d64e06cb2c374f1
parent66e3e94af9a94e5892419b1257e9177ce0d8498a (diff)
Test all key types by default.
-rwxr-xr-xscripts/time-signature.py55
1 files changed, 29 insertions, 26 deletions
diff --git a/scripts/time-signature.py b/scripts/time-signature.py
index 1ec7535..8b4cc5f 100755
--- a/scripts/time-signature.py
+++ b/scripts/time-signature.py
@@ -83,47 +83,50 @@ class ECDSAKey(object):
def main():
- #key_choices = tuple(k for k in key_table if k.startswith("rsa_"))
- key_choices = tuple(key_table)
- key_default = key_choices[0]
-
parser = argparse.ArgumentParser(description = __doc__,
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
- parser.add_argument("-i", "--iterations", default = 100, type = int, help = "iterations")
- parser.add_argument("-p", "--pin", default = "fnord", help = "user PIN")
- parser.add_argument("-s", "--slot", default = 0, type = int, help = "slot number")
- parser.add_argument("-t", "--token", action = "store_true", help = "store key on token")
- parser.add_argument("-l", "--libpkcs11", default = libpkcs11_default, help = "PKCS #11 library")
- parser.add_argument("-k", "--key", default = key_default,
- choices = key_choices, help = "test key")
+ parser.add_argument("-i", "--iterations", default = 100, type = int, help = "iterations")
+ parser.add_argument("-p", "--pin", default = "fnord", help = "user PIN")
+ parser.add_argument("-s", "--slot", default = 0, type = int, help = "slot number")
+ parser.add_argument("-t", "--token", action = "store_true", help = "store key on token")
+ parser.add_argument("-l", "--libpkcs11", default = libpkcs11_default, help = "PKCS #11 library")
+ parser.add_argument("-k", "--key", choices = tuple(key_table), nargs = 1, help = "test just one key")
+ parser.add_argument("-q", "--quiet", action = "store_true", help = "be less chatty")
args = parser.parse_args()
p11 = PKCS11(args.libpkcs11)
- print "Starting test with key {}, {} iterations".format(args.key, args.iterations)
+ if not args.quiet:
+ print "Initializing"
p11.C_Initialize()
session = p11.C_OpenSession(args.slot)
p11.C_Login(session, CKU_USER, args.pin)
- k = key_table[args.key]
- k.create(args, p11, session, "Your mother was a hamster")
+ for name in args.key or key_table:
+
+ print "Starting test with key {}, {} iterations".format(name, args.iterations)
+
+ k = key_table[name]
+ k.create(args, p11, session, "Your mother was a hamster")
+
+ mean = datetime.timedelta(seconds = 0)
- mean = datetime.timedelta(seconds = 0)
+ for i in xrange(args.iterations):
+ t0 = datetime.datetime.now()
+ p11.C_SignInit(session, k.ckm, k.handle)
+ sig = p11.C_Sign(session, k.tbs)
+ t1 = datetime.datetime.now()
+ k.verify(sig)
+ if not args.quiet:
+ print "{:4d} {}".format(i, t1 - t0)
+ mean += t1 - t0
- for i in xrange(args.iterations):
- t0 = datetime.datetime.now()
- p11.C_SignInit(session, k.ckm, k.handle)
- sig = p11.C_Sign(session, k.tbs)
- t1 = datetime.datetime.now()
- k.verify(sig)
- print "{:4d} {}".format(i, t1 - t0)
- mean += t1 - t0
+ mean /= args.iterations
+ print "mean {}".format(mean)
- mean /= args.iterations
- print "mean {}".format(mean)
+ p11.C_DestroyObject(session, k.handle)
- p11.C_DestroyObject(session, k.handle)
p11.C_CloseAllSessions(args.slot)
p11.C_Finalize()