progs/perftest.c: Fix key-size handling.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 10 Nov 2018 13:58:54 +0000 (13:58 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 24 Nov 2018 21:53:38 +0000 (21:53 +0000)
  * Allow a key-size parameter to `enc', because algorithms like
    Rijndael have key-size-dependent performance.  This uses the `-b'
    option, because `-B' is already the buffer size for the inner loop.

  * For consistency, use `-b' for the key size in `ksched' too.

  * Finally, check explicit key sizes for validity rather than just
    rounding off and potentially crashing.

progs/perftest.c

index a87ca96..5fa6b7f 100644 (file)
@@ -496,7 +496,9 @@ static void *ksched_init(opts *o)
     die(1, "must specify encryption scheme name");
   if ((c->c = gcipher_byname(o->name)) == 0)
     die(1, "encryption scheme `%s' not known", o->name);
-  c->ksz = keysz(o->gbits/8, c->c->keysz);
+  c->ksz = keysz(o->fbits/8, c->c->keysz);
+  if (o->fbits%8 || (o->fbits && c->ksz != o->fbits/8))
+    die(1, "bad key size %u for %s", o->fbits, o->name);
   c->k = xmalloc(c->ksz);
   rand_get(RAND_GLOBAL, c->k, c->ksz);
   return (c);
@@ -526,7 +528,9 @@ static void *enc_init(opts *o)
     die(1, "must specify encryption scheme name");
   if ((cc = gcipher_byname(o->name)) == 0)
     die(1, "encryption scheme `%s' not known", o->name);
-  ksz = keysz(0, cc->keysz);
+  ksz = keysz(o->fbits/8, cc->keysz);
+  if (o->fbits%8 || (o->fbits && ksz != o->fbits/8))
+    die(1, "bad key size %u for %s", o->fbits, o->name);
   k = xmalloc(ksz);
   rand_get(RAND_GLOBAL, k, ksz);
   c->c = GC_INIT(cc, k, ksz);
@@ -673,10 +677,10 @@ Options:\n\
 -l, --list [ITEM...]   List all the various names of things.\n\
 \n\
 -C, --name=NAME                Select curve/DH-group/enc/hash name.\n\
--b, --field-bits       Field size for g-prime and rsa.\n\
+-b, --field-bits       Field size for g-prime and rsa;\n\
+                         key bits for ksched and enc.\n\
 -q, --no-check         Don't check field/group for validity.\n\
--B, --group-bits       Group size for g-prime; key size for ksched;\n\
-                         data size for enc and hash.\n\
+-B, --group-bits       Group size for g-prime; data size for enc and hash.\n\
 -n, --factors=COUNT    Number of factors for {exp,mul}-sim;\n\
                          inner iterations for enc and hash.\n\
 -i, --intervals=COUNT  Number of intervals to run for.  [0; forever]\n\