summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2026-09-16 11:50:10 +0200
committerEric Biggers <ebiggers@kernel.org>2026-09-30 09:33:54 -0700
commite09cbc96ff8c94d477a07b2e35b4b4886dc9cf30 (patch)
treec135b1c34bbb0ca3ad42a093a83992d58670fed9 /include
parent97560fd98d4d36b2fd656a6270e15cb2218fcbe2 (diff)
downloadlinux-e09cbc96ff8c94d477a07b2e35b4b4886dc9cf30.tar.gz
linux-e09cbc96ff8c94d477a07b2e35b4b4886dc9cf30.zip
lib/crypto: sha1: Provide functions for zeroizing hmac_sha1 structures
In certain cases crypto code needs to zeroize their local hmac_sha1_key or hmac_sha1_ctx structures after use to avoid leaking sensitive material. Provide hmac_sha1_zeroize_key() and hmac_sha1_zeroize_ctx() helper functions that e.g. can be used with __cleanup() to automatically zeroize the structures when they go out of scope. While we're at it, replace the related memzero_explicit() call in lib/crypto/sha1.c with a call to the new helper function. Signed-off-by: Thomas Huth <thuth@redhat.com> Link: https://patch.msgid.link/20260916095022.604354-9-thuth@redhat.com Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/sha1.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/crypto/sha1.h b/include/crypto/sha1.h
index 4d973e016cd6..bc0046bffeae 100644
--- a/include/crypto/sha1.h
+++ b/include/crypto/sha1.h
@@ -7,6 +7,7 @@
#define _CRYPTO_SHA1_H
#include <linux/types.h>
+#include <linux/string.h>
#define SHA1_DIGEST_SIZE 20
#define SHA1_BLOCK_SIZE 64
@@ -97,6 +98,15 @@ struct hmac_sha1_key {
};
/**
+ * hmac_sha1_zeroize_key() - Zeroize an hmac_sha1_key structure
+ * @key: The hmac_sha1_key to zeroize
+ */
+static inline void hmac_sha1_zeroize_key(struct hmac_sha1_key *key)
+{
+ memzero_explicit(key, sizeof(*key));
+}
+
+/**
* struct hmac_sha1_ctx - Context for computing HMAC-SHA1 of a message
* @sha_ctx: private
* @ostate: private
@@ -107,6 +117,15 @@ struct hmac_sha1_ctx {
};
/**
+ * hmac_sha1_zeroize_ctx() - Zeroize an hmac_sha1_ctx structure
+ * @ctx: The hmac_sha1_ctx context to zeroize
+ */
+static inline void hmac_sha1_zeroize_ctx(struct hmac_sha1_ctx *ctx)
+{
+ memzero_explicit(ctx, sizeof(*ctx));
+}
+
+/**
* hmac_sha1_preparekey() - Prepare a key for HMAC-SHA1
* @key: (output) the key structure to initialize
* @raw_key: the raw HMAC-SHA1 key