Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3086700ybd; Fri, 28 Jun 2019 02:36:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxz/RK2IU6+eBql3ngkh/e0jq6XvhFAMjgF+AHjOmmA7+MSCHmdTRyzSX84xWN6SZuMADJ0 X-Received: by 2002:a17:90a:214f:: with SMTP id a73mr11819277pje.21.1561714616824; 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=h3hDzAWAtbbFDe5cXjZF8xUbAJXqv63PjTp1oDcOzWgIVii6boub2EiuHrbpTjIWDu VzMZhunauwQeIsvkVxEhS/V3fxrlp7OEhFFCXkIupSToPTbkEQNgUR0RsNoJ1OY/2JNQ 7xXVG2R5QR9rN8kceNTx5HfE8td49z6G+8A6rPZioQHirA6zY7rnbsDrCjXo0XOK46L1 VSJ7bKPerdxlRPvaV58RE65CRJyDrPg7vND9lfuSY5LVus26VHfE/+f1YVunAxOVeD7s LXE2Ewood3YJ7bOA4vqrKkLXgebMWIguyZ8A2MSaAApedFqgSUqD0fQTatjevuykFb/W lwGA== 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=mVr3GoJIY9k3V5AjmsEshtajgyAmfjEoLBpibvf8QC0=; b=bFhAMwpWSdcBF9Y+oeyOHWallR5/Miw6JzYlV9ZGnY/RHRBox5/al6BQmvRTDquV0u ggs4bnWFMWVbTu87+8RKGAvFPcQfLbm1pe/WdpVBVC4m50XXRs13Tn3uV31+MXozvIwi B4J8+ydvrDlTNp8x1Quog9lLC3/fGotUV7DjnrLQs8bR/thRaqmau7YbVgi5gXgj8bag WpEl/2vfLpGfa9gmF+8gHCd4R0swdj+BdRm8E/omcYvGPpGQUkGNUUXrK6KOvb9wmH02 jH8+VDHQH7sbpbYA10HQLn3sTJIfvH6pVHQ7yXToAni3+Vxg5G6jW2UzpEni741kJSKf dcyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sAcWFWKu; 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 b14si1582414pgi.434.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=sAcWFWKu; 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 S1726750AbfF1JgH (ORCPT + 99 others); Fri, 28 Jun 2019 05:36:07 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38542 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbfF1JgH (ORCPT ); Fri, 28 Jun 2019 05:36:07 -0400 Received: by mail-wr1-f65.google.com with SMTP id d18so5547289wrs.5 for ; Fri, 28 Jun 2019 02:36:06 -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=mVr3GoJIY9k3V5AjmsEshtajgyAmfjEoLBpibvf8QC0=; b=sAcWFWKuJ7fXkTu+ReSdp0tphDtZM/xbQcgp7XxytaBrAIcivRRo/7vb2svQiAWKjC CEZZ2sB9OhDSbTvMu7nodVbcD3QcqwFLSc4tuX810t3+7dCHyaqiSpP0lOeaH2o+8spW /3/C9nTXaWWsjr40hx/f4CfQ9eM6zLke8QsO2fF/N6RugZe2g/RKgBRUtNY2s/ZAzP8m qzEusQI0dGDS36Zn0i/EXOD30GSDfHf4YV40Sj1053Xc66X+zP85G6TaTtncIIjD0zhp wvFb9CgWk0fpia22L+4/dSEqJsEqgsqta+XEuQhTDTqw53nlMMbht5REGgrmfi44D/RU XehA== 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=mVr3GoJIY9k3V5AjmsEshtajgyAmfjEoLBpibvf8QC0=; b=bCzTS6le9vQ5nXzJFlBvYWnxbGYjcvVgUsXbrCiPIM187S+aOu5P48msyty/vl7fTT LfJmq9fHbG0i3RIqXmDsevOVn3JrlWFRikex981SITSEDd+9Hh8mN9WlKkhrZvzagolJ /OGOppvEZU91F70BrIMqM6tioSIZWm6lszquhwAWzIb31GJzwy3Ow3Vn6M6ypdxCfNB5 bL6Qi2ZOdG4zg0E7yufcMn6UeGDBzz/in/jNRfWolNvUBW3yGtAne9/UTy0c6pWwxDPj XADFMEuuTE5Es8zygwMYM+8hsr6v+k5D5lJPQ3TNfipNv2oZD3KPrhjvUzzb2zZr2/B7 E+jw== X-Gm-Message-State: APjAAAVpegwAnyCoCc/fgtaFZGBrsTfWN7OUrLk9gmPoylc7bFF3xJoS PmiZ25NNnk/m0C/ssg/azt8baXvUypMnHg== X-Received: by 2002:adf:ea8b:: with SMTP id s11mr598774wrm.100.1561714565259; Fri, 28 Jun 2019 02:36:05 -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.36.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 02:36:04 -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 25/30] crypto: 3des - move verification out of exported routine Date: Fri, 28 Jun 2019 11:35:24 +0200 Message-Id: <20190628093529.12281-26-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 In preparation of moving the shared key expansion routine into the DES library, move the verification done by __des3_ede_setkey() into its callers. Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/des3_ede_glue.c | 4 ++++ crypto/des_generic.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index 5c610d4ef9fc..0a7da05994df 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -358,6 +358,10 @@ static int des3_ede_x86_setkey(struct crypto_tfm *tfm, const u8 *key, u32 i, j, tmp; int err; + err = crypto_des3_ede_verify_key(tfm, key); + if (err) + return err; + /* Generate encryption context using generic implementation. */ err = __des3_ede_setkey(ctx->enc_expkey, &tfm->crt_flags, key, keylen); if (err < 0) diff --git a/crypto/des_generic.c b/crypto/des_generic.c index c94a303da4dd..271cc689c0cc 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -851,10 +851,6 @@ int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, { int err; - err = __des3_verify_key(flags, key); - if (unlikely(err)) - return err; - des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; des_ekey(expkey, key); @@ -867,8 +863,12 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; u32 *expkey = dctx->expkey; + int err; + + err = crypto_des3_ede_verify_key(crypto_skcipher_tfm(skcipher), key); + if (err) + return err; return __des3_ede_setkey(expkey, flags, key, keylen); } -- 2.20.1