From patchwork Wed Feb 3 14:33:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 375417 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp388982jah; Wed, 3 Feb 2021 06:35:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5BlcxORVlya/V/Pm9gzKKVQzWm8vmwDyBeR3UlvaofvBU9m1JIr5LqGxl2+cZfnRoGxus X-Received: by 2002:a17:906:854f:: with SMTP id h15mr3402545ejy.2.1612362920960; Wed, 03 Feb 2021 06:35:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612362920; cv=none; d=google.com; s=arc-20160816; b=koPL7Pv/jy5lh6vrkBNYw11rmBNMEiEmpr23cGkt63RvWNGSsYkVsCarM8BnNfFZQz yhOI6A0SUoe3uH9zgeTusPGAaXG5Ty8fE0Nkd6rVxNlICjSnZTeXxUVKNxWRKlim+ira fC/dKprSkUOZOjtDpgTlwUC5Zxce/VLt/NKTbjlM852dbB6d7Y4gX0JU8MgJsyZdWHMS TOTV3SXB4e3xA09N7xhqXirpV1aXvaZpjncywUMc5u68HWeAhNaEq57vw6ewuBkzCBsQ oDg4bp9lAgk/dCGTeDNujvtMhLhP3agfSXBAZefMw9Gokj/ofQoy4eommJpVQPeuISXg hn7g== 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=+Uh3JollLTG+dAe2nrFPwv+L2m02OQeUEuYSFXryNKA=; b=oAbGBtfCwWWEF4E4+/bXTqZpI5BhpmXZC7MxBaz8FikgO9mYms/e/u6Xd55thHXaiq Fb+xCajMcUR2b+a1CimIxbpsIln39yBnq2zK/FMNBl+LH9UTUYKzk68IBw2Q1KWAc/lR 7gZ6bewKalZnLa/SDCIdt4Df7B3gGIEoMqrL3ACY6QeRu/t1egpR43IUEqOEo90wRs3R rugxRuTEZmhU6egf7FkVbN78hrHW77tKdPLECs+RAsjjXtZhY4lS4PJ0MBZLH09OZ4Ms vVALWh2SekDzENuVgfltGVvlTPyU5Kgr1N9PIBZ/f6+P6KbD15eOGnT0aUxRKeAk+rSB RdCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NfK/+uIg"; 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.20; Wed, 03 Feb 2021 06:35:20 -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="NfK/+uIg"; 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 S233011AbhBCOfM (ORCPT + 2 others); Wed, 3 Feb 2021 09:35:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232903AbhBCOec (ORCPT ); Wed, 3 Feb 2021 09:34:32 -0500 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F0CC0617AA for ; Wed, 3 Feb 2021 06:33:16 -0800 (PST) Received: by mail-qt1-x829.google.com with SMTP id e11so30592qtg.6 for ; Wed, 03 Feb 2021 06:33:16 -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=+Uh3JollLTG+dAe2nrFPwv+L2m02OQeUEuYSFXryNKA=; b=NfK/+uIgybzpmnDkFqO6IuK2o3JDCVPeFz4z0KcAKVxGfIjpB61ZVAIVCWTuHZMRDr YCCQQ6DGFGEC9iGjmUkhfUmgTDKwHPmyuduKipooERCIAhXU6xPPhe+T/Hme3wsVarLn NEkCy1LdJhl8/ZAyHMLbyTBxirDM2GM5y9PLMWJs7J3IrgPzXHbrO2vkJVLmb68KRS7N VThzzQTfRRfP4qyypdVCXGn/P10EzEvdLOUZkF+07StqP5DCdLZ+Xds243DskFNSg1iy cMBn415hgvVfhDai+fL5+R2dX7/zjFTNiXzGsveo70ZeKldXyp6KxwedmIDFSM0NOh6i WZWw== 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=+Uh3JollLTG+dAe2nrFPwv+L2m02OQeUEuYSFXryNKA=; b=I80rVXG4dZBjRRmd+Pk95d12KgHrdx/3Obhj6ETUinLLnrOY+KyItsDkKaTBc74VZG Go5vev2rYvMspd6pjF/U6K+E5CHV/l/+njQcuoaB4dhRyCtvxCgZNSwGqS7yuh7RcjHE yePUpqnaXVwsYkOhwwiC5Zt3RnUfWv7zqrGa7W1gPgmcGzX8sXVQ7HtKFRETjLEB/k9b QV7W9nTnihLboLsT7xac8bhGHomQzR1sJEMGVTDDjjouvyTv1xn08+iG+oV2CnLqsE9y Sg818eSmumKrhTEN1g6NSxJzbhqL7gguvMnHS+zfUczartQwoxwlee5fTz/h5QJvQxTl EI4g== X-Gm-Message-State: AOAM530VJW3p+Xvjy3csHOyTZw62iSAJwaYn5nKS/cxE2KgSEOqSQsqc WUc/yoN8D0z+sUVHdaCfWxmHIQ== X-Received: by 2002:aed:204d:: with SMTP id 71mr2683694qta.318.1612362795500; Wed, 03 Feb 2021 06:33:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 06:33:14 -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 06/11] crypto: qce: skcipher: Return error for non-blocksize data(ECB/CBC algorithms) Date: Wed, 3 Feb 2021 09:33:02 -0500 Message-Id: <20210203143307.1351563-7-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 ECB/CBC encryption/decryption requires the data to be blocksize aligned. Crypto engine hangs on non-block sized operations for these algorithms. Return invalid data if data size is not blocksize aligned for these algorithms. Signed-off-by: Thara Gopinath --- drivers/crypto/qce/skcipher.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.25.1 diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index 331b3c3a5b59..28bea9584c33 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -254,6 +254,7 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) struct qce_cipher_ctx *ctx = crypto_skcipher_ctx(tfm); struct qce_cipher_reqctx *rctx = skcipher_request_ctx(req); struct qce_alg_template *tmpl = to_cipher_tmpl(tfm); + unsigned int blocksize = crypto_skcipher_blocksize(tfm); int keylen; int ret; @@ -265,6 +266,17 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt) if (!req->cryptlen) return -EOPNOTSUPP; + /* + * ECB and CBC algorithms require message lengths to be + * multiples of block size. + * TODO: The spec says AES CBC mode for certain versions + * of crypto engine can handle partial blocks as well. + * Test and enable such messages. + */ + if (IS_ECB(rctx->flags) || IS_CBC(rctx->flags)) + if (!IS_ALIGNED(req->cryptlen, blocksize)) + return -EINVAL; + /* qce is hanging when AES-XTS request len > QCE_SECTOR_SIZE and * is not a multiple of it; pass such requests to the fallback */