X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/fa54fe1eda6977fc8aef0c154f8483e351e20bdd..f387fcb17a980fe165218d217b0187a8c279508a:/catcrypt.c diff --git a/catcrypt.c b/catcrypt.c index 08fbb53..4c343a4 100644 --- a/catcrypt.c +++ b/catcrypt.c @@ -276,8 +276,7 @@ static int encrypt(int argc, char *argv[]) seq = 0; for (;;) { h = GM_INIT(m); - STORE32(bb, seq); - GH_HASH(h, bb, 4); + GH_HASHU32(h, seq); seq++; if (GC_CLASS(c)->blksz) { GC_ENCRYPT(cx, 0, bb, GC_CLASS(c)->blksz); @@ -314,6 +313,7 @@ static int encrypt(int argc, char *argv[]) freeenc(e); if (s) freesig(s); freekem(km); + if (fp != stdin) fclose(fp); if (of) fclose(ofp); key_close(&kf); dstr_destroy(&d); @@ -366,7 +366,7 @@ static int decrypt(int argc, char *argv[]) { "output", OPTF_ARGREQ, 0, 'o' }, { 0, 0, 0, 0 } }; - i = mdwopt(argc, argv, "af:o:qv", opt, 0, 0, 0); + i = mdwopt(argc, argv, "abf:o:qv", opt, 0, 0, 0); if (i < 0) break; switch (i) { case 'a': ef = "pem"; break; @@ -460,6 +460,7 @@ static int decrypt(int argc, char *argv[]) key_fulltag(sk, &d); printf("INFO good-signature %s\n", d.buf); } + freesig(s); } else if (verb) printf("INFO no-signature\n"); @@ -487,8 +488,7 @@ static int decrypt(int argc, char *argv[]) GC_SETIV(c, d.buf); } h = GM_INIT(m); - STORE32(d.buf, seq); - GH_HASH(h, d.buf, 4); + GH_HASHU32(h, seq); seq++; chunk_read(e, &d, &b); if ((tag = buf_get(&b, GM_CLASS(m)->hashsz)) == 0) { @@ -501,6 +501,7 @@ static int decrypt(int argc, char *argv[]) printf("FAIL bad ciphertext chunk: authentication failure\n"); exit(EXIT_FAILURE); } + GH_DESTROY(h); if (!BLEFT(&b)) break; GC_DECRYPT(c, BCUR(&b), BCUR(&b), BLEFT(&b)); @@ -522,7 +523,7 @@ static int decrypt(int argc, char *argv[]) rewind(rfp); dstr_reset(&d); dstr_ensure(&d, 65536); - if (ofp == stdout) printf("DATA\n"); + if (verb && ofp == stdout) printf("DATA\n"); for (;;) { n = fread(d.buf, 1, d.sz, rfp); if (!n) break; @@ -543,6 +544,7 @@ static int decrypt(int argc, char *argv[]) GC_DESTROY(cx); GM_DESTROY(m); freekem(km); + if (fp != stdin) fclose(fp); if (of) fclose(ofp); key_close(&kf); dstr_destroy(&d);