From patchwork Sat Jun 22 00:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167449 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1376858ilk; Fri, 21 Jun 2019 17:32:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvg3s+J0mMZivmhNk8MqsaltMd0ARxJvrrc+a4gXUi9eSDD5bCzoCFnBR3r9NR7RgbearS X-Received: by 2002:a63:2a83:: with SMTP id q125mr6173659pgq.102.1561163532716; Fri, 21 Jun 2019 17:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561163532; cv=none; d=google.com; s=arc-20160816; b=tKLSsyEGOP3mKpSnDls4soQGTF+yV0WtMixEGC9XTyjOK0jVABVmci4lipyGfmmwq4 wCpLJCnF5z5LzIwuNOjDklzbKykVboK6PCJvOrwWA7IMmVtBXQVsAboBBl92tK7XcX9H WV3gwMjjLL7+DvLSNBRDhx2W1qpiH3kqsPMiYZfknm2xI/8SWI97YamWYCn2iMeU8GRL 79Rgu6wX7Ps1ifh8lRVjo0MaNVxf/ThiP8Kr3bUoDUjSU2yc5pqSMum6TTd7NFbRuXnN /XE+Kzxnz32qqL8jm1GnbMyT2df4hTI9Q3cPF4kI0pv/4QZF5QYRgjSPm1qxh3H/Zi+f XjXw== 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=+sdt/3gJ4yj04TA6LoWxsEfYMxca+n+KFCJfOd7D3AQ=; b=tmjMH4eBy7dEQ2LEjVNhIawFmxGL+ww3esEw/A6wwmjUqmYywxfnK6AL9oMhBJJtWa 9mjDUBrwgYXQYKqx2T7u3H43Zvh1dHB79Lj/r8awMoDWRiMMVnE0Kto4DaWcwMdmG17C ZPX1GkcxTcDM5FU/d+RSVDCm5XukNgiRuWx+NdvKCtVZLWHwlWjukyaa7yi9JRCojRmW Ng4GvpPT4LcZsaxZ7o4TGzHQyIYZjncAvQJ+iSp2edYfVDfEm1D6zqiRGArOlY2zguVj i+digidl5DLbyHKCmQ/qoToYpXdh5O/n4bp2v0PBRxIDfBYfI+L7iL70+28mTfrU+7oN tFaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZmbmJll2; 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 v10si4096271plg.320.2019.06.21.17.32.12; Fri, 21 Jun 2019 17:32:12 -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=ZmbmJll2; 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 S1726212AbfFVAcL (ORCPT + 3 others); Fri, 21 Jun 2019 20:32:11 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36798 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726237AbfFVAcL (ORCPT ); Fri, 21 Jun 2019 20:32:11 -0400 Received: by mail-wr1-f67.google.com with SMTP id n4so6915692wrs.3 for ; Fri, 21 Jun 2019 17:32:10 -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=+sdt/3gJ4yj04TA6LoWxsEfYMxca+n+KFCJfOd7D3AQ=; b=ZmbmJll21x+q8cTsz00X56alzpx01OH6084Y11pxU0bcdWi1u9FYSgaGlfpsLkgatp LdSM/x7tS/qyYoJseoB95llS9+HHMA1ehsiJAgOIXNrk24jjtJJ1Oe3Ymefgxnhf0AZC Kfiuga+35cFFXSv1Kn9yadUc7Kgd5wAZsKNybkMg/rnVXWrezfG55CIfdSbrtycqWDnp l57E+yDkTkygoHOBjnvKwbvDhh0VCsCAIvtAUPzS2R+/zyFBMbQFXwhj3vQzLjKJvAUc 8cODyBNtmAlacBgesrjoDpGjXdyUUDDBtA+IH+lmkWoDh3v4t3yNy8PbIWgLuMagkhAI lSvw== 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=+sdt/3gJ4yj04TA6LoWxsEfYMxca+n+KFCJfOd7D3AQ=; b=tQt6wdGebDR0n2gIoiCbq4RwAbBhDO1dIaVQU11O2lTjoUsajfXxFiAVOMW5mvNcI5 +w9jnV5G/8qDmdQi273HTxqIrx2WRzVGX1DyioYDr2UwqBwE5sZEiCtlPT0HL0DPEzTW +vzyulFAjdSD6YNP8zoVbZKs+B1Up6GCxpyVeRVOfwWUPlQXV8qditygL6wyGB9uzmao aVOVOcl0X8//vqBs6u5Xdh8NgTdWWYIRqXsvrdF9x8Rt1fQEtM2MF7PopxCZ9fuKgBQW nIbs8Gvc1CpKWPktwoqAn1Jx7XENKIkW5Oorj7IiHPsCyAX6DoJM+f8HnEgMmn5ocNbT zpQA== X-Gm-Message-State: APjAAAWBbYk6YN3m2P/wm9LAOxSkmz8svfHhood0U/fl3mRNyGh2EJXO sgIkaDrN+MocA35T+m3ctqvpl6RkR7Ty/yx7 X-Received: by 2002:a5d:6243:: with SMTP id m3mr5058729wrv.41.1561163529444; Fri, 21 Jun 2019 17:32:09 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:99d4:1ff0:ed6:dfbb]) by smtp.gmail.com with ESMTPSA id v18sm4792019wrd.51.2019.06.21.17.32.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 17:32:08 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [RFC PATCH 24/30] crypto: ux500/des - switch to new verification routines Date: Sat, 22 Jun 2019 02:31:06 +0200 Message-Id: <20190622003112.31033-25-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622003112.31033-1-ard.biesheuvel@linaro.org> References: <20190622003112.31033-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 | 32 +++++--------------- 1 file changed, 8 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..9342e8e6398b 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, keylen); + if (unlikely(err)) + return err; memcpy(ctx->key, key, keylen); ctx->keylen = keylen; @@ -1019,17 +1006,14 @@ 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, + keylen); + if (unlikely(err)) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen;