Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3358694pxb; Sun, 7 Feb 2021 06:43:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEWbbg0HTexZSBJRY1GhSixaOdqJTM0xuFkcA6cIobtGzulNsWXSEE8X6cWMFQN2YOKoW4 X-Received: by 2002:a17:906:fa18:: with SMTP id lo24mr12760226ejb.221.1612709031585; Sun, 07 Feb 2021 06:43:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612709031; cv=none; d=google.com; s=arc-20160816; b=0MCA9COPjrvBqQyZ/biBIVd357pMX0QCivYeOywOOGVrDoIJVwGZZ4Tq/4x+QZBCnO ZW425OBP8dW5jp9rNDjBPoYENKxrlb5B2jS6bMfuFwSRcKGP2nphsGVazpeDXOkp4AuW gmg9QL1xYH+xOAV33vYEM46xtQ9mBBXePQPJpIza3IhKxkqf2BL7ZAPftYv2daGOBxGQ DuLRJ8zTv6HPbnbN1xLXHzBM9Q7ashGNAjDKMpA8cVzTuSIuB5R2EyjIdZgU0atmDVsA yBAQEufQ59Kgd+J7JN1zdkt3qwAauaePIUdXEKW3XIFDfH84teryuslBa5lBebjiYwdX aOVg== 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=qH6pF/G1SFg+K0bTJv0NKKhaRdQW632kFeXNuGpnkfE=; b=a+Qc39LUGfVAZF+FuGlXYgRC85D+Wpl+BSEL4RtTR4Vg9Hjz9/KIAkoYY38uC2nY3C XVkcr3bns2+a19mjjpLPgIqNYXXnAY06IqixYNpX6AbEmaI66wPbX5PhOJC/yUfo8y5S sUg8h3yTBJQ+WE1x9It6gvVVSutQQNs/pyhWL1U8bDp0Vet10LWkmtNiUOCZVxup8yMM FMXoLyUK3psUK9VcLvq0dXG7Aa3iUNt9mqrrIWEp/eQMxPHKmw68cQw9Mslg5htHZGKm PEBOiD05s+MoOdET+JGahhHz8BMI/k1yl4J/3Eir1ehaqoOukwZoPgYC6X4C3tgncgGj /F/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tK0RaRfl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 d1si8779649ejj.357.2021.02.07.06.43.27; Sun, 07 Feb 2021 06:43:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=tK0RaRfl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S229815AbhBGOlP (ORCPT + 99 others); Sun, 7 Feb 2021 09:41:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhBGOlL (ORCPT ); Sun, 7 Feb 2021 09:41:11 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9466DC061793 for ; Sun, 7 Feb 2021 06:39:51 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id s77so11944926qke.4 for ; Sun, 07 Feb 2021 06:39:51 -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=qH6pF/G1SFg+K0bTJv0NKKhaRdQW632kFeXNuGpnkfE=; b=tK0RaRfltPOjC5dp1sHYm+mCxuY0YDjYZ6xk71WaUByyrhWJkhni3fjIOWgzPNwGIm Kjx+O+3rSilNy9OhM/DmTYZx/u7mkOwIkEVAyHkwTJzhH5xFJl53HXAdSEEMBZkfwQ9v 8rIqDKCdRS9j0tQWc48BmXN7gNBa6kR45kc9VAgYxAE5LFbBFusbHC4x17PSGK2s/qnq ngy3VQX+dYuCZ/8MP15Wz64Q/1j5JA8hGpEGuHQiFh6Mk26Zo1kqp62YbhHKNVGln0gv XD/utxdmryUpjmMmIK1I143ah6L59XvFux7JN6BbNEJI35q0eyo3rO2LGv5KY0rfJBhR FJ4A== 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=qH6pF/G1SFg+K0bTJv0NKKhaRdQW632kFeXNuGpnkfE=; b=hkjcpNlIuNOvB9lmur37frH+jwdlhS8wZ72IitfRtpxKuv7ViyPpcDTCvRobblWlWv 4E+hVtiW9cPnAFKmwLu3IKBno3Ebeake32HURuvcI5qqcgK+WhywUEwreYSTQWXkpgNu i/K236+JKH2scJuy7lSgS8JoDoA5DHrchxz7mxlRuAVSdDT74F0Ce93lZCWpwPXA0sTW HUj536XzqyF/Z2uiHd9picBDKPRu901LnjJbCoIZDEfHVTHv7kflgyjr9oCTwN9ny5xG nBckK0uJgdLHPV9VJowSrHf1Sw8vdqKxMYNOz9Ywf1F1tgRnVN9mo+gxwRnF1WXau4ZR oMDg== X-Gm-Message-State: AOAM5316AsrPI4cchDFHrpEbGLerBKh5nHyZumFwGdRxChLlFTJpKAox L8j1zAgXIYS2fQ7jEjlXu/ukVg== X-Received: by 2002:a37:418d:: with SMTP id o135mr12805811qka.426.1612708790818; Sun, 07 Feb 2021 06:39:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 06:39:50 -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 03/11] crypto: qce: skcipher: Return unsupported if key1 and key 2 are same for AES XTS algorithm Date: Sun, 7 Feb 2021 09:39:38 -0500 Message-Id: <20210207143946.2099859-4-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Crypto engine does not support key1 = key2 for AES XTS algorithm; the operation hangs the engines. Return -EINVAL in case key1 and key2 are the same. Signed-off-by: Thara Gopinath --- drivers/crypto/qce/skcipher.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/qce/skcipher.c b/drivers/crypto/qce/skcipher.c index a2d3da0ad95f..12955dcd53dd 100644 --- a/drivers/crypto/qce/skcipher.c +++ b/drivers/crypto/qce/skcipher.c @@ -167,16 +167,33 @@ static int qce_skcipher_setkey(struct crypto_skcipher *ablk, const u8 *key, struct crypto_tfm *tfm = crypto_skcipher_tfm(ablk); struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); unsigned long flags = to_cipher_tmpl(ablk)->alg_flags; + unsigned int __keylen; int ret; if (!key || !keylen) return -EINVAL; - switch (IS_XTS(flags) ? keylen >> 1 : keylen) { + /* + * AES XTS key1 = key2 not supported by crypto engine. + * Revisit to request a fallback cipher in this case. + */ + if (IS_XTS(flags)) { + __keylen = keylen >> 1; + if (!memcmp(key, key + __keylen, __keylen)) + return -ENOKEY; + } else { + __keylen = keylen; + } + + switch (__keylen) { case AES_KEYSIZE_128: case AES_KEYSIZE_256: memcpy(ctx->enc_key, key, keylen); break; + case AES_KEYSIZE_192: + break; + default: + return -EINVAL; } ret = crypto_skcipher_setkey(ctx->fallback, key, keylen); -- 2.25.1