From patchwork Mon Aug 5 17:00:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 170601 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538551ile; Mon, 5 Aug 2019 10:02:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8GHnzwRARS9nOTntJZ8mLCZQQ44mPQ5ygvoi2CnuoZMb6sat5VIfLT49EH/ol2HBWDvn8 X-Received: by 2002:a63:6f8f:: with SMTP id k137mr83895139pgc.90.1565024543057; Mon, 05 Aug 2019 10:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024543; cv=none; d=google.com; s=arc-20160816; b=P2mvbjfPePnRl7zIdeuANNe+7RCKOEAxP3KgvCIB/dvd/cFoJ11y3rZXjHB+LI2RRA pVnfM0HbzkiPjUXTxsLe8nzhhUwejwO6L0JsKAVpO3YlDabeFlbh7fW1j2FZTUL3daob ui0O8hTE7/sR6xM7clY+2aqIxZ+Hu4ccxj74yvUprlJyDMvo/jzxEnzZyMDMbc5N/eMz hKP2d8kloRwiQRDcPDcDUx0b7jBYS/V9SBxnkRtXxwr+nQKSqsgcu3RasR/Azxy95A3Q YE/42Zvl7GxEFR2C24PInQUsCUGtUk4keiERfcyau/agHP2WMA5q4ORy2u6RZeY2uMAX 2UwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=uex6NH3fEHD2Fb4AO2tkVhWWyS7SvDedMCikId0x2XQ=; b=dsV3DqcPfCqSHtZFRY4k+wZmmMxuuBnr3zuTt3ksKb+m/0eZ2Zr94PfpSqexvmBs8s QK7Tz8Ep8bp9wrZWJiXnm0v3ObeH3z5MAp3eOFgwORlYvYCqIe3qsTU6YyMf3qERv4p8 uAnpn2NsrrUaJNu1g9gf0hessgxF4WXeXAXDG74qOCY1Ks+O19JICIUhiOZ8SkNndxcK 9ikKWPj/+CV4yQ7AUhd9AzR9pA0v8Z8iPYuWzAjOMZxlp4mP9lSMx3nyI0p3mPxLbTTs nWft3xueO7Zma4NDIzafo5oTnS4O/YAg/DdbiJS/bpZJLI6YJTjFlbqt/RAQbmY0+2Yq 9z/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dAejN+5s; 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 36si44243069pla.80.2019.08.05.10.02.22; Mon, 05 Aug 2019 10:02: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=dAejN+5s; 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 S1728870AbfHERCW (ORCPT + 3 others); Mon, 5 Aug 2019 13:02:22 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33725 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERCV (ORCPT ); Mon, 5 Aug 2019 13:02:21 -0400 Received: by mail-wr1-f65.google.com with SMTP id n9so85263784wru.0 for ; Mon, 05 Aug 2019 10:02:20 -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; bh=uex6NH3fEHD2Fb4AO2tkVhWWyS7SvDedMCikId0x2XQ=; b=dAejN+5sZrwEBwnrbyPfSWqjSePeLrWDFqTl+erYCwebfqu7XJcPIvc2K0oyjsG/wO HL4XfoXuwIKhGuV1snWU57SPMHU4uBeGuyzzDSFDVr/pm1oFx0dEAf0z6z1Cgv8vPBUh n0OY821IrmDfBp6Hy78sXmgeEtzah90DSuMBJG4CT1Cfi6AhIMx23YFQ/OyPAUaUudDO 5XR5HEv7uJGHeuWmR3MYN8bvlVEJPkcWABNCbj/FRjU4O8rDrNxfN14ApvuTq86M20IV rcPiBM93eo2kfJcpAyYpSxNh93oFUTJT6zWLRoXFwrfhxdtD4YsymK+GccKsm4L2jO96 p0pA== 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; bh=uex6NH3fEHD2Fb4AO2tkVhWWyS7SvDedMCikId0x2XQ=; b=iO2Q1k9Qn+4wjIRtm/FlewCguUiwZZwCERmq+/eeB9c/nh/iKonMtpwp8zGdyFU9p5 +vIa/6p5dhHzXtAIn5jqcaR4wBkZZW9vRyBRX/QvcIrsAz/C/HlpsFH18woLh7beBGUi IQCpyD0Qm9KV7Rly0BsKlMhKYYFHZvkfXBjWSSyj+ZicKvfSSF9tOsIzsQfYaHV5tK9t kw1uJzR/ieEnIGz4TMjH+zvCj5iE47fVhwx9ZPXFqa+MybID0KI0mfjl5j8qLuiBIYtE tAbiWUtKLnxikfXB87ovbzc68Uok+dn3SpG0IP82IHOC+mCJgHyi39C58C/m+GI5ef7v ghJA== X-Gm-Message-State: APjAAAUiPDTH55bSzYfF4XgkCWWZz+lpm2rdVtgFLBAMPcm6uRuFmXFQ o/0TloXYq8KVCecmeT+MgXLQ9J1ZkEUSFg== X-Received: by 2002:adf:8364:: with SMTP id 91mr161962985wrd.13.1565024539552; Mon, 05 Aug 2019 10:02:19 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:a407:da00:582f:8334:9cd9:7241]) by smtp.gmail.com with ESMTPSA id j9sm95669383wrn.81.2019.08.05.10.02.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 10:02:18 -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 v4 25/30] crypto: 3des - move verification out of exported routine Date: Mon, 5 Aug 2019 20:00:32 +0300 Message-Id: <20190805170037.31330-26-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805170037.31330-1-ard.biesheuvel@linaro.org> References: <20190805170037.31330-1-ard.biesheuvel@linaro.org> 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(-) -- 2.17.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index 968386c21ef4..ec608babc22b 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -348,6 +348,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 c4d8ecda4ddf..2a4484c8803c 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -846,10 +846,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); @@ -862,8 +858,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); }