From patchwork Tue Apr 7 08:51:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F68220553 for ; Tue, 7 Apr 2015 08:52:52 +0000 (UTC) Received: by lbfb1 with SMTP id b1sf11254973lbf.2 for ; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=UNsZqGzEp+2H2wLgIQeT6xyMoIbNOQe695pS9F8/f9Q=; b=gyto9iAhC5mX66WAwYWdk6mq45lR33UbbK0t6r8pBgu1NI6VzwPO8qGbyLdoQqt3Zs Y1Ol/aWu5bloNYI16c8mPX8sE+VekZ6d/NR5qxxo17Gc01VcAOrVdXU1byHtrxaiBECO Hxa+QU4xJ6xubPn+oNjQOyi9hWFh8fXOp8ZnHLExg7BlZZUIuwlaF9pQak87Ky6lhdsw rZMYELdaIB2eJGWUoZ7/3hwjKF2hlw49aZBDSiD+RtSFg1qSm/mG/jUGE8N+XaQzrQ2u fcyX7ii7bhJq33ia3RFBu6mZ092gqQNFjWDDS5bWDtFNH/swF1jyFZ0o5zSZ0s6a06zO QfUQ== X-Gm-Message-State: ALoCoQmvKLFsED8lNjGUj9cy4KDfblcnNfKfNiFSDQK+uvq1l8rMmvIWk7P4YaC/MU2d7+0G9/7f X-Received: by 10.112.160.197 with SMTP id xm5mr3815914lbb.15.1428396771324; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.2 with SMTP id x2ls14480lag.99.gmail; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) X-Received: by 10.152.42.141 with SMTP id o13mr17263997lal.33.1428396771176; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id mp6si5474465lbb.4.2015.04.07.01.52.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2015 01:52:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lboc7 with SMTP id c7so37285054lbo.1 for ; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr17233176lba.19.1428396771076; Tue, 07 Apr 2015 01:52:51 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp291678lbt; Tue, 7 Apr 2015 01:52:49 -0700 (PDT) X-Received: by 10.68.137.70 with SMTP id qg6mr27521383pbb.125.1428396764198; Tue, 07 Apr 2015 01:52:44 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4si2547968pdj.248.2015.04.07.01.52.42 for ; Tue, 07 Apr 2015 01:52:44 -0700 (PDT) Received-SPF: none (google.com: linux-crypto-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753074AbbDGIwl (ORCPT ); Tue, 7 Apr 2015 04:52:41 -0400 Received: from mail-wg0-f53.google.com ([74.125.82.53]:33468 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbbDGIwl (ORCPT ); Tue, 7 Apr 2015 04:52:41 -0400 Received: by wgin8 with SMTP id n8so48681424wgi.0 for ; Tue, 07 Apr 2015 01:52:39 -0700 (PDT) X-Received: by 10.194.108.9 with SMTP id hg9mr38445021wjb.68.1428396759904; Tue, 07 Apr 2015 01:52:39 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.4.191]) by mx.google.com with ESMTPSA id q10sm9935641wjr.41.2015.04.07.01.52.37 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Apr 2015 01:52:38 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, herbert@gondor.apana.org.au, samitolvanen@google.com, jussi.kivilinna@iki.fi Cc: stockhausen@collogia.de, Ard Biesheuvel Subject: [PATCH v3 07/16] crypto/arm: move SHA-1 ARM asm implementation to base layer Date: Tue, 7 Apr 2015 10:51:55 +0200 Message-Id: <1428396724-19962-8-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1428396724-19962-1-git-send-email-ard.biesheuvel@linaro.org> References: <1428396724-19962-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Ard Biesheuvel --- arch/arm/crypto/sha1-ce-glue.c | 3 +- arch/arm/{include/asm => }/crypto/sha1.h | 3 + arch/arm/crypto/sha1_glue.c | 116 ++++++------------------------- arch/arm/crypto/sha1_neon_glue.c | 2 +- 4 files changed, 29 insertions(+), 95 deletions(-) rename arch/arm/{include/asm => }/crypto/sha1.h (67%) diff --git a/arch/arm/crypto/sha1-ce-glue.c b/arch/arm/crypto/sha1-ce-glue.c index a9dd90df9fd7..e93b24c1af1f 100644 --- a/arch/arm/crypto/sha1-ce-glue.c +++ b/arch/arm/crypto/sha1-ce-glue.c @@ -13,12 +13,13 @@ #include #include -#include #include #include #include #include +#include "sha1.h" + MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions"); MODULE_AUTHOR("Ard Biesheuvel "); MODULE_LICENSE("GPL v2"); diff --git a/arch/arm/include/asm/crypto/sha1.h b/arch/arm/crypto/sha1.h similarity index 67% rename from arch/arm/include/asm/crypto/sha1.h rename to arch/arm/crypto/sha1.h index 75e6a417416b..ffd8bd08b1a7 100644 --- a/arch/arm/include/asm/crypto/sha1.h +++ b/arch/arm/crypto/sha1.h @@ -7,4 +7,7 @@ extern int sha1_update_arm(struct shash_desc *desc, const u8 *data, unsigned int len); +extern int sha1_finup_arm(struct shash_desc *desc, const u8 *data, + unsigned int len, u8 *out); + #endif diff --git a/arch/arm/crypto/sha1_glue.c b/arch/arm/crypto/sha1_glue.c index e31b0440c613..c5a9519aaaad 100644 --- a/arch/arm/crypto/sha1_glue.c +++ b/arch/arm/crypto/sha1_glue.c @@ -22,125 +22,55 @@ #include #include #include +#include #include -#include +#include "sha1.h" asmlinkage void sha1_block_data_order(u32 *digest, const unsigned char *data, unsigned int rounds); - -static int sha1_init(struct shash_desc *desc) -{ - struct sha1_state *sctx = shash_desc_ctx(desc); - - *sctx = (struct sha1_state){ - .state = { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, - }; - - return 0; -} - - -static int __sha1_update(struct sha1_state *sctx, const u8 *data, - unsigned int len, unsigned int partial) +static void sha1_arm_block_fn(int blocks, u8 const *src, u32 *state, + const u8 *head, void *p) { - unsigned int done = 0; - - sctx->count += len; - - if (partial) { - done = SHA1_BLOCK_SIZE - partial; - memcpy(sctx->buffer + partial, data, done); - sha1_block_data_order(sctx->state, sctx->buffer, 1); - } - - if (len - done >= SHA1_BLOCK_SIZE) { - const unsigned int rounds = (len - done) / SHA1_BLOCK_SIZE; - sha1_block_data_order(sctx->state, data + done, rounds); - done += rounds * SHA1_BLOCK_SIZE; - } - - memcpy(sctx->buffer, data + done, len - done); - return 0; + if (head) + sha1_block_data_order(state, head, 1); + if (blocks) + sha1_block_data_order(state, src, blocks); } - int sha1_update_arm(struct shash_desc *desc, const u8 *data, unsigned int len) { - struct sha1_state *sctx = shash_desc_ctx(desc); - unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; - int res; - - /* Handle the fast case right here */ - if (partial + len < SHA1_BLOCK_SIZE) { - sctx->count += len; - memcpy(sctx->buffer + partial, data, len); - return 0; - } - res = __sha1_update(sctx, data, len, partial); - return res; + return sha1_base_do_update(desc, data, len, sha1_arm_block_fn, NULL); } EXPORT_SYMBOL_GPL(sha1_update_arm); - -/* Add padding and return the message digest. */ -static int sha1_final(struct shash_desc *desc, u8 *out) +int sha1_finup_arm(struct shash_desc *desc, const u8 *data, + unsigned int len, u8 *out) { - struct sha1_state *sctx = shash_desc_ctx(desc); - unsigned int i, index, padlen; - __be32 *dst = (__be32 *)out; - __be64 bits; - static const u8 padding[SHA1_BLOCK_SIZE] = { 0x80, }; - - bits = cpu_to_be64(sctx->count << 3); - - /* Pad out to 56 mod 64 and append length */ - index = sctx->count % SHA1_BLOCK_SIZE; - padlen = (index < 56) ? (56 - index) : ((SHA1_BLOCK_SIZE+56) - index); - /* We need to fill a whole block for __sha1_update() */ - if (padlen <= 56) { - sctx->count += padlen; - memcpy(sctx->buffer + index, padding, padlen); - } else { - __sha1_update(sctx, padding, padlen, index); - } - __sha1_update(sctx, (const u8 *)&bits, sizeof(bits), 56); - - /* Store state in digest */ - for (i = 0; i < 5; i++) - dst[i] = cpu_to_be32(sctx->state[i]); - - /* Wipe context */ - memset(sctx, 0, sizeof(*sctx)); - return 0; -} - + if (len) + sha1_base_do_update(desc, data, len, sha1_arm_block_fn, NULL); + sha1_base_do_finalize(desc, sha1_arm_block_fn, NULL); -static int sha1_export(struct shash_desc *desc, void *out) -{ - struct sha1_state *sctx = shash_desc_ctx(desc); - memcpy(out, sctx, sizeof(*sctx)); - return 0; + return sha1_base_finish(desc, out); } +EXPORT_SYMBOL_GPL(sha1_finup_arm); - -static int sha1_import(struct shash_desc *desc, const void *in) +/* Add padding and return the message digest. */ +static int sha1_final(struct shash_desc *desc, u8 *out) { - struct sha1_state *sctx = shash_desc_ctx(desc); - memcpy(sctx, in, sizeof(*sctx)); - return 0; + return sha1_finup_arm(desc, NULL, 0, out); } - static struct shash_alg alg = { .digestsize = SHA1_DIGEST_SIZE, - .init = sha1_init, + .init = sha1_base_init, .update = sha1_update_arm, .final = sha1_final, - .export = sha1_export, - .import = sha1_import, + .finup = sha1_finup_arm, + .export = sha1_base_export, + .import = sha1_base_import, .descsize = sizeof(struct sha1_state), .statesize = sizeof(struct sha1_state), .base = { diff --git a/arch/arm/crypto/sha1_neon_glue.c b/arch/arm/crypto/sha1_neon_glue.c index 0b0083757d47..5d9a1b4aac73 100644 --- a/arch/arm/crypto/sha1_neon_glue.c +++ b/arch/arm/crypto/sha1_neon_glue.c @@ -28,8 +28,8 @@ #include #include #include -#include +#include "sha1.h" asmlinkage void sha1_transform_neon(void *state_h, const char *data, unsigned int rounds);