Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp552354rwb; Tue, 27 Sep 2022 00:59:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MtGm2XfwcUnEOI76Y4KWImSpzBm5OvkMbYG0AZBeHkrFVB1iFuHQxc9rWU3+1KOCawkgU X-Received: by 2002:a17:90b:1652:b0:202:a9b6:a693 with SMTP id il18-20020a17090b165200b00202a9b6a693mr3184229pjb.57.1664265543085; Tue, 27 Sep 2022 00:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664265543; cv=none; d=google.com; s=arc-20160816; b=KDQb+wUmhds8Qj2aWOjtP3SAdU9THeqf5fFjDB/KOEzBqzGkSCROxjJKpjOpVj26C2 Dsh7bUdlZRq5hXPY++Wr5H3Qsqxu7IhG9u7R4/TiY2pEIJCy3VyjlJs4Z9qh1Fy5xcto 0b7+Oqvl6CiILo6sPSqpTcWwtFHHQJTI88DfNLcP4oUi9us7ytYxn+yDzc9bqoUWjX2e C3x4pLly0iEBnpek0Z7PKiZWVTL1lpc3Tq7EabrK2Niko8B7pZlnrKroB4kvWSY4B7yj erQHLEVARqEu2blvRkPMEGKASldwou8NB4gNLru4br1156PHdvWMFZDQurgrEtvoWLt0 xfgQ== 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=wCkVCvA/OsuyWYCVDNeyxSSD9IkIMZ8yETdXk3EZhVr776/u23jx4bf4pLPSON9so1 bzErc2Kw+aHSML/Fzm8+P5qHNap/t04muyGZS1jbOTYGNrJZ+cMWe9zRfK+5CZ/Tf1JX pcHFwp27iTqOFvC6aOHfimOK35NYKQIW/LqQwnqduaVJMpj4WSaVD7+Z6V8mcKJbDz9P rcYj40yhxiG1msxJMDBXxsXt4qbkmYB4uFybe2Mmach77vQfL4xNrnQsZq95c/ZAw8tY IjhUgyF3vpwTjdqtQD4UC/S7KA6YwC6A/qWdCKIaMSU/439Zoa0A0TY15LNDgtn0UdbI bMbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=n7kRyUqN; 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 r24-20020a63a558000000b0043c1ef6aeafsi1199205pgu.522.2022.09.27.00.58.50; Tue, 27 Sep 2022 00:59:03 -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=n7kRyUqN; 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 S231330AbiI0H4I (ORCPT + 99 others); Tue, 27 Sep 2022 03:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231331AbiI0Hzr (ORCPT ); Tue, 27 Sep 2022 03:55:47 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A46739E0E2 for ; Tue, 27 Sep 2022 00:55:41 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l8so5987655wmi.2 for ; Tue, 27 Sep 2022 00:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Lb5wXjXl71KLOn69lH3EgInZyalgQlnigOqDmtk2Tt0=; b=n7kRyUqNGoOgpPCI9RAaDptp44hDn8HLIUD/5MufJyUFwbUHFvsmN8TqneO3R4nDUI dgazNQY1irolv5+pnQeY+LJJjNg/69LsymFpZiPl/oT4vx8lNBoyj4HpflzUFkSBmnhy fBsUeoVzlq7+GME1AMbqMwbVJavpAJ70/894ANaAkc3+OKWumAK1+uskfJ3ox0N8muTg Y4IJ+W+VYAT/SvSywKLOlTu5niuz1IZrUkd5Cl/YNsKA+5yEiKuiZF1B6dH6CgQ3AU/f 6wumlOfxXHzIHF24CqhYUvvvgHOhi4keYT+jmkvXE3YXcqnKERLrmXhV/il5V3WXIuYi cEnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Lb5wXjXl71KLOn69lH3EgInZyalgQlnigOqDmtk2Tt0=; b=FfEXBnSRt7c0Ywe1OAADSy8SWn30FEDLLxALCy3QFXZV/HA0SPeQth6iJBBAdGNBnv lkI0G4PQRarjKsVugj04rCzFRcuK+vH5iVV9JmLzNfew2PyUAZDowokNkWRq/uqIG4vS YKS9GxRRKDJV2+ue1MF5+YDEXD9UCm4uAX5Lr2xlAz67aFIWlErixqhSvQ39ZOyQz5Gr Qi15V+uCEhG5bDGCGjqjkCoLzCGBmc0LBgIf0lqrnN7Kd9oJAMW8WnnWjLQBAMSxUejJ SNI5CkU2CYWxKfwPLKefy+JxEyyj2O7uz667g4Lc5MLUzLvmIyMyNsFcqe/L4evV8XI1 bW3A== X-Gm-Message-State: ACrzQf09BDGY1B7BJ93OQ51HqdazqsljEm2mo6IEuCiWrufhY1HQsP1A p2H7c4oA0mbAK6rSbx5CSWNCow== X-Received: by 2002:a05:600c:4186:b0:3b4:a660:1d29 with SMTP id p6-20020a05600c418600b003b4a6601d29mr1615632wmh.120.1664265340931; Tue, 27 Sep 2022 00:55: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 x8-20020adfdcc8000000b0022afbd02c69sm1076654wrm.56.2022.09.27.00.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 00:55:40 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, ardb@kernel.org, davem@davemloft.net, herbert@gondor.apana.org.au, krzysztof.kozlowski+dt@linaro.org, mturquette@baylibre.com, robh+dt@kernel.org, sboyd@kernel.org Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Corentin Labbe , John Keeping Subject: [PATCH v10 07/33] crypto: rockchip: add fallback for ahash Date: Tue, 27 Sep 2022 07:54:45 +0000 Message-Id: <20220927075511.3147847-8-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220927075511.3147847-1-clabbe@baylibre.com> References: <20220927075511.3147847-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 autolearn=ham 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