From patchwork Thu Jun 27 12:03:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167947 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2249668ilk; Thu, 27 Jun 2019 05:03:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFDNlpbQ98jO4r1SMN3l7mrA+dAVmsHK9afvTj+cSMyGH2NSVD4esLGmCb6EUbEmTD0BtF X-Received: by 2002:a17:90a:ae12:: with SMTP id t18mr5807941pjq.32.1561637027011; Thu, 27 Jun 2019 05:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561637027; cv=none; d=google.com; s=arc-20160816; b=bKOFIn8Goam+FQ8S8g3s0hr3fXhICZhqb/m1Zj78qhpJI1nnrTYkxTpIb3VWVLUKJD hDpLuKaWuGAugeZqDWSZIxAoro3Rs6PLWRmpx9KixGpZwEw+75y+aI3W1URlJRl1JGKB JM3QgS+Pe3DPNIPaA1kDNkhOE39+w9jxnxNbGf+E6HflrofNTA1KEnWGDeG2LpXHh53+ wWhTB2Bfmm3aBlXsvj6O1uL/Ch3JN/bZgmyaEzm4yglUPTyBYzaDWy75CFOO8BO0mvE+ NjU2+x6DrwrVyNx8kjet4w6zcx34cVjD6A8+y8BJZMALIXKgeYsYFlWUfnzgrusSloCK 1I8g== 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=oG9DTc9EahpQGLRdj2tQuSEAjZr8slfDrgTwwpr3SnQ=; b=hOhbgH5R9CPkq5Hm1+FLLmDmLUKoItlY+puYdLj/8ed7CJ1PE+7Ba4o1xzUe8ZLTm4 vxOtXsKqlK0PbGl2tfVJbw4xAjNC1XZtgZnECqKFSXc/kromWdUU17q+MKWfyafONtv7 YZgb+lFzlkc54n8KSUUw2I1DzhibZFyyGfzY8K8amZqcWe960OHkntNpQYonw9tfaNyY xgPvbZO+9aTyEhlSm28z0cEO7y3MqXzFQGJ9psuGluggPuRk5YlmfZjlLb+LsR0vjq2k SFwTgRKgS1uArdJlRVSbC1RgjwT6f0io83cN5zBBct2gGfQxNY656YlvP/HjeXs75PfA UC6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OibWrrWJ; 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 m39si2229121plg.155.2019.06.27.05.03.46; Thu, 27 Jun 2019 05:03:47 -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=OibWrrWJ; 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 S1726827AbfF0MDq (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:46 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53961 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfF0MDp (ORCPT ); Thu, 27 Jun 2019 08:03:45 -0400 Received: by mail-wm1-f68.google.com with SMTP id x15so5471747wmj.3 for ; Thu, 27 Jun 2019 05:03:44 -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=oG9DTc9EahpQGLRdj2tQuSEAjZr8slfDrgTwwpr3SnQ=; b=OibWrrWJc4eJTybBU/L/T5IjE3SEoyzhROe0PHfBSbZ0BGN/SKA6TC36DmtSZvxTah nHWrEVHbJPZLsXz0o2TLwV164IP5dOCCPInAmH4kkL4NtCG0HBJawbHEaeSWKhf30pIb 85WnRLV/v4q6opXspSDF09Y83eWEk3o2A82J2xkbuMMph52Ja4BE4yYvmhNX+A4lvKX6 CiZ2CvUAl0ty+MWENzla4YcHaDcVstf03ucBm2ev0O5YB40WUXkeU51veafg3Fi5siVK jP2dzfmyDb53dVxBE9G/Pjrtavii2d1Of3ugOczYzPsrBL2Y2xfNS/tT/ubYcZeHX5Jh KTAA== 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=oG9DTc9EahpQGLRdj2tQuSEAjZr8slfDrgTwwpr3SnQ=; b=Bqr+ZWdjxCv0pLGRIxAvRVJs1FkKheSjOFD19XamdG5HNn4nECoFP03H/iTDrTs5j6 aUPRFYiQOi9WbPF3vyR0SCrgvDL377XndMgmphU2NQF7cOm0fkH57ljeG661wNGDzNsv n/34GOK4N0VaStRASge96S82E4O+VO8gpS8Jw9qQ8MbUTwWNJviskQrM8MuYLmCAdrOW lO9dVhGKS7cWG9zI0JWrakBJknJWLXKl2/xgmoPIkkT+w7Xxq8j7Eqi33fyy/0JAsPJg TnwEJI8la3hMDH7z9XKkpIMCQ186ErhVcleN1SuUBUBmqBvSjfCanmAT7wSy+hvHjlsJ xFvA== X-Gm-Message-State: APjAAAX5zyjLfWA7c0aaP+CCziKnm24qx+0KbUa9BkD7l1xwGKZ4RlR+ ARLb1I4cwPCdj7k4Xal+iUgaBrYgyh62PA== X-Received: by 2002:a1c:e90f:: with SMTP id q15mr3162485wmc.89.1561637023784; Thu, 27 Jun 2019 05:03:43 -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.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:43 -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 16/30] crypto: n2/des - switch to new verification routines Date: Thu, 27 Jun 2019 14:03:00 +0200 Message-Id: <20190627120314.7197-17-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 Signed-off-by: Ard Biesheuvel --- drivers/crypto/n2_core.c | 26 ++++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c index 0d5d3d8eb680..d313958d09a9 100644 --- a/drivers/crypto/n2_core.c +++ b/drivers/crypto/n2_core.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -759,21 +759,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 (unlikely(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); @@ -786,15 +778,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 (unlikely(err)) return err; - } ctx->enc_type = n2alg->enc_type;