Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp328069pxb; Wed, 3 Feb 2021 06:37:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUAVAmwE9lv6q0Ti/JrokhDGbgj9Pu0bmojpqAzDUktGk9Q8bfG1QE/mORWSqSJE2ZR4TP X-Received: by 2002:a50:cd8c:: with SMTP id p12mr3273086edi.114.1612363071587; Wed, 03 Feb 2021 06:37:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612363071; cv=none; d=google.com; s=arc-20160816; b=BsLv0wUBYwicDTnVB/ps59SUQ3hvulSINgu+bDh+7oY/abz8iSCdBsMighz9rZyZbX gFISIzkgTX+I6PfbGR9DCQ6LeiJeCrAvKtArNovTuXEGw8dBta5Pw6+Nr2/fAgtz+SMJ TvvCAFbvMe7vGT/aCSWHuZOZVORhu0xKV9iNDL56m/G4OqIXeEkVvAIp9IJjBZ/2XsAp clA9LBxh0ek8YV7UVRBAdPsg3bvi5wIivBJmo1kLk/LeF+b4BIK3e4GQPwzqA6wlN4kN GC+JKP4MbP8Ip+0kiBh/QP1JuHB2/nV9eNwSOSCQC8KE+Vk+ORyOcli6G0YRJ0Vl/xei xB1w== 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=qAEMuSuTweSpBoh1Kn21LueYeOxUmFO1NBvTGd43Vu3QWbw+xoeaXdBk/f9jZzXeS+ sTegOMLYBxjWbllD8yhYt/jaff0c9LBpd4Ah7tdzg+Q/3doK+/DDyjL0UyIzOk2SBssQ RNPEoP41HfLOuogOD0PzDfLbx3w4sWYOg8R4HpjIAvCpuLM7wGkDZ3c2iDd2ec1yyIcQ 61tTlTNCGEZT/h81tO2cpjegshkxju8qpvn18Rzq6hu3MLHug/r1q5zHsxmK5gVpNa1P salsbUqfh/bOrIdhLX1RZCO6AWJ37ypSC6Jmvlve+wtz5+/FNSBeDmuVRNY76A6mc8Ac 8qCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aFhCdAPN; 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 p1si1263508edm.218.2021.02.03.06.37.21; Wed, 03 Feb 2021 06:37: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=aFhCdAPN; 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 S232941AbhBCOef (ORCPT + 99 others); Wed, 3 Feb 2021 09:34:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232853AbhBCOeb (ORCPT ); Wed, 3 Feb 2021 09:34:31 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22C5EC06178C for ; Wed, 3 Feb 2021 06:33:13 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id v126so23463774qkd.11 for ; Wed, 03 Feb 2021 06:33:13 -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=aFhCdAPN/YL22McZM81VXUVWm6cZq+icW7D7mDIbkcCakVss0d3fBGjUiPMOZP5b/G 1Ikg4/W7bCqt57vQncxOSgchloc7P/uIr+KMadW4jPQaylWz80EyIAgysn4KTB6wfqfJ X5HRK1chHI20yvfOlBqmlz05ztOV+9zVoBaRLu7KMGCP+gwk+nF4FFCne+4wBQh0omJn /dWnDpZABhLyo8WafKD9Egv7Fr44A0QR0nKT9rebhqogKSL9kNhs7HBBKRXZs0SIE7kt 2GIwTHrcTpkeB6kiIJtO2tbLVWtBkrzpExUItfHG9i1RGmZ4R8zGJqYYZCXoO4HG1AoM IqHg== 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=FctgjeKDKu1BRoIJoYOXVhTeAldoA3a49+4KcMaAVpx1WCfr8dsAHDEz1CKUJLPVOE 8Z1r8C5E8DngdTDz6iwpkWSlqcaqBPHh2whEc7uaqdAW1brX31tOyK8fkZPhIdN5HwrY VQ+DteCR2HCMlP97+G8BQ0n93+tIQnys3Ach+35q2ir1CkLCYOYqDGBCkGLfnVB0OA8T smo0CZfD2jX4celHnYmHeMYjNwOZMP9CpeMLnPq5i0o9AYYu6cPUXrOpTrOFHXHwgF2t WBXKgoF4VYP2uzGw5oimQqN5go5cOgdUX+HRMP42MSni/qJ+fsWZwbJ1n6AW5yrjRmL3 i5lA== X-Gm-Message-State: AOAM533PflxDCV/wySHYohSX+hvqCBNZCNPDvmAiDnCPxy50YKAQg6lX 5Y5tZWxkSLk7OwJNqIHBhWhaCw== X-Received: by 2002:a37:2e87:: with SMTP id u129mr2754756qkh.344.1612362792387; Wed, 03 Feb 2021 06:33:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 06:33:11 -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 03/11] crypto: qce: skcipher: Return unsupported if key1 and key 2 are same for AES XTS algorithm Date: Wed, 3 Feb 2021 09:32:59 -0500 Message-Id: <20210203143307.1351563-4-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 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