From patchwork Mon Jan 2 18:21:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9493989 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6B8D560414 for ; Mon, 2 Jan 2017 18:23:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60F6D20008 for ; Mon, 2 Jan 2017 18:23:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5567226907; Mon, 2 Jan 2017 18:23:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F237D20008 for ; Mon, 2 Jan 2017 18:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752971AbdABSXX (ORCPT ); Mon, 2 Jan 2017 13:23:23 -0500 Received: from mail-wj0-f176.google.com ([209.85.210.176]:34193 "EHLO mail-wj0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756391AbdABSWV (ORCPT ); Mon, 2 Jan 2017 13:22:21 -0500 Received: by mail-wj0-f176.google.com with SMTP id sd9so244612525wjb.1 for ; Mon, 02 Jan 2017 10:22:20 -0800 (PST) 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=NJiqhZ8Rhi8ObTD8ZBOERJwCRlhTw4dC8dzCUJLGavQ=; b=Me8J6XJGsJGddDA+dxW9VF3V4STOoTGWQjmyytqB8SC4r6XF+3BVJIpQaeA8owm6+e nA8evqGaSG2zCg3rt435M/auYJQxnjIF0b1tn26drL+bjAjUVxb3MgPwYCTl4TP4b4aY 1HNNPDFXtQxVuyV2/M2W5NVV+Ecq28gg8IXiI= 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=NJiqhZ8Rhi8ObTD8ZBOERJwCRlhTw4dC8dzCUJLGavQ=; b=iZlHx4rjmvhvgm1qOSm31+z2lGf8t/GJwvkN2G0drw7LDyO4p5yUr8galHBUXQ/6U4 Ywv2VQF6VhlpwoZqHugMK1+r+aCOFOE7VEwSxX939CcWkRBNNeny1z/Oe+nW79c4hnj6 41UqmVtKKGQ3GJvAIDLhHD8hC5yXoVaGnVKoGNghkSKZ41XyzZsfcv1TkxLtGyX5oAYT cfFCSr+9pqdAtcIyRNM+f5vtuqMxDM7yf9FDM5pOl1kP/j0G6+w7pQg6DBFYOG25/FwI OciiaEAlQw9jkkBGwNVyXa5eh5yT2FreI08CKiENJ8bpmL4KXcJtRSzXRqeDzETZM3tf rvmw== X-Gm-Message-State: AIkVDXK6LIeeHSBzwt0YeY2FNtlgo5723WU6E1uP8/mLRHBv+CNdNJcJrmaJcXpNoWXBZ4Fx X-Received: by 10.194.56.99 with SMTP id z3mr57827427wjp.55.1483381339561; Mon, 02 Jan 2017 10:22:19 -0800 (PST) Received: from localhost.localdomain ([105.146.125.96]) by smtp.gmail.com with ESMTPSA id l67sm85077652wmf.0.2017.01.02.10.22.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jan 2017 10:22:18 -0800 (PST) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH 1/6] crypto: generic/aes - export encrypt and decrypt entry points Date: Mon, 2 Jan 2017 18:21:03 +0000 Message-Id: <1483381268-12987-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483381268-12987-1-git-send-email-ard.biesheuvel@linaro.org> References: <1483381268-12987-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 X-Virus-Scanned: ClamAV using ClamSMTP The generic AES code already shares its key schedule generation routines (and its S-boxes) with other implementations via external linkage. In the same way, export the core encrypt/decrypt routines so they may be reused by other drivers as well. This facility will be used by the bit slicing implementation of AES in XTS mode for arm64, where using the 8-way cipher (and its ~2 KB expanded key schedule) to generate the initial tweak is suboptimal. Signed-off-by: Ard Biesheuvel --- crypto/aes_generic.c | 10 ++++++---- include/crypto/aes.h | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crypto/aes_generic.c b/crypto/aes_generic.c index 3dd101144a58..26fd7b8c2e5f 100644 --- a/crypto/aes_generic.c +++ b/crypto/aes_generic.c @@ -1326,7 +1326,7 @@ EXPORT_SYMBOL_GPL(crypto_aes_set_key); f_rl(bo, bi, 3, k); \ } while (0) -static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) +void crypto_aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); const __le32 *src = (const __le32 *)in; @@ -1366,6 +1366,7 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) dst[2] = cpu_to_le32(b0[2]); dst[3] = cpu_to_le32(b0[3]); } +EXPORT_SYMBOL_GPL(crypto_aes_encrypt); /* decrypt a block of text */ @@ -1398,7 +1399,7 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) i_rl(bo, bi, 3, k); \ } while (0) -static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) +void crypto_aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); const __le32 *src = (const __le32 *)in; @@ -1438,6 +1439,7 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) dst[2] = cpu_to_le32(b0[2]); dst[3] = cpu_to_le32(b0[3]); } +EXPORT_SYMBOL_GPL(crypto_aes_decrypt); static struct crypto_alg aes_alg = { .cra_name = "aes", @@ -1453,8 +1455,8 @@ static struct crypto_alg aes_alg = { .cia_min_keysize = AES_MIN_KEY_SIZE, .cia_max_keysize = AES_MAX_KEY_SIZE, .cia_setkey = crypto_aes_set_key, - .cia_encrypt = aes_encrypt, - .cia_decrypt = aes_decrypt + .cia_encrypt = crypto_aes_encrypt, + .cia_decrypt = crypto_aes_decrypt } } }; diff --git a/include/crypto/aes.h b/include/crypto/aes.h index 7524ba3b6f3c..297fbba5d27b 100644 --- a/include/crypto/aes.h +++ b/include/crypto/aes.h @@ -32,6 +32,9 @@ extern const u32 crypto_fl_tab[4][256]; extern const u32 crypto_it_tab[4][256]; extern const u32 crypto_il_tab[4][256]; +void crypto_aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in); +void crypto_aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in); + int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len); int crypto_aes_expand_key(struct crypto_aes_ctx *ctx, const u8 *in_key,