From: Niels Möller Date: Wed, 30 Oct 2024 09:06:04 +0000 (+0100) Subject: Include count in the copied state X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97acbbf002693ffb51f3070d349dacf11a9cc5fd;p=thirdparty%2Fnettle.git Include count in the copied state --- diff --git a/hmac-internal.h b/hmac-internal.h index 2861e730..20d24947 100644 --- a/hmac-internal.h +++ b/hmac-internal.h @@ -44,14 +44,10 @@ _nettle_hmac_set_key (size_t state_size, void *outer, void *inner, const struct nettle_hash *hash, size_t key_size, const uint8_t *key); -#define _NETTLE_HMAC_DIGEST(outer, inner, ctx, digest_size, f, digest) do { \ - f ((ctx), (ctx)->block); \ - memcpy (&(ctx)->state, (outer), sizeof ((ctx)->state)); \ - (ctx)->count = 1; \ - (ctx)->index = (digest_size); \ - f ((ctx), (digest)); \ - memcpy (&(ctx)->state, (inner), sizeof ((ctx)->state)); \ - (ctx)->count = 1; \ +#define _NETTLE_HMAC_DIGEST(outer, inner, ctx, f, digest) do { \ + memcpy (&(ctx)->state, (outer), sizeof (outer)); \ + f ((ctx), (digest)); \ + memcpy (&(ctx)->state, (inner), sizeof ((inner))); \ } while (0) #endif /* NETTLE_HMAC_INTERNAL_H_INCLUDED */ diff --git a/hmac-sha256.c b/hmac-sha256.c index bcb7e60b..6adc62de 100644 --- a/hmac-sha256.c +++ b/hmac-sha256.c @@ -48,7 +48,6 @@ hmac_sha256_set_key(struct hmac_sha256_ctx *ctx, { _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state, ctx->state.block, &nettle_sha256, key_length, key); - ctx->state.count = 1; } void @@ -62,5 +61,7 @@ void hmac_sha256_digest(struct hmac_sha256_ctx *ctx, uint8_t *digest) { - _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, SHA256_DIGEST_SIZE, sha256_digest, digest); + sha256_digest (&ctx->state, ctx->state.block); + ctx->state.index = SHA256_DIGEST_SIZE; + _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, sha256_digest, digest); } diff --git a/hmac.h b/hmac.h index 2abb3b20..dbfbbbe8 100644 --- a/hmac.h +++ b/hmac.h @@ -166,8 +166,8 @@ hmac_sha1_digest(struct hmac_sha1_ctx *ctx, /* hmac-sha256 */ struct hmac_sha256_ctx { - uint32_t outer[_SHA256_DIGEST_LENGTH]; - uint32_t inner[_SHA256_DIGEST_LENGTH]; + char outer[offsetof(struct sha256_ctx, index)]; + char inner[offsetof(struct sha256_ctx, index)]; struct sha256_ctx state; };