From patchwork Thu Aug 15 09:00:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171410 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918113ily; Thu, 15 Aug 2019 02:01:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMmQjzgazR2KK2ScRn0wk/NpWcFLewSq/QvWijglzifSzkIx6jCKfkna1j/NzNK8ZfoQNv X-Received: by 2002:a63:ff0c:: with SMTP id k12mr2610870pgi.186.1565859705899; Thu, 15 Aug 2019 02:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859705; cv=none; d=google.com; s=arc-20160816; b=ineBWiCyfvfVw+pCh/22YSXgrJK7PULNJMJXL64zQRibMMEHbp/p46jc3qz+bn6Dv4 9AqDtvYAAdplLJokwjxnZglxy04oYfmOIdQGNndNmyPpWlRfMES1zErXL3rRz/EzGSfS EUlLt6dicmMpSqHhKYTvYbClNjc2vBPRvdBMmQ8VMhpyTEtqvp4rZ8NY6IMXYhqHO3pd g1k9nU/fz1KjoDYYtOUC9f52S4WfcV0aoqubrv2qkBMPtPPvL4VrC0lPB1Ek3d3eWIp/ IPZ/lAc97MhBX3IP7u+BlmnLCWrLZ54t1LCY9vHdkNQtfbo57xO+8B6DpMz/p6U3/V8V vPBA== 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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=nZvrzjTAO2pcGFdh2htDMV+gZd+Hf6EeO0X8PPrR12o7oUZkPpMR3gLjGtZv2IrCY3 90eX3Gs80Sj/uXr0q1zpfP0Ah5yzprmlfajiqDXBLI8GqY/7/J/5E1ISi87/L26pjwVd ZAazwSiDYsfFlBLRWY2G88cnIQhHcSVkOiy3FOQRz55JLrWqRhPFcXwJXKuWyYs0+XD9 IyNcLxr7kKVQruNROh4Rx5pfWftdGnlAbEZRvk92IFDP2rvaRhfBePJFUCtUTTZTyCI/ rx/WdrAVT7dXfAZy+Ywv96KAxqfK1TVw7LUenEG9QzXAl1ghemz7r+zR4za/ujHUKCYl zzVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zxx4WGbI; 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.01.45; Thu, 15 Aug 2019 02:01:45 -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=zxx4WGbI; 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 S1730760AbfHOJBp (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:45 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44440 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBp (ORCPT ); Thu, 15 Aug 2019 05:01:45 -0400 Received: by mail-wr1-f68.google.com with SMTP id p17so1562952wrf.11 for ; Thu, 15 Aug 2019 02:01:43 -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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=zxx4WGbIdT6+v94U7dIhYd9lERYrChqa0Wfpl6qPST7cp34Zu/yL/MjXIbJrhGPWAz MM0Eqs5Ym1JnKJQMl0fnaHgsT4JNRfq3aXD1K0XEq9zBxzeR2Yk6vFLdXJtC5N7NzeQF /LCgUNf5i9LCyMWmPkcaugC+P39z+9js3RM/9tNHTEg3iMZn505zrSGVOHB2mXOIdkiP NGoZJF4IA5tZ5U/kkXmXLNTtXua8c3iYp+Ej0PseOBQ0PH88jhL3V6Zw+6p03TViP169 jboiUO55vJ/8QL6IQ0e0QcFy2dprJSlecXys6PLgp8+7RCvPSw6kB8lHnwrMCWmPnSil rfXw== 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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=Uunwbc3L+mzrVsvVsvm1W7w6nGXdy+r3h1jgs1lbSKnDP+2fGGwONJSf46zo3q2O3e EXsDgA1zO0H/M26ySFmYzn8sIaZQDbjh+k5ok7IqdDXW8mWQcjfl3LoX6IVjcbRJf4l4 eOjT7T1RAOYiRsob8i6gibGqJHsaIQKibRm3LKzbTus2QU/GdApk9HzoleEh0I0UkhU/ tzUvfjIl3aYuf4VXABFy1YxlHHRxe5dQ+B0+CMPT7PulrTe4sXnHy4yoog4sfPURUr4Y YgCQ5sPeN3uxoXGR5Rsz5/OAPnk6finiit2mViLhuFq0xlFzBLkrKgrU7dlzccfSCjAk I9VA== X-Gm-Message-State: APjAAAW9d2bqQNgo5kX6d5fzqEcpC1Tx2KB1DHZpo6PLOfRxQdmpR2Pm 7QZptonn84FEKnAO41ClWMHQD0O413M4e6SX X-Received: by 2002:adf:e504:: with SMTP id j4mr4157939wrm.222.1565859702930; Thu, 15 Aug 2019 02:01:42 -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.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:42 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 10/30] crypto: ccree/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:52 +0300 Message-Id: <20190815090112.9377-11-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/ccree/cc_aead.c | 24 ++++---------------- drivers/crypto/ccree/cc_cipher.c | 15 ++++-------- 2 files changed, 8 insertions(+), 31 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c index a9779a212b18..d3e8faa03f15 100644 --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include "cc_driver.h" #include "cc_buffer_mgr.h" @@ -649,33 +649,17 @@ static int cc_des3_aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_authenc_keys keys; - u32 flags; int err; err = crypto_authenc_extractkeys(&keys, key, keylen); if (unlikely(err)) - goto badkey; - - err = -EINVAL; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; + return err; - flags = crypto_aead_get_flags(aead); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(aead, flags); - goto out; - } + err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?: + cc_aead_setkey(aead, key, keylen); - err = cc_aead_setkey(aead, key, keylen); - -out: memzero_explicit(&keys, sizeof(keys)); return err; - -badkey: - crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); - goto out; } static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key, diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 5b58226ea24d..c7ec20e90fc0 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -411,16 +411,9 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key, * HW does the expansion on its own. */ if (ctx_p->flow_mode == S_DIN_to_DES) { - u32 tmp[DES3_EDE_EXPKEY_WORDS]; - if (keylen == DES3_EDE_KEY_SIZE && - __des3_ede_setkey(tmp, &tfm->crt_flags, key, - DES3_EDE_KEY_SIZE)) { - dev_dbg(dev, "weak 3DES key"); - return -EINVAL; - } else if (!des_ekey(tmp, key) && - (crypto_tfm_get_flags(tfm) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; + if ((keylen == DES3_EDE_KEY_SIZE && + verify_skcipher_des3_key(sktfm, key)) || + verify_skcipher_des_key(sktfm, key)) { dev_dbg(dev, "weak DES key"); return -EINVAL; }