diff options
| author | Thomas Huth <thuth@redhat.com> | 2026-09-16 11:50:03 +0200 |
|---|---|---|
| committer | Eric Biggers <ebiggers@kernel.org> | 2026-09-30 09:33:54 -0700 |
| commit | 72f4c2eae4036d0d5e63f9aa548c2688f8f99ff1 (patch) | |
| tree | 85a2c130749ec76d92113354a14e70415da907f4 /include | |
| parent | 572af6872e520c7102e58362ef7cd7c2ed4342be (diff) | |
| download | linux-72f4c2eae4036d0d5e63f9aa548c2688f8f99ff1.tar.gz linux-72f4c2eae4036d0d5e63f9aa548c2688f8f99ff1.zip | |
lib/crypto: aes: Provide functions for zeroizing aes_key and aes_enckey
Some crypto functions need to zeroize their local aes_key or aes_enckey
structures after use to avoid leaking sensitive material on the stack.
Provide aes_zeroize_key() and aes_zeroize_enckey() helper functions that
can be used with __cleanup() to automatically zeroize the structs when
they go out of scope.
While we're at it, replace the memzero_explicit() calls in lib/crypto/aes.c
with the new helper functions.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://patch.msgid.link/20260916095022.604354-2-thuth@redhat.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/aes.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 3279cfa54608..9fe868161e1d 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -102,6 +102,15 @@ struct aes_enckey { }; /** + * aes_zeroize_enckey() - Zeroize an aes_enckey structure + * @key: The aes_enckey to zeroize + */ +static inline void aes_zeroize_enckey(struct aes_enckey *key) +{ + memzero_explicit(key, sizeof(*key)); +} + +/** * struct aes_key - An AES key prepared for encryption and decryption * @aes_enckey: Common fields and the key prepared for encryption * @inv_k: This generally contains the round keys for the AES Equivalent @@ -115,6 +124,15 @@ struct aes_key { union aes_invkey_arch inv_k; }; +/** + * aes_zeroize_key() - Zeroize an aes_key structure + * @key: The aes_key to zeroize + */ +static inline void aes_zeroize_key(struct aes_key *key) +{ + memzero_explicit(key, sizeof(*key)); +} + /* * Please ensure that the first two fields are 16-byte aligned * relative to the start of the structure, i.e., don't move them! |
