Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3086709ybd; Fri, 28 Jun 2019 02:36:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxB0udqD2ak3yqdbE5V5RUHQcL175eDet/pOT6+UB7gxykcg1cdr9FvoJPzOtIUponsyhUr X-Received: by 2002:a17:90a:d681:: with SMTP id x1mr11688944pju.13.1561714616983; Fri, 28 Jun 2019 02:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561714616; cv=none; d=google.com; s=arc-20160816; b=Kdi7TryNxE3E//kQJPgKNldZSckjrs4plfDL5trmGYl7YLpl4WPMiCuHQzxP9L1tBA /cCqjOeuRT4V+Atdx2eYUpO4hOOa5AfkfUqbmKJD4jUE/Li1hmhxXnXk4dQBYYIhEjri yjRbM1To4Dkbl/m3E7NJAOAJx/UnFFaZSuIGCmo6jPYBaD0k4Xqjg+5aHwJ01/FUTwTu tJYtaPsTULRiJZcKvvko77uLanOUebkzEcXwP6evOoqCJmsEHG8H08GpJ+H6ejH4X4Qh 6wxFhF73CDkQ8iQ8I5J2p6UXW247KXsy1xCEkLlHuH6f2C59ht5ojSHjFmwLz9Gr9eMR B5mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K222XYBP17tSu5k19NnMFnfodyv8IVdo2b46vWib5MQ=; b=gJ97U2tniqDYQdYSDxxl701dqwI7SdQ8LLQjLwk0xmvfbB+w9YTQcAk0qcki37QpV5 WhMP9Sq3ChR1SZt+124jKBext6M6eeuqW5BL4k4YAQgp48hFsFKntnFra6O0X8Qc+EOd YUnbKpS8qTPspjh8BZbPeiNsFQ46OqsxiAvjAhLXr/iyv5A5dV4d202Oi/qE/BCbD6k0 WPD9tChRzpsZwOaqX/QJ64/cEU5DhEYnaWebAZHUJcDxmNULVt9bXhBEd7crBPiS5W58 XxLgl40N/8Zp6xHgN6FqF6jJt+PCseTa4fBUKItyh80/93JjgfxU9SFJtHkqIxARrhDX ci6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cX4JGEFX; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id g8si1678852plt.273.2019.06.28.02.36.43; Fri, 28 Jun 2019 02:36:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cX4JGEFX; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 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 S1726603AbfF1JgE (ORCPT + 99 others); Fri, 28 Jun 2019 05:36:04 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35557 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbfF1JgB (ORCPT ); Fri, 28 Jun 2019 05:36:01 -0400 Received: by mail-wm1-f67.google.com with SMTP id c6so8334933wml.0 for ; Fri, 28 Jun 2019 02:35:59 -0700 (PDT) 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=K222XYBP17tSu5k19NnMFnfodyv8IVdo2b46vWib5MQ=; b=cX4JGEFXO5VmJM2e5FpHXtbXwUVXAEsK/csLWR+EqZoubHgnfh7BAMiw7xAOU54xj3 abheNFTjuHtphO6hpRH+XLstLP0MWJlS2DwliWghS+beVeH6pNwtT44wragY4VqlK4aL wA0Wh2WojWF/C3Q9bKrP3lDz3x/IPMc7o2lcXlxMGnOaxKY+HKiSqIYSifzmFOyUekES O8+LwTu+DB+2M5U7PDoPiV4YZxrz+OLVyaYcH2KZGk8w2JgTPyx63wme7eZ4DmJ/R6kQ gD6H6ulB7A+kFc++VxdMqtR3UjXVWt5hi1VNeknvzKAcaehWAXtLmhRNW9z802yK+6hC DiEg== 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=K222XYBP17tSu5k19NnMFnfodyv8IVdo2b46vWib5MQ=; b=si5MWVNu7RIYigFEKJAamn/CwJshti1wuG5JJIlc+W6IQacQbeou48vKGaJylVPfAM Kb8GJcvvr53gyVUaHDoyT1BU52iPVDRodKaXj3s2zOdobuRskj7EnVl6mJYcnsW1XzTR QXefxqSTDB3jmoo1rY5/XayDCiSa0YnEQj1txWyvnTu0oZQeF8pcg0XjH0OJj0JWFDD5 Mtg3QAbmPa7UxDImluez7PoiGKeRoo9gT1Kq8osCT44cUp18i9Xs+/vtipVTnD2ILSHN IMOPEzyz0oB2o986wMTPm4R9KVSE2uip7hqcFONJ8RyiKvLIYWjSJztFPm+jv+5qY6Dl OwFA== X-Gm-Message-State: APjAAAU09onZaYFToo1/+YLPvxGNAYD/wvtsWhWNj5dD9Uob2OImI4ZU 5qsoOJk5XZg9yLKuYWizNFR2r5I7aN9AuA== X-Received: by 2002:a1c:a654:: with SMTP id p81mr6210556wme.36.1561714558596; Fri, 28 Jun 2019 02:35:58 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id m24sm1709910wmi.39.2019.06.28.02.35.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 02:35:58 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@kernel.org, horia.geanta@nxp.com, Ard Biesheuvel Subject: [PATCH v3 19/30] crypto: qce/des - switch to new verification routines Date: Fri, 28 Jun 2019 11:35:18 +0200 Message-Id: <20190628093529.12281-20-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190628093529.12281-1-ard.biesheuvel@linaro.org> References: <20190628093529.12281-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Signed-off-by: Ard Biesheuvel --- drivers/crypto/qce/ablkcipher.c | 55 ++++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/crypto/qce/ablkcipher.c b/drivers/crypto/qce/ablkcipher.c index 8d3493855a70..d9e067885a0e 100644 --- a/drivers/crypto/qce/ablkcipher.c +++ b/drivers/crypto/qce/ablkcipher.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include "cipher.h" @@ -162,27 +162,17 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, { struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); - unsigned long flags = to_cipher_tmpl(tfm)->alg_flags; int ret; if (!key || !keylen) return -EINVAL; - if (IS_AES(flags)) { - switch (keylen) { - case AES_KEYSIZE_128: - case AES_KEYSIZE_256: - break; - default: - goto fallback; - } - } else if (IS_DES(flags)) { - u32 tmp[DES_EXPKEY_WORDS]; - - ret = des_ekey(tmp, key); - if (!ret && (crypto_ablkcipher_get_flags(ablk) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) - goto weakkey; + switch (keylen) { + case AES_KEYSIZE_128: + case AES_KEYSIZE_256: + break; + default: + goto fallback; } ctx->enc_keylen = keylen; @@ -193,24 +183,32 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, if (!ret) ctx->enc_keylen = keylen; return ret; -weakkey: - crypto_ablkcipher_set_flags(ablk, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; +} + +static int qce_des_setkey(struct crypto_ablkcipher *ablk, const u8 *key, + unsigned int keylen) +{ + struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); + int err; + + err = crypto_des_verify_key(crypto_ablkcipher_tfm(ablk), key); + if (err) + return err; + + ctx->enc_keylen = keylen; + memcpy(ctx->enc_key, key, keylen); + return 0; } static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, unsigned int keylen) { struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); - u32 flags; int err; - flags = crypto_ablkcipher_get_flags(ablk); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(ablk, flags); + err = crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(ablk), key); + if (err) return err; - } ctx->enc_keylen = keylen; memcpy(ctx->enc_key, key, keylen); @@ -382,8 +380,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def, alg->cra_ablkcipher.ivsize = def->ivsize; alg->cra_ablkcipher.min_keysize = def->min_keysize; alg->cra_ablkcipher.max_keysize = def->max_keysize; - alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? - qce_des3_setkey : qce_ablkcipher_setkey; + alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? qce_des3_setkey : + IS_DES(def->flags) ? qce_des_setkey : + qce_ablkcipher_setkey; alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; -- 2.20.1