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.

Link: https://patch.msgid.link/20260831192411.99035-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
Eric Biggers 2026-08-31 12:24:11 -07:00
parent fd73f4a665
commit 0247a1ed52
2 changed files with 3 additions and 4 deletions

View File

@ -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

View File

@ -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);