From patchwork Thu Feb 4 21:43:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 376336 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp1655710jah; Thu, 4 Feb 2021 13:46:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPRKp923bjZlnKCblu+M3zNDMVp5oF+oqmbsyFmCovfqnj0EToekf06rNiYUTcbuvrdF5r X-Received: by 2002:a17:906:a14e:: with SMTP id bu14mr1051316ejb.303.1612475199972; Thu, 04 Feb 2021 13:46:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612475199; cv=none; d=google.com; s=arc-20160816; b=IIqrRkV8FyzDyoMv3lM1kKa5I/NnRvxuUrxrA6eFQKpbI2agjojjZ+cbU2nRRHLJBS YSJcyb7eeEKuPQEd1Tp6jeVc81hyjQkAHK/2+1YZiPbNfOARKA7wkxWKt9YA2ZuGJx4C S3TxUEEsCNTPTx4+wcFP2zpYHrQtBNJ3fQUlQbu5t36gR2Es0v3tcLwOZok/mLiNeXqX 1e0hErdULNMm7g9nBzM0qtiWoKpUOXPuXPalz9vZ0lsMf9ioFDNHttXPEJrC2kWVGCRO Ei8UBDBvWPeZML3wbydIsRUcZ78nzFY3XlgaPDfrngpFQPlASKyfQ45Usc34yaRemcDp q5Dg== 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=QL7UCH32HRfcwYFo/OihKYejmQ9XVroK1tPKK/3bNQ0=; b=Evj5yuxVaoeQYuBE6FLxZ8C0BG0xz0NHoB4DyWxz5roqyPwHLi7Yt0xGFlKsI8UBnM 6o9Wgh3TPcqdL3GdVJAp2b6odXc7aw5qVBJhSO7YVx3LZQ4MgHC5+vp/Z53XxIe8p4cu PljixKtt1zH2uQFU7nFlctoUx1SxnfcKKzChdDzVD7sQZ9YTgXxMY+0zLv8hLmZDRo44 1sb4Jh2fU7mB/9H4tMF9Fbt+gLVVduqJHTTRDLNNvVyLOnGXP7ZCBO2Z0rPyTOrUK6WZ ILSgSslIGE2v8XS19VPm5HnvGeD8zPwNCVAG0nBk14yo9lCo3FqufAK/A5yrKviwvaBz medA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LnP8z+oM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j4si3983455ejv.17.2021.02.04.13.46.39; Thu, 04 Feb 2021 13:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LnP8z+oM; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 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 S229500AbhBDVpa (ORCPT + 2 others); Thu, 4 Feb 2021 16:45:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbhBDVpX (ORCPT ); Thu, 4 Feb 2021 16:45:23 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F0EC06178C for ; Thu, 4 Feb 2021 13:44:03 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id n15so4918416qkh.8 for ; Thu, 04 Feb 2021 13:44:03 -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 :mime-version:content-transfer-encoding; bh=QL7UCH32HRfcwYFo/OihKYejmQ9XVroK1tPKK/3bNQ0=; b=LnP8z+oMAn848LJIEfdOqDBRJds5HSWKBf6vcIKvI4CiADXTlE+/N/zNNkHCrIhLAY VTnY0I4xXiXCCK5k2VfTkPZn2rie5BlnPXqovi1k1P1LnF23GdUuBQfgx8oYknHJSjYQ wGR3Bt/8er4TGA3nLtM0hHK3K4Z3Pl95Nlhwz6yzWtVgoVIkzAA+lx44rV/cZkM6PWG5 aSGnvDIUsEt16bCvEo6zj/EdwYg+QNp2B7C1vnR5BgxazIQzWS9pp5oTRDdKGpGuxTmj NDdBY0bPPi3X/3nVVvjSzb86atdmKAsX7D+MQIEYE+FPn5rhSny22sSuEeL+KfMo7YMh 499Q== 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:mime-version:content-transfer-encoding; bh=QL7UCH32HRfcwYFo/OihKYejmQ9XVroK1tPKK/3bNQ0=; b=fC8kHmiMvVv9AOHS22tkodMFu7dGjhD+ZddJwaJYK7GPM7JFVfwe4OQw5eXooHDmgb 3bBFVNywbz59n0GLO3uM1xmRqzKEdEBcXSTNUlmxjIlg8XPMFHW8RKpAVyshz8enebMD ycYH4RBaJOaQj+oeavsx4fm2uq2qdLTvFYrBKj3L1kn5wKlwcj5wKkxXz7R1PPFMDhvR ljAiKd+lY07hqEfqtqGAP80CE9ytcXfR2kGqDJGmN/XTMyfHvUa3Q7EoPELD5a70pkRV q4dX7q/bHWUCvh8XsD1q9MmNn26I/TlRrS7S/lDV4ywrR6bdFo6+XuGPi+n8UDabT7Up FlDQ== X-Gm-Message-State: AOAM530lrgdRpTwZh8myASMUPDDd7oPHL9cMqFW2ceoptrLz4/u6Ds/O lORGxDyI057qL1vBuDNyyeuiCw== X-Received: by 2002:a37:a753:: with SMTP id q80mr1285453qke.29.1612475042611; Thu, 04 Feb 2021 13:44:02 -0800 (PST) Received: from pop-os.fios-router.home (pool-71-163-245-5.washdc.fios.verizon.net. [71.163.245.5]) by smtp.googlemail.com with ESMTPSA id h185sm6353858qkd.122.2021.02.04.13.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 13:44:02 -0800 (PST) From: Thara Gopinath To: herbert@gondor.apana.org.au, davem@davemloft.net, bjorn.andersson@linaro.org Cc: ebiggers@google.com, ardb@kernel.org, sivaprak@codeaurora.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/11] crypto: qce: sha: Hold back a block of data to be transferred as part of final Date: Thu, 4 Feb 2021 16:43:50 -0500 Message-Id: <20210204214359.1993065-3-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210204214359.1993065-1-thara.gopinath@linaro.org> References: <20210204214359.1993065-1-thara.gopinath@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org If the available data to transfer is exactly a multiple of block size, save the last block to be transferred in qce_ahash_final (with the last block bit set) if this is indeed the end of data stream. If not this saved block will be transferred as part of next update. If this block is not held back and if this is indeed the end of data stream, the digest obtained will be wrong since qce_ahash_final will see that rctx->buflen is 0 and return doing nothing which in turn means that a digest will not be copied to the destination result buffer. qce_ahash_final cannot be made to alter this behavior and allowed to proceed if rctx->buflen is 0 because the crypto engine BAM does not allow for zero length transfers. Reviewed-by: Bjorn Andersson Signed-off-by: Thara Gopinath --- drivers/crypto/qce/sha.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.25.1 diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index 7da562dca740..2813c9a27a6e 100644 --- a/drivers/crypto/qce/sha.c +++ b/drivers/crypto/qce/sha.c @@ -216,6 +216,25 @@ static int qce_ahash_update(struct ahash_request *req) /* calculate how many bytes will be hashed later */ hash_later = total % blocksize; + + /* + * At this point, there is more than one block size of data. If + * the available data to transfer is exactly a multiple of block + * size, save the last block to be transferred in qce_ahash_final + * (with the last block bit set) if this is indeed the end of data + * stream. If not this saved block will be transferred as part of + * next update. If this block is not held back and if this is + * indeed the end of data stream, the digest obtained will be wrong + * since qce_ahash_final will see that rctx->buflen is 0 and return + * doing nothing which in turn means that a digest will not be + * copied to the destination result buffer. qce_ahash_final cannot + * be made to alter this behavior and allowed to proceed if + * rctx->buflen is 0 because the crypto engine BAM does not allow + * for zero length transfers. + */ + if (!hash_later) + hash_later = blocksize; + if (hash_later) { unsigned int src_offset = req->nbytes - hash_later; scatterwalk_map_and_copy(rctx->buf, req->src, src_offset,