From patchwork Thu Aug 15 09:00:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171414 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918222ily; Thu, 15 Aug 2019 02:01:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5SmEZ/aAX/zvUPhI42mTvZCU+CiSZQV6M+jsuYZcSTpy+2ZNrcyCVdU+AsZqY8b0BHCpS X-Received: by 2002:aa7:81d4:: with SMTP id c20mr4343266pfn.235.1565859712190; Thu, 15 Aug 2019 02:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859712; cv=none; d=google.com; s=arc-20160816; b=EmHZAF+jz5lVc9+na/ziLGdtHO7D/fHXDv0uTGMFYGAPBx1lHAjECguugepfUf53wS 2Q9fM2jqzJCfBnnCOnoy3U6lRVzfiSUBxCeWt3ST5SrZN1b1/0WLMIGpqVyGWlagMvP+ D1BEjqGiF/Njt12mc4fc31U0ZCKIgdqPuZrNbqz8xXiGtse9XRV+x41ySD0lo1dX8XFc 0GyqEU2uBpziOdmBuzRWOrFZ4rOc4eAM22msS9zSwYuriyOPUX+Y5tANYNUprEW5GIfS ZG6kvKEK768faJqu3sVAJ7fWkGvUDF4zRz9KzhX6oBDpMfC6jua9jo7qUfygOh7TB+L3 KdNA== 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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=UeCWijh6nivmf+cdScOxMyqZ5BlENfmYzLHGvtX1CY2c53L+dTKXRw80K0W35ZAKMn SSGHR6Q0fh6RjfEXq9qYCO1mOR+6e+pgK/RwHzq4I/oTXkaGw0APonIvUHRud47HQ+6d YkSa56R8R3fwHKgtMGp7Be2AAgHtW/tUHGlSX4x49H6mAaiP4EC7Mw2fzz7BEFzYD6Zb cvpD8cFXfznFf/Nh8qKIOhqV/2QGqojl/AD36vJLffQfux9NlXfTY8tShiu2rOlICVGs hZLHpNx6+GXSqlDwz6MDFQ2MvBGYDLFJVjcj00Czuuh3EJ21VTKY4SsCAYlnFyFeb14C H6vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r5tONMdJ; 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 g5si1559088plt.271.2019.08.15.02.01.51; Thu, 15 Aug 2019 02:01:52 -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=r5tONMdJ; 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 S1730798AbfHOJBv (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:51 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40060 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730793AbfHOJBv (ORCPT ); Thu, 15 Aug 2019 05:01:51 -0400 Received: by mail-wm1-f66.google.com with SMTP id v19so674327wmj.5 for ; Thu, 15 Aug 2019 02:01:49 -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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=r5tONMdJ0NxxlvsctrofXLbL0C4JjABzo02ffFe+aDQ/6b1crHkcbt5r+vgPoVIYv9 O8v0i//+SXVjgwBrX94dNLYvXlnlfdjpeVRGLxFOGtmy+WK937HWR4glJhYX2nrGtga1 T/vAnfKuO142T0CXMVPRJOui+PtjmYcu56b+HpkyFjcfQCaji+1p0kpus2WApT7dMQV6 vDmqwnwfc6TFZRqe8Upl7aDtua53zfgO5Luh05KKAPHXL3u66pk55poIkFtXwy4CpmbH nL085NI7y7kiCM4lZiJdX4GAawOKd81/eJW0OM+IB4BRNJVOEnPxGfV4ekbrXoq+fXSK iWMg== 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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=ryU4N1e9LZpqocvrADxT986gb5VNUr1WSR1aoBGq4/JQ8+7bcNpcOMHCgoE1xbZmjW MzbbbCq/TV6ZRlmVDSKwFi0O0u/yuuipoYNpSVpEvCpQXgpsnWP3rO8yRolSezkDWqlh 9h+/bKSbWYqGQHnBum/AnKOghNHx4+yOZdi+theRXmZRqjl3erlpXlRxTjhwmFHgv9i+ OVkaycfHTmdqQ712hJ3B16vfJKmfyv6g10VToKKB7uaECSHBjvw2cjGvf0WPEgaSnWoP I6UvdUZGVY57bLvfCZemPHN288gEVO85KJl2Dvhw1yVuvVTYThsvaOaWPXzceFuTKfmV qeOw== X-Gm-Message-State: APjAAAXiMnMHseqQD+S96xPF6nnUQ9jkhO0OgWi7XULkiOatpvXS4u0S bxO/e63V701mztFpPIOP34xuUgqCH+H0i4f6 X-Received: by 2002:a1c:b146:: with SMTP id a67mr1688118wmf.124.1565859708821; Thu, 15 Aug 2019 02:01:48 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:a407:da00:f1b5:e68c:5f7f:79e7]) by smtp.gmail.com with ESMTPSA id x20sm3857533wrg.10.2019.08.15.02.01.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:47 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 14/30] crypto: ixp4xx/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:56 +0300 Message-Id: <20190815090112.9377-15-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190815090112.9377-1-ard.biesheuvel@linaro.org> References: <20190815090112.9377-1-ard.biesheuvel@linaro.org> 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/ixp4xx_crypto.c | 27 +++++--------------- 1 file changed, 6 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c index acedafe3fa98..f3c81bdffaf0 100644 --- a/drivers/crypto/ixp4xx_crypto.c +++ b/drivers/crypto/ixp4xx_crypto.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -756,10 +756,7 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt, } cipher_cfg |= keylen_cfg; } else { - u32 tmp[DES_EXPKEY_WORDS]; - if (des_ekey(tmp, key) == 0) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - } + crypto_des_verify_key(tfm, key, key_len); } /* write cfg word to cryptinfo */ *(u32*)cinfo = cpu_to_be32(cipher_cfg); @@ -851,14 +848,8 @@ static int ablk_setkey(struct crypto_ablkcipher *tfm, const u8 *key, static int ablk_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int key_len) { - u32 flags = crypto_ablkcipher_get_flags(tfm); - int err; - - err = __des3_verify_key(&flags, key); - if (unlikely(err)) - crypto_ablkcipher_set_flags(tfm, flags); - - return ablk_setkey(tfm, key, key_len); + return verify_ablkcipher_des3_key(tfm, key) ?: + ablk_setkey(tfm, key, key_len); } static int ablk_rfc3686_setkey(struct crypto_ablkcipher *tfm, const u8 *key, @@ -1181,7 +1172,6 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { struct ixp_ctx *ctx = crypto_aead_ctx(tfm); - u32 flags = CRYPTO_TFM_RES_BAD_KEY_LEN; struct crypto_authenc_keys keys; int err; @@ -1193,12 +1183,8 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, if (keys.authkeylen > sizeof(ctx->authkey)) goto badkey; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; - - flags = crypto_aead_get_flags(tfm); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) + err = verify_aead_des3_key(tfm, keys.enckey, keys.enckeylen); + if (err) goto badkey; memcpy(ctx->authkey, keys.authkey, keys.authkeylen); @@ -1209,7 +1195,6 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, memzero_explicit(&keys, sizeof(keys)); return aead_setup(tfm, crypto_aead_authsize(tfm)); badkey: - crypto_aead_set_flags(tfm, flags); memzero_explicit(&keys, sizeof(keys)); return err; }