From patchwork Mon Aug 5 17:00:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 170592 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538052ile; Mon, 5 Aug 2019 10:02:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPSeHSTqqmKcs85BSOyCpAkYxy0U5AovQen8DoiB3uqLHpEhAorCmWN+2uAvr3SY0H1zdw X-Received: by 2002:a17:90a:3548:: with SMTP id q66mr19320227pjb.17.1565024520128; Mon, 05 Aug 2019 10:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024520; cv=none; d=google.com; s=arc-20160816; b=j17OzIc9v/m1RQd61aCgO2bMWryV9gvFvsRMj3qg74doiAnLQPBmSXPw0FOYoQo/ZP XegbUiJ4qFZTM9FJdGVU1IC/NcHxSvPuz+yh3C7r5WZRuekejI/4WN3R7uGaj1pXi/6l kE3n0rjwJFmZG9SvuPUZwVDdW9EIivGw/mvNU8McqgGcZ1xEIhehmZNo/7vdn/2hn8pV 8+LuOjlGgeP38C9CHTnQlnELu0vxMxeT05EOwRElpGXxk03XILQbVCNIzvROeN5yU1+2 cHBdH7Ak/D11JNK13Tvb9n0epS2OGHNrZmYz7HT40ge+k3hMgaUDjHiQ1COAJLB6MbMI 9iCQ== 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=l75t/dMwz3Dca4AbndWnCxvkr19XiVvwzyPSZ/AWGvQ=; b=KFhejpICK5VtmsllYlj5crLJGFQGhzuFjIFTqVpsFT4dbv6cHPxp6o3Qypda/3S05v NkbqjVxFz49YJpmev9Mr5YWeCPErsQtBmaRn9jtL30HyqtKqjNR+Hqx+138TbmaW1YDJ Z+HOPotqo/uNCify+dCe0Wvpl7Ks+egbwHGLrhexijmUWEGfKEeGLF+gN1aLbBjR7OHA z8SV00XX9tHocvOcaAcTZK0l1cduXjiOTkbygEuGI/FoVCHXZAn2XsJMJKhv1e+Imkpb tni2r3lyUjblL10gC4j1tRKQBN26t8nuZZrHOoR6zxGWHLr2oHFUEfdRptHdAY9IiKET bZWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wdhJ4M/x"; 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.01.59; Mon, 05 Aug 2019 10:02:00 -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="wdhJ4M/x"; 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 S1729282AbfHERB7 (ORCPT + 3 others); Mon, 5 Aug 2019 13:01:59 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:38281 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERB5 (ORCPT ); Mon, 5 Aug 2019 13:01:57 -0400 Received: by mail-wm1-f65.google.com with SMTP id s15so52371407wmj.3 for ; Mon, 05 Aug 2019 10:01:56 -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=l75t/dMwz3Dca4AbndWnCxvkr19XiVvwzyPSZ/AWGvQ=; b=wdhJ4M/xV309R2I1BFf4/mRxDKTvOSlu8QUOhnv6Dmto7U3n8JCQ6m/++Dc/ERZW6t DlquOvzZ5ZCeJhfAwxo33KAz+WBpV/iC+nWuFPx9AeUC9d/qYVdcozIOrsoxW5XyrdtG 1YVNxvylN8qpOy997nyAeOIJro6jVFWNQ1WR7N8tVg9ZLAK3n+3BlwfDrF6FEuXssAZL bDfVhI/h5xB627NsZl1xG3dSWw4iGTqRn1UJUa7eO1j2N9wLAyy+b8k5RVIBJAGHsL9L drI849vdYaTaUjOB3rqYbtyV5g9AkbrPJy9LJj2D307aYyEpOBArX7iTgMP5pFwu/urQ RUHg== 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=l75t/dMwz3Dca4AbndWnCxvkr19XiVvwzyPSZ/AWGvQ=; b=fx+SE5dDg/80XWMQ7hq3VUfi6z50Ff83Epy62lH2eGTfdCTwweqI6E/DPxAYzYCzMm RHLMGxDrVD8C5RPxWtB3S0nDi1KJXsX57r4XWBtB6HVKQMCwtFH4VczdlD0KMB6mArDF A6vSViEQ1u5Z1Lm0PktQRVcvch+MP9XkfEtglAobJhi3kGAYm5uYOKGj287co5lLqad+ /gqaznueGrHlLEVRZ/K0/h+pSIcb6pwS9q/nlBeLonV32X5C3KuqhlFkA7fTlobDrOUW ESCiqCb4ZD/NEodRAcSKJGy+z2sB+LS/9bjs2CYfzWoGLWO909apGIVblyThuARmPH8D 0JOA== X-Gm-Message-State: APjAAAVJ/ofSFBbDXpyIonBbi84SYW7Arpy+s82WhJr+lC8Jf/mccIMl LrmLQx4SSxhiv2ZN5pobnAwgDJ9bX1/R9A== X-Received: by 2002:a05:600c:114f:: with SMTP id z15mr19376097wmz.131.1565024515571; Mon, 05 Aug 2019 10:01:55 -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.01.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 10:01:54 -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 16/30] crypto: n2/des - switch to new verification routines Date: Mon, 5 Aug 2019 20:00:23 +0300 Message-Id: <20190805170037.31330-17-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 Signed-off-by: Ard Biesheuvel --- drivers/crypto/n2_core.c | 26 ++++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c index 760e72a5893b..bad1719a902f 100644 --- a/drivers/crypto/n2_core.c +++ b/drivers/crypto/n2_core.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -760,21 +760,13 @@ static int n2_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm); struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm); - u32 tmp[DES_EXPKEY_WORDS]; int err; - ctx->enc_type = n2alg->enc_type; - - if (keylen != DES_KEY_SIZE) { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } + err = crypto_des_verify_key(tfm, key); + if (err) + return err; - err = des_ekey(tmp, key); - if (err == 0 && (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + ctx->enc_type = n2alg->enc_type; ctx->key_len = keylen; memcpy(ctx->key.des, key, keylen); @@ -787,15 +779,11 @@ static int n2_3des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm); struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm); - u32 flags; int err; - flags = crypto_ablkcipher_get_flags(cipher); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); + err = crypto_des3_ede_verify_key(tfm, key); + if (err) return err; - } ctx->enc_type = n2alg->enc_type;