diff options
| author | Thomas Huth <thuth@redhat.com> | 2026-09-16 11:50:05 +0200 |
|---|---|---|
| committer | Eric Biggers <ebiggers@kernel.org> | 2026-09-30 09:33:54 -0700 |
| commit | f0bcf2d3ef935d0fdb76ca23786fe9880ad80827 (patch) | |
| tree | c6ee0580df5c7d5662d53abba5014d353652aa00 /include | |
| parent | bde4dcd6cac5cbdaa3144adffeb3a0c1d9bba064 (diff) | |
| download | linux-next-f0bcf2d3ef935d0fdb76ca23786fe9880ad80827.tar.gz linux-next-f0bcf2d3ef935d0fdb76ca23786fe9880ad80827.zip | |
lib/crypto: aes-gcm: Provide functions for zeroizing aes_gcm* structures
In certain cases crypto code needs to zeroize their local aes_gcm_key
or aes_gcm_ctx structures after use to avoid leaking sensitive material.
Provide aes_gcm_zeroize_key() and aes_gcm_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() calls in
lib/crypto/aes.c with calls to the new helper functions.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://patch.msgid.link/20260916095022.604354-4-thuth@redhat.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/crypto/aes-gcm.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/include/crypto/aes-gcm.h b/include/crypto/aes-gcm.h index 2aee62f01989..a81b00fd8e27 100644 --- a/include/crypto/aes-gcm.h +++ b/include/crypto/aes-gcm.h @@ -22,6 +22,15 @@ struct aes_gcm_key { }; /** + * aes_gcm_zeroize_key() - Zeroize an aes_gcm_key structure + * @key: The aes_gcm_key to zeroize + */ +static inline void aes_gcm_zeroize_key(struct aes_gcm_key *key) +{ + memzero_explicit(key, sizeof(*key)); +} + +/** * struct aes_gcm_ctx - Context for incrementally en/decrypting a message */ struct aes_gcm_ctx { @@ -59,6 +68,15 @@ struct aes_gcm_ctx { }; /** + * aes_gcm_zeroize_ctx() - Zeroize an aes_gcm_ctx structure + * @ctx: The aes_gcm_ctx to zeroize + */ +static inline void aes_gcm_zeroize_ctx(struct aes_gcm_ctx *ctx) +{ + memzero_explicit(ctx, sizeof(*ctx)); +} + +/** * aes_gcm_preparekey() - Prepare a key for AES-GCM encryption and decryption * @key: (output) The key structure to initialize * @in_key: The raw AES-GCM key @@ -66,8 +84,8 @@ struct aes_gcm_ctx { * @authtag_len: Length of the authentication tag in bytes: * 4, 8, 12, 13, 14, 15, or 16. 16 is recommended. * - * 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_gcm_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: |
