diff options
author | John Baldwin <jhb@FreeBSD.org> | 2021-12-09 19:52:42 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2021-12-09 19:52:42 +0000 |
commit | 6113a08b98e403de5b92cc0a30fdc60489eccc48 (patch) | |
tree | 60d1c0be000b44f91e48f077912edd01076e7f94 /sys/crypto | |
parent | b54d12841e1a188e37bca943f003ad340492a4cd (diff) | |
download | src-6113a08b98e403de5b92cc0a30fdc60489eccc48.tar.gz src-6113a08b98e403de5b92cc0a30fdc60489eccc48.zip |
cryptosoft: Fully support per-operation keys for auth algorithms.
Only pre-allocate auth contexts when a session-wide key is provided or
for sessions without keys. For sessions with per-operation keys,
always initialize the on-stack context directly rather than
initializing the session context in swcr_authprepare (now removed) and
then copying that session context into the on-stack context.
This approach permits parallel auth operations without needing a
serializing lock. In addition, the previous code assumed that auth
sessions always provided an initial key unlike cipher sessions which
assume either an initial key or per-op keys.
While here, fix the Blake2 auth transforms to function like other auth
transforms where Setkey is invoked after Init rather than before.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33316
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/blake2/blake2-sw.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/sys/crypto/blake2/blake2-sw.c b/sys/crypto/blake2/blake2-sw.c index 449ef2be94f5..dafe0e3f84a4 100644 --- a/sys/crypto/blake2/blake2-sw.c +++ b/sys/crypto/blake2/blake2-sw.c @@ -28,8 +28,6 @@ extern int blake2s_ref(uint8_t *out, const void *in, const void *key, struct blake2b_xform_ctx { blake2b_state state; - uint8_t key[BLAKE2B_KEYBYTES]; - uint16_t klen; }; CTASSERT(sizeof(union authctx) >= sizeof(struct blake2b_xform_ctx)); @@ -39,24 +37,21 @@ blake2b_xform_init(void *vctx) struct blake2b_xform_ctx *ctx = vctx; int rc; - if (ctx->klen > 0) - rc = blake2b_init_key_ref(&ctx->state, BLAKE2B_OUTBYTES, - ctx->key, ctx->klen); - else - rc = blake2b_init_ref(&ctx->state, BLAKE2B_OUTBYTES); + rc = blake2b_init_ref(&ctx->state, BLAKE2B_OUTBYTES); if (rc != 0) - panic("blake2b_init_key: invalid arguments"); + panic("blake2b_init: invalid arguments"); } static void blake2b_xform_setkey(void *vctx, const uint8_t *key, u_int klen) { struct blake2b_xform_ctx *ctx = vctx; + int rc; - if (klen > sizeof(ctx->key)) - panic("invalid klen %u", (unsigned)klen); - memcpy(ctx->key, key, klen); - ctx->klen = klen; + rc = blake2b_init_key_ref(&ctx->state, BLAKE2B_OUTBYTES, key, + klen); + if (rc != 0) + panic("blake2b_init_key: invalid arguments"); } static int @@ -96,8 +91,6 @@ const struct auth_hash auth_hash_blake2b = { struct blake2s_xform_ctx { blake2s_state state; - uint8_t key[BLAKE2S_KEYBYTES]; - uint16_t klen; }; CTASSERT(sizeof(union authctx) >= sizeof(struct blake2s_xform_ctx)); @@ -107,24 +100,21 @@ blake2s_xform_init(void *vctx) struct blake2s_xform_ctx *ctx = vctx; int rc; - if (ctx->klen > 0) - rc = blake2s_init_key_ref(&ctx->state, BLAKE2S_OUTBYTES, - ctx->key, ctx->klen); - else - rc = blake2s_init_ref(&ctx->state, BLAKE2S_OUTBYTES); + rc = blake2s_init_ref(&ctx->state, BLAKE2S_OUTBYTES); if (rc != 0) - panic("blake2s_init_key: invalid arguments"); + panic("blake2s_init: invalid arguments"); } static void blake2s_xform_setkey(void *vctx, const uint8_t *key, u_int klen) { struct blake2s_xform_ctx *ctx = vctx; + int rc; - if (klen > sizeof(ctx->key)) - panic("invalid klen %u", (unsigned)klen); - memcpy(ctx->key, key, klen); - ctx->klen = klen; + rc = blake2s_init_key_ref(&ctx->state, BLAKE2S_OUTBYTES, key, + klen); + if (rc != 0) + panic("blake2s_init_key: invalid arguments"); } static int |