From patchwork Thu Aug 15 09:01: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: 171424 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918537ily; Thu, 15 Aug 2019 02:02:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjs8WBsXUnpSfX00FstW09vVMV7JPSK8El7F+g7Bfd/me4dtaOVjr4YNOF4CSQa5xqqE/L X-Received: by 2002:a17:902:f087:: with SMTP id go7mr3407387plb.330.1565859729628; Thu, 15 Aug 2019 02:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859729; cv=none; d=google.com; s=arc-20160816; b=Rt+/EBBpVircmNqraSn0QaLxqk5PzPNr37GxqfJdxX8vMYxxS9UlW+Vtn7HFl+XGi4 IWqrtWaYIthyqkHG+gW87m9aRyKWYGSnPZvfG4kEqobS4/2A+8MF9o1Y1k/jGc37HW8d ZXUbi2Y9pmE9hJcZD5VzJeCbOfA2HKPxtMz8dBt67cPntBr0x0MSrl+qcexvI/mG4mZQ m9d3PUbPGY2Q3MLoPS+BbyEKI5Z+lNiDtoS/6EYVmPEjvNEvVL8yZIr3buMeVz3QNpOm YmCQLHLzvFOG/fbLCQQ/N5qEhtix4UCuMa0RzzA/9Wx+0bD2Hc/QuCRAF5TFrAGuqk4x rTyw== 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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=Icr9wXNNsQ01eFioStCvnfCK0xMouKds/r816eZ8dBiZJJdY4fItMco1FcgqFwHpyj MYBudVyMVao9s5wjBNVH26OOYJU5WpRxEWh3gI8U8C/tXeU1H0E0MtVo2jhW1/z3u72x Tup8SkmXWl1u7ViTqw46uwMW/J1pZkDNaOARJYaqkFXCVGMRQLGGpJAgoASzuloQcJiZ BkSLuXKdCyejrC5gKOyYhEBNvegrG1Q4t022ZfdE+n65qNd4KQzq5ICOs1P5ZwGTtzw9 qv2H5VrEUKLIcMJKfSXPzpeXwvNGi8Yk5tUoI80yCALDYTyp+I7a3r/3Ee5dvibH/B+V 0Sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVqmOF1q; 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.02.09; Thu, 15 Aug 2019 02:02:09 -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=hVqmOF1q; 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 S1730806AbfHOJCJ (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:09 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33096 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730812AbfHOJCI (ORCPT ); Thu, 15 Aug 2019 05:02:08 -0400 Received: by mail-wm1-f65.google.com with SMTP id p77so592734wme.0 for ; Thu, 15 Aug 2019 02:02:07 -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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=hVqmOF1qu+II6tfY1zd1ybrlI9y2D9MSn93KwiDis2+WcuqorSMuQtbT1uLXWF3TIO e2f9UbNNN4WVMhtOV9Xd/mhOCZjDv3x5kPi2cMnC+WlBr4V1OlPerlxr1vkX4H7cdHAH 1qzgZdatL4CXvv/pPEypzuKNjz51GVpMtg7uBndVdD3yz9KAoARJZYebXFqZMboO5+wM kYffU97K8UeQ4f+t0HxaB2g1AA4WLunEY73296dOIoWAQuVfIwy3DTm8g6wOHnJTC9Az q5WT+eJVRmnh+tpyCIbqfx4KRzaCEPMzOkdfmQgWBcoGXywsYKF+HkNfx9jAPVgR09bQ Zv6A== 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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=pCJMZa+eBWLVDu0YmOTYM32Mxw/9hcfr87FmgPLzAvwOyN7R+i+7xe6rK6lm/0Z7Sa bSSqoLPeJUFqKkz1VxvN+5cbnhMGTJyYZdAqH7SOCYteNx9y4OvLtFQzfI5VOACDgPpM 3UCy2UKWotT/tohrrUuvYZO//ob8tvq7h1B0V5m+OaCIT+IpnfUZOTk1blK38UDIwdHm qzhf8CK9aJHIglbQgU/jKcDpBfzwSvJOqjBhLkg2rFpERJcz9HhfA5chK9dHLlJiynYj gHccpmj5dx9pBIYhKtzM+hlB5Kvn9zvqfhvbdVD7wXDCJpdH77g0X4vDXsg21UOB5LZn oSaA== X-Gm-Message-State: APjAAAVFbTn7M3nTWu7NxeJ24iMouygLOOJpzeQcddxxgCSwIg0CPWSS GdXqYRY7YW3clgo635FRSV5zoW/MJHpzIbe1 X-Received: by 2002:a1c:b146:: with SMTP id a67mr1689392wmf.124.1565859726346; Thu, 15 Aug 2019 02:02:06 -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.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:05 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 24/30] crypto: ux500/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:06 +0300 Message-Id: <20190815090112.9377-25-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/ux500/cryp/cryp_core.c | 31 +++++--------------- 1 file changed, 7 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c index b4beb54c0dbe..e966e9a64501 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 = verify_ablkcipher_des_key(cipher, key); + if (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 = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen;