aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-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()