[PATCH 18/33] fscrypt: Use aes_ecb_encrypt() for v1 key derivation
From: Eric Biggers
Date: Tue Jul 07 2026 - 01:39:39 EST
Now that there's a library function aes_ecb_encrypt(), use it instead of
a loop of aes_encrypt() calls.
Note that the use of AES-ECB here is purely for the key derivation
function used by the deprecated v1 encryption policies. v2 encryption
policies use HKDF-SHA512 instead. Nevertheless, the original version
has to continue to be supported for backwards compatibility.
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
fs/crypto/Kconfig | 2 +-
fs/crypto/keysetup_v1.c | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/crypto/Kconfig b/fs/crypto/Kconfig
index 983d8ad1f417..7662d8c45f07 100644
--- a/fs/crypto/Kconfig
+++ b/fs/crypto/Kconfig
@@ -3,7 +3,7 @@ config FS_ENCRYPTION
bool "FS Encryption (Per-file encryption)"
select CRYPTO
select CRYPTO_SKCIPHER
- select CRYPTO_LIB_AES
+ select CRYPTO_LIB_AES_ECB # for deprecated v1 key derivation function
select CRYPTO_LIB_SHA256
select CRYPTO_LIB_SHA512
select KEYS
diff --git a/fs/crypto/keysetup_v1.c b/fs/crypto/keysetup_v1.c
index e6e527c73f16..70385d82fa73 100644
--- a/fs/crypto/keysetup_v1.c
+++ b/fs/crypto/keysetup_v1.c
@@ -20,7 +20,7 @@
* managed alongside the master keys in the filesystem-level keyring)
*/
-#include <crypto/aes.h>
+#include <crypto/aes-ecb.h>
#include <crypto/utils.h>
#include <keys/user-type.h>
#include <linux/hashtable.h>
@@ -240,8 +240,7 @@ static int setup_v1_file_key_derived(struct fscrypt_inode_info *ci,
static_assert(FSCRYPT_FILE_NONCE_SIZE == AES_KEYSIZE_128);
aes_prepareenckey(&aes, ci->ci_nonce, FSCRYPT_FILE_NONCE_SIZE);
- for (unsigned int i = 0; i < derived_keysize; i += AES_BLOCK_SIZE)
- aes_encrypt(&aes, &derived_key[i], &raw_master_key[i]);
+ aes_ecb_encrypt(derived_key, raw_master_key, derived_keysize, &aes);
err = fscrypt_set_per_file_enc_key(ci, derived_key);
--
2.54.0