From patchwork Sun Feb 7 14:39:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 378113 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp3953872jah; Sun, 7 Feb 2021 06:41:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQKv4+qYXePiivNwK2cbsIP3CV/qERpcDHbLbpXfrD6STbn1VU02npPBKEm5+jNoICMEde X-Received: by 2002:a17:906:a448:: with SMTP id cb8mr12750387ejb.174.1612708918499; Sun, 07 Feb 2021 06:41:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612708918; cv=none; d=google.com; s=arc-20160816; b=i4W36w4eOe12iwm1gBXw3nMlIPhGoVeaILeTqCXShUt+BEvUl1/OYWEwYSHUVSrWTO s5+da0gB0fGIDHizrbTZvYSOunbr/2TwQIBRAOGqNFy/GSuQGcQNvJYU4Sz+Rksm2ubI ZvvOqMRdDFtC9waV34sOTaOWkn42jfMavys6cdsZMU/WlmVLx3Xnc7mgeVHpSIg9o8Gu RP/bilY4Km3Kc0gEhu+5eBOZ8Zir5bjbwh1BewLxy1eaW+CuVGYIplEZ5BWQgz+VzIfY sZS3gckDfcSF1kswrQHJC2hDjXkY4qy5QxbChdQCLL7JNRaLt7640eQAsKteeHkoBJy5 oNWg== 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=S32eqA1vN/Vl5dBrhU4OJJBjkvmwmaSiyavgAPvk1RzmJMyTyad1P5De+t1ISpMi7R U34FwyOycvXX6bJCfwJrig6ZV29LA6XUF7TipM6fq4xq5dLdDcAje1JOoZraYwf+pP6d gNhASiMnLjy2yqTC1YfVuglnirmgz1GvK/8IiHRDgfmuVjxyi5sYRAFq3AeqggpqBNbG jrEh533TbJzZHE6nBsh/mVi3ZqxEMm9FWhTC3bY8ksMu68d/QNAWyOsFW81y6j77YNic 2GsEssU5oNws++cf9cl4dmjJLB807gAdI0Hiin5K6Ua4TK6QhsluZ043Dy3Cz/aeoBm3 KizQ== 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-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.58; Sun, 07 Feb 2021 06:41:58 -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=tK0RaRfl; 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 S229959AbhBGOlP (ORCPT + 2 others); Sun, 7 Feb 2021 09:41:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbhBGOlL (ORCPT ); Sun, 7 Feb 2021 09:41:11 -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 83D26C06178C for ; Sun, 7 Feb 2021 06:39:51 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id a12so11908821qkh.10 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=hk+1rELJynklNDTXAkrhEqQDP1yt6B8b+OGuayqc+FADKacce830/oe8Rzm2HZSumH 3vUOnyJSWyRNmtkFGvstsx4qWFUQv6Y2GwMe1zO2E5Gk26YPMkR9+JG/MW0qt+TFwgnx T+/IyPYpr+yD1gHdmVA/SkXYH2PlxziLVnZ+tv8O4FZZEnSH14Xk7VF0VIaiQmHhnzwk zEGRwxKk63mRKTp9ghsabr1s3SaOhlGST4fVM4TvWr3LkOJ80v3GBa5WJ4LDwyPzJhMJ ZPIbd7R9BIHXvGLG5ocvEVMnMBSAh4ZLf/Zvd3AuZfwLfhRsWYbFKfmKc/jMi27BGHBZ u54w== X-Gm-Message-State: AOAM531+6Oi0/3xJqOHP9ezTaqJN+qGzQJm4QSx2hoH5Ap5vB5qAwhKW nK8xJL6gkZfdUiz+4kFga/32NYzoMPpLCg== 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 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);