crypto: amcc - switch to AES library for GCM key derivation
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 2 Jul 2019 19:41:42 +0000 (21:41 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 26 Jul 2019 04:58:12 +0000 (14:58 +1000)
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>
drivers/crypto/Kconfig
drivers/crypto/amcc/crypto4xx_alg.c

index 72d6c2ca08096634cdac9c0b72cf65a719b8bee0..69d1bbd5d9bfcd24e1bc6be536cb9c8c12c5702c 100644 (file)
@@ -312,7 +312,7 @@ config CRYPTO_DEV_PPC4XX
        depends on PPC && 4xx
        select CRYPTO_HASH
        select CRYPTO_AEAD
-       select CRYPTO_AES
+       select CRYPTO_LIB_AES
        select CRYPTO_CCM
        select CRYPTO_CTR
        select CRYPTO_GCM
index cbfc607282f48238b932d62be7a257d0cfa4a021..a42f8619589d3949426863044b5e844e651e685b 100644 (file)
@@ -527,28 +527,20 @@ static int crypto4xx_aes_gcm_validate_keylen(unsigned int keylen)
 static int crypto4xx_compute_gcm_hash_key_sw(__le32 *hash_start, const u8 *key,
                                             unsigned int keylen)
 {
-       struct crypto_cipher *aes_tfm = NULL;
+       struct crypto_aes_ctx ctx;
        uint8_t src[16] = { 0 };
-       int rc = 0;
-
-       aes_tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_NEED_FALLBACK);
-       if (IS_ERR(aes_tfm)) {
-               rc = PTR_ERR(aes_tfm);
-               pr_warn("could not load aes cipher driver: %d\n", rc);
-               return rc;
-       }
+       int rc;
 
-       rc = crypto_cipher_setkey(aes_tfm, key, keylen);
+       rc = aes_expandkey(&ctx, key, keylen);
        if (rc) {
-               pr_err("setkey() failed: %d\n", rc);
-               goto out;
+               pr_err("aes_expandkey() failed: %d\n", rc);
+               return rc;
        }
 
-       crypto_cipher_encrypt_one(aes_tfm, src, src);
+       aes_encrypt(&ctx, src, src);
        crypto4xx_memcpy_to_le32(hash_start, src, 16);
-out:
-       crypto_free_cipher(aes_tfm);
-       return rc;
+       memzero_explicit(&ctx, sizeof(ctx));
+       return 0;
 }
 
 int crypto4xx_setkey_aes_gcm(struct crypto_aead *cipher,