From patchwork Fri Jan 19 12:04:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 125156 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp259633ljf; Fri, 19 Jan 2018 04:05:23 -0800 (PST) X-Google-Smtp-Source: ACJfBots4OQ3dgOYrzc1rLva8ozeN3v1jOAIj4oBEahJM8Z9QtkWDpxXlhSEUX9Y7LVUaKeAq/ZN X-Received: by 10.98.192.134 with SMTP id g6mr34882419pfk.91.1516363523811; Fri, 19 Jan 2018 04:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516363523; cv=none; d=google.com; s=arc-20160816; b=MpB/+gz/0rLsyX7PUgBPb30CnWFBOJcebibouCFUcw10fUReOjEm45YUHLLLQfxW5q x/5EcKcIXViEDLOYMbVzSFtc72upjalPDeE/quM5cV6q72jJhJArKvbisWnnfVaAM6YC Y0hWv2mNjLCbEJBSfWVhaiVwHIh9PdPC9O7dAWN9y4tC+Xukn43kzcAoclQOu6IoEwtb U4B2BsvKhWpg4PvtF9uLpa4XAZpvChNksb53VGiDWggtUpqqv+7FeFUuP4mdGFNqDQSd 9nwqExULsKAIgg0pvU8IFSREOwv94akYy7SkeF5pcXTEUrDHCuQOMuOj6MlcBlPsV3Jf Y2qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=x7LwwIlodxDjEAx+lEEG6yxb2ZdR3cWCxFTuPRdrzNQ=; b=ILulvbEuBLvQhBwX5gu060bUOg2qZKpRJtmAuzwk7HkNGAtovqRBYQgZD426HY2JjU 757u738Zlz8zijEYh5YB5o8opHswgWrIJ6npHlZXfnuMc9NZsbKnnUlGGcAVi1NQyMLj 1ZKsgHx0J7a0qYDQDzPQA9vp/KUwJ3EfFFA89ZidAdqQKrQ/VqBZruN7G8wqr1RZRarX hlwCSMlgRfY9q17r6sXC9tIv/QSno3VjKU1CTEIpsGJjPOEpYDbOaNbH0V33xP+yoFQT WB81aFDehesnVDoG9fNgQlAZQmgLFMyFdXZ+ZJfpP5SigC+pLcbPN3lyygldoPVtWSPX qVbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eiEXlkfb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si5314051pgq.384.2018.01.19.04.05.23; Fri, 19 Jan 2018 04:05:23 -0800 (PST) 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 header.s=google header.b=eiEXlkfb; 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 S1754759AbeASMFW (ORCPT + 1 other); Fri, 19 Jan 2018 07:05:22 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:43163 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754232AbeASMFW (ORCPT ); Fri, 19 Jan 2018 07:05:22 -0500 Received: by mail-wm0-f65.google.com with SMTP id g1so2956109wmg.2 for ; Fri, 19 Jan 2018 04:05:21 -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=x7LwwIlodxDjEAx+lEEG6yxb2ZdR3cWCxFTuPRdrzNQ=; b=eiEXlkfbuu6CzzF8j7yFS3rXYD6/hkhV7a81xqBQbFygn2fQHDfriIVent07FrdIkp XFnfFQVVP/6K7gOlPXvQLVPKKUZY7SbLP0g/DiXmnrDh4946CrEk3uQSmCtJlSUhQy+u cFTOVwRDGhVHkpziJGNGQd2OOqGMrUpTcuvaQ= 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=x7LwwIlodxDjEAx+lEEG6yxb2ZdR3cWCxFTuPRdrzNQ=; b=HyyVGNXTtM4E22EWfUW08XpoOiZVOx9OM8LvkHLjG3i4CCCEq1iVAk6PIVsebhsxs4 xto2w3hNavW1aK8aY2/XqDCAbFSpLqhrttDCd/VLA/ncv51SUQsiFZpEObSvepjm38uD nEsmWAQfKMDZiBgfAmCJ8tm5/PFBzlRGBwkSSA7loX10titGZCCXVAvuptgMtqqatHyf z9GehXuY1ba3gC16w7tZwwcpcC+TvU7KZ6oNWTnVAfTPszAEdUn+3t0s5AUS2Zdn0u6v 2+80rfaG9eoQ9CSjrJysbgwes8C2dw/MGFAKuE3KORLCAPupRt/5lmjOxld1756XSVqD TG9Q== X-Gm-Message-State: AKwxytdnUy64fV4JsLjatHdSDg5ZTj/W7MOtWR5Jwy8Nn7AjT7AOqohb jWB02qBZ1oDdd7UMWyVBVT2KE2m+5Ms= X-Received: by 10.28.22.67 with SMTP id 64mr7648252wmw.28.1516363520594; Fri, 19 Jan 2018 04:05:20 -0800 (PST) Received: from localhost.localdomain ([160.170.62.40]) by smtp.gmail.com with ESMTPSA id 127sm1039149wmk.14.2018.01.19.04.05.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 04:05:19 -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 4/8] crypto/generic: sha3 - export init/update/final routines Date: Fri, 19 Jan 2018 12:04:36 +0000 Message-Id: <20180119120440.31556-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180119120440.31556-1-ard.biesheuvel@linaro.org> References: <20180119120440.31556-1-ard.biesheuvel@linaro.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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(-) -- 2.11.0 diff --git a/crypto/sha3_generic.c b/crypto/sha3_generic.c index c7084a24eaf9..a965b9d80559 100644 --- a/crypto/sha3_generic.c +++ b/crypto/sha3_generic.c @@ -145,7 +145,7 @@ static void __attribute__((__optimize__("O3"))) 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); @@ -157,8 +157,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); @@ -194,8 +195,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; @@ -220,12 +222,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", @@ -234,9 +237,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", @@ -245,9 +248,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", @@ -256,9 +259,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