From patchwork Sun Feb 7 14:39:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 378110 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3953851jah; Sun, 7 Feb 2021 06:41:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJySeBaK31hb8bvpRaWeP1Z4cfWObSDpM97n6b/2QBM/dWuYH87tdCO24sjCQYYhNt14jcJ6 X-Received: by 2002:a17:906:c1d9:: with SMTP id bw25mr12568140ejb.452.1612708916998; Sun, 07 Feb 2021 06:41:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612708916; cv=none; d=google.com; s=arc-20160816; b=aaz5FEsML2W2iGENRhLT6Jck49dVDnL/QquCUUamiuEQ6oq1Se9BsUDUWnyzifas6R j0luFTJtwZAZWJEVMQXkgUzUMWgWwqJcQH6egeByu6juwvXHQ+PgCNXaELZVuuR7wOBN w0f633Bp7xbQCFI/7P6Muytjr7BSuODGWGrVccOjvBwPbIqobAVnvvhBETWO0RtXBN3T fj/Y+wOc1hpcZ3dyvlsBZ6BFN6ZZ9RNS0kL3koUPq68PvlbrNaXq0gwqjWo21VWJBtth e3eLABR/Sk6Szkg9kt6/SCJwZj79Z4pOB461VQSkwW3oy+kJ/kUQnsURKhz/8+AkikWa +kog== 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=Hw5JiWngDfOuUjdoO4gTv+h7PJoLao8vhKub2P8JHASwogxdeYO1o23Zyx/iRMFI7b LDWODrPr6fF2xC4VWFBKyMTM/xK32ZI5IxHmbW0O8FS0F6PAODKD9+UxrZBVwwMIVrLK sDRQEJ4Qmt74LJXKQHh9GLNShnKKQNOCIRP9VQaeDBHuLA5TYJ2DO7MCn0KSkIR8jOLK HS3d8+4y1r66RMzlGLvLWCU0+Ptv/TMx1ZJk3yv/j1rtDB1MoOXED/iqcDhZKb1d4Fof HWBoqgdz+VbcKYIeucRsEb4+uk+n9UhybUSl0+xeYGgcfSgusw7BHXE1Q7rcuwGeKtkM 7LxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eJtteYal; 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 g26si9550734edy.55.2021.02.07.06.41.56; Sun, 07 Feb 2021 06:41:56 -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=eJtteYal; 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 S229927AbhBGOlO (ORCPT + 2 others); Sun, 7 Feb 2021 09:41:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbhBGOlL (ORCPT ); Sun, 7 Feb 2021 09:41:11 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB933C06178B for ; Sun, 7 Feb 2021 06:39:50 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id u20so11932932qku.7 for ; Sun, 07 Feb 2021 06:39:50 -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=eJtteYalWZ91+K2C6akaMpspY+GsXxbUfl6WHlqZ1i3V1Pptqdt0DQ3P/XOsoEZcBD DnqgzYnJa+D3tgBbR83rlgpoExPLwI3dzeDncD1789fOnUEvG3/WGybKDpwRoKmcwGdJ tgUa7PHaTa1Cutu9CFLSXuflvBMSCWFBkEkjFT3FX9Ma+zolZ34AadTJldj3XT5kiYlr wsS8ojdQTmZKVB2hsxgQbYC44dYLCiu4iqIRHAWfoBF/4qbZVhGJ7bUzE7apkTQcckp7 PuG+9+mUIcJKvOK5n7zSww0kRNNrRabR2DLdY/GrxBhYceJdGwrT55rSBZ+l+5eAS+PX ug9w== 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=GntTc+wCgwLvakpiPrgm/sZj2nICWos+0PPfH1GiNQk9UdQDcN3lQD8zfEJx3yDs27 cM9G8NbV/Aal0JugPSFL9uyNsMyJ8f/i8DxtbacMxYAwEiYmzpuEgq95iPPMCaGdRMG4 /UBXcnix/swzif9Sh/1Y6yPKhaPy3+BH7oSYtAqv3luKqKKBJGVnnvLEMxX7KvAeCOC5 ToyeZuzzD3Dt8h3swBK40iME+CtdEJEEjqrf7/tHbNJKRSr/bT+GikIzfpgBj6ojl/9I OSKEgtt9k82JJ/u+3lHoVnziuB236jkaa9HTeuOIQDaUY+lB3I8rjvXP0fsQwc2yTt4n JPrg== X-Gm-Message-State: AOAM533IaG0BJ+2WQeWJJo+awl5EvtlJTWshtLf5OManiC5o2+1EAmvV MhJMqPkVlAgqrkJ2KoCW5JRwJA== X-Received: by 2002:a37:b56:: with SMTP id 83mr12927210qkl.355.1612708789990; Sun, 07 Feb 2021 06:39:49 -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 c81sm13941493qkb.88.2021.02.07.06.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 06:39:49 -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 v6 02/11] crypto: qce: sha: Hold back a block of data to be transferred as part of final Date: Sun, 7 Feb 2021 09:39:37 -0500 Message-Id: <20210207143946.2099859-3-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210207143946.2099859-1-thara.gopinath@linaro.org> References: <20210207143946.2099859-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,