From patchwork Fri Jan 12 13:15:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10160825 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 69CBD602A7 for ; Fri, 12 Jan 2018 13:15:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59C18289E3 for ; Fri, 12 Jan 2018 13:15:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E96F289E6; Fri, 12 Jan 2018 13:15:47 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 DD873289E3 for ; Fri, 12 Jan 2018 13:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933687AbeALNPq (ORCPT ); Fri, 12 Jan 2018 08:15:46 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:42282 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933581AbeALNPo (ORCPT ); Fri, 12 Jan 2018 08:15:44 -0500 Received: by mail-wr0-f195.google.com with SMTP id e41so4943556wre.9 for ; Fri, 12 Jan 2018 05:15:43 -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=v8Bhnd9C9B9ZBVbB0Yy0hA/IjJ48lpBox8pz2sJM+K4=; b=kujcXoKb5TXMpXt5hFxmS00gVTuEpiyKwTGm0i5cIHzLVv78+Recq4UQvXYkcfqdd5 VzEl0FKCCJADKl87ODv1XI5bBv169HhXRsJhZcjoVUHeszjqCp32zdYujWDb7w/IWgEa tfvPXX3EToj9t0iOz3Q/FJzgfi41miF4691YU= 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=v8Bhnd9C9B9ZBVbB0Yy0hA/IjJ48lpBox8pz2sJM+K4=; b=Fl7dUh2AkPOseQDFOU9VOBo4TrDEsenced0Bp92sy2QQLH3qAXbawSGo0ROdPHim7S eqbfFtUsHLasKUIQkJ59tRTnA3borUs/t2bAjuLkBEXI7kM6vgyy71KShTGhXACbPWnA ur5CzVevjy57F/UwEnMViewq97MuNenh7Jh4oTAeqRD5U7Du6h95qGBxQqtEe/qcKtqp WMRVjeoum0kDNtdsM/TMgehbYadvFHkwX6ExOb7fswxnsynp/aoBcAxXVLNbUthoBsgh eNbWhZyd0V3TzN+giPBseFe7Er27Xo4L6FcIst3gheKk3vwd127zAXvatKidqI0uTrhp 1WMQ== X-Gm-Message-State: AKGB3mIWHbusGnHr53aJ+1HvZfULGibrWHun3dW+NqFw4tSdVmBY5TNg YiBMgj9DxLgGSkjjQ1q84xl96A== X-Google-Smtp-Source: ACJfBovpzanMmZ2+jl/oj1UEL8hj0g42UCO1ujCo6FruSTwjXa1zHJD5Bz7R9RhnRlSOs3vSbSYquw== X-Received: by 10.223.147.197 with SMTP id 63mr24340972wrp.156.1515762943189; Fri, 12 Jan 2018 05:15:43 -0800 (PST) Received: from localhost.localdomain ([105.141.218.128]) by smtp.gmail.com with ESMTPSA id o98sm16081395wrb.19.2018.01.12.05.15.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 05:15:42 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, will.deacon@arm.com, catalin.marinas@arm.com, steve.capper@linaro.org, jgarzik@redhat.com, Ard Biesheuvel Subject: [PATCH 3/5] crypto/generic: sha3 - export init/update/final routines Date: Fri, 12 Jan 2018 13:15:20 +0000 Message-Id: <20180112131522.25663-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180112131522.25663-1-ard.biesheuvel@linaro.org> References: <20180112131522.25663-1-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 To allow accelerated implementations to fall back to the generic routines, e.g., in contexts where a SIMD based implementation is not allowed to run, expose the generic SHA3 init/update/final routines to other modules. Signed-off-by: Ard Biesheuvel --- crypto/sha3_generic.c | 33 +++++++++++--------- include/crypto/sha3.h | 5 +++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c index 677247d429a1..86db5baafc83 100644 --- a/crypto/sha3_generic.c +++ b/crypto/sha3_generic.c @@ -87,7 +87,7 @@ static void keccakf(u64 st[25]) } } -static int sha3_init(struct shash_desc *desc) +int crypto_sha3_init(struct shash_desc *desc) { struct sha3_state *sctx = shash_desc_ctx(desc); unsigned int digest_size = crypto_shash_digestsize(desc->tfm); @@ -99,8 +99,9 @@ static int sha3_init(struct shash_desc *desc) memset(sctx->st, 0, sizeof(sctx->st)); return 0; } +EXPORT_SYMBOL(crypto_sha3_init); -static int sha3_update(struct shash_desc *desc, const u8 *data, +int crypto_sha3_update(struct shash_desc *desc, const u8 *data, unsigned int len) { struct sha3_state *sctx = shash_desc_ctx(desc); @@ -136,8 +137,9 @@ static int sha3_update(struct shash_desc *desc, const u8 *data, return 0; } +EXPORT_SYMBOL(crypto_sha3_update); -static int sha3_final(struct shash_desc *desc, u8 *out) +int crypto_sha3_final(struct shash_desc *desc, u8 *out) { struct sha3_state *sctx = shash_desc_ctx(desc); unsigned int i, inlen = sctx->partial; @@ -162,12 +164,13 @@ static int sha3_final(struct shash_desc *desc, u8 *out) memset(sctx, 0, sizeof(*sctx)); return 0; } +EXPORT_SYMBOL(crypto_sha3_final); static struct shash_alg algs[] = { { .digestsize = SHA3_224_DIGEST_SIZE, - .init = sha3_init, - .update = sha3_update, - .final = sha3_final, + .init = crypto_sha3_init, + .update = crypto_sha3_update, + .final = crypto_sha3_final, .descsize = sizeof(struct sha3_state), .base.cra_name = "sha3-224", .base.cra_driver_name = "sha3-224-generic", @@ -176,9 +179,9 @@ static struct shash_alg algs[] = { { .base.cra_module = THIS_MODULE, }, { .digestsize = SHA3_256_DIGEST_SIZE, - .init = sha3_init, - .update = sha3_update, - .final = sha3_final, + .init = crypto_sha3_init, + .update = crypto_sha3_update, + .final = crypto_sha3_final, .descsize = sizeof(struct sha3_state), .base.cra_name = "sha3-256", .base.cra_driver_name = "sha3-256-generic", @@ -187,9 +190,9 @@ static struct shash_alg algs[] = { { .base.cra_module = THIS_MODULE, }, { .digestsize = SHA3_384_DIGEST_SIZE, - .init = sha3_init, - .update = sha3_update, - .final = sha3_final, + .init = crypto_sha3_init, + .update = crypto_sha3_update, + .final = crypto_sha3_final, .descsize = sizeof(struct sha3_state), .base.cra_name = "sha3-384", .base.cra_driver_name = "sha3-384-generic", @@ -198,9 +201,9 @@ static struct shash_alg algs[] = { { .base.cra_module = THIS_MODULE, }, { .digestsize = SHA3_512_DIGEST_SIZE, - .init = sha3_init, - .update = sha3_update, - .final = sha3_final, + .init = crypto_sha3_init, + .update = crypto_sha3_update, + .final = crypto_sha3_final, .descsize = sizeof(struct sha3_state), .base.cra_name = "sha3-512", .base.cra_driver_name = "sha3-512-generic", diff --git a/include/crypto/sha3.h b/include/crypto/sha3.h index 1339dcdbc9b2..080f60c2e6b1 100644 --- a/include/crypto/sha3.h +++ b/include/crypto/sha3.h @@ -26,4 +26,9 @@ struct sha3_state { u8 buf[SHA3_224_BLOCK_SIZE]; }; +int crypto_sha3_init(struct shash_desc *desc); +int crypto_sha3_update(struct shash_desc *desc, const u8 *data, + unsigned int len); +int crypto_sha3_final(struct shash_desc *desc, u8 *out); + #endif