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: 124343 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2049121qgn; Fri, 12 Jan 2018 05:15:47 -0800 (PST) X-Google-Smtp-Source: ACJfBov8rooG1gJJywOfz+6qIyOSddX1winW3rZR1xEbVlqHPNIJctQs94NmlfOXMgMIHDfYcjCu X-Received: by 10.101.70.138 with SMTP id h10mr20725733pgr.446.1515762947254; Fri, 12 Jan 2018 05:15:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515762947; cv=none; d=google.com; s=arc-20160816; b=Escv7rWT3HJWQcvrX+7TA88RVwAS783vMQ+UH8EsP5WivyAXiJdy7z+Q8ApgN21oHt hObU2WZD8ljhO9Lc8dsNFUcIdCPDZ6lE0M227keZ0VaMkBd4hF+sNOKvibMAJC0Xm/yo u//8trioaxCR0kc5UqLr4uJyTTiqcsrmpJ27PUiaZcqb1yNZUwxSKJSS+X6i8e2TuESH zzeLL3ts+xO7DULst8hGbWF738kZB6avCfQ+eDdmCglYdN9+g7mFURKtC/ySyWpDEhWi YhMctLYdlZlmwKuZjV2+MbytB0g7eA6t71akr8pHheMdHic1W/i6t4G9R4j/vPkIiuki XpBQ== 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=v8Bhnd9C9B9ZBVbB0Yy0hA/IjJ48lpBox8pz2sJM+K4=; b=0K9w5aDK2XhDsKs/XAnbR95RQOf0hgbw6llJfaQlXuWOpkW0Tx7hmqdCXC8mJ2CteZ sm/Q1Srp0LVpsfI+u7mjEQTAztKenksay5bs8rOeMEJG9bpQOqxQ6IEHzcK+8JgzXeQi i3LipjH9L9Fb551/bCAaffigBGn/A1CB9rSN/76dFZH+QrHFbVg5XoSslS68pJWf2UlF 6IYcDPD8znKtVXyZHmLgMTTp3YjlX1uPvuuO6P5zdEa8Te+/Sc06/Q2t6rsG3/l5fqyO RAwgcRPMlcwrvzcn7sVo6+6sb+Oa/D1QPAUITGhaQIfj5RVl88byNUQzUQhS/XfXVNCj /MSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kujcXoKb; 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 c29si3834030pgn.727.2018.01.12.05.15.46; Fri, 12 Jan 2018 05:15:47 -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=kujcXoKb; 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 S933687AbeALNPq (ORCPT + 1 other); 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-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 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 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