From: Mark Wooding Date: Tue, 20 Aug 2019 13:18:36 +0000 (+0100) Subject: progs/cc-kem.c: Split `aead_init' into two pieces. X-Git-Tag: 2.5.0~14^2~1 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb/commitdiff_plain/025c793f03564bfa2ead5fd64d26586f8b3009e4?ds=inline progs/cc-kem.c: Split `aead_init' into two pieces. This will let us use the same machinery with different user interfaces. --- diff --git a/progs/cc-kem.c b/progs/cc-kem.c index 0974f4fa..0942a2e5 100644 --- a/progs/cc-kem.c +++ b/progs/cc-kem.c @@ -178,27 +178,35 @@ typedef struct aead_encctx { size_t nsz, tsz; } aead_encctx; -static bulk *aead_init(key *k, const char *calg, const char *halg) +static bulk *aead_internalinit(key *k, const gcaead *aec) { aead_encctx *ctx = CREATE(aead_encctx); + + ctx->key = 0; + ctx->aec = aec; + if ((ctx->nsz = keysz_pad(4, aec->noncesz)) == 0) + die(EXIT_FAILURE, "no suitable nonce size for `%s'", aec->name); + ctx->tsz = keysz(0, ctx->aec->tagsz); + + return (&ctx->b); +} + +static bulk *aead_init(key *k, const char *calg, const char *halg) +{ + const gcaead *aec; const char *q; dstr t = DSTR_INIT; key_fulltag(k, &t); if ((q = key_getattr(0, k, "cipher")) != 0) calg = q; - if (!calg) ctx->aec = &chacha20_poly1305; - else if ((ctx->aec = gaead_byname(calg)) == 0) + if (!calg) aec = &chacha20_poly1305; + else if ((aec = gaead_byname(calg)) == 0) die(EXIT_FAILURE, "AEAD scheme `%s' not found in key `%s'", calg, t.buf); - ctx->key = 0; - if ((ctx->nsz = keysz_pad(4, ctx->aec->noncesz)) == 0) - die(EXIT_FAILURE, "no suitable nonce size for `%s'", calg); - ctx->tsz = keysz(0, ctx->aec->tagsz); - dstr_destroy(&t); - return (&ctx->b); + return (aead_internalinit(k, aec)); } static int aead_commonsetup(aead_encctx *ctx, gcipher *cx)