/*----- Utilities ---------------------------------------------------------*/
-/* --- @keyreport@ --- *
- *
- * Arguments: @const char *file@ = filename containing the error
- * @int line@ = line number in file
- * @const char *err@ = error text message
- * @void *p@ = unimportant pointer
- *
- * Returns: ---
- *
- * Use: Reports errors during the opening of a key file.
- */
-
-static void keyreport(const char *file, int line, const char *err, void *p)
-{
- moan("error in keyring `%s' at line `%s': %s", file, line, err);
-}
-
/*----- Static variables --------------------------------------------------*/
static const char *keyring = "keyring";
if (argc - optind > 1 || (f & f_bogus))
die(EXIT_FAILURE, "Usage: encrypt [-OPTIONS] [FILE]");
- if (key_open(&kf, keyring, KOPEN_READ, keyreport, 0))
+ if (key_open(&kf, keyring, KOPEN_READ, key_moan, 0))
die(EXIT_FAILURE, "can't open keyring `%s'", keyring);
if ((k = key_bytag(&kf, kn)) == 0)
die(EXIT_FAILURE, "key `%s' not found", kn);
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);
freeenc(e);
if (s) freesig(s);
freekem(km);
+ if (fp != stdin) fclose(fp);
if (of) fclose(ofp);
key_close(&kf);
dstr_destroy(&d);
{ "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;
} else
optind++;
- if (key_open(&kf, keyring, KOPEN_READ, keyreport, 0))
+ if (key_open(&kf, keyring, KOPEN_READ, key_moan, 0))
die(EXIT_FAILURE, "can't open keyring `%s'", keyring);
e = initdec(eo, fp, checkbdry, "CATCRYPT ENCRYPTED MESSAGE");
key_fulltag(sk, &d);
printf("INFO good-signature %s\n", d.buf);
}
+ freesig(s);
} else if (verb)
printf("INFO no-signature\n");
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) {
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));
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;
GC_DESTROY(cx);
GM_DESTROY(m);
freekem(km);
+ if (fp != stdin) fclose(fp);
if (of) fclose(ofp);
key_close(&kf);
dstr_destroy(&d);