From patchwork Thu Jun 27 12:03:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167962 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2252615ilk; Thu, 27 Jun 2019 05:05:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9wO5GOXd92vuQPMhgz23RLp5aAeMj0B1kOiAQDIj8SWg45CxkTfYi3DtCZWd5513cVMJZ X-Received: by 2002:a17:90a:9281:: with SMTP id n1mr5482875pjo.25.1561637037838; Thu, 27 Jun 2019 05:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561637037; cv=none; d=google.com; s=arc-20160816; b=y3XxPNkK9BPJauoKCTQ4A3+V12cdwyCIvuT3cR/h1rEWsMByQPI8LGr9wCLHQyFBa7 XDBnVLlBTo3kFTnJdpiST1mnItFyEqSfsUYY9hz0TJYksIZOUdSh8QVSlyt7R9w5Zke9 zkHGY3ETKBZharYvsomL2hPYQhcKXOiyBzohOtGAPGRC46IP1g+rQ6bqbByw178ZPWGU 2C2IYpOUXCFAS7XgNC8fJA6LXOG9bqtK2KGYVPjGxfyYnH0P3mtNaahy25mqMDcDDq9P VXXJn0ztKovKlArKfBMcL9i+yf+XHo1p1dtOV26PlFjd1ltx/rRL4DZBRdeYL2zMhFZ3 Kyaw== 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=2ioky3fpyGzGrutebcm9SiIqrDnulKn3sb2MnhR7QvI=; b=Uno5KO7JXseVa5C/upaX/mc70yiFdy/DAaiY61x8wapw4jmwc6JSHgGp/OGMnOXj4V cABZZy7K/1GIUHCH0scyGpF2Xw0Mdw8wDBCseA/RxlnZhM8p533atnKOBDDaU6oXzXT8 I9ZR1CjgTQu0GRSyF7jzBTwJaXjzimjd3R1oZNyODBIALgZ1PqgTwjTAhzK//nDQ0jjG loETHONQGQ1N+YcFiPjJuVrAaQvaG+EvrDRMtUhpjYiE1x39z20zhlvxLg1QAcO6Nq9x AgSLXmkztrl0AOxe5xi+7MtNdRNw+NSd+ZF4lkP91OBYxKPJIT2f22SiYYqjUufQEqLI NkWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gaJMvy1d; 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 f72si2632585pfa.67.2019.06.27.05.03.57; Thu, 27 Jun 2019 05:03:57 -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=gaJMvy1d; 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 S1726903AbfF0MDz (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:55 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34778 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbfF0MDz (ORCPT ); Thu, 27 Jun 2019 08:03:55 -0400 Received: by mail-wr1-f67.google.com with SMTP id k11so2280267wrl.1 for ; Thu, 27 Jun 2019 05:03:54 -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=2ioky3fpyGzGrutebcm9SiIqrDnulKn3sb2MnhR7QvI=; b=gaJMvy1d4pog6kqA8ImpHgejwkmq3ZUKh0j2/sL895rzLUP+msW5h2AnsZUJ5R5H6z KqtLkBmOnFRp/PwIv2Nhbk21QgeRtZeB2fn9mje9RANOXsjwk/f84SDiwCHyu1TDpyte ICZ3f2vIh6+Bxo+ch+iYToDomYOfiqsB6yry9TeJU56nZE4yTo+yR6DY/ZdH+RPyAFFC 8wK2GwfiXlAVAyLlfEhBs7DfjweRnqq+ZgzAB/6QF8ge6/TyL+2K8XbOGswZ9velF/u2 LWPT/8uv8EIn/PxkVMYkUahZ7lZ5b20a/U8vvIkZdpGN4daZdaobbICUvCO4/nsyvtwf NCbQ== 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=2ioky3fpyGzGrutebcm9SiIqrDnulKn3sb2MnhR7QvI=; b=YwqWkVfFolgvtLN4HBUnCMt/qIMJ2xcfEnvPLMi7L+BJvdkf8qpd6C2ZI//CxtorSH Y8TK3ACJLCor65BPyGrTirQU8mxycYqA7OTdZ36PH1IYBGM6nMvyEM1bvbdVNGXPCj5r Uj8azUDGn2vTwQGTflcEWWGgd1AQ1+IdQdw/FduHqytpOqT/BfofQRIo1qKu9oeZWVu5 uG5uNS72EOyQmQmPyX88PsH5ezppJS5NlX+UCDJ7zy1wuNo30HWk0jO2nouPYp1lIBog R7NCk+2JbvPkS1SgWjESsLp3uvIg/TYvBFhIDDSdn93cuNe8yzFwO/Mk3ikWN1jLa1Yo 3KFQ== X-Gm-Message-State: APjAAAWStMuLv2jZzvMs00cf6DSLqHXMOv9/6DI48jMRntd5OfwbeACe UCbpwwZt8wJfVtUoCcVDds9Dwel/Hia3Jg== X-Received: by 2002:a5d:56cb:: with SMTP id m11mr2986899wrw.255.1561637033424; Thu, 27 Jun 2019 05:03:53 -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 z126sm7732431wmb.32.2019.06.27.05.03.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:52 -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 v2 25/30] crypto: 3des - move verification out of exported routine Date: Thu, 27 Jun 2019 14:03:09 +0200 Message-Id: <20190627120314.7197-26-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190627120314.7197-1-ard.biesheuvel@linaro.org> References: <20190627120314.7197-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 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.20.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index 5c610d4ef9fc..df1b81f06764 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 (unlikely(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..ce482fb5abee 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 (unlikely(err)) + return err; return __des3_ede_setkey(expkey, flags, key, keylen); }