Skip to content

Commit f6680cb

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: x86/aes-ni - use AES library instead of single-use AES cipher
The RFC4106 key derivation code instantiates an AES cipher transform to encrypt only a single block before it is freed again. Switch to the new AES library which is more suitable for such use cases. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent c552ffb commit f6680cb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

arch/x86/crypto/aesni-intel_glue.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -628,26 +628,21 @@ static int xts_decrypt(struct skcipher_request *req)
628628
static int
629629
rfc4106_set_hash_subkey(u8 *hash_subkey, const u8 *key, unsigned int key_len)
630630
{
631-
struct crypto_cipher *tfm;
631+
struct crypto_aes_ctx ctx;
632632
int ret;
633633

634-
tfm = crypto_alloc_cipher("aes", 0, 0);
635-
if (IS_ERR(tfm))
636-
return PTR_ERR(tfm);
637-
638-
ret = crypto_cipher_setkey(tfm, key, key_len);
634+
ret = aes_expandkey(&ctx, key, key_len);
639635
if (ret)
640-
goto out_free_cipher;
636+
return ret;
641637

642638
/* Clear the data in the hash sub key container to zero.*/
643639
/* We want to cipher all zeros to create the hash sub key. */
644640
memset(hash_subkey, 0, RFC4106_HASH_SUBKEY_SIZE);
645641

646-
crypto_cipher_encrypt_one(tfm, hash_subkey, hash_subkey);
642+
aes_encrypt(&ctx, hash_subkey, hash_subkey);
647643

648-
out_free_cipher:
649-
crypto_free_cipher(tfm);
650-
return ret;
644+
memzero_explicit(&ctx, sizeof(ctx));
645+
return 0;
651646
}
652647

653648
static int common_rfc4106_set_key(struct crypto_aead *aead, const u8 *key,

0 commit comments

Comments
 (0)