From patchwork Mon Aug 5 17:00:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 170597 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538297ile; Mon, 5 Aug 2019 10:02:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjjotTudhcJPR+IM29bBJVoCHbcQnm51+rU8WXUaIV0mGqg+RucRcm1GeLhCT9cODoDKfc X-Received: by 2002:a17:90a:b115:: with SMTP id z21mr18880025pjq.64.1565024531224; Mon, 05 Aug 2019 10:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024531; cv=none; d=google.com; s=arc-20160816; b=J+RQmjY5hIAlMDXPg1tuX+GXsxCMhMIQ7ren3WbbWjvDAMDHkj5is1X+lqWuyWv5jh kIx8nTz0wciAvNREKWWFMz5XRnBhQNtWUswS0bErqat/e42TteArf+cAFo5ePxGvlguI Hi0hF2iI66RCdtjkg5YdD0cietfDS6abFKwrcHXUq3+paCPKOGgKG7LOg5xo+8CrkBig OFgrFxrfIiJ19m8/NLv0tgFGETidkblRhDqiRsQIRINRQPq20bWJFQC+yMYYdxTAk81S T+lB1gRSUJNZQSr6UplHabxOR0H7kKFgHt8jy2z6cNHTxzzElYp3Hd27h/MRur+ZmQsI dJ7Q== 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=9oZqlT+Ip3tp7/dloqkra7bobLN3ro1GYng6jmL31Tk=; b=p7RbiR4xeuvqoX/VeFEMIBlSzqohvr6ahUnRIHmhoWTDLaPYjypfN31ldCrF7Ovo7t KIU+kP6SuCqRJvvJ+zHuMw6GFi+cM3SVJLROGrCSaEYItioMhmDCEX0McgOXgn/6y3/K kiQSA1zayQ7wiuqt4hYCve0hzKbLnRWBTqqmajaIbZkBRbFhTIuzyp+X1JNp867DsXlk PiMIWDmJF39XkHFRTQRR+3xydTXJbW34xXTXo//Uo/zX9PY7/PC+0hI/o81ajTBjmULX bawesWX+5wnEGpMz1C0rC/e9enspaIIOe6RHqAKfWQmTexOiEyLXksV0+Jj1Qdad+eLQ iWYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X1UdoxMP; 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.11; Mon, 05 Aug 2019 10:02:11 -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=X1UdoxMP; 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 S1729901AbfHERCK (ORCPT + 3 others); Mon, 5 Aug 2019 13:02:10 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39339 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERCK (ORCPT ); Mon, 5 Aug 2019 13:02:10 -0400 Received: by mail-wm1-f66.google.com with SMTP id u25so63359296wmc.4 for ; Mon, 05 Aug 2019 10:02:09 -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=9oZqlT+Ip3tp7/dloqkra7bobLN3ro1GYng6jmL31Tk=; b=X1UdoxMP1PP7LGTgUczoAeG0wCY3NO6KnJO8Z67dvA4HZCTI1G2Tiv/dk7bhcssspG NY8nhJTVfzG8FM9WKP9ZO/r1nKm1pzdlCb1k+uZ/yeebtohCL5e16MQ2TDY0DB82DZJc RLNMBij2B38h/eau5N5tUDvdNGJr+ZeQyngGtnZvWJGtCpmR7UnuNBApPhU6IrSGOd2s sAftOqM6iX7TrO4T9vAmYb3DaImdtibk5g6lsDUhAtGc2xFjI/ihnsHCo6wWSbPNNn1u iBK8MnMGLf5C13mcZKduTL6R96ksXSCfiAbH5J6j8wy3j3Ef4aYJOwMoPSOlJhvRrYGQ qCrA== 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=9oZqlT+Ip3tp7/dloqkra7bobLN3ro1GYng6jmL31Tk=; b=BOPnYhIhiDleC7srpTyHEPnberPWXQB0cqPJ1K6+NFb4kYFtagKCCLWDZuEoBR+mMc TWcvJPEtYMxF36K1/l1glbgOb03KjJYYVPkmAZg64tKXTnxKyDPTeSDF7ahz5atVon8t C9KGjm+0UiPsDPujqt0rDzNrgVlSLD2xB0B75AJRfIkyIV6LCz4eLvpMI5SFGKFZdI97 tVuuwAsNnk/3HB42iqFZOvAtHMyWtqVizdTa7wdVOZ5ONbQX2A2eIY9MiotrIHh5S4hm 0G3NU4D3+LfmYBTfMIV57bCS8PmwdDrR+NmqytPVZZWW3WHkFBHWVHPyX9fzKpesDD3/ NJgA== X-Gm-Message-State: APjAAAVIh4mNNTGwyzkVcQf2YnS6cEvZUAtgILJ7wxrfsOYnz25PLnUE xledb/Hoooy4arR2SUNXCqRNzeUNGwV64A== X-Received: by 2002:a7b:c7cb:: with SMTP id z11mr17846582wmk.24.1565024528609; Mon, 05 Aug 2019 10:02:08 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 10:02:07 -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 21/30] crypto: stm32/des - switch to new verification routines Date: Mon, 5 Aug 2019 20:00:28 +0300 Message-Id: <20190805170037.31330-22-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/stm32/stm32-cryp.c | 30 ++++---------------- 1 file changed, 5 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index 98ae02826e8f..a704b1d38436 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include @@ -767,35 +767,15 @@ static int stm32_cryp_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, static int stm32_cryp_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; - - if (keylen != DES_KEY_SIZE) - return -EINVAL; - - if ((crypto_ablkcipher_get_flags(tfm) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) && - unlikely(!des_ekey(tmp, key))) { - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } - - return stm32_cryp_setkey(tfm, key, keylen); + return crypto_des_verify_key(crypto_ablkcipher_tfm(tfm), key) ?: + stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { - u32 flags; - int err; - - flags = crypto_ablkcipher_get_flags(tfm); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(tfm, flags); - return err; - } - - return stm32_cryp_setkey(tfm, key, keylen); + return crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(tfm), key) ?: + stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_aes_aead_setkey(struct crypto_aead *tfm, const u8 *key,