X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/45c0fd363937c6e9b05da04a9167e9912c05ca0c..f0c52873e4c1e3a16bb2d5a086df2526f698e4ac:/catcrypt.c diff --git a/catcrypt.c b/catcrypt.c index a1e3495..d10739d 100644 --- a/catcrypt.c +++ b/catcrypt.c @@ -133,7 +133,7 @@ static int encrypt(int argc, char *argv[]) const char *err; int i; int en; - size_t n; + size_t n, chsz; dstr d = DSTR_INIT; octet *tag, *ct; buf b; @@ -261,6 +261,7 @@ static int encrypt(int argc, char *argv[]) assert(GC_CLASS(c)->blksz <= sizeof(bb)); dstr_ensure(&d, sizeof(bb) + GM_CLASS(m)->hashsz); seq = 0; + chsz = MASK16 - GM_CLASS(m)->hashsz; for (;;) { h = GM_INIT(m); GH_HASHU32(h, seq); @@ -269,7 +270,7 @@ static int encrypt(int argc, char *argv[]) GC_ENCRYPT(cx, 0, bb, GC_CLASS(c)->blksz); GC_SETIV(c, bb); } - n = fread(bb, 1, sizeof(bb), fp); + n = fread(bb, 1, chsz, fp); if (!n) break; buf_init(&b, d.buf, d.sz); tag = buf_get(&b, GM_CLASS(m)->hashsz); @@ -529,19 +530,18 @@ static int decrypt(int argc, char *argv[]) if (ferror(rfp) || fclose(rfp)) die(EXIT_FAILURE, "error unbuffering output: %s", strerror(errno)); } - if (ofp && (fflush(ofp) || ferror(ofp) || fclose(ofp))) - die(EXIT_FAILURE, "error writing output: %s", strerror(errno)); e->ops->decdone(e); if (verb && ofp != stdout) printf("OK decrypted successfully\n"); + if (ofp && (fflush(ofp) || ferror(ofp) || fclose(ofp))) + die(EXIT_FAILURE, "error writing output: %s", strerror(errno)); freeenc(e); GC_DESTROY(c); GC_DESTROY(cx); GM_DESTROY(m); freekem(km); if (fp != stdin) fclose(fp); - if (of) fclose(ofp); key_close(&kf); dstr_destroy(&d); return (0);