From patchwork Mon Aug 5 17:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 170600 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538470ile; Mon, 5 Aug 2019 10:02:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyE/C7DyGzPLDmgGtlTJxMIE50rYS+V33UirInfkaaZtzUSmGsbN7mdoct02BJGLWopcqpY X-Received: by 2002:a63:4846:: with SMTP id x6mr101791788pgk.332.1565024539609; Mon, 05 Aug 2019 10:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024539; cv=none; d=google.com; s=arc-20160816; b=cyWiH/o3sXo2ldL0irnuFc+RVHFhuOmLFOq1A411rXYAdMOpeMGWc2Uhk1KYRDB/R+ XGNlX63gp8KOZrMrBlUAwhyEUexMbfRfMyzvvHNX9FT4cNtGS+DRL6ugnxCOMcspxgGN lmhpmVpnXa6B+3J3AhBmELVqFw1OmzDh6SC/sYMELSSTYhUzFe6W82zCjiMCSJ5yzyVk 691sbonogExQcSXbhyhvbnBehFvVxkqWFt/oquUvj68p0rpyRcXo2myBdlGZ2YrAJ/Gm WHqdOhg0lTn6S4qFobLy6RUT0tjXzrffPuTE6B1UybMzzZYKuWJU2M8A0r8UGzmPpor2 uWaQ== 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=SK3G8mftmBkSyQQ38QCarXxu9hLxdoWAD1b59wF92Zg=; b=rrcDh0omZn8ryM8dYDlqHAU0ZWLduCsi+S9TrQM4NZ4pzksKuwtbOP31vtnqQGJnRF HXFxOlHAgdDTg9nWOOICd4+7eYxUadqtZN1BzEf8FVi1T05uO5DYWqGqh3lPT8doaEys hMN/czsSZX9xKrNhLeGvlQeDLC1I4dHpbWOukdnYR41XsNKMbAGdtLLZVxpTCHTxnOAi /dT6/RmaZNHiWd23geLbec9QtfYHzVNVcgDGfnRMCf3t86ebTbm8IRjWwi60pbctzW2u FreStfrA5ZppKxRsasffGp3PY57LYEvgWABtlLfaZvzZJPFzaI67tC24U/VFI8WWGauJ xgTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o4WRoOJ8; 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.02.19; Mon, 05 Aug 2019 10:02:19 -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=o4WRoOJ8; 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 S1729198AbfHERCT (ORCPT + 3 others); Mon, 5 Aug 2019 13:02:19 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41328 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERCS (ORCPT ); Mon, 5 Aug 2019 13:02:18 -0400 Received: by mail-wr1-f68.google.com with SMTP id c2so81915793wrm.8 for ; Mon, 05 Aug 2019 10:02:17 -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=SK3G8mftmBkSyQQ38QCarXxu9hLxdoWAD1b59wF92Zg=; b=o4WRoOJ8Uwn4tZuh2mtviMkMtPpXMeYPQcz9zx4O4FJdwIcf4G7bilSJf91U4KRLJX qP8yzH+dsSxQKK6+OaY9lhngFyWoznx73Svpmo3BX6Fqgnas3qpeuF5cbnVPrt2FzB7c jSg55l5bIr9Yt2nuWYcLIjle4w/lqQjHHrnmQkc1SbaaTB3jjBya2IAU/E7KdpRuMjcU LOtRmy+1q/MearQ326eNUN198w5wR3UXpWgqgOespSLXKiLqvJ915Qy3xXdiXM0uIw0X fQ2SIWNJMce07raJKku08P8h/T7wV2xIZi9jBxIAQBYnZdSxnGhZwBOuURS3yxrqZCK+ FRpA== 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=SK3G8mftmBkSyQQ38QCarXxu9hLxdoWAD1b59wF92Zg=; b=Jlb9MCGit9p3bYAUYVL5eicpx4SF4C+7eu9aDlJmThPUNgWzosgJHDYXtSJral4BGt /oI//6TCwpkfJtDA0JueLDPWb1OqVk2i32tKdqVTMikD7qcXkoaMlULbCJWtWBMXUtz1 9kOGKELxhFdZrLbZp/YltJK1ymsdQShlJQyfhNgvImk6SqK6OugNCKeEsJU75TwGqAT6 UWRCk4iZ6+D7GJHLUonqrSSbtQq7BQdatjM6cDseOjGuThl+04Sume+S8lMNr+Nt+DZr ZskI+zCnPH6a6BLt7a914IcB1RWe/oEUYYzXKlLZo22xN7gsleVoXtLzrD7F4cGRrBoO wvIQ== X-Gm-Message-State: APjAAAXI2Yil/Y6s9lfL0vggaAiEDMXT5LOrLusWSxwgcTfNYhLzGMJo 0TskKhAv8xazyBNTfCiddEJ4ppTz41HweQ== X-Received: by 2002:adf:e343:: with SMTP id n3mr125259033wrj.103.1565024536548; Mon, 05 Aug 2019 10:02:16 -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.02.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 10:02:15 -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 24/30] crypto: ux500/des - switch to new verification routines Date: Mon, 5 Aug 2019 20:00:31 +0300 Message-Id: <20190805170037.31330-25-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/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..34fe3f36804c 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 (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 (err) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen;