Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: amcc - switch to AES library for GCM key derivation

The AMCC code for GCM key derivation allocates a AES cipher to
perform a single block encryption. So let's switch to the new
and more lightweight AES library instead.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
da3e7a97 28a220aa

+9 -17
+1 -1
drivers/crypto/Kconfig
··· 312 312 depends on PPC && 4xx 313 313 select CRYPTO_HASH 314 314 select CRYPTO_AEAD 315 - select CRYPTO_AES 315 + select CRYPTO_LIB_AES 316 316 select CRYPTO_CCM 317 317 select CRYPTO_CTR 318 318 select CRYPTO_GCM
+8 -16
drivers/crypto/amcc/crypto4xx_alg.c
··· 527 527 static int crypto4xx_compute_gcm_hash_key_sw(__le32 *hash_start, const u8 *key, 528 528 unsigned int keylen) 529 529 { 530 - struct crypto_cipher *aes_tfm = NULL; 530 + struct crypto_aes_ctx ctx; 531 531 uint8_t src[16] = { 0 }; 532 - int rc = 0; 532 + int rc; 533 533 534 - aes_tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_NEED_FALLBACK); 535 - if (IS_ERR(aes_tfm)) { 536 - rc = PTR_ERR(aes_tfm); 537 - pr_warn("could not load aes cipher driver: %d\n", rc); 534 + rc = aes_expandkey(&ctx, key, keylen); 535 + if (rc) { 536 + pr_err("aes_expandkey() failed: %d\n", rc); 538 537 return rc; 539 538 } 540 539 541 - rc = crypto_cipher_setkey(aes_tfm, key, keylen); 542 - if (rc) { 543 - pr_err("setkey() failed: %d\n", rc); 544 - goto out; 545 - } 546 - 547 - crypto_cipher_encrypt_one(aes_tfm, src, src); 540 + aes_encrypt(&ctx, src, src); 548 541 crypto4xx_memcpy_to_le32(hash_start, src, 16); 549 - out: 550 - crypto_free_cipher(aes_tfm); 551 - return rc; 542 + memzero_explicit(&ctx, sizeof(ctx)); 543 + return 0; 552 544 } 553 545 554 546 int crypto4xx_setkey_aes_gcm(struct crypto_aead *cipher,