From patchwork Mon Apr 25 20:20:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 566852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6F78C4332F for ; Mon, 25 Apr 2022 20:21:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245198AbiDYUYr (ORCPT ); Mon, 25 Apr 2022 16:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245235AbiDYUYm (ORCPT ); Mon, 25 Apr 2022 16:24:42 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C41741299CC for ; Mon, 25 Apr 2022 13:21:35 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id q23so9599474wra.1 for ; Mon, 25 Apr 2022 13:21:35 -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=yzvgVyreo6slTFAo6yIfKz7ssJtwxUt4QGb+bB9VZnw=; b=g0W+RBEU2DVpJOcyQb0vAUSv0HySUb4wrQLTjDRQrYCkExGUJA/3kkqNl0TsH6B07P G/BdSyXPm/hK9AbPy6f0CrBKYAQNBJmoe9sQtUdwCzylYu/94cy9W6P5Wl7539OpClEm ubCViQLyOoHAgmatfdvMXkQrqlad3KNyTv4cE6vE9tTgWvmCkblTaD0r6Uzkq4GGnL57 22BAgHrvM7j+J2otUMXw4psRsRtPR8+unx7wQLZfJdGHmwE87mss0UoI88KNbCtgCt9U zcW5E58jf+v3OMBs0KIq8FYMFa6WNSZqWZK3/BCSfwVRfTvlySDTa5SEhxCO+c45NIcs oLSA== 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=yzvgVyreo6slTFAo6yIfKz7ssJtwxUt4QGb+bB9VZnw=; b=4doV8US08RYUHkE0qEhvu3/9jOJLV3ElBcI1ApRWs+eLMlm7goTtuSAHnC/GReEJKt YIMEda/e1SkkWT//uUHHMJgmYAmHButI9b62mcZmXuWU9bBWpC70YfLI1sl1UXGzC5yn uMnJclWfB4OnZ1ygP9MSlw8AJ1znbISx7ZA9tHFuSpMnRqBR/+qGP4tzLJVaW2Tj8tbq jeBTwfGGygUA4p7emCg3Qn7XIb9pVLn4q8V/wkuLPgP3KN2X7iYvotZGdjOrbegDVzSQ ZhzDvqvgc7lWCUKL6jtYRajTW12RnqlReQIiUYjmQ0Q6ntg3RSrTH5YZxMZuctMJw1gW Il2g== X-Gm-Message-State: AOAM532Ae2WROFG5bc9jT9TemGU+Bxx+ItWDlHYEmV7LU3TIGwwAx7+a KnZF+aJH2v3Jk6ljPsPe/ZWpXw== X-Google-Smtp-Source: ABdhPJwaSWCN4u/OFWV2DnC80dUm1T8fYKILu0YE8V/VULdmNc7nx+qeTGdxShpo3cm0Mud1zMUXlg== X-Received: by 2002:adf:db86:0:b0:205:bccf:8cbf with SMTP id u6-20020adfdb86000000b00205bccf8cbfmr15278513wri.346.1650918094282; Mon, 25 Apr 2022 13:21:34 -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 p3-20020a5d59a3000000b0020a9132d1fbsm11101003wrr.37.2022.04.25.13.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 13:21:33 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, herbert@gondor.apana.org.au, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Corentin Labbe Subject: [PATCH v6 07/33] crypto: rockchip: add fallback for ahash Date: Mon, 25 Apr 2022 20:20:53 +0000 Message-Id: <20220425202119.3566743-8-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425202119.3566743-1-clabbe@baylibre.com> References: <20220425202119.3566743-1-clabbe@baylibre.com> MIME-Version: 1.0 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") 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 = {