From patchwork Wed Jan 20 18:48:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 367076 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp745689jam; Wed, 20 Jan 2021 11:19:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZ8cxf5MPA5LzyFNy+yhRQjkr3yH0+QMqudJbCgv7vwri7F3lWfiI1Bk7drlUna8PXVDJ+ X-Received: by 2002:a17:907:3e9c:: with SMTP id hs28mr7237238ejc.176.1611170374259; Wed, 20 Jan 2021 11:19:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611170374; cv=none; d=google.com; s=arc-20160816; b=uqRvFQkhiL5buJA7EqiPudbU95tfQy48zBPnxHygk0je4CY8Z5VrBbluhIwtxVjSgH +41T8WT+Sxn9hHtx1eMFFvlsicAXqGr9jDUq46ttGMoWOkkB9qe2522JPqgP7a4q+qOq WNZ1vt3V5JZaDAquch56oWk6l34Cd2n3Y6u2Cf+dwtaos697EJ8zD87o+ptOtT7DcpEV HWgUDIBh/pov+xQB2t7TieJt02A8CpI5OJ8IbQMiyFKH7wqS6vUOBd3vRJXBABBNGw5B HnVCnJaHDvKLku2fqo1x9vO+UBq8OgWGtZaxon/i/YQp/+EnFfFWdg902JLOINDM9p5p B64Q== 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=FzoTTNnCPyrLt8K8sPUqSR8uOcEXNVFa8VbUu/a/sAw=; b=oszCTtUYKNL2xRaZRr2a3rLZCTyk+LMO+adHBqxdT+jgvHo48rPc24MkUWQrdeZAgk 78YS0aheNvqYiyb/2DZwPSB6ZOPqaY9cVe+KZZBqKFnAtVrAE0j1fpA+dL+0kMUD9dJA 6X/Ixgq1U+607a6rx4tcupZH37aSiF1YFts9XKGyuLuEQrtkKKtT33iG9O7f/5ngJ87X FfsQVVTruiNIotDrikqTrkypJ4cUIJ3IBFbDA2UMsk/2H9MXl3ETqqZCDfSnEXI4YGMS t/Heh6FAQGGO2fOpVTfBd/3Q0XEGKr2RNPFlgTAcTRrnlVOmfp0nXBlNFKfaBYiEcq75 8Hxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W91aASl7; 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 dr2si934728ejc.663.2021.01.20.11.19.34; Wed, 20 Jan 2021 11:19:34 -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=W91aASl7; 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 S2392187AbhATTSp (ORCPT + 2 others); Wed, 20 Jan 2021 14:18:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392093AbhATSuu (ORCPT ); Wed, 20 Jan 2021 13:50:50 -0500 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B196C061786 for ; Wed, 20 Jan 2021 10:48:48 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id z9so7088357qtv.6 for ; Wed, 20 Jan 2021 10:48:48 -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=FzoTTNnCPyrLt8K8sPUqSR8uOcEXNVFa8VbUu/a/sAw=; b=W91aASl733ZLAOz8W+VMfENwcB2YPmp1GP6Wgb63CXAmhQmR6LaS/yhs84yWRvx4Bu tEdoA7BJSo9Nwrrs2m6QS31O5EjD9GmwUXaBTCrERFRKu1r5nI38LH0fVaB5qanAQuDV UIAhK4d6cgWnm1ymFmaBl39JuRbGYpA9zkryhYv87Q+0uWrVVoefmulSoXPIp+8pm/AC KQMr9nja785KJWnwJzrIRP3FyEg9k+KQWgdSRzwUs48cKKrFmgPNmj+f+2kgP1AVnlRS fX3nSufc/rPl7aK0NFNjsbxGZ31QZdzr3GKRZNS9hNde/lttH0oLCjxZKiQ6T7pvtTu/ wVmA== 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=FzoTTNnCPyrLt8K8sPUqSR8uOcEXNVFa8VbUu/a/sAw=; b=lEzaWEFwQIoH0AF5TCSXNAr/4iOSKFDqs4KAitojWJHF/VS1A9Gr3dvA2TdcOEC8lS Vo+17pfqDVVvI0sfHoBlFx8HYHtfTrQs0UsWcw0wKwPHUorQDjKuUUIMBiRg+QlJGCsr sBqKzbueZvopNNL53tqB9JKQyWtDFAl/DT+e9GST43GzspuarVpO/TGG7aVdhd5niOj9 82C/pKcmeqWCF5YHIjYCXcJ3NXi6YO0ogVeEkUh7Q6vUU8Z4d1uiA3ZwTg/SG6Fx4drJ F6/Whl9YC5Q8DulHMklvuVwBUr4SFkjYOH4AmDHv5prY507MxL2LPvtXR1/XFfp/j350 39/g== X-Gm-Message-State: AOAM532M5ulrfTcTzeeH7e3gSQcSx2ZyaFE1Oq80WXbghilYl7sOPd8j rAdEK89UULYN6twJH8RxZs0RQA== X-Received: by 2002:aed:3629:: with SMTP id e38mr10150279qtb.354.1611168527314; Wed, 20 Jan 2021 10:48:47 -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 w8sm1769903qts.50.2021.01.20.10.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 10:48:46 -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 v3 2/6] drivers: crypto: qce: sha: Hold back a block of data to be transferred as part of final Date: Wed, 20 Jan 2021 13:48:39 -0500 Message-Id: <20210120184843.3217775-3-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120184843.3217775-1-thara.gopinath@linaro.org> References: <20210120184843.3217775-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. Signed-off-by: Thara Gopinath --- drivers/crypto/qce/sha.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.25.1 Reviewed-by: Bjorn Andersson diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index 08aed03e2b59..dd263c5e4dd8 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,