From patchwork Sun Mar 26 18:49:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 96023 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp923290qgd; Sun, 26 Mar 2017 11:57:40 -0700 (PDT) X-Received: by 10.99.2.139 with SMTP id 133mr19944259pgc.168.1490554660688; Sun, 26 Mar 2017 11:57:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si10147965plq.107.2017.03.26.11.57.40; Sun, 26 Mar 2017 11:57:40 -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; 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 S1751724AbdCZS5P (ORCPT + 1 other); Sun, 26 Mar 2017 14:57:15 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:33830 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751660AbdCZS5J (ORCPT ); Sun, 26 Mar 2017 14:57:09 -0400 Received: by mail-wr0-f179.google.com with SMTP id l43so27331057wre.1 for ; Sun, 26 Mar 2017 11:57:07 -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=4se0bxUfDpTOce4vvHAhVEndDjnF7kqIUvifUrMRXxg=; b=PYA+2WrwTf+aumXSVTM4YPMRRsDuq6du5dZUXHxUVWNHJ2eTJq5uUEWvzjFIhz9dyk l2eT3p7MDzetSzdfM1J+Ml1UiXdDi6Anl+AeqNDCl7kazCbjS0zx3bz+K7w415ekTU2X YWWy3plWEvrjiKuAuq3rS+YH08fegJlHrJx3c= 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=4se0bxUfDpTOce4vvHAhVEndDjnF7kqIUvifUrMRXxg=; b=CiAbeJFw6Qrm5uc34bOpjF6wqnrF+HTL/J5QIcER386nBhrCQ6jxFXlhqH5VF8bNio oQvi9zADWDvCKLExPkPonsW/iVE6s+5He3jknZSyTGxPdG1T/sx1KTvuDq+TAMlHitAA eeM5Hl5Pbi6q8heuEpxXEIXCyakuusdYf/iEo+48a8tkKomxIh7ElM6i6NYFgs/9xfIH 4XASGGdjiBEFmvETkIMLWJMTpWo653J6D42EI+v3OlPGs4/eGGlWAy0cxAx8lbLBewzt sCMZ4qiUGtkcay3+cMVtTfTKZ04L8VHMydF2yiveJt2Q4FFBkSzG1a4RpKT/WmNdEz0g 2ZMA== X-Gm-Message-State: AFeK/H33tpWIEOySzEquGNEl2L60eaIw9ZpiVdhTUgyiE/z7H6pYXEjzgzoN+/5TJw7aXWZx X-Received: by 10.28.236.209 with SMTP id h78mr6616546wmi.97.1490554165166; Sun, 26 Mar 2017 11:49:25 -0700 (PDT) Received: from localhost.localdomain ([196.81.160.3]) by smtp.gmail.com with ESMTPSA id i133sm11362112wmg.26.2017.03.26.11.49.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Mar 2017 11:49:24 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au Cc: nico@linaro.org, ebiggers3@gmail.com, Ard Biesheuvel Subject: [PATCH 5/7] crypto: aes - move crypto_aes_expand_key() to fixed-time AES driver Date: Sun, 26 Mar 2017 19:49:06 +0100 Message-Id: <1490554148-10953-6-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490554148-10953-1-git-send-email-ard.biesheuvel@linaro.org> References: <1490554148-10953-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Both the original generic AES code and the new fixed-time AES driver contain C implementations of crypto_aes_expand_key() which are functionally equivalent to each other. However, the former version pulls in crypto/aes_generic.o in its entirety, consisting of 16 KB of lookup tables and fully unrolled encrypt and decrypt routines, none of which are of any interest to most users of crypto_aes_expand_key. So unexport the version in crypto/aes_generic.o, and export the version in crypto/aes_ti.o, and fix up all Kconfig dependencies of users of crypto_aes_expand_key. Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/Kconfig | 2 +- arch/arm64/crypto/Kconfig | 2 +- crypto/aes_generic.c | 7 +++---- crypto/aes_ti.c | 7 ++++--- drivers/crypto/Kconfig | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/arch/arm/crypto/Kconfig b/arch/arm/crypto/Kconfig index b9adedcc5b2e..d3fab7792eda 100644 --- a/arch/arm/crypto/Kconfig +++ b/arch/arm/crypto/Kconfig @@ -73,7 +73,7 @@ config CRYPTO_AES_ARM_BS depends on KERNEL_MODE_NEON select CRYPTO_BLKCIPHER select CRYPTO_SIMD - select CRYPTO_AES + select CRYPTO_AES_TI help Use a faster and more secure NEON based implementation of AES in CBC, CTR and XTS modes diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig index d92293747d63..e36b671363a3 100644 --- a/arch/arm64/crypto/Kconfig +++ b/arch/arm64/crypto/Kconfig @@ -68,7 +68,7 @@ config CRYPTO_AES_ARM64_NEON_BLK tristate "AES in ECB/CBC/CTR/XTS modes using NEON instructions" depends on ARM64 && KERNEL_MODE_NEON select CRYPTO_BLKCIPHER - select CRYPTO_AES + select CRYPTO_AES_TI select CRYPTO_SIMD config CRYPTO_CHACHA20_NEON diff --git a/crypto/aes_generic.c b/crypto/aes_generic.c index ca554d57d01e..56693e6f4f09 100644 --- a/crypto/aes_generic.c +++ b/crypto/aes_generic.c @@ -1201,7 +1201,7 @@ EXPORT_SYMBOL_GPL(crypto_il_tab); } while (0) /** - * crypto_aes_expand_key - Expands the AES key as described in FIPS-197 + * aes_expand_key - Expands the AES key as described in FIPS-197 * @ctx: The location where the computed key will be stored. * @in_key: The supplied key. * @key_len: The length of the supplied key. @@ -1214,7 +1214,7 @@ EXPORT_SYMBOL_GPL(crypto_il_tab); * described in FIPS-197. The first slot (16 bytes) of each key (enc or dec) is * for the initial combination, the second slot for the first round and so on. */ -int crypto_aes_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, +static int aes_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, unsigned int key_len) { u32 i, t, u, v, w, j; @@ -1271,7 +1271,6 @@ int crypto_aes_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, } return 0; } -EXPORT_SYMBOL_GPL(crypto_aes_expand_key); /** * crypto_aes_set_key - Set the AES key. @@ -1291,7 +1290,7 @@ int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, u32 *flags = &tfm->crt_flags; int ret; - ret = crypto_aes_expand_key(ctx, in_key, key_len); + ret = aes_expand_key(ctx, in_key, key_len); if (!ret) return 0; diff --git a/crypto/aes_ti.c b/crypto/aes_ti.c index 92644fd1ac19..a3aae39e3a07 100644 --- a/crypto/aes_ti.c +++ b/crypto/aes_ti.c @@ -167,8 +167,8 @@ static u32 subw(u32 in) (__aesti_sbox[(in >> 24) & 0xff] << 24); } -static int aesti_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, - unsigned int key_len) +int crypto_aes_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, + unsigned int key_len) { u32 kwords = key_len / sizeof(u32); u32 rc, i, j; @@ -232,6 +232,7 @@ static int aesti_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key, return 0; } +EXPORT_SYMBOL_GPL(crypto_aes_expand_key); static int aesti_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) @@ -239,7 +240,7 @@ static int aesti_set_key(struct crypto_tfm *tfm, const u8 *in_key, struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); int err; - err = aesti_expand_key(ctx, in_key, key_len); + err = crypto_aes_expand_key(ctx, in_key, key_len); if (err) return err; diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index 0ea163122df2..a2e3739ba3bd 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -26,7 +26,7 @@ config CRYPTO_DEV_PADLOCK_AES tristate "PadLock driver for AES algorithm" depends on CRYPTO_DEV_PADLOCK select CRYPTO_BLKCIPHER - select CRYPTO_AES + select CRYPTO_AES_TI help Use VIA PadLock for AES algorithm. @@ -189,7 +189,7 @@ config CRYPTO_CRC32_S390 config CRYPTO_DEV_MV_CESA tristate "Marvell's Cryptographic Engine" depends on PLAT_ORION - select CRYPTO_AES + select CRYPTO_AES_TI select CRYPTO_BLKCIPHER select CRYPTO_HASH select SRAM @@ -203,7 +203,7 @@ config CRYPTO_DEV_MV_CESA config CRYPTO_DEV_MARVELL_CESA tristate "New Marvell's Cryptographic Engine driver" depends on PLAT_ORION || ARCH_MVEBU - select CRYPTO_AES + select CRYPTO_AES_TI select CRYPTO_DES select CRYPTO_BLKCIPHER select CRYPTO_HASH