From patchwork Thu Jun 27 12:02:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167958 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2249551ilk; Thu, 27 Jun 2019 05:03:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiGzbw1pvPZyFhEnPaD9lq1XYLYvTzhG448nDYo5PwbsvpHTIiTRV97lRnqZieO7zHt/gq X-Received: by 2002:a17:90a:2385:: with SMTP id g5mr5839168pje.12.1561637022574; Thu, 27 Jun 2019 05:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561637022; cv=none; d=google.com; s=arc-20160816; b=Se2/LzHMbguhABY6E2I85wLHcUFJCmPYBqRIwft4N9IF1hMdknuhlDYLT66E8tIGY5 pBndQ0IZUyv3RODfOGSpn9GyzguS0llPIXgyKJ8gyEvoW/vHk8n5GSovL9mwHswD6tir lH0D2VkZevzxIxc6e7VWuQ/t60MqfKt+qrydLDpGMsj+jkewfRmF6V+HPG1PvlfsYBq8 GgIfwxoVMaA30awIO0x+hoF/TxsdgYb7bKucyDSlX7gg61YfxIm5kWnctJlJhHAUSkBn IKtgLkJNjIROOKfPX1GTmhN5o2xEaKkqMsIVUw3O2pb+sZrqtw66VcROpAOfQzRTDLsP Ap8g== 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=0BmAQ2xBY6YvXGaq2o5vjDuCRmHdlrsYW9+Mlp1M+vM=; b=FqUysQ46BxMsDHzPYDq4PaclabwshUyYXGp3e2W84Al758t9MYeH+TtNwXBwsCD7VZ /rlbzv6CkLkRIhF8+Wc14L8I5hYqfNbfuoXJT+RupoHK7UYBtdK3n+9r3n8I0uQP3Dq2 CUfWp9ypjYOw9jlXsjKL4DKgDq/s/lh9zz6N9lcweo7Z4PHgOp32RY7das+lObukSyh5 TrU028F4EUcAfnyAFtfzSJv6LV7ZnCnRlbkDD9m+nyH4kjGozcvg5M9p2K0y26CB4Cgx IQOFkLOzdxo1ihs+5/kuLbpyzi+RDUbU+3FB/NBBvfhCn6q0mrImkHfj6apOv6em4cVS y0JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b1OjzH+i; 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 m39si2229121plg.155.2019.06.27.05.03.42; Thu, 27 Jun 2019 05:03:42 -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=b1OjzH+i; 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 S1726711AbfF0MDl (ORCPT + 3 others); Thu, 27 Jun 2019 08:03:41 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34914 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbfF0MDl (ORCPT ); Thu, 27 Jun 2019 08:03:41 -0400 Received: by mail-wm1-f65.google.com with SMTP id c6so5427968wml.0 for ; Thu, 27 Jun 2019 05:03:39 -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=0BmAQ2xBY6YvXGaq2o5vjDuCRmHdlrsYW9+Mlp1M+vM=; b=b1OjzH+iNBCvpUvpJm9oA8voc14pDPqhn1XM5euaGAbwZnzuDSu0IIQfGaObCMQaUX A6H9o4qZ3wAPn17/eb24RZfcRmiO0LV4D9PlSlAwq5OzLHdC71R1pMEE4oXvHbcYTrJc aE1BjMvoM+StJfklpMlELp6bopgpWQB3kgQ1v9sp2wtpW8jLgvRlrcCxAQ3kX5f8V83g tg4YSioxp6tw6ShbqpIDbQh4T8GU8Rrm/dHbPpXwzsFnVw/1eAnpYX9KewEH8y9SN6zS fa98+B/yssJ6gffgvzqtffu1g4unzVXJDeo72QZ6L7PGM6IjTR7RNrZe2ZIS5udMfUJx ozZQ== 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=0BmAQ2xBY6YvXGaq2o5vjDuCRmHdlrsYW9+Mlp1M+vM=; b=g9vhulc3bIHyOXYoSm5CIQmA4ZZxAALVnNtkoLs7WT3lGc5BbsSOGmm8M6Yfp5Uwd+ 6fZVw+XjRSR8ESgaJ+XXZPJhCz1kh+rdU9ZJeci0R64R/UD0++zacD5ftGEsg2o+Symc SODnclen7iZFlFD2Kblg5oOuZWaO30fN9pdeuDJvFioSkK4+e02cOi+H/0W+yGvfEgrJ joFlTSL8DflvNijKGlbSDI/limYMdRfEdcGZwclbeM6G0gLK5zHijl9Wpj3X3GgY0wEz xHqYKPrFqhhH7D0GPYzC/KnLHRrxmS3VPVW8Dmu+i38nR7m13BJEQbsCQ0OIfliEdzc5 PyyA== X-Gm-Message-State: APjAAAVeeQHTb1yxSb7yU9Vtcv13WKsYl6lWR75iL7JSfTqYHSKCX3cE WAJyglcwoj3mVJpeY08xy5S6f96Unoj0cA== X-Received: by 2002:a05:600c:20c3:: with SMTP id y3mr3136453wmm.3.1561637018471; Thu, 27 Jun 2019 05:03:38 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id z126sm7732431wmb.32.2019.06.27.05.03.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 05:03:37 -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 v2 11/30] crypto: hifn/des - switch to new verification routines Date: Thu, 27 Jun 2019 14:02:55 +0200 Message-Id: <20190627120314.7197-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190627120314.7197-1-ard.biesheuvel@linaro.org> References: <20190627120314.7197-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/hifn_795x.c | 30 +++++--------------- 1 file changed, 7 insertions(+), 23 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c index d656be0a142b..000477e4a429 100644 --- a/drivers/crypto/hifn_795x.c +++ b/drivers/crypto/hifn_795x.c @@ -30,7 +30,7 @@ #include #include -#include +#include static char hifn_pll_ref[sizeof("extNNN")] = "ext"; module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444); @@ -1948,25 +1948,13 @@ static void hifn_flush(struct hifn_device *dev) static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int len) { - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); struct hifn_context *ctx = crypto_tfm_ctx(tfm); struct hifn_device *dev = ctx->dev; + int err; - if (len > HIFN_MAX_CRYPT_KEY_LENGTH) { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -1; - } - - if (len == HIFN_DES_KEY_LENGTH) { - u32 tmp[DES_EXPKEY_WORDS]; - int ret = des_ekey(tmp, key); - - if (unlikely(ret == 0) && - (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } - } + err = crypto_des_verify_key(crypto_ablkcipher_tfm(cipher), key); + if (unlikely(err)) + return err; dev->flags &= ~HIFN_FLAG_OLD_KEY; @@ -1981,15 +1969,11 @@ static int hifn_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, { struct hifn_context *ctx = crypto_ablkcipher_ctx(cipher); struct hifn_device *dev = ctx->dev; - u32 flags; int err; - 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 (unlikely(err)) return err; - } dev->flags &= ~HIFN_FLAG_OLD_KEY;