From patchwork Wed Feb 3 14:32:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 375416 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp388964jah; Wed, 3 Feb 2021 06:35:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxRlw8EeC7+4aZ9Snu0nmbzuRfbqfHNwAMsTvkZHvN9SGYLXpbQzagm7ZFlwvWB7OAQvZg X-Received: by 2002:a17:907:7785:: with SMTP id ky5mr3568738ejc.176.1612362920106; 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=DCBvHweEbZsdS6jid8tSXyCw6zgep+TvZiYgSAS79+cfY/kN1EyL+YFszZGYRwd5Sx +UmIuJDTaxQrDYA1ISawzp6/CoOC+2ieORHsP9EOg+QnoYufB5zBYW7GzFnCeboBl+h2 SaDrIwR+pBIFsybvMaGB3+O+HYAidBYLq7XykT9Bvjdo3FwvFTa5m/MG/j+It3hJoR9K LNuzW3lVy9uKUaQgMUx+KpONIs6Q8r7QyT9c1BsED4Zd6+Dq5LnUuC9NuCI9MlCge5iC XCaLKg5uYYnmaiYsXax1SksgC5FIdF4ifFpBqJRlU28MLxVonaE3lX1R21RpN0oH5IV2 ZWhw== 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=iT1RH/DMaFNlCaUat/QGQx2Cj9iSd7GRWeSBqB4Ro69HeHHAiMAeSXySleIgOWYHQW I3k3ApxbWk016lyoagZ8Yfwx2FORYUQZ8sX2XtVOI8ths5oWEl5JoRgX6tHOxjhRlny2 t04sbBav2F2eHJxYO5h0PUlrt1FZvXhm8DWVWcW9psF01XtXKxi3g/6s9emx++7XrSyT zk1wBmR3OHRKySRTVP0UiwZxVzLXlPz4stmhN+Jlc+vNy6VCzoXjHNrfvzINMi995daP mbrodinf8nMwSMkgLJijla3FCG7lQHpgOcJAdJ2CZ7yxod15g4/LUS3T41wS3oUtTVDS AupA== 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-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.19; 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=aFhCdAPN; 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 S232934AbhBCOee (ORCPT + 2 others); Wed, 3 Feb 2021 09:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232848AbhBCOeb (ORCPT ); Wed, 3 Feb 2021 09:34:31 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2275CC06178B for ; Wed, 3 Feb 2021 06:33:13 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id a19so23535452qka.2 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=epbMXBai0pZYHEGMEIG223d2uK2pjMvVaRqIGAeg0ZS3/wsRo2q/qAPUd2yT1DpHZh xCJ4sYHtILYmmdbX2XZ+Rwrl3jvtkdyg5sJ7smO+Bs3+0GBWnZ7YA1l7hqSlzqYbBC18 7oa41RZoP5le+Tk3KgQ5zP1mCGD7RNwsOd9VBmqUHTuKHeuLeYVjEmJC1L2B6B8pGQCS 33/19bDHK5BrcejLU1Zhp/tE6nLpncdMToP/YCYtgxOp0S4HkedNM4WCHd0n44JrstVy Fte6qukFPni1LUCBouaEnt8PEU66ZWwYLyFjLICeY6PVO248WcrtHKwAweHllzvsLk8W d++g== X-Gm-Message-State: AOAM533AtI87chiQLJ1FKGBr4gckMpuakpPgjfC7u0HQW3D+afapndSL nI2wTMYZA2KEQiQPgt730wCZMw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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(-) -- 2.25.1 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);