From patchwork Wed Feb 3 14:32:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 375415 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp388958jah; Wed, 3 Feb 2021 06:35:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp++GBSNONuFEGvQGrLUZAR7VTmJmb63+iYG2ho3zciaRamDQitRI1tN61PRY6eWH1uio4 X-Received: by 2002:a17:906:b752:: with SMTP id fx18mr3223746ejb.17.1612362919712; Wed, 03 Feb 2021 06:35:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612362919; cv=none; d=google.com; s=arc-20160816; b=Niom1UtoPUgbHYLPyTQDcZmsZb7FEvueED7ge7BXbI2gJuso2T7Q/pnbhlooGbhHc/ yaVmWX3DPq5Vtm8StO1exLE6vK/Xol4XYLoFmdy1lNa3pDGxSZTJMlYpO8JFV6tXtrc4 1kvJ6Ili1nBMQPc/OhIHVe4IHJUftxIkRpuAqmWSDwQdlABdiKFW665nMkpPX5LBN0th RiuWxXosqs/zVFXXhmiaG4gnn66VJ/vnmN9fC+K6agWVZV3qZ6jxQf+IjLF9K/7Ych57 uxIHH37fHK4sv05CjodRlFoPENUKxLjjFfSZ8L6gr305GFgiJ67t9Zf82FGBFLe0XIaX j4iw== 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=uksNnzHRuWvpXMI4aSId1xngqmQe06fCD5OoPJgAWng=; b=fhk8DAx4hFhyHHIhsKm1lmwTXdjqrxQOrpS1Z3s3+lEYko+46gu4hR6P/IckVcAp4z MQGQBSiUZE5BSgvGwjsu8h6hmFvq+pa4d030IdiBVRmH3FQdfkfnAosxgXonV/N/f9wX rtKgxevIoNKhd6J2+Kn14SkGTvHGQgI11uPUNcHWGsvJrZRiSphLKhC6tVmDiJAKz7FY mYvlCwa6OZxr9IzrA3Xj/k90rUDIsCQTotaIoAk+vtBWmVm2QfF7xjv0iJj7pkDgzRuu N70cfN1zV7bTs4klh7hPGIn8mjJnVoP5VjhXPY1EpOPLh8O5T3YWIGbxqx3pKavwc+hT Yk+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G3cYYZHA; 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 s18si1533688ejd.741.2021.02.03.06.35.19; Wed, 03 Feb 2021 06:35:19 -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=G3cYYZHA; 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 S232848AbhBCOef (ORCPT + 2 others); Wed, 3 Feb 2021 09:34:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232847AbhBCOeb (ORCPT ); Wed, 3 Feb 2021 09:34:31 -0500 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4615EC06178A for ; Wed, 3 Feb 2021 06:33:12 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id r20so14075691qtm.3 for ; Wed, 03 Feb 2021 06:33:12 -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=uksNnzHRuWvpXMI4aSId1xngqmQe06fCD5OoPJgAWng=; b=G3cYYZHApyAjGvQh6/bf039aehtbg3lTurFDKjeWPGZHGI9NzSnQI1iVe4t+2grxWo mRU7l01aWIdhQS3gANSX8rvbA8aXnZihjklSln+08vFmdpxYriUdjglEDevluwZBpq6p ul8AB+EA0vUa2f5zIvaGGlPwtTO7sgBxv8iK7lnRJRzLE4nWTp5yAew7QT72DE2j66WN XRyvBu6ivXgM7Ij50VhEzPpQwXRiWQXGjjzS2VsM+j1TmC8+p1oK+Y9R6kMURoayNpZa Ppm/B4yEiYqVb0PJ6tmdR7p8YbcqHQqMjDuJs6F+EkXbjOMZN2HJdS5B4ktrIOQF2ksn aioQ== 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=uksNnzHRuWvpXMI4aSId1xngqmQe06fCD5OoPJgAWng=; b=T7LTwSo2akW1yGZIAln9sQUmEg1Y9oBhcotZZUJAx/Q/onLtAe0t30zA0MmlG/dpRd qwadztg9QBe8Eqcvh7uKWudRQ/xLeN7Vnlo21NLQ+dWfvKbdYOGJnR2zqnbLFgow2JJr 6kLDcghmk2TArbG3cNDkiaSQcwFWS7/6gT+Jkjx304d6b/UG+9IKhqk7MCVH99B0vaJz 6+00wBzNhbihOpb0zndCCoTFG/ain1Wl3SIivBEWaTSIGE124I7LllKQpn/frVhA99Mv Nzi9LeCA/KDZOdfW3sZLy/xW+5FJHT1PPbvo37dBiy5grFbA6ObkNoWU7MeQYSlQZ3yU UcoQ== X-Gm-Message-State: AOAM532nUPqqS8K94N/YokuNsWT3p5yUKhmvhFqogcLhGl/nnZeMFCMB rRyfJnngszNLm09g6lqh5cOtbQ== X-Received: by 2002:ac8:59cd:: with SMTP id f13mr2754307qtf.258.1612362791507; Wed, 03 Feb 2021 06:33:11 -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 v15sm1775433qkv.36.2021.02.03.06.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 06:33:10 -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 v4 02/11] crypto: qce: sha: Hold back a block of data to be transferred as part of final Date: Wed, 3 Feb 2021 09:32:58 -0500 Message-Id: <20210203143307.1351563-3-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210203143307.1351563-1-thara.gopinath@linaro.org> References: <20210203143307.1351563-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 500290b40916..c8bfa9db07b8 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,