From patchwork Sat Jun 22 00:31:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 167448 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1376853ilk; Fri, 21 Jun 2019 17:32:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyASbIPvlqTcjzuSKN+JbBAo871YzOMB57UNtJaZ5RG+juOvsPNsqLJQIbVSFpObhMwbOwr X-Received: by 2002:a17:90a:8a0b:: with SMTP id w11mr9961183pjn.125.1561163532407; Fri, 21 Jun 2019 17:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561163532; cv=none; d=google.com; s=arc-20160816; b=N4UhFGNxlqOocltFfAI90b2WpN0i1DwlA7+4AGRcRUvCO1pdovHVAhM4jHR1GEvFbM JU1MhDC7ny9r67Jaf5NHqjSjEgo/cZLxJAtKZ0jcrpbw0W6EX+bTBx2DCiV5RLXwSMe/ Cq9oaD6i08fTOJqciWG7wj0F7TvKx16XsnU5C7VzHSbjKbWDZ1a053P32unBXlZC3ZCJ YQD2nOFNXpFv2r7KxNDPsqJuqNT665aoPjaPpgg8BUHHApLmniaa5kj/SA/pMJGiC05x kamlbbEJRxDoGfdadfv8ed6EIOntdufcwqqaWozTW+ul7CFbHavxsIYy8B4iit2Iiacv 1vpg== 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=8ECamVGrenRrFvw0EKJFpRTvGkUBrF3jVsxmqTaUFNc=; b=eYtBrv8ms2eYayeUvtM3DQ+m1YY8UeptcTO0twTcgHzp4WBgiMIcb2sCfNSLh7eu3H Ovf8nOh6v9V07NHYrPXn756qvfrSlWofmyTOkHxqOJ1tN5jWhOK19c5EdvEEnPLWKqF1 t16rHyYb0zexHXePR/6ZbP7tlaXzMYLa1706nGpXuasxYMlatWuFHFZOIWXOQSk98OR3 3pR1ho8KlbzC7M6wVuYzLXwJ0n3lyNOM2QLf6gL8ynm32f+FWdfYpqkDGPNVIElSPdFw t6h/HsQRuCdjEry+8oiQxd0XqdgN29IH9Hr8cGROnwCrT6x7yiLbOKL3XURgKhXkni2Y 79XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VISEf18Q; 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.32.12; Fri, 21 Jun 2019 17:32:12 -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=VISEf18Q; 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 S1726250AbfFVAcL (ORCPT + 3 others); Fri, 21 Jun 2019 20:32:11 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40829 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbfFVAcK (ORCPT ); Fri, 21 Jun 2019 20:32:10 -0400 Received: by mail-wr1-f66.google.com with SMTP id p11so8100477wre.7 for ; Fri, 21 Jun 2019 17:32: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 :mime-version:content-transfer-encoding; bh=8ECamVGrenRrFvw0EKJFpRTvGkUBrF3jVsxmqTaUFNc=; b=VISEf18QwcsCpnpxGjFbR3q7mDOPmNA/ZtZ14P/RgS2SnOGoJ/MqIHKwpl8YCWaepm +YdcjYANEv5+lHp+k/EYrTRRNH8he5iBVgHgy0qIIuQjTuNM4mzHqVZwmgLUTo3vmY4c 8Jsc5GsLp+eU+AW3Dyoq3zQ54rbcE22GhPvoRMR8AWTaHbBtLa8Z6U+heezqmVIoDxiq 3vx0b4XPWkX8IxlowU6e36Cd/wNKIpCX4g+de++znJpUs5yYdMLYijcDIkSggg4j9NV+ JsQiq0bDan1AxjEWThfjmdA38cN7SNtxuWkEeZJyVA2TLMcmZPlQ3KQKLfgUhmveQyes P2IQ== 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=8ECamVGrenRrFvw0EKJFpRTvGkUBrF3jVsxmqTaUFNc=; b=Y7DDmViR9A1Ge4nXZK6z7bA+86+/qilTnM6rCguD7lpK8gl6yw6G3vJzemdHbGUqKk eham0dPlqj9sMokNpkpukySx2JvwaBWX6E4Yy2x9HP+hEys30C+MmL/fGCNKOE8H4g3X X9GreKMIqiO+fXYUNXUW8bMXxDQDAvRgpzOBRbLhfM5n8gfL1QH4MyyolBzQo4YPVsHE QysfONWygz29Ro97kHbkxYAE6y7GIgkI51KeBkDalbxX8e2EPxJwlxYF0q0V7cD5kpD7 JIFBc+Q0BXPGddyagvpORrrKTBnpJGUhQhBv4QON5GhX4EmDyBzF1ptye4KIwooyiqv1 UDeg== X-Gm-Message-State: APjAAAXJVUxym2Im7L3Jcab4HAU3xRlKGeCMzQ2G+MYqFFm4TefqX5Hu K9cgmalXjTFujasrVjh+jK41o0xz3qD6fR29 X-Received: by 2002:a5d:4992:: with SMTP id r18mr7274973wrq.107.1561163528517; Fri, 21 Jun 2019 17:32:08 -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.32.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 17:32:07 -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 23/30] crypto: talitos/des - switch to new verification routines Date: Sat, 22 Jun 2019 02:31:05 +0200 Message-Id: <20190622003112.31033-24-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/talitos.c | 33 +++++++------------- 1 file changed, 11 insertions(+), 22 deletions(-) -- 2.20.1 diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index c865f5d5eaba..ec759576ebd3 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -920,16 +920,11 @@ static int aead_des3_setkey(struct crypto_aead *authenc, if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE) goto badkey; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) + err = crypto_des3_ede_verify_key(crypto_aead_tfm(authenc), keys.enckey, + keys.enckeylen); + if (unlikely(err)) goto badkey; - flags = crypto_aead_get_flags(authenc); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(authenc, flags); - goto out; - } - if (ctx->keylen) dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); @@ -1538,14 +1533,11 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *cipher, static int ablkcipher_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; + int err; - if (unlikely(crypto_ablkcipher_get_flags(cipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) && - !des_ekey(tmp, key)) { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } + err = crypto_des_verify_key(crypto_ablkcipher_tfm(cipher), key, keylen); + if (unlikely(err)) + return err; return ablkcipher_setkey(cipher, key, keylen); } @@ -1553,15 +1545,12 @@ static int ablkcipher_des_setkey(struct crypto_ablkcipher *cipher, static int ablkcipher_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - 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, + keylen); + if (unlikely(err)) return err; - } return ablkcipher_setkey(cipher, key, keylen); }