chiark
/
gitweb
/
~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
progs/rspit.c: Better handling of block cipher IVs.
[catacomb]
/
progs
/
rspit.c
diff --git
a/progs/rspit.c
b/progs/rspit.c
index 7ca1cce836fd7fb9070070479714a1c5834fdb68..2793fb414934a278ba6227fd3b070f129545a5dd 100644
(file)
--- a/
progs/rspit.c
+++ b/
progs/rspit.c
@@
-831,9
+831,14
@@
static grand *gen_ofb(unsigned i)
break;
case 'i': {
char *p;
break;
case 'i': {
char *p;
+ DRESET(&iv);
unhex(optarg, &p, &iv);
if (*p)
die(EXIT_FAILURE, "bad hex IV `%s'", optarg);
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);
} 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 (!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);
r->ops->misc(r, GRAND_SEEDBLOCK, iv.buf);
- }
dstr_destroy(&d);
dstr_destroy(&iv);
dstr_destroy(&d);
dstr_destroy(&iv);
@@
-888,9
+888,14
@@
static grand *gen_counter(unsigned i)
break;
case 'i': {
char *p;
break;
case 'i': {
char *p;
+ DRESET(&iv);
unhex(optarg, &p, &iv);
if (*p)
die(EXIT_FAILURE, "bad hex IV `%s'", optarg);
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);
} 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 (!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);
r->ops->misc(r, GRAND_SEEDBLOCK, iv.buf);
- }
dstr_destroy(&d);
dstr_destroy(&iv);
dstr_destroy(&d);
dstr_destroy(&iv);