Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3745762ybi; Tue, 2 Jul 2019 12:43:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzfbCToyiPCCCuT8SBOFOLgHgR16WgbQg/W0qtMpqRMK36XgBoB8rj0K+fYJmjdhan/eMFR X-Received: by 2002:a17:902:549:: with SMTP id 67mr37141054plf.86.1562096588226; Tue, 02 Jul 2019 12:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562096588; cv=none; d=google.com; s=arc-20160816; b=XjDJipFg6hA1dXt/CXoPLP7reHe9ZTR+s0LZ7JDFm859u0WJ4PWgiRCrvSdJshRWib AFyv2iuHx3TDWwb3TkzZY0E78o1rpzCmM5coGxaNrd83aj8DQRJEd/BdYAkpuzO4cuop DHrbD2oI+Vtx3Sj6T2mAv0eUSajhLvd3+bp+6y3iD7SxX0X4YxU9dNyjwFZ1q0CyzU2t jc/0CKQiG1ll0JqR5AReCoJ2bi9liAbYWEp4xDAhqRB4m/i6noXOW3LlKa2UV+hKIWIG PAjn6aiMQ9xMpMf0SizeXyA/AbGCDRvoI1XyY6GVGVmcdB+zdwemGHUvf39O4OMX+Exp Styg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=VQ3v2advvdDgCgxLjFb+IrRE2Pm4FCw8P9b47+HGrWM=; b=Obdmte5zjf8VWVhfRcmpdZhLruy6+Wcva86FNOx8mtV7pxyHroz0M4B5P8VQBskeCS M7xYXX0oIK9mcv3WyTReHczSGB5kQScaLAtuFn4sMmM8VlEsIZI+JOqevFhe/dgvyQps j/vytcmNcvbfklH1uLkkXl24PjjU2OD00w+4HZobgSMAiXivZRTQehU0ndK8aOuJIdPV SAIVMRpltRx2J7FHi0VYv2Q1jY1lrbtf/KHt6QUJJjMMcIOHS/QeDacIuEzgtmv5Qtcf WW4mbiZez5DH4lYRuwVI8m7dWOZFVC6E6O9+fW62Tb4lhULLqaWA48bmyLgo6tYpSsKV hm6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a5jJXAy9; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9si15329053pfl.287.2019.07.02.12.42.54; Tue, 02 Jul 2019 12:43:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a5jJXAy9; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbfGBTmo (ORCPT + 99 others); Tue, 2 Jul 2019 15:42:44 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33804 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbfGBTmo (ORCPT ); Tue, 2 Jul 2019 15:42:44 -0400 Received: by mail-lj1-f196.google.com with SMTP id p17so18207336ljg.1 for ; Tue, 02 Jul 2019 12:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VQ3v2advvdDgCgxLjFb+IrRE2Pm4FCw8P9b47+HGrWM=; b=a5jJXAy92Km3JOrJb1aLFv81FKj0y0B7GbXDsQYA6S9sCF7LQ+4cgq2FzJ0aWjb2IO jOC4O2jvHItRVgMr6MNswrwrvMeThRyJahksL6CaXzHKeidi9tS7FIKY4h3euKKm/rd1 AUJAzD7foHXEnzcD+8KF52+idI7CA6Hz/8vLNgFRqVVl/lzqVGyCewaS0qcIxxCYJjJx zD2m5wvm8N7E8CJK8tXItzf1VH2gYxsMOQsiCuldxQFSA3lQHMqbfjxFT2YzO9u0uY3v 37Nu9xVjcQ0RARCYxPPpwBZzW+y5eCXS3+S8hS/QSgdJURoYc6EF6LTtSXb5R089xFuj 8kuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VQ3v2advvdDgCgxLjFb+IrRE2Pm4FCw8P9b47+HGrWM=; b=tcLadTcVuxirM7gylzF7BfQ5uv9xD/Ct6Fq8wqey1cYWxFWctC0RnNEbUbl9ZEz8dh u2FK8UlYsMDqLpK+auuuIxIuW+MDTvRHeGXdDQt1B3bFmzySdbwLkl3rftWyjRaTBGmQ XLd5kEEyctybCBwRotKDF74wZ2zjPL70O3+G0Gn2KSZUDl3gxydlTP9OAJH0pVXEEOxJ u0AT9bBTPK1klFbjgHkPUHyZSU3bnw3YFWKOdiKcIOeKl6Fe1ND3e4mNwzAut4Xhwgos 5t5nvct7FqGLCh+lcNhkRA1ajMISsYYEf6Fv9qmXwfozlnHy8EtmFoFcUIxrVJRjisxt 3byw== X-Gm-Message-State: APjAAAUYb3Dgw2B5XDTH4IWlIJsCIzCpW/KL/SE5PLXe0Rtblri3EYNs sVvKJfgEY3nweM7ip4UWHFSkrd9AVjzVuIdj X-Received: by 2002:a2e:3c1a:: with SMTP id j26mr18680446lja.230.1562096562363; Tue, 02 Jul 2019 12:42:42 -0700 (PDT) Received: from e111045-lin.arm.com (89-212-78-239.static.t-2.net. [89.212.78.239]) by smtp.gmail.com with ESMTPSA id 24sm4475163ljs.63.2019.07.02.12.42.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 12:42:41 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [PATCH v4 24/32] crypto: amcc/aes - switch to AES library for GCM key derivation Date: Tue, 2 Jul 2019 21:41:42 +0200 Message-Id: <20190702194150.10405-25-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702194150.10405-1-ard.biesheuvel@linaro.org> References: <20190702194150.10405-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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 --- drivers/crypto/Kconfig | 2 +- drivers/crypto/amcc/crypto4xx_alg.c | 24 +++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index b30b84089d11..c7ac1e6d23d4 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -311,7 +311,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 diff --git a/drivers/crypto/amcc/crypto4xx_alg.c b/drivers/crypto/amcc/crypto4xx_alg.c index 26f86fd7532b..d3660703a36c 100644 --- a/drivers/crypto/amcc/crypto4xx_alg.c +++ b/drivers/crypto/amcc/crypto4xx_alg.c @@ -536,28 +536,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, -- 2.17.1