Linux FSCRYPT development
 help / color / mirror / Atom feed
* [PATCH] fscrypt: Use aes_ecb_encrypt() for v1 key derivation
@ 2026-08-31 19:24 Eric Biggers
  0 siblings, 0 replies; only message in thread
From: Eric Biggers @ 2026-08-31 19:24 UTC (permalink / raw)
  To: linux-fscrypt; +Cc: linux-crypto, linux-kernel, Eric Biggers

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@kernel.org>
---
 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 cd934e31dec4..4cfbf4b51be7 100644
--- a/fs/crypto/Kconfig
+++ b/fs/crypto/Kconfig
@@ -5,7 +5,7 @@ config FS_ENCRYPTION
 	select BLK_INLINE_ENCRYPTION_FALLBACK if BLOCK
 	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 87fe13ccb253..d9ac7c4328f8 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>
@@ -246,8 +246,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);
 

base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
-- 
2.55.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-31 19:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 19:24 [PATCH] fscrypt: Use aes_ecb_encrypt() for v1 key derivation Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox