diff options
| author | Thomas Huth <thuth@redhat.com> | 2026-09-16 11:50:04 +0200 |
|---|---|---|
| committer | Eric Biggers <ebiggers@kernel.org> | 2026-09-30 09:33:54 -0700 |
| commit | bde4dcd6cac5cbdaa3144adffeb3a0c1d9bba064 (patch) | |
| tree | 1ebabeda3a48a8f6eb76f1e4b18d1d0a8dbf6556 /include | |
| parent | 72f4c2eae4036d0d5e63f9aa548c2688f8f99ff1 (diff) | |
| download | linux-next-bde4dcd6cac5cbdaa3144adffeb3a0c1d9bba064.tar.gz linux-next-bde4dcd6cac5cbdaa3144adffeb3a0c1d9bba064.zip | |
lib/crypto: aes-xts: Provide function for zeroizing aes_xts_key
In certain cases crypto code functions need to zeroize their local
aes_xts_key structures after use to avoid leaking sensitive material.
Provide an aes_xts_zeroize_key() helper function that e.g. can be
used with __cleanup() to automatically zeroize the struct when it
goes out of scope.
While we're at it, replace the related memzero_explicit() call in
lib/crypto/aes.c with a call to the new helper function.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://patch.msgid.link/20260916095022.604354-3-thuth@redhat.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/aes-xts.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/include/crypto/aes-xts.h b/include/crypto/aes-xts.h index b9e828265e58..3a52e1cf40b5 100644 --- a/include/crypto/aes-xts.h +++ b/include/crypto/aes-xts.h @@ -23,6 +23,15 @@ struct aes_xts_key { }; /** + * aes_xts_zeroize_key() - Zeroize an aes_xts_key structure + * @key: The aes_xts_key to zeroize + */ +static inline void aes_xts_zeroize_key(struct aes_xts_key *key) +{ + memzero_explicit(key, sizeof(*key)); +} + +/** * aes_xts_preparekey() - Prepare a key for AES-XTS encryption and decryption * @key: (output) The key structure to initialize * @in_key: The raw AES-XTS key @@ -30,8 +39,8 @@ struct aes_xts_key { * @flags: Optional flag XTS_FORBID_WEAK_KEYS to forbid keys whose two halves * are the same. * - * Users should use memzero_explicit() to zeroize the key struct at the end of - * its lifetime. (But if this function fails, zeroization is unnecessary.) + * Users should use aes_xts_zeroize_key() to zeroize the key struct at the end + * of its lifetime. (But if this function fails, zeroization is unnecessary.) * * Context: Any context. * Return: |
