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

index ab5da30890a65b78943a201d07cc7744497233ab..1791cb4405f6d322b1cc44b36caac73e5084f085 100644 (file)
@@ -3,6 +3,7 @@
    HMAC-Streebog message authentication code.
 
    Copyright (C) 2016 Dmitry Eremin-Solenikov
+   Copyright (C) 2024 Niels Möller
 
    This file is part of GNU Nettle.
 
 #endif
 
 #include "hmac.h"
+#include "hmac-internal.h"
 
 void
 hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,
                         size_t key_length, const uint8_t *key)
 {
-  HMAC_SET_KEY(ctx, &nettle_streebog512, key_length, key);
+  _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state,
+                       ctx->state.block, &nettle_streebog512, key_length, key);
 }
 
 void
@@ -55,19 +58,28 @@ void
 hmac_streebog512_digest(struct hmac_streebog512_ctx *ctx,
                        uint8_t *digest)
 {
-  HMAC_DIGEST(ctx, &nettle_streebog512, digest);
+  /* Using _NETTLE_HMAC_DIGEST doesn't work since
+     STREEBOG512_DIGEST_SIZE == STREEBOG512_BLOCK_SIZE. */
+  streebog512_digest (&ctx->state, ctx->state.block);
+  memcpy (&ctx->state, ctx->outer, sizeof (ctx->outer));
+  streebog512_update (&ctx->state, STREEBOG512_DIGEST_SIZE, ctx->state.block);
+  streebog512_digest (&ctx->state, digest);
+  memcpy (&ctx->state, ctx->inner, sizeof (ctx->inner));
 }
 
 void
 hmac_streebog256_set_key(struct hmac_streebog256_ctx *ctx,
                         size_t key_length, const uint8_t *key)
 {
-  HMAC_SET_KEY(ctx, &nettle_streebog256, key_length, key);
+  _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state,
+                       ctx->state.block, &nettle_streebog256, key_length, key);
 }
 
 void
 hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
                        uint8_t *digest)
 {
-  HMAC_DIGEST(ctx, &nettle_streebog256, digest);
+  streebog256_digest (&ctx->state, ctx->state.block);
+  ctx->state.index = STREEBOG256_DIGEST_SIZE;
+  _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, streebog256_digest, digest);
 }
diff --git a/hmac.h b/hmac.h
index 4625f6145296257df9058435153fde0c82e25634..65964acfd3e1cb1f708a2cc6478f0e8c5a3694c8 100644 (file)
--- a/hmac.h
+++ b/hmac.h
@@ -254,7 +254,7 @@ hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
 
 
 /* hmac-streebog */
-struct hmac_streebog512_ctx OLD_HMAC_CTX(struct streebog512_ctx);
+struct hmac_streebog512_ctx HMAC_CTX (struct streebog512_ctx, offsetof (struct streebog512_ctx, index));
 
 void
 hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,