Skip to contentSkip to conversation

fscrypt: Use aes_ecb_encrypt() for v1 key derivation

PATCH Applied Eric Biggers 1 participant 2 messages Aug 31 – Sep 18

Subsystems (2)
lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fscrypt: Use aes_ecb_encrypt() for v1 key derivation

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.

---
 fs/crypto/Kconfig       | 2 +-
 fs/crypto/keysetup_v1.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
fs/crypto/Kconfig +1 -1
index cd934e31dec4..4cfbf4b51be7 100644
@@ -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
fs/crypto/keysetup_v1.c +2 -3
index 87fe13ccb253..d9ac7c4328f8 100644
@@ -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

Signature · 1 line
2.55.0
author maintainer Applied
#1 lore raw
Quoted 8 lines · 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.

Quoted 5 lines
---
 fs/crypto/Kconfig       | 2 +-
 fs/crypto/keysetup_v1.c | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

Applied to https://git.kernel.org/pub/scm/fs/fscrypt/linux.git/log/?h=for-next

- Eric