]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Update hmac-sm3.
authorNiels Möller <nisse@lysator.liu.se>
Wed, 30 Oct 2024 10:25:24 +0000 (11:25 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 22 Jun 2025 19:11:04 +0000 (21:11 +0200)
hmac-sm3.c
hmac.h

index 67a21dde1b3df34258e88b6318fda514dcf30368..bba2afe736d9bed2cec4b1faaf2a035cc877327b 100644 (file)
@@ -3,6 +3,7 @@
    HMAC-SM3 message authentication code.
 
    Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
+   Copyright (C) 2024 Niels Möller
 
    This file is part of GNU Nettle.
 
 #endif
 
 #include "hmac.h"
+#include "hmac-internal.h"
 
 void
 hmac_sm3_set_key(struct hmac_sm3_ctx *ctx,
                 size_t key_length, const uint8_t *key)
 {
-  HMAC_SET_KEY(ctx, &nettle_sm3, key_length, key);
+  _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state,
+                       ctx->state.block, &nettle_sm3, key_length, key);
 }
 
 void
@@ -55,5 +58,7 @@ void
 hmac_sm3_digest(struct hmac_sm3_ctx *ctx,
                uint8_t *digest)
 {
-  HMAC_DIGEST(ctx, &nettle_sm3, digest);
+  sm3_digest (&ctx->state, ctx->state.block);
+  ctx->state.index = SM3_DIGEST_SIZE;
+  _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, sm3_digest, digest);
 }
diff --git a/hmac.h b/hmac.h
index 6ffe501d68d48340601e2c7c7e8fa48eacec4474..4625f6145296257df9058435153fde0c82e25634 100644 (file)
--- a/hmac.h
+++ b/hmac.h
@@ -281,7 +281,7 @@ hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
                        uint8_t *digest);
 
 /* hmac-sm3 */
-struct hmac_sm3_ctx OLD_HMAC_CTX(struct sm3_ctx);
+struct hmac_sm3_ctx HMAC_CTX (struct sm3_ctx, offsetof (struct sm3_ctx, index));
 
 void
 hmac_sm3_set_key(struct hmac_sm3_ctx *ctx,