From patchwork Thu Jun 27 12:03:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167961 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2251869ilk; Thu, 27 Jun 2019 05:05:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwUlkO+dUwD0I9wgRcrR3A7ttFmFLbxueB6x/A6ZX9GGbbTvKITkIJkxyaM7qGIF4tBTsQ X-Received: by 2002:a63:4d4a:: with SMTP id n10mr3402157pgl.396.1561637037457; 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=GX3BGmIANiW5XA6Ehoz66URWAlQdSAnRZx+P2zrZzRvmC5BvuV35RcaBonFjOSiIX2 jxWDXBYiyxyODs3XxGcLEw7poR85hAPdYu+wCVjew3KAynfuuscZ1xae6zmJkj2MuybZ t/lWpjUTyHeMXHob5mnMFxJe0tvuGIi6Xn1Yundse7tx1XQNApInAR3m4/yep6hM0xRp HNr05Qe6dqZZEq2CfyR3/BZhE5grwdhIlbVCVbC5w1y6PfHtAt9V97XgqZ5NbigmQRIV nL/KTi7AGvUstLQMx8XGnfXxXur9FpA1h/omoSG4QywvwHzA/XynWqKscFtCXIs+gklS 6tlQ== 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=3jS478ttYwvYZg/uCBgId5hMyypjMuzMWsJAXYXWARw=; b=PLuuAVnSb2rOIrsyqRzFKfXtOFmow9rg5KOjtIgJmSC3o8xJzvyW4+aUsbH5uiPIsA 8isNJXk2Q3eFmwWXXyUm5Xn8rE+6/xkw8bv7ZohtNMmCiLWjwWk4go3WIpXpAk2koBfT +kV++8x69D9ke4cxfTnNGxlolhzM7xTvRa6zM0BG/MW5Hh/lKG2Sp3GtPmibKFpZVXuH p61mQlJwkGv3qqdaLaiJcmp9ltkZaIjx37A14/ZbzEpKN+woD3KFRQLlBq7NgOskKc63 PFBRl2cUsSiQqIRLY4FMJhy7VIELovGCISi5C5JeV0X1JDXQ9UFQZOIqrHrJ4skfT+Bp fQlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z23P99xO; 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=z23P99xO; 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 S1726874AbfF0MDz (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:55 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42832 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726876AbfF0MDy (ORCPT ); Thu, 27 Jun 2019 08:03:54 -0400 Received: by mail-wr1-f66.google.com with SMTP id x17so2242216wrl.9 for ; Thu, 27 Jun 2019 05:03:53 -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=3jS478ttYwvYZg/uCBgId5hMyypjMuzMWsJAXYXWARw=; b=z23P99xOEKsqgIO0KRsNTbwiDdIHkrmLdA2iLWUL0VM5xiw1ilEG8X4BN2mPi9DOZ4 QpRyupsaBG3plICWP+HXIm9CN5mqfKrZ9CHxs/+c0DfIfLyKnlmMmFvbHheDgkq8or73 8Ea4JxNQhhQsJSTer7k/6A3yZgDOsP93L84zKFU7oi1VjMViCEyZONQ/mkeHUohVQBrv SVmgHYjgnUfBrdVFgUP8sB+uODvbK2Wp5Z8vCIjxbZAqIdRy7U1TpmT+As8Lx7c/V6nK lSYoKs33j7MApU0zi+O61y8BGuCbpFq/bnesF3P2kVsFUftt3cR5VsRxThbkqMwYl605 Ny+g== 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=3jS478ttYwvYZg/uCBgId5hMyypjMuzMWsJAXYXWARw=; b=ufVX64meYjIjpViSNoUI5g9wW2NJUqESyl/tql5vESM3tnxGLTl7q+VrW0tUfVHjlo HMrYJD2g6Y8FRGOiWTMe/7pwJO02Hv8/emvZhJI6KECI9KxcfbLt6emtQzNL+Mii5aHW 65A/w6QTm7IxDv50WH/tw2ScAVDZz6e6j6i4p5DAgYrSumO4ZHIC5oJhHnS0SMazHMGz 0zjtJPst73XBle3qoXHgWYy8W1WcXQ8b0/WF1nwXwQ0VCiP8D7CiU+pAAtvY9j3HYCKc DHDSuM63bC0evNEcs2WBNdjlqhdDdoScLpVM+6AKAV6Ggndmg2ncgYjaK+1FM3Xew/Gj APBQ== X-Gm-Message-State: APjAAAUzfc3jEjjtt9xQkfPv3efsTMNC+n1xrtYBsf7wdxHzaLiAlETl 3c6ijYNbMX8pQDM7Um4lCx/0l/6VET8qKQ== X-Received: by 2002:adf:ea88:: with SMTP id s8mr2919766wrm.68.1561637032419; Thu, 27 Jun 2019 05:03:52 -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.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:51 -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 24/30] crypto: ux500/des - switch to new verification routines Date: Thu, 27 Jun 2019 14:03:08 +0200 Message-Id: <20190627120314.7197-25-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/ux500/cryp/cryp_core.c | 31 +++++--------------- 1 file changed, 7 insertions(+), 24 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c index 7a93cba0877f..447bddd72fe7 100644 --- a/drivers/crypto/ux500/cryp/cryp_core.c +++ b/drivers/crypto/ux500/cryp/cryp_core.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -987,26 +987,13 @@ static int des_ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher); - u32 *flags = &cipher->base.crt_flags; - u32 tmp[DES_EXPKEY_WORDS]; - int ret; + int err; pr_debug(DEV_DBG_NAME " [%s]", __func__); - if (keylen != DES_KEY_SIZE) { - *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; - pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_BAD_KEY_LEN", - __func__); - return -EINVAL; - } - ret = des_ekey(tmp, key); - if (unlikely(ret == 0) && - (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_WEAK_KEY", - __func__); - return -EINVAL; - } + err = crypto_des_verify_key(crypto_ablkcipher_tfm(cipher), key); + if (unlikely(err)) + return err; memcpy(ctx->key, key, keylen); ctx->keylen = keylen; @@ -1019,17 +1006,13 @@ static int des3_ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher); - u32 flags; int err; pr_debug(DEV_DBG_NAME " [%s]", __func__); - 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(crypto_ablkcipher_tfm(cipher), key); + if (unlikely(err)) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen;