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

index 20d2494708a34c4d25203dc9f5c5283e3fdd3456..3fbb1f8b6eb1e08ecbcd5a0ed06974da0e063677 100644 (file)
@@ -32,6 +32,8 @@
 #ifndef NETTLE_HMAC_INTERNAL_H_INCLUDED
 #define NETTLE_HMAC_INTERNAL_H_INCLUDED
 
+#include <string.h>
+
 #include "nettle-types.h"
 #include "nettle-meta.h"
 
index afbdc5214c1162eae0dff7529c0535ac4fae3a8e..240cd92ac1671dbe65211a73107273d219c183d5 100644 (file)
@@ -2,7 +2,7 @@
 
    HMAC-MD5 message authentication code.
 
-   Copyright (C) 2002 Niels Möller
+   Copyright (C) 2002, 2024 Niels Möller
 
    This file is part of GNU Nettle.
 
 #endif
 
 #include "hmac.h"
+#include "hmac-internal.h"
 
 void
 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
                 size_t key_length, const uint8_t *key)
 {
-  HMAC_SET_KEY(ctx, &nettle_md5, key_length, key);
+  _nettle_hmac_set_key (sizeof(ctx->outer), ctx->outer, ctx->inner, &ctx->state,
+                       ctx->state.block, &nettle_md5, key_length, key);
 }
 
 void
@@ -55,5 +57,7 @@ void
 hmac_md5_digest(struct hmac_md5_ctx *ctx,
                uint8_t *digest)
 {
-  HMAC_DIGEST(ctx, &nettle_md5, digest);
+  md5_digest (&ctx->state, ctx->state.block);
+  ctx->state.index = MD5_DIGEST_SIZE;
+  _NETTLE_HMAC_DIGEST (ctx->outer, ctx->inner, &ctx->state, md5_digest, digest);
 }
index 6adc62dea85ee1f02bdc6aaf814433b9235f810d..aa9ce206b9b5a1e4ce013d2ee6e6e24117a8aeb7 100644 (file)
@@ -2,7 +2,7 @@
 
    HMAC-SHA256 message authentication code.
 
-   Copyright (C) 2003 Niels Möller
+   Copyright (C) 2003, 2024 Niels Möller
 
    This file is part of GNU Nettle.
 
@@ -39,8 +39,6 @@
 
 #include "hmac.h"
 #include "hmac-internal.h"
-#include "memxor.h"
-#include "sha2-internal.h"
 
 void
 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
diff --git a/hmac.h b/hmac.h
index dbfbbbe828e7cf49e8cdaded21af657f70be451e..c39c1a3dc3f14a20bc9212ca3c061819c4df646b 100644 (file)
--- a/hmac.h
+++ b/hmac.h
@@ -104,7 +104,10 @@ hmac_digest(const void *outer, const void *inner, void *state,
            uint8_t *digest);
 
 
-#define HMAC_CTX(type) \
+#define HMAC_CTX(type, size)                           \
+{ char outer[size]; char inner[size]; type state; }
+
+#define OLD_HMAC_CTX(type) \
 { type outer; type inner; type state; }
 
 #define HMAC_SET_KEY(ctx, hash, length, key)                   \
@@ -118,7 +121,7 @@ hmac_digest(const void *outer, const void *inner, void *state,
 /* HMAC using specific hash functions */
 
 /* hmac-md5 */
-struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
+struct hmac_md5_ctx HMAC_CTX(struct md5_ctx, offsetof(struct md5_ctx, index));
 
 void
 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
@@ -134,7 +137,7 @@ hmac_md5_digest(struct hmac_md5_ctx *ctx,
 
 
 /* hmac-ripemd160 */
-struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
+struct hmac_ripemd160_ctx OLD_HMAC_CTX(struct ripemd160_ctx);
 
 void
 hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
@@ -150,7 +153,7 @@ hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
 
 
 /* hmac-sha1 */
-struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
+struct hmac_sha1_ctx OLD_HMAC_CTX(struct sha1_ctx);
 
 void
 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
@@ -165,11 +168,7 @@ hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
                 uint8_t *digest);
 
 /* hmac-sha256 */
-struct hmac_sha256_ctx {
-  char outer[offsetof(struct sha256_ctx, index)];
-  char inner[offsetof(struct sha256_ctx, index)];
-  struct sha256_ctx state;
-};
+struct hmac_sha256_ctx HMAC_CTX (struct sha256_ctx, offsetof(struct sha256_ctx, index));
 
 void
 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
@@ -197,7 +196,7 @@ hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
                   uint8_t *digest);
 
 /* hmac-sha512 */
-struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
+struct hmac_sha512_ctx OLD_HMAC_CTX(struct sha512_ctx);
 
 void
 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
@@ -225,7 +224,7 @@ hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
                   uint8_t *digest);
 
 /* hmac-gosthash94 */
-struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
+struct hmac_gosthash94_ctx OLD_HMAC_CTX(struct gosthash94_ctx);
 
 void
 hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
@@ -239,7 +238,7 @@ hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
 hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
                       uint8_t *digest);
 
-struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
+struct hmac_gosthash94cp_ctx OLD_HMAC_CTX(struct gosthash94cp_ctx);
 
 void
 hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
@@ -255,7 +254,7 @@ hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
 
 
 /* hmac-streebog */
-struct hmac_streebog512_ctx HMAC_CTX(struct streebog512_ctx);
+struct hmac_streebog512_ctx OLD_HMAC_CTX(struct streebog512_ctx);
 
 void
 hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,
@@ -282,7 +281,7 @@ hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
                        uint8_t *digest);
 
 /* hmac-sm3 */
-struct hmac_sm3_ctx HMAC_CTX(struct sm3_ctx);
+struct hmac_sm3_ctx OLD_HMAC_CTX(struct sm3_ctx);
 
 void
 hmac_sm3_set_key(struct hmac_sm3_ctx *ctx,