From patchwork Tue Apr 7 08:51:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 46817 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CF1E920553 for ; Tue, 7 Apr 2015 08:52:57 +0000 (UTC) Received: by widjs5 with SMTP id js5sf1870311wid.3 for ; Tue, 07 Apr 2015 01:52:57 -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=hMCGdNVSkrN4kUaBrfDj9AcUX9RAFB+LJWEwc22c1JM=; b=IVueXNv9+388mbazuJieddjNxcDYfr5yG0Ee9PqT31Pm0sSrhFDz20+Fa1/vu+EiCG AjHft7GGhjP3o+8ezoMWAs+T0KRnOyNHxZx8N8Puriq65Qrrg6r5D3HBxWcgTvyWsuKS mhBDx2xUpF8pvxcsaySFBWuNHHhmQMfufDqRUYa57Hf4KDHcR//RH2cj/GMHjDs5UlQh 4RgSsXiBJDtejhw/Geznj7p3vWED3H6tDgcMjeH8xzEdMmTOEUE9/iT5liXZuJUyxFkU MISFuM3TFaFpWSH50PRAJgYuQLW5hvtbSIbsfP0scM+XN+pFkXhRoQSWQxh2OQkgdm14 kALg== X-Gm-Message-State: ALoCoQmuavS4L/pvlg0dHA+DXc8dGXFEESyp6ocE0j2NQAOcBZYmV9zGwREUSW9unotw1A6uGta5 X-Received: by 10.152.206.36 with SMTP id ll4mr3897111lac.6.1428396777037; Tue, 07 Apr 2015 01:52:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.226 with SMTP id m2ls15114laa.71.gmail; Tue, 07 Apr 2015 01:52:56 -0700 (PDT) X-Received: by 10.152.88.46 with SMTP id bd14mr16960169lab.71.1428396776756; Tue, 07 Apr 2015 01:52:56 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id wu8si5438229lac.157.2015.04.07.01.52.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2015 01:52:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbzk7 with SMTP id zk7so37379708lbb.0 for ; Tue, 07 Apr 2015 01:52:56 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr2349839lbc.86.1428396776655; Tue, 07 Apr 2015 01:52:56 -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 l1csp291718lbt; Tue, 7 Apr 2015 01:52:55 -0700 (PDT) X-Received: by 10.66.66.41 with SMTP id c9mr33821635pat.128.1428396767912; Tue, 07 Apr 2015 01:52:47 -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.47 for ; Tue, 07 Apr 2015 01:52:47 -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 S1753161AbbDGIwq (ORCPT ); Tue, 7 Apr 2015 04:52:46 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:36194 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752963AbbDGIwq (ORCPT ); Tue, 7 Apr 2015 04:52:46 -0400 Received: by wizk4 with SMTP id k4so8930947wiz.1 for ; Tue, 07 Apr 2015 01:52:44 -0700 (PDT) X-Received: by 10.180.10.102 with SMTP id h6mr2498565wib.37.1428396764783; Tue, 07 Apr 2015 01:52:44 -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.42 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Apr 2015 01:52:44 -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 09/16] crypto/arm: move SHA-1 ARMv8 implementation to base layer Date: Tue, 7 Apr 2015 10:51:57 +0200 Message-Id: <1428396724-19962-10-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.173 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/Kconfig | 1 - arch/arm/crypto/sha1-ce-glue.c | 108 +++++++++++------------------------------ 2 files changed, 28 insertions(+), 81 deletions(-) diff --git a/arch/arm/crypto/Kconfig b/arch/arm/crypto/Kconfig index 458729d2ce22..5ed98bc6f95d 100644 --- a/arch/arm/crypto/Kconfig +++ b/arch/arm/crypto/Kconfig @@ -31,7 +31,6 @@ config CRYPTO_SHA1_ARM_CE tristate "SHA1 digest algorithm (ARM v8 Crypto Extensions)" depends on KERNEL_MODE_NEON select CRYPTO_SHA1_ARM - select CRYPTO_SHA1 select CRYPTO_HASH help SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2) implemented diff --git a/arch/arm/crypto/sha1-ce-glue.c b/arch/arm/crypto/sha1-ce-glue.c index e93b24c1af1f..9d0e86e5647b 100644 --- a/arch/arm/crypto/sha1-ce-glue.c +++ b/arch/arm/crypto/sha1-ce-glue.c @@ -10,13 +10,13 @@ #include #include +#include #include #include #include #include #include -#include #include "sha1.h" @@ -24,104 +24,52 @@ MODULE_DESCRIPTION("SHA1 secure hash using ARMv8 Crypto Extensions"); MODULE_AUTHOR("Ard Biesheuvel "); MODULE_LICENSE("GPL v2"); -asmlinkage void sha1_ce_transform(int blocks, u8 const *src, u32 *state, - u8 *head); +asmlinkage void sha1_ce_transform(int blocks, u8 const *src, u32 *state, + const u8 *head, void *p); -static int sha1_init(struct shash_desc *desc) +static int sha1_ce_update(struct shash_desc *desc, const u8 *data, + unsigned int len) { 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 shash_desc *desc, const u8 *data, - unsigned int len) -{ - struct sha1_state *sctx = shash_desc_ctx(desc); - unsigned int partial; - - if (!may_use_simd()) + if (!may_use_simd() || + (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE) return sha1_update_arm(desc, data, len); - partial = sctx->count % SHA1_BLOCK_SIZE; - sctx->count += len; - - if ((partial + len) >= SHA1_BLOCK_SIZE) { - int blocks; + kernel_neon_begin(); + sha1_base_do_update(desc, data, len, sha1_ce_transform, NULL); + kernel_neon_end(); - if (partial) { - int p = SHA1_BLOCK_SIZE - partial; - - memcpy(sctx->buffer + partial, data, p); - data += p; - len -= p; - } - - blocks = len / SHA1_BLOCK_SIZE; - len %= SHA1_BLOCK_SIZE; - - kernel_neon_begin(); - sha1_ce_transform(blocks, data, sctx->state, - partial ? sctx->buffer : NULL); - kernel_neon_end(); - - data += blocks * SHA1_BLOCK_SIZE; - partial = 0; - } - if (len) - memcpy(sctx->buffer + partial, data, len); return 0; } -static int sha1_final(struct shash_desc *desc, u8 *out) +static int sha1_ce_finup(struct shash_desc *desc, const u8 *data, + unsigned int len, u8 *out) { - static const u8 padding[SHA1_BLOCK_SIZE] = { 0x80, }; - - struct sha1_state *sctx = shash_desc_ctx(desc); - __be64 bits = cpu_to_be64(sctx->count << 3); - __be32 *dst = (__be32 *)out; - int i; - - u32 padlen = SHA1_BLOCK_SIZE - - ((sctx->count + sizeof(bits)) % SHA1_BLOCK_SIZE); - - sha1_update(desc, padding, padlen); - sha1_update(desc, (const u8 *)&bits, sizeof(bits)); - - for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++) - put_unaligned_be32(sctx->state[i], dst++); - - *sctx = (struct sha1_state){}; - return 0; -} + if (!may_use_simd()) + return sha1_finup_arm(desc, data, len, out); -static int sha1_export(struct shash_desc *desc, void *out) -{ - struct sha1_state *sctx = shash_desc_ctx(desc); - struct sha1_state *dst = out; + kernel_neon_begin(); + if (len) + sha1_base_do_update(desc, data, len, sha1_ce_transform, NULL); + sha1_base_do_finalize(desc, sha1_ce_transform, NULL); + kernel_neon_end(); - *dst = *sctx; - return 0; + return sha1_base_finish(desc, out); } -static int sha1_import(struct shash_desc *desc, const void *in) +static int sha1_ce_final(struct shash_desc *desc, u8 *out) { - struct sha1_state *sctx = shash_desc_ctx(desc); - struct sha1_state const *src = in; - - *sctx = *src; - return 0; + return sha1_ce_finup(desc, NULL, 0l, out); } static struct shash_alg alg = { - .init = sha1_init, - .update = sha1_update, - .final = sha1_final, - .export = sha1_export, - .import = sha1_import, + .init = sha1_base_init, + .update = sha1_ce_update, + .final = sha1_ce_final, + .finup = sha1_ce_finup, + .export = sha1_base_export, + .import = sha1_base_import, .descsize = sizeof(struct sha1_state), .digestsize = SHA1_DIGEST_SIZE, .statesize = sizeof(struct sha1_state),