This will let us use the same machinery with different user interfaces.
size_t nsz, tsz;
} 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);
{
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;
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);
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);
-
+ return (aead_internalinit(k, aec));
}
static int aead_commonsetup(aead_encctx *ctx, gcipher *cx)
}
static int aead_commonsetup(aead_encctx *ctx, gcipher *cx)