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: 11019551 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F8C71708 for ; Thu, 27 Jun 2019 12:03:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2221528ABA for ; Thu, 27 Jun 2019 12:03:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16BB728AF3; Thu, 27 Jun 2019 12:03:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB3D728ABF for ; Thu, 27 Jun 2019 12:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726903AbfF0MDz (ORCPT ); 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-Google-Smtp-Source: APXvYqzDXc17EQgabDax6tyf7t3yds2Z0DRKE2Sc4ynz9qHgAODldlz5X1tUIBlJobveFV/bje0BEg== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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..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); }