From: Mark Wooding Date: Mon, 22 Dec 2014 20:32:58 +0000 (+0000) Subject: progs/rspit.c: Better handling of block cipher IVs. X-Git-Tag: 2.2.0~7^2~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb/commitdiff_plain/1cdc3a62b8f436fb78e00a1b6da20857d37b526f progs/rspit.c: Better handling of block cipher IVs. * Check the IV length during option parsing, rather than at the end. * Don't accumulate IV material because we don't do that with keys. --- diff --git a/progs/rspit.c b/progs/rspit.c index 7ca1cce8..2793fb41 100644 --- a/progs/rspit.c +++ b/progs/rspit.c @@ -831,9 +831,14 @@ static grand *gen_ofb(unsigned i) break; case 'i': { char *p; + DRESET(&iv); unhex(optarg, &p, &iv); if (*p) die(EXIT_FAILURE, "bad hex IV `%s'", optarg); + if (iv.len != ciphertab[i].blksz) { + die(EXIT_FAILURE, "bad IV length %lu (must be %lu)", + (unsigned long)iv.len, (unsigned long)ciphertab[i].blksz); + } } break; default: return (0); @@ -843,13 +848,8 @@ static grand *gen_ofb(unsigned i) if (!d.len) randkey(&d, ciphertab[i].keysz); r = ciphertab[i].ofb(d.buf, d.len); - if (iv.len) { - if (iv.len != ciphertab[i].blksz) { - die(EXIT_FAILURE, "bad IV length %lu (must be %lu)", - (unsigned long)iv.len, (unsigned long)ciphertab[i].blksz); - } + if (iv.len) r->ops->misc(r, GRAND_SEEDBLOCK, iv.buf); - } dstr_destroy(&d); dstr_destroy(&iv); @@ -888,9 +888,14 @@ static grand *gen_counter(unsigned i) break; case 'i': { char *p; + DRESET(&iv); unhex(optarg, &p, &iv); if (*p) die(EXIT_FAILURE, "bad hex IV `%s'", optarg); + if (iv.len != ciphertab[i].blksz) { + die(EXIT_FAILURE, "bad IV length %lu (must be %lu)", + (unsigned long)iv.len, (unsigned long)ciphertab[i].blksz); + } } break; default: return (0); @@ -900,13 +905,8 @@ static grand *gen_counter(unsigned i) if (!d.len) randkey(&d, ciphertab[i].keysz); r = ciphertab[i].counter(d.buf, d.len); - if (iv.len) { - if (iv.len != ciphertab[i].blksz) { - die(EXIT_FAILURE, "bad IV length %lu (must be %lu)", - (unsigned long)iv.len, (unsigned long)ciphertab[i].blksz); - } + if (iv.len) r->ops->misc(r, GRAND_SEEDBLOCK, iv.buf); - } dstr_destroy(&d); dstr_destroy(&iv);