From 178c254085727e7ee6e026e69a1f18cd0ab674e0 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 10 Nov 2018 13:58:54 +0000 Subject: [PATCH] progs/perftest.c: Fix key-size handling. * 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/progs/perftest.c b/progs/perftest.c index a87ca96e..5fa6b7fa 100644 --- a/progs/perftest.c +++ b/progs/perftest.c @@ -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\ -- 2.11.0