From patchwork Thu Aug 15 09:00: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: 171413 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918203ily; Thu, 15 Aug 2019 02:01:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqy60fEYVHNY0z5zhj177JhdRXOWKlDFA32acMHhFrv5IzMNELs4U5cOzWzNqSbu8yxSrUfS X-Received: by 2002:a63:dd0b:: with SMTP id t11mr2726145pgg.410.1565859711059; Thu, 15 Aug 2019 02:01:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859711; cv=none; d=google.com; s=arc-20160816; b=pGrZFSQs/rSkbgDrnnUx/gJk0rox8tDpQaYV65F6mkDy9ChHpESsBeQjA5gCDYzNxV 5MbvZ6LqUlqNGdqSbSQoq/1Wj0MJD8LLCHWEgaKJe63HJ6Q6fOyqrUugIC8p1ldFvzXP l7uVqPhOTa7iZIhq/mtxEU1L+H/9nzU4PgI5E0Y9eki1yaZR8Gv6VOqBF1UeVLIs71DZ tchda7Q0haWMPTMQ+4xPUxpZloPg42asDdrPJRlOd1ADKqwm3evOaaveQp1JwvzaRWTU dMso2Fl4VWHrdwC6zUD3p5NrkhAhVJtFc5y86dg7tHqLlGmger0f9rbKDNseH3hlSYOs NsYQ== 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=TcK6DnEUHoFqNwmgqurEfwn1kW0ngDG/2DCrPdXKlHo=; b=gaxCd4v6NNHv6wFQklAobmq9hfGtHElLZCoYDipn7GWWYvu0KZH/L/IG5PIxcrC5PM EHl+wsXEDThVl5mDVAEmnjsOE4CmPzGMuNc9DrLn/9luno1vNbAXhKM4L//9D6ZBHHtu lYEtYPSgSk+EUHXS0+w0ooaXOegQPJVMjEUi2a4f1yQbKidPDgMZ8+Nbp6rRBqfh23rq UUOemZQv2lJnz/ZtyELei+QdyEqqM3keZ2r4R4zAKcZG+7RpfkaV5lKjSftWAbBMaaB0 uFHhw/fycEs5+ZU6tIl6oj3V8h64oleWkgCgfLgHo8E1K8Q/AeqvuUUStYM8VGdzxBHa y3ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xdnyBaXv; 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.50; Thu, 15 Aug 2019 02:01:51 -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=xdnyBaXv; 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 S1730797AbfHOJBu (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:50 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55952 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBu (ORCPT ); Thu, 15 Aug 2019 05:01:50 -0400 Received: by mail-wm1-f65.google.com with SMTP id f72so673374wmf.5 for ; Thu, 15 Aug 2019 02:01:48 -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=TcK6DnEUHoFqNwmgqurEfwn1kW0ngDG/2DCrPdXKlHo=; b=xdnyBaXvZFRUSkPBqMMhcgroGSy7l+VQT5/Nb0ww1JMeJAwUJ11FEwSGvxqhb3soD7 3eBfF/vm3S90Fj3iKvX1vMgOJVvwpuW91b4dAzm4YXNPO0LVrl1ncan5KXfKL2GxV+A/ SVIjCWdfwXPqd6j10hXAyZ3f2Sz4v1PBzVCbmDb7waQZq9fvQ/V3GwYgfhDECZwK42v/ SCujl0P7Fly70pjg5kUNdyGODAiQnFcJRzlDYPhDIrc4CmZ4AQCqrvSTjSxyoGXOrvAw jjMDpVt0v8iZaQcheHHECw231+oVvjY+YWi6BWPUAvZRITpgOjZ953IWuvnms1OihXek iv9A== 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=TcK6DnEUHoFqNwmgqurEfwn1kW0ngDG/2DCrPdXKlHo=; b=R30ejyR0OgS9maADevfBnxdMDJN2K88ItDJp+O1kNH/X2CEKPuDHnLjJKEps64WSQB kkGa/cueGCuGn+S+xV8TdcJPEOey+eIwSqfwby2/t7+nsVlZxB0i0Cr0ScU4DOIcHPc5 9VtnfQv6kVHU8VitiU4DH/Ph1ACqFJMzFMhW6ktCxggSZ31iBUhgSMaaGTMF75Lt3ofa 6Na9DT5VbgkU0EIgOWDWhbgKe5Ou/vI70NMGHDb+bupGMhkEqOyRm/vlmPrV4rZwiD+4 mgyd7DGoHDkFLyhLiriv2MMDyg2DWw+pp2xquhPQPM6J5vvcyng9zGrgyqmNYOKNDOiq AR0A== X-Gm-Message-State: APjAAAVWYF5Sz6BUCP56gpg/7RQLWNxB/sIqGqYtVzqe9vWOkCz02w4T kflJzzRdZvfeYcdLD6JKemQs0Gx1isjW4Zq8 X-Received: by 2002:a05:600c:2056:: with SMTP id p22mr1550852wmg.159.1565859707282; Thu, 15 Aug 2019 02:01:47 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:46 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 13/30] crypto: safexcel/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:55 +0300 Message-Id: <20190815090112.9377-14-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/inside-secure/safexcel_cipher.c | 24 ++++++-------------- 1 file changed, 7 insertions(+), 17 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c index 5682fe8b606e..16c4d5460334 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -220,7 +220,6 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key, struct safexcel_crypto_priv *priv = ctx->priv; struct crypto_authenc_keys keys; struct crypto_aes_ctx aes; - u32 flags; int err = -EINVAL; if (crypto_authenc_extractkeys(&keys, key, len) != 0) @@ -241,12 +240,7 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key, /* Encryption key */ switch (ctx->alg) { case SAFEXCEL_3DES: - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; - flags = crypto_aead_get_flags(ctfm); - err = __des3_verify_key(&flags, keys.enckey); - crypto_aead_set_flags(ctfm, flags); - + err = verify_aead_des3_key(ctfm, keys.enckey, keys.enckeylen); if (unlikely(err)) goto badkey_expflags; break; @@ -1192,16 +1186,12 @@ static int safexcel_cbc_des_decrypt(struct skcipher_request *req) static int safexcel_des_setkey(struct crypto_skcipher *ctfm, const u8 *key, unsigned int len) { - struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm); - struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; + struct safexcel_cipher_ctx *ctx = crypto_skcipher_ctx(ctfm); int ret; - ret = des_ekey(tmp, key); - if (!ret && (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + ret = verify_skcipher_des_key(ctfm, key); + if (ret) + return ret; /* if context exits and key changed, need to invalidate it */ if (ctx->base.ctxr_dma) @@ -1299,8 +1289,8 @@ static int safexcel_des3_ede_setkey(struct crypto_skcipher *ctfm, struct safexcel_cipher_ctx *ctx = crypto_skcipher_ctx(ctfm); int err; - err = des3_verify_key(ctfm, key); - if (unlikely(err)) + err = verify_skcipher_des3_key(ctfm, key); + if (err) return err; /* if context exits and key changed, need to invalidate it */