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

index 1d9af7d702c20382a1f5748d0d77a1d838709ee8..dc588a0eb139ef8d43d3532c8a237bbc316487d3 100644 (file)
 #include <string.h>
 
 #include "hmac.h"
-#include "memxor.h"
-
-#define IPAD 0x36
-#define OPAD 0x5c
+#include "hmac-internal.h"
 
 void
 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
                    size_t key_length, const uint8_t *key)
 {
-  uint8_t digest[SHA224_DIGEST_SIZE];
-
-  sha224_init (&ctx->state);
-  if (key_length > SHA224_BLOCK_SIZE)
-    {
-      sha224_update (&ctx->state, key_length, key);
-      sha224_digest (&ctx->state, digest);
-      key = digest;
-      key_length = SHA224_DIGEST_SIZE;
-    }
-
-  memset (ctx->state.block, OPAD, SHA224_BLOCK_SIZE);
-  memxor (ctx->state.block, key, key_length);
-  sha224_update (&ctx->state, SHA224_BLOCK_SIZE, ctx->state.block);
-  memcpy (ctx->outer, ctx->state.state, sizeof(ctx->outer));
-
-  sha224_init (&ctx->state);
-  memset (ctx->state.block, IPAD, SHA224_BLOCK_SIZE);
-  memxor (ctx->state.block, key, key_length);
-  sha224_update (&ctx->state, SHA224_BLOCK_SIZE, ctx->state.block);
-  memcpy (ctx->inner, ctx->state.state, sizeof(ctx->outer));
+  _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state,
+                       ctx->state.block, &nettle_sha224, key_length, key);
 }
 
 void
 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
                   uint8_t *digest)
 {
-  uint8_t inner_digest[SHA224_DIGEST_SIZE];
-  sha224_digest (&ctx->state, inner_digest);
-
-  memcpy (ctx->state.state, ctx->outer, sizeof (ctx->state.state));
-  ctx->state.count = 1;
-  sha224_update (&ctx->state, SHA224_DIGEST_SIZE, inner_digest);
-  sha224_digest (&ctx->state, digest);
-
-  memcpy (ctx->state.state, ctx->inner, sizeof (ctx->state.state));
-  ctx->state.count = 1;
+  sha224_digest (&ctx->state, ctx->state.block);
+  ctx->state.index = SHA224_DIGEST_SIZE;
+  _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, sha224_digest, digest);
 }