Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3087116ybd; Fri, 28 Jun 2019 02:37:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxA9kemITXfAWhp2QYkfXa+qkv2B269Da4rpClH569II6VP7D2yE6ESkwcBBKatiJSgs+pB X-Received: by 2002:a17:90a:360c:: with SMTP id s12mr12125891pjb.30.1561714643234; Fri, 28 Jun 2019 02:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561714643; cv=none; d=google.com; s=arc-20160816; b=RItTwMeMGGnHr0VEoUBkd0FCLTyg3gkGmn40TOKfnarnVsGnPXzrzh/CCnAfRl6icL YGHKcaMya3DeBxzT6kgkOyzlUGvtY9U68Shc/IVMiQXsx7TarMdTukVQMXJURzGNCO98 Eo1qHTRJK+ma4tZUc79FDzYLrOmcySmdVxzQTOk90pV5fYL6Z46N9M9tbUNl5Fe9M64z FJ/8DymFh/bUMrEHoZVrx2uxzGbvx1nRPf4auYX3szsr5i45OfcpS3q/He9+zcb2XMWR mNN557NKT35wtv8u+hUSXwC+fh9eG81qFMpKmhnCmkU3O/c1QDGdoh30pdmtMxOh4dF6 vQcg== 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=vwaL2yVe7/AKlyXh+T/GXc8ok7UKbj/+xTW1NBqnpb4=; b=tLwMekXhIDUwWlMncyIisSGH+Cp5mm3867ybPXOXASMtgiRDogQL3m/oy5b2KMK1hg dbMUz91qRqkCnAkP1psAoTQxOny4k/wERD9DhpO0iAniDttl2texMCMsNWnt6bFi+7y0 ZzMofeGLTI63ZBWKT+cdhOS7QGLcciSot3XzlOVNnACQ6+y5Byz/+Ty+PcmwkYkDMGV5 iDFP4EHx3CF8CjHtFrRAh0OqWcx84Rvd3Hx+XAU/bmMt7LBezDKzS7JsWF0H/O3c/LSZ dwUSV686y4kQ6r0QIzg4G7Y5lNbufNKLHA+XjFu7aXkkV+06t8l9FGK9a8zsBAl68lQi cSig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u0YiHDiQ; 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 2si1708351pla.22.2019.06.28.02.37.09; Fri, 28 Jun 2019 02:37:23 -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=u0YiHDiQ; 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 S1726702AbfF1JgE (ORCPT + 99 others); Fri, 28 Jun 2019 05:36:04 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37838 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726603AbfF1JgD (ORCPT ); Fri, 28 Jun 2019 05:36:03 -0400 Received: by mail-wm1-f67.google.com with SMTP id f17so8303872wme.2 for ; Fri, 28 Jun 2019 02:36:02 -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=vwaL2yVe7/AKlyXh+T/GXc8ok7UKbj/+xTW1NBqnpb4=; b=u0YiHDiQaaomNI6u1pcoD8swbgBPyeG6v1G34oq7OgmUZlCuiPro/PemYVF+Utpch3 nSREYEzQOTRdmYEWeZQPtYj1E8TccrqCQTX9kb6KGPcVZuTAEWlansinybtY6M7ORmPc BIH3CORthIIpx4pif9qHJHOwHgA0pK5QMfawy5+zaCAifQY3ykDPZBwyEvYjZ37kn/U5 Y8gMuW4OwcBYXU11T9P0l9llcLN3HEUarzAAHEvQ9QAqoA+pWFdWLA6GZIP8Zzsj4BBJ 9VYZuvGTWBTB+saiZ49w7eTJN+0DdolF0D9x4FYLDSOczLBMXcznCLIs8kIcb83pRqt+ kzkA== 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=vwaL2yVe7/AKlyXh+T/GXc8ok7UKbj/+xTW1NBqnpb4=; b=NyXlYe9XZFBy6c9DiEnz9dnm6b+aZaERdFyZk7vVlLQUHnV5RuXAgHulubEql+ZrIs Bsa2oMlN/HmVOfV0dumd+FYC78pqeQqTMOZS1SeXA0n60TKp6DcDwCi/YPofcCpkrjOK SuU4yxJX0MjM4eazjbLtvVOb1DkAsyjMDRzI0CO2pIAPAIErBSc2tLbTIkOwkdFAOgHR 9ylA3D/UVwmE10vXBuIcFz86rXMI7JurcEbvA66rFNWk7Ayucoc5i8js4tuq1w4zmyvg M+is6luoOg/YgNctM5q/7GZaqWaVbqBbc4v3ixa3pAO4oGAJ97NcItawz3SW4DogUGE2 vs+Q== X-Gm-Message-State: APjAAAWkkUFKByPrtPJMGndmfQGCkpeMEpPWb9onGETu+4hGlQGEdJ8+ bLFbzf3k0x3bcvmUT8Fv1kar7+CyXNdGiQ== X-Received: by 2002:a1c:a6d1:: with SMTP id p200mr6774382wme.169.1561714561074; Fri, 28 Jun 2019 02:36:01 -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.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 02:36:00 -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 21/30] crypto: stm32/des - switch to new verification routines Date: Fri, 28 Jun 2019 11:35:20 +0200 Message-Id: <20190628093529.12281-22-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/stm32/stm32-cryp.c | 30 ++++---------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index cddcc97875b2..377d7f9ad470 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include @@ -767,35 +767,15 @@ static int stm32_cryp_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; - - if (keylen != DES_KEY_SIZE) - return -EINVAL; - - if ((crypto_ablkcipher_get_flags(tfm) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) && - unlikely(!des_ekey(tmp, key))) { - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } - - return stm32_cryp_setkey(tfm, key, keylen); + return crypto_des_verify_key(crypto_ablkcipher_tfm(tfm), key) ?: + stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { - u32 flags; - int err; - - flags = crypto_ablkcipher_get_flags(tfm); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(tfm, flags); - return err; - } - - return stm32_cryp_setkey(tfm, key, keylen); + return crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(tfm), key) ?: + stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_aes_aead_setkey(struct crypto_aead *tfm, const u8 *key, -- 2.20.1