From patchwork Sat Dec 19 03:30:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 345964 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp2710225jai; Fri, 18 Dec 2020 19:32:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVA6hXNhH6uZYju60sy1GHtXWP3U4W4hpJrLLTIQzBY731UI2+ED5szR4VanePAS5SQxmw X-Received: by 2002:a17:906:68d1:: with SMTP id y17mr6937469ejr.447.1608348731600; Fri, 18 Dec 2020 19:32:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608348731; cv=none; d=google.com; s=arc-20160816; b=k93nceM85GMoRFG9wBSNoGcyAZnA7Ie4krGlc3MS8efk7ddqG2A/81tSL6VQh40sid 3GJxjbmfCswYef31oliXP3jwWhFkgJzWLo7TfmCubMzkbsrWJnyO1wv9/ilJcLT1v9Ym S76KRdahgi3o06TV4dV4hEyM4bw9Qxa8gx3j7mNOUISyrIXhzfyUyjzpJF4NWIrdrn68 EL/QVFYRBo9zTqXOFZbhhd6cahDppq90W4eZQ2o7qkdkU2hGfq83vEC33mezxx6eOGJ2 Uo/SMv9qqxUZE8mtRO3otcuyEYNdx3ixIspqFXewDUAOiaMrQIpF87DddUZrDZB+Ahg8 5XPA== 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=G+dMsLBrY99BUWGLKr1cRQ/g1Fbgha5c1iEnYj8qjJo=; b=Qh4ABDSwZC8uB7xkrNriNXKZCgdbO/44Ly6uxeTQIoBAVbBDOT6eEUdawn1e+x6ot7 r3hy/dUVUhpjmgL7W50rnmY3LLI0gIYENQ3gSraMEiBJ1nglFDu6YioHOW2OKiEtST4D Juym3R6Sf0Rdex7VirsyQKuPn0yrraSm6EKDNNSwSJU6JerXyf9V2uykN/7EDkHP5ytT KAObcvnkzwWU7vzbPnQDjJHHw02SeOxlyAJ7iHCi8eHy3a/V2GX74AKxZS6ogRk5jQtV ITlaks6kLDgHqoKSaPPHETEzU84BOcyZpUrwwpMMM4u0kFYj5dxgn62SsNtu3iTD/4OI I87w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vT8jy5Mp; 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 s2si7383558eds.424.2020.12.18.19.32.11; Fri, 18 Dec 2020 19:32:11 -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=vT8jy5Mp; 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 S1726411AbgLSDbM (ORCPT + 2 others); Fri, 18 Dec 2020 22:31:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbgLSDbM (ORCPT ); Fri, 18 Dec 2020 22:31:12 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9F29C061248 for ; Fri, 18 Dec 2020 19:30:31 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id f26so2508959qka.0 for ; Fri, 18 Dec 2020 19:30:31 -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=G+dMsLBrY99BUWGLKr1cRQ/g1Fbgha5c1iEnYj8qjJo=; b=vT8jy5MptC7VW2zdcTnk29uYgSz67EeJOfAP4ek4gPwzqbeurSmmjfcUW9xpmBn2zf hTEOcc7PR7X0O2TeTsexiKHG9k7tD3TG4JxiBSlLhgOIITNcdWgbN1zcYBWPsIrA1vU4 iA47XFB35EOXuYsPkWL2ovbUfR9QYXKe9n+jgBrlCHKyFkNs3GAodS1ifcuFiasH47GU FPvErgetFEvolLBB6MDR2N58MQRkRrWbZyHi1hFj2cV5u/bO0RajCqxCYNeUMD14jty7 qYM26i6S9bL9TuKw5tLRlM6MN+Mhf5boMygkj9QzbexJ6JwbaKicCUkbYMCt3BUCzwyJ B5Cw== 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=G+dMsLBrY99BUWGLKr1cRQ/g1Fbgha5c1iEnYj8qjJo=; b=f1tkX8eVa1WX6jE0gEj5nGs5rzPsBJ9T0QtlAHOpSKH6VzzzCHwc75hvsU4F2tq3PB vpejdphIH4xW4gPMSyuQqN49+a4YLK7kIHh6oZQlYz3vnoLpEhJCPCsu3xAvcXQrhq1Q AGlELkHPn76gBTv0S++ib2zdXxb2xlBGhr9PO5GLk0DfGW5VlwGnR/MGEQ2N2NM0gxrp uaCvUFg/FL6GcSvlUO4gYmciyD00dy0cgDuBO1op2i8y9+moMG3D3n0YDRJedPfYJKOI qgLUsWDOwh1NIoz7mafmgHTZrwhRiNjgQbX2SRs8fXOBQ+3hMuZzU52+/AKuVEuPQcFd sN1Q== X-Gm-Message-State: AOAM5306rjbnJIXaG0fjykUKWu2lX0BYLy2fca/Kzgr/2XE6fO8PjGpH cVXnoEg/FEtbFYoyJ6pqHHKr1g== X-Received: by 2002:a05:620a:10b7:: with SMTP id h23mr8222309qkk.249.1608348631006; Fri, 18 Dec 2020 19:30:31 -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 y16sm4376045qki.132.2020.12.18.19.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Dec 2020 19:30:30 -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 2/6] drivers: crypto: qce: sha: Hold back a block of data to be transferred as part of final Date: Fri, 18 Dec 2020 22:30:23 -0500 Message-Id: <20201219033027.3066042-3-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201219033027.3066042-1-thara.gopinath@linaro.org> References: <20201219033027.3066042-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 diff --git a/drivers/crypto/qce/sha.c b/drivers/crypto/qce/sha.c index b8428da6716d..02d89267a806 100644 --- a/drivers/crypto/qce/sha.c +++ b/drivers/crypto/qce/sha.c @@ -193,6 +193,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,