Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2219987imw; Wed, 6 Jul 2022 02:07:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sk7N1d7yPpaZFfSaxFuWjdoM66IL6/+ul+v39ZS120IFToN6/e2nluc+j3hJRm+Rxsk+ZP X-Received: by 2002:a05:6402:cba:b0:43a:6b17:f6b5 with SMTP id cn26-20020a0564020cba00b0043a6b17f6b5mr18270040edb.330.1657098426238; Wed, 06 Jul 2022 02:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657098426; cv=none; d=google.com; s=arc-20160816; b=YZTp1i76QtXqCfuSikvNqNIgwC6dC2J0f2yDaZbfCLNKn/WtO7lpXQZ1a17FEzWJ19 P90dsablk6UWFb3I/S6Hf92as+vPUECSP5X3Ws46A/15Uu5qD0sL2OOIngXJ1rH5xIxL 0MqTOZ4Nx2SZZGZ2up+HBExdeWpBX78UEERfpPCVyLslgpV7TXQwi8n6Z4vbaZCmqB0S ebgHye7oOwscWgLqBVa01H5ehBQicyAlnVLpYYR0x9B77zv2HI1BGqDhj8qr+prX6PYc xWoNZXGMf+3N0K+AGeCWJe944glFQTLzNus4F7z8eEuVha1u2es0N8TB6xBbU2c6sGNn VF0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Lb5wXjXl71KLOn69lH3EgInZyalgQlnigOqDmtk2Tt0=; b=GKiBaEL2UWOOImFMZsF0VRDFWRIpx3gKCNQtT4UPuz7tKDaTO/XXg+si/VZFJWKdti 6iyIAWZM+gzggT8ZNek0RbE+8W3jh+H/9sP0lBZEFqFVWlu9Ttk7aaRcnJpZQ+5Ps7/Q QaWd54lSBjO2Bp8ZnF6v/7R3hLYJy5nWNSXbBm8OEBgiG0GspScdxQJg60V7FbHmb1Ia 0g88qxuAHNWu2bObMRX0RGvy4fJeTsC0qjbnFIgL0jLef/qX5YmyZG3HJlXOpgYydK17 foGBgTI01bHWGJ8Bzh0ST6iE9TKsCWm2kNZlH9aQxcAINPy3MB7OzV9vL/W9hUMPGtZs MI6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=zzT8S8RH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm3-20020a05640222c300b00437a0492fa8si1859892edb.415.2022.07.06.02.06.42; Wed, 06 Jul 2022 02:07:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=zzT8S8RH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232696AbiGFJFP (ORCPT + 99 others); Wed, 6 Jul 2022 05:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232700AbiGFJE6 (ORCPT ); Wed, 6 Jul 2022 05:04:58 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D566422B37 for ; Wed, 6 Jul 2022 02:04:41 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id c131-20020a1c3589000000b003a19b2bce36so5596586wma.4 for ; Wed, 06 Jul 2022 02:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lb5wXjXl71KLOn69lH3EgInZyalgQlnigOqDmtk2Tt0=; b=zzT8S8RHrwSOYDYb4nSxX1Vj2+7cZjylmxpA5nZxp11NT/r63jTYcVVHZVl1lod/vB s4xJiX61UpU/2yD2nDSoAXIUQOjT25go1QRplexRcmJizflXuNntueAVYZ4v4ZLopP8/ gL6ba9Slb3Y8RCW5lRpR8O/XRgUTDBfYs8WszlEED2WevNhp5huie9+dYgrB0wxuN+Bt iaN0wmPl8OrU95zsa3j5H2CK/L2eZYGG0cPCFukjkmOKO5VREcFxavuSxGROA/kv+GHZ kEbvvxkjoCQ+tNJ+fYZc2xx2gOoSiQyhMMtENoQzsznYrFRR1EAxEVMH9i+YrweM2h9E Xbhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lb5wXjXl71KLOn69lH3EgInZyalgQlnigOqDmtk2Tt0=; b=c8l+ywECjjo31X8xO9b5G9D9P9gUuDsqp8MLHmZ/J+AmTYDFM0ok6RVSI1CJ69N/BZ vw8kw+Tj0fkhCa3hs+R3ZkWGDXYrqdKdXqZKHtufTibrk3dVlzIL607fV1UASweeAJ+d 5BfgI1hKAypFkvOQ3cNuexJmPEvZgKLI800ZgUmjY7WKkHte5nQ5D7mf1k1//f4gR2oQ fIySGBbNSw+m1ztkXxrK56M0tietYd7S/2R7XYLGFUchCszu5g+ls3JvohOB5khXj7mM uy03u1Lg7OiHFWLze+JTa3qb9PMwTPpPcb7/4PA4n7w8UzNs58ni06qUqXyfAsdM2+qV MirA== X-Gm-Message-State: AJIora+xGPYGp+Iwf7P4B+UDcd/8J9JAOCNUHZlvAVo9n083Fvj4Z2aU wLlFREtw57uunLDeQG3uTYlk2A== X-Received: by 2002:a7b:cb93:0:b0:3a0:4d00:2517 with SMTP id m19-20020a7bcb93000000b003a04d002517mr41934646wmi.117.1657098280280; Wed, 06 Jul 2022 02:04:40 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id v11-20020adfe28b000000b0021d6ef34b2asm5230223wri.51.2022.07.06.02.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 02:04:39 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, herbert@gondor.apana.org.au, krzysztof.kozlowski+dt@linaro.org, mturquette@baylibre.com, p.zabel@pengutronix.de, robh+dt@kernel.org, sboyd@kernel.org Cc: linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, john@metanate.com, didi.debian@cknow.org, Corentin Labbe Subject: [PATCH v8 07/33] crypto: rockchip: add fallback for ahash Date: Wed, 6 Jul 2022 09:03:46 +0000 Message-Id: <20220706090412.806101-8-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706090412.806101-1-clabbe@baylibre.com> References: <20220706090412.806101-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Adds a fallback for all case hardware cannot handle. Fixes: ce0183cb6464b ("crypto: rockchip - switch to skcipher API") Reviewed-by: John Keeping Signed-off-by: Corentin Labbe --- drivers/crypto/rockchip/rk3288_crypto_ahash.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c b/drivers/crypto/rockchip/rk3288_crypto_ahash.c index 49017d1fb510..16009bb0bf16 100644 --- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c +++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c @@ -16,6 +16,40 @@ * so we put the fixed hash out when met zero message. */ +static bool rk_ahash_need_fallback(struct ahash_request *req) +{ + struct scatterlist *sg; + + sg = req->src; + while (sg) { + if (!IS_ALIGNED(sg->offset, sizeof(u32))) { + return true; + } + if (sg->length % 4) { + return true; + } + sg = sg_next(sg); + } + return false; +} + +static int rk_ahash_digest_fb(struct ahash_request *areq) +{ + struct rk_ahash_rctx *rctx = ahash_request_ctx(areq); + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); + struct rk_ahash_ctx *tfmctx = crypto_ahash_ctx(tfm); + + ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm); + rctx->fallback_req.base.flags = areq->base.flags & + CRYPTO_TFM_REQ_MAY_SLEEP; + + rctx->fallback_req.nbytes = areq->nbytes; + rctx->fallback_req.src = areq->src; + rctx->fallback_req.result = areq->result; + + return crypto_ahash_digest(&rctx->fallback_req); +} + static int zero_message_process(struct ahash_request *req) { struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); @@ -167,6 +201,9 @@ static int rk_ahash_digest(struct ahash_request *req) struct rk_ahash_ctx *tctx = crypto_tfm_ctx(req->base.tfm); struct rk_crypto_info *dev = tctx->dev; + if (rk_ahash_need_fallback(req)) + return rk_ahash_digest_fb(req); + if (!req->nbytes) return zero_message_process(req); else @@ -309,6 +346,7 @@ static void rk_cra_hash_exit(struct crypto_tfm *tfm) struct rk_ahash_ctx *tctx = crypto_tfm_ctx(tfm); free_page((unsigned long)tctx->dev->addr_vir); + crypto_free_ahash(tctx->fallback_tfm); } struct rk_crypto_tmp rk_ahash_sha1 = { -- 2.35.1