summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2026-09-16 11:50:07 +0200
committerEric Biggers <ebiggers@kernel.org>2026-09-30 09:33:54 -0700
commit91b4ebff7a88ee3a0570b0058b054ecf527cefa2 (patch)
treecbb5304054e0093d959e6c55dcf6e2b663bcde74 /include
parentdbb5091fb6c937ff312257aaf9b772216c3ca8f6 (diff)
downloadlinux-91b4ebff7a88ee3a0570b0058b054ecf527cefa2.tar.gz
linux-91b4ebff7a88ee3a0570b0058b054ecf527cefa2.zip
lib/crypto: md5: Provide functions for zeroizing hmac_md5 structures
In certain cases crypto code functions need to zeroize their local hmac_md5_key or hmac_md5_ctx structures after use to avoid leaking sensitive material on the stack. Provide hmac_md5_zeroize_key() and hmac_md5_zeroize_ctx() helper functions that e.g. can be used with __cleanup() to automatically zeroize the structure when it goes out of scope. While we're at it, replace the related memzero_explicit() call in lib/crypto/md5.c with a call to the new helper function. Signed-off-by: Thomas Huth <thuth@redhat.com> Link: https://patch.msgid.link/20260916095022.604354-6-thuth@redhat.com Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/md5.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/crypto/md5.h b/include/crypto/md5.h
index c47aedfe67ec..1ed89c15b662 100644
--- a/include/crypto/md5.h
+++ b/include/crypto/md5.h
@@ -4,6 +4,7 @@
#include <crypto/hash.h>
#include <linux/types.h>
+#include <linux/string.h>
#define MD5_DIGEST_SIZE 16
#define MD5_HMAC_BLOCK_SIZE 64
@@ -99,6 +100,15 @@ struct hmac_md5_key {
};
/**
+ * hmac_md5_zeroize_key() - Zeroize an hmac_md5_key structure
+ * @key: The hmac_md5_key to zeroize
+ */
+static inline void hmac_md5_zeroize_key(struct hmac_md5_key *key)
+{
+ memzero_explicit(key, sizeof(*key));
+}
+
+/**
* struct hmac_md5_ctx - Context for computing HMAC-MD5 of a message
* @hash_ctx: private
* @ostate: private
@@ -109,6 +119,15 @@ struct hmac_md5_ctx {
};
/**
+ * hmac_md5_zeroize_ctx() - Zeroize an hmac_md5_ctx structure
+ * @ctx: The hmac_md5_ctx context to zeroize
+ */
+static inline void hmac_md5_zeroize_ctx(struct hmac_md5_ctx *ctx)
+{
+ memzero_explicit(ctx, sizeof(*ctx));
+}
+
+/**
* hmac_md5_preparekey() - Prepare a key for HMAC-MD5
* @key: (output) the key structure to initialize
* @raw_key: the raw HMAC-MD5 key