From patchwork Sat Jun 22 00:30:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167436 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1376658ilk; Fri, 21 Jun 2019 17:31:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzb2dNC61OyZq0nujRzC59KtjXtI//ef6kOvYBta5vxNwC18phMjvEijbTjd/uf6lxriwwF X-Received: by 2002:a17:90a:9a8d:: with SMTP id e13mr10149656pjp.77.1561163519275; Fri, 21 Jun 2019 17:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561163519; cv=none; d=google.com; s=arc-20160816; b=LTpzDC6VsQh/PmSHlBKHyvkJaNCigGSDYJ7OMkoyvGieXQB9YZ6SzOy4XUSiiDhUaH exL/j8qMJSPdEfW8XM58Sr+TTUa/niHUYIde334OtpHL1Kin9nHjwhQdk6mFydVzsy63 8wewU1lQ/ezlb+sk0WF8jyBstovWxo1E8niHqmdxZytjmqUivRywmynwN3/ASt4jhJcq HOABh+pDX+6EDUR805FUshmljLoseJlpkCXBMhoLeSePnecA2s5k4lsZR5E+XkR3MKc/ iC3cA27aABek37MblttvWGhq1Kt8YVDee9b9GDCYAxsRFYB2mRr4b5u3Q5hp/1dcEmiA TXvQ== 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=skPEgyB6K58F0JFBqiqoUFb0RrK94HT325v0Xt9TX8Q=; b=chEJXUXLDY3K8maG4umjqVcs7x6QzmwmkduRmW3vTN6ukjcN4xzzP4eKZ+cq0mJt/L z7s6Xtg20JIpgogRcGyYqedn/jr0c1yt7bQYI6af6t1QEZMmuIOnpdHINCQ75xBmUUrf CrEEXe4AQfXuW479bjbJ14AWBCxVT90Y3djAE+CUzJCzKRhkBySSG3NSQPV2kpQccoMf J2Eqf0JNOYpv50KSypXAnwihIqVdDmChCsd4MB4BhZaGR0SnG77Rd09n7hJg3nmuuxUW NyVjyc3Z/RBISbLEMIjeap6u+Z2OULsvumw9DzphmCxVEBNOwQkIonq/W3uC3SIpsIqk Nr8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z1utctrf; 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 v10si4096271plg.320.2019.06.21.17.31.59; Fri, 21 Jun 2019 17:31:59 -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=Z1utctrf; 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 S1726194AbfFVAb6 (ORCPT + 3 others); Fri, 21 Jun 2019 20:31:58 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33546 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbfFVAb6 (ORCPT ); Fri, 21 Jun 2019 20:31:58 -0400 Received: by mail-wm1-f67.google.com with SMTP id h19so10135382wme.0 for ; Fri, 21 Jun 2019 17:31:56 -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=skPEgyB6K58F0JFBqiqoUFb0RrK94HT325v0Xt9TX8Q=; b=Z1utctrfbMwUyC3wz3j6Et4vmqX1pyhe9NhJdH1Ti5/f46RdZt+RAejlWBoQLdncgg BWHgz4iAE23K8g2EYOFWkr5M2JdlijKTmCxLtBPocscVRqaovDI4EFy7yPBy70QqHCiK zQy8HVDKQWypSklTUXDol6Z+7mxrXLnZNJVsngh0wqWAgk7kPy2jQSPM1SWy124AZHBM z2fOJK4FaypaNn5ipoDB5KzLdZFWsLLah3+i1P5arjzAwBF/grDxGdSyLMeh4Yvn3TTa clXnqivhDYf03oCf9t3aJFZ1ZrUfWlWIGkY8x2g+woJ1RurKa2ltArl+wU3GgMPcpUHr 2vKQ== 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=skPEgyB6K58F0JFBqiqoUFb0RrK94HT325v0Xt9TX8Q=; b=ffvZmpSN+VMNI2y9Uvl+A6oJnaOEDMXD4ESbPHV6yd42Erh0P+u1R4gxqFcq8ILqm/ yy//b41DZG5n0g9zbl9/ga1XLx4DsAQkhWfmx5FiazlR2258XRnugk+B7xeN6N18jkc/ UBt6TDfsrli5doBj6JlJotTXlc/pywyDYypPb91Nmp2teRUBxG87GAT89SaQca/boggJ chpAb7gmUw9AZE1RU4VNUfunkf33/OetCNRPSaSp3fU40UoJ56vmvFeCVGSNoTuPY1dB f0VX+aTurjkMtIV1bNkb8z/BEkr6cJa8qshJP7Kmz+LZ9QIhJuYGUqlWBgUAtpwT+GHr ma8w== X-Gm-Message-State: APjAAAVzNeDqWVNvpUuFx5HiQEGVClCeNzC0k4Vwla2QusmkFRgCJevJ uh30Lns76wvBWzuNya0+Zp5UGnYS+DbdqEd5 X-Received: by 2002:a1c:e183:: with SMTP id y125mr5636663wmg.152.1561163515978; Fri, 21 Jun 2019 17:31:55 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:99d4:1ff0:ed6:dfbb]) by smtp.gmail.com with ESMTPSA id v18sm4792019wrd.51.2019.06.21.17.31.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 17:31:55 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, ebiggers@google.com, Ard Biesheuvel Subject: [RFC PATCH 11/30] crypto: hifn/des - switch to new verification routines Date: Sat, 22 Jun 2019 02:30:53 +0200 Message-Id: <20190622003112.31033-12-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190622003112.31033-1-ard.biesheuvel@linaro.org> References: <20190622003112.31033-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..3eb1ca59e90c 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, len); + 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, len); + if (unlikely(err)) return err; - } dev->flags &= ~HIFN_FLAG_OLD_KEY;