aboutsummaryrefslogtreecommitdiff
path: root/tests/time-keygen.py
blob: fcd47c68fcdbe800a7a620485a609434f0238e5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

"""
Time libhal RSA key generation
"""

from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from datetime import datetime, timedelta

from cryptech.libhal import *

parser = ArgumentParser(description = __doc__, formatter_class = 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("-t", "--token",      action  = "store_true",       help = "store key on token")
parser.add_argument("-k", "--keylen",     default = 2048, type = int,   help = "key length")
args = parser.parse_args()

hsm = HSM()
hsm.login(HAL_USER_NORMAL, args.pin)

flags = HAL_KEY_FLAG_USAGE_DIGITALSIGNATURE | (HAL_KEY_FLAG_TOKEN if args.token else 0)
sum   = timedelta()

for n in xrange(1, args.iterations):

    t0 = datetime.now()

    k  = hsm.pkey_generate_rsa(args.keylen, flags)

    t1 = datetime.now()

    k.delete()

    sum += t1 - t0

    print "{:4d} this {} mean {}".format(n, t1 - t0, sum / n)