From patchwork Thu Aug 15 09:00:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171401 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1917861ily; Thu, 15 Aug 2019 02:01:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwH+BNU24nuueoT0kJ93A2YYQdesdE1Z4zOsAVeRxtq05UxlVHlyeV9FacjNOTEWMLII93G X-Received: by 2002:aa7:90d4:: with SMTP id k20mr4230935pfk.78.1565859690154; Thu, 15 Aug 2019 02:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859690; cv=none; d=google.com; s=arc-20160816; b=b/v1ecSOnDVAvR4EIWkKhA7q0psuf3cjotHuPvrxHj/lDixCKLMtqepiIXKZi5OoHY 5sZyY751iyVdnT7I6YZRn+Swg/WFJ4TXaUG0oCI89GRylv60PD3jcCWDGoIoSQq7s6TV UFLAc36Ku8xcpmS7ZpLKB2dRuCARZ9LXBD4iiVYvtmJHDlSixq1t/bxwhV1LPUaH9RWE eI6IjBQUvN7tpQSHMwrth895qNotarwsWvGDUQKQJyFshENqDfk8qTzBotJH4tkVwMwK w+DIb/39IJvguCLq4kcHn0BWeO2SCSX3anRtU5XDhXLd4d7Uk6D0/mRil32nIhoIh++8 HcNQ== 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=3e2r3FOBL6j9iIvv8ejDaqbpez9yR+KjkK0z8y6sTy4=; b=hfLvFVhB+eC6QDQjSkfbSnWxTFZ6fV70lLLlmnxhQ/S5h6AhUlTkyIKhR+VXKjtaTl GWeyxD82RffZzkQH49L4E0QeaSQjQ7C9a6GmcxqYY3s6TTntoqR8VpFD2bbX75IJ46Bm uZr1NhD4EQk8WKyh/hz53qhfWlBpwuq+lwJ8IoqGEZHFfdHLaJVeLu6Ezb6hJQzmovPR jMpw+pc9XyaSLkQDokYTqEDIvQ9NkuiCcBjOur7HxoL/eLzskp5mU3giPRv3Wn9WVl1h Hiq0QXJ6Z1P63+MdaU+B4n9DOUQYja/SZdkrySLovThi9PZoBAtqqmbjJuKtVmZVhAau nAhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZBzs54Jx; 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.29; Thu, 15 Aug 2019 02:01:30 -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=ZBzs54Jx; 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 S1730781AbfHOJB3 (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:29 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37603 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730775AbfHOJB3 (ORCPT ); Thu, 15 Aug 2019 05:01:29 -0400 Received: by mail-wm1-f68.google.com with SMTP id z23so681722wmf.2 for ; Thu, 15 Aug 2019 02:01:26 -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=3e2r3FOBL6j9iIvv8ejDaqbpez9yR+KjkK0z8y6sTy4=; b=ZBzs54JxjasIE9zXkcHOSaxoSJtCfjasy9gTPfsbnUhNZ09AVgBcFEcpyEdGK55eTa DZbdcesQ5BY0S2ClFh87V435c2qBOYN2cZJI62iZxgC+bztejgShWAKviwsz2PpoHltC vYM/kU81U1TeE5FDmXMYKGsmsmlH9qMjyQgYoFsE2JAHLKswValBXAqVWIUI7+WWLFKx sifztdmq30Jw1b6Fcb4ac6Y7tr943srTqE69nsJCgvY0hGvCUPT92kyPSbD6RQfFjbEG c/9N5WkvgYdWlpFyI+iiZgzacEk8LFN1ZiltzBCPBV3PdwSTcoE2L9r8Y/bKUDgVlL1l smQg== 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=3e2r3FOBL6j9iIvv8ejDaqbpez9yR+KjkK0z8y6sTy4=; b=il8T5kJKEzSpQsJvU99e4jZ2v7erIN+cLvyAyDTIUEiYCXEzujoL9Ah8dC3ZhXncVT 30OmujU1Pqh4fW+5O68OkQz595s/p3XS7mGwIY7RSMNIHSHBnjUzf4fh2a/YY0voJtLQ TFDgtcWFYXHWyVmcAlBeBorOo00nM6bi+SMrAdeTODTh35vjtPhLfsxX9b60t7yWEXX+ BpGYmuWg08l46XnyWhLCCHBRpegCkcGEcn6YeQ7s78/7vc7gWnliNyM9xhqrDj+3Klpb OO1laK8QzgmjEIytBAj/WOGX5pwKB4vi0K+aBu5eLP5z+hT8NwACJ3DmbCWeWxvZExUx TOJQ== X-Gm-Message-State: APjAAAU2E2jbO9uTazmChEoL3X86MJ0hLwE6rrvjCZu+Ti+NCsFPVumE DfqLoRf7avTt6AcQAsS+3tHZJ+em6sQRyVxu X-Received: by 2002:a7b:ca54:: with SMTP id m20mr704720wml.102.1565859685962; Thu, 15 Aug 2019 02:01:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:25 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 01/30] crypto: des/3des_ede - add new helpers to verify keys Date: Thu, 15 Aug 2019 12:00:43 +0300 Message-Id: <20190815090112.9377-2-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 The recently added helper routine to perform key strength validation of triple DES keys is slightly inadequate, since it comes in two versions, neither of which are highly useful for anything other than skciphers (and many drivers still use the older blkcipher interfaces). So let's add a new helper and, considering that this is a helper function that is only intended to be used by crypto code itself, put it in a new des.h header under crypto/internal. While at it, implement a similar helper for single DES, so that we can start replacing the pattern of calling des_ekey() into a temp buffer that occurs in many drivers in drivers/crypto. Signed-off-by: Ard Biesheuvel --- crypto/des_generic.c | 13 -- include/crypto/internal/des.h | 141 ++++++++++++++++++++ 2 files changed, 141 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/crypto/des_generic.c b/crypto/des_generic.c index dc085514408a..c4d8ecda4ddf 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -841,19 +841,6 @@ static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) d[1] = cpu_to_le32(L); } -/* - * RFC2451: - * - * For DES-EDE3, there is no known need to reject weak or - * complementation keys. Any weakness is obviated by the use of - * multiple keys. - * - * However, if the first two or last two independent 64-bit keys are - * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the - * same as DES. Implementers MUST reject keys that exhibit this - * property. - * - */ int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, unsigned int keylen) { diff --git a/include/crypto/internal/des.h b/include/crypto/internal/des.h new file mode 100644 index 000000000000..f5d2e696522e --- /dev/null +++ b/include/crypto/internal/des.h @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * DES & Triple DES EDE key verification helpers + */ + +#ifndef __CRYPTO_INTERNAL_DES_H +#define __CRYPTO_INTERNAL_DES_H + +#include +#include +#include +#include +#include + +/** + * crypto_des_verify_key - Check whether a DES key is weak + * @tfm: the crypto algo + * @key: the key buffer + * + * Returns -EINVAL if the key is weak and the crypto TFM does not permit weak + * keys. Otherwise, 0 is returned. + * + * It is the job of the caller to ensure that the size of the key equals + * DES_KEY_SIZE. + */ +static inline int crypto_des_verify_key(struct crypto_tfm *tfm, const u8 *key) +{ + u32 tmp[DES_EXPKEY_WORDS]; + int err = 0; + + if (!(crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) + return 0; + + if (!des_ekey(tmp, key)) { + crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); + err = -EINVAL; + } + + memzero_explicit(tmp, sizeof(tmp)); + return err; +} + +/* + * RFC2451: + * + * For DES-EDE3, there is no known need to reject weak or + * complementation keys. Any weakness is obviated by the use of + * multiple keys. + * + * However, if the first two or last two independent 64-bit keys are + * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the + * same as DES. Implementers MUST reject keys that exhibit this + * property. + * + */ + +/** + * crypto_des3_ede_verify_key - Check whether a DES3-EDE key is weak + * @tfm: the crypto algo + * @key: the key buffer + * + * Returns -EINVAL if the key is weak and the crypto TFM does not permit weak + * keys or when running in FIPS mode. Otherwise, 0 is returned. Note that some + * keys are rejected in FIPS mode even if weak keys are permitted by the TFM + * flags. + * + * It is the job of the caller to ensure that the size of the key equals + * DES3_EDE_KEY_SIZE. + */ +static inline int crypto_des3_ede_verify_key(struct crypto_tfm *tfm, + const u8 *key) +{ + int err = -EINVAL; + u32 K[6]; + + memcpy(K, key, DES3_EDE_KEY_SIZE); + + if ((!((K[0] ^ K[2]) | (K[1] ^ K[3])) || + !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && + (fips_enabled || (crypto_tfm_get_flags(tfm) & + CRYPTO_TFM_REQ_FORBID_WEAK_KEYS))) + goto bad; + + if ((!((K[0] ^ K[4]) | (K[1] ^ K[5]))) && fips_enabled) + goto bad; + + err = 0; +out: + memzero_explicit(K, DES3_EDE_KEY_SIZE); + return err; + +bad: + crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); + goto out; +} + +static inline int verify_skcipher_des_key(struct crypto_skcipher *tfm, + const u8 *key) +{ + return crypto_des_verify_key(crypto_skcipher_tfm(tfm), key); +} + +static inline int verify_skcipher_des3_key(struct crypto_skcipher *tfm, + const u8 *key) +{ + return crypto_des3_ede_verify_key(crypto_skcipher_tfm(tfm), key); +} + +static inline int verify_ablkcipher_des_key(struct crypto_ablkcipher *tfm, + const u8 *key) +{ + return crypto_des_verify_key(crypto_ablkcipher_tfm(tfm), key); +} + +static inline int verify_ablkcipher_des3_key(struct crypto_ablkcipher *tfm, + const u8 *key) +{ + return crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(tfm), key); +} + +static inline int verify_aead_des_key(struct crypto_aead *tfm, const u8 *key, + int keylen) +{ + if (keylen != DES_KEY_SIZE) { + crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); + return -EINVAL; + } + return crypto_des_verify_key(crypto_aead_tfm(tfm), key); +} + +static inline int verify_aead_des3_key(struct crypto_aead *tfm, const u8 *key, + int keylen) +{ + if (keylen != DES3_EDE_KEY_SIZE) { + crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); + return -EINVAL; + } + return crypto_des3_ede_verify_key(crypto_aead_tfm(tfm), key); +} + +#endif /* __CRYPTO_INTERNAL_DES_H */ From patchwork Thu Aug 15 09:00:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171402 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1917867ily; Thu, 15 Aug 2019 02:01:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDaC0W2vHCwZpLSPRI1j3XtoOa8YQXKlVa8Bx76kI9y4oiQZF8o68ZvWtejmvJdYQToJAb X-Received: by 2002:a17:90a:a78b:: with SMTP id f11mr1339701pjq.16.1565859690446; Thu, 15 Aug 2019 02:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859690; cv=none; d=google.com; s=arc-20160816; b=I60oLEw0MKNxkdYfMSqL1qo6wVoLmnWR7EqoFMUMqSSVmTOtZYBHjc2YJO0ys3AXNW fUcEUjjtDOFrpmrluHGwNyw5+2K86cYqbi9k0+/7qRLd6ixWaXblkoKTD6YrRh6dXjvS 8PH1/I//G9RH2Gu6jNdkAH0bcT3oYhqPhmPlqxbhtyG42MjXtqIWecQvOAkeKwVbvDYI HUiJgxJhG/2Tr39+kNY3B7rFQbKt3mGXAOnREhuTmTTQrtOzAhhHFpoP8uptrIhKHkc1 NxQBrVWJ3s916UySJnhljccybd9I0ghqNknuR+2/H0w01IMQTUFHiGA7gnI3+T28JYtw khhw== 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=ODcjsTe5qXMA4WZkrKmlnC58iAmLOZMMRVocLXEZvzE=; b=vYvWfFWU/rkUox3tZ8NZPeHCxtsopSYIqrey0UqPakq2PVkp0y8h3lAPSDVnrYcksT DcIWSgULNXfSvO6goVZu3YG+2PlyEQX8Za+3pPwdbid+VEk/T6TPWkocIlfHOyhjgbzk PyBaJllX4Tr7SVQZPAdADWhp/XAvF9DuR4VfCPnedQ//e4cioj3qoXpRh4330Vkz/cA3 G/WwbG12/DN+Sjd7DE9Noe3JaxYRGBj8nQ2fvZ8Vww/0vwEO/RANS4ALz8oteVACJdDU NJ/IrW8lUkQbwue+mWLtHo+Xz9rIXDy+YkgfvYv3R3WqPt3jPO0MrmihcC/H8eNRHWQ7 Zn3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VcaU+n5R; 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.30; Thu, 15 Aug 2019 02:01:30 -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=VcaU+n5R; 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 S1730783AbfHOJB3 (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:29 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37392 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730774AbfHOJB3 (ORCPT ); Thu, 15 Aug 2019 05:01:29 -0400 Received: by mail-wr1-f65.google.com with SMTP id z11so1597247wrt.4 for ; Thu, 15 Aug 2019 02:01:28 -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=ODcjsTe5qXMA4WZkrKmlnC58iAmLOZMMRVocLXEZvzE=; b=VcaU+n5RpAF30HGVzg5qX7yBeDSBRiw6u9nrkKRw6HWgzWlFzEnHeJSyETvJ5lEkHp g1EEIooQdPq9I+jp3Id39fnyH5Lk7yrtCvLX+xA/OryirnlvSHvMW+lDPrnNXhpcNRHk Rbygt55ncquhe1aQn0izmdfcgXNZ/6wx6XJM618QD/FNZwlAYVDTm9ulRub1Eg84fUlu 9WCewfW3ZP2a/5rivLVrY3D3ioy79LOnMDCvfdSlQQ8Ge/OKr8SDyQCBWlB7bOFnHV2n GsP26IgsFcoqyirG1cgDoGP/mlNzfkZIH4dzTpF0Mxmub1G8AjkR2aIZdeWgnJBkscu6 4iKQ== 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=ODcjsTe5qXMA4WZkrKmlnC58iAmLOZMMRVocLXEZvzE=; b=KA5QOqfL/Y+293CpKyudcrWRHQMIQRZy2HlyfI70DaQf2h3cBACFint7TxppVkwNdI hjnD6EHHSU5DbmVFV4wec50NVSH2ERs+ig5jW+05cN1kyReVmiNdlKux1E42QrjOwUhJ 8OCbPNHfEoeu3xNaAyZxqnHrmD6W2fXe2B/OjYnXh5Q5YAQmeiToCo+Z0HugqsLgm6Ko wGILdZIutfHwzFtK3MTlRpR1Vhl5Rx3foX0IpSXLsYcrPrvnWf0xn9NSAGBoFzMfW+LA Fj66h53t3VxqkslWk+D3JznR3yWPJQudlpiK8WphvwEGmbFtxL4/jTdVnq2eQR3CBcKP ORAg== X-Gm-Message-State: APjAAAU4v6dIe06OCDY83C9sUi3CtGpNQG04jtsNHldo6NalXZQfmQ7W rSqwwKbnPHybKcI+45LyEZyBamEQ1eDdJR2r X-Received: by 2002:adf:fc81:: with SMTP id g1mr4242015wrr.78.1565859687305; Thu, 15 Aug 2019 02:01:27 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:26 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 02/30] crypto: s390/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:44 +0300 Message-Id: <20190815090112.9377-3-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 Switch to the refactored DES key verification routines. While at it, rename the DES encrypt/decrypt routines so they will not conflict with the DES library later on. Reviewed-by: Harald Freudenberger Signed-off-by: Ard Biesheuvel --- arch/s390/crypto/des_s390.c | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index 374b42fc7637..439b100c6f2e 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #define DES3_KEY_SIZE (3 * DES_KEY_SIZE) @@ -35,27 +35,24 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len) { struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; + int err; - /* check for weak keys */ - if (!des_ekey(tmp, key) && - (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + err = crypto_des_verify_key(tfm, key); + if (err) + return err; memcpy(ctx->key, key, key_len); return 0; } -static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) +static void s390_des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE); } -static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) +static void s390_des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) { struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); @@ -76,8 +73,8 @@ static struct crypto_alg des_alg = { .cia_min_keysize = DES_KEY_SIZE, .cia_max_keysize = DES_KEY_SIZE, .cia_setkey = des_setkey, - .cia_encrypt = des_encrypt, - .cia_decrypt = des_decrypt, + .cia_encrypt = s390_des_encrypt, + .cia_decrypt = s390_des_decrypt, } } }; @@ -227,8 +224,8 @@ static int des3_setkey(struct crypto_tfm *tfm, const u8 *key, struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); int err; - err = __des3_verify_key(&tfm->crt_flags, key); - if (unlikely(err)) + err = crypto_des3_ede_verify_key(tfm, key); + if (err) return err; memcpy(ctx->key, key, key_len); From patchwork Thu Aug 15 09:00:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171403 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1917898ily; Thu, 15 Aug 2019 02:01:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMJfdAnC7SrZ8vCR3C2BHT0c9FEO6tMwRoZthVTaIxZmTPJ/xt5YmoHvt3HvAmfy/wcp84 X-Received: by 2002:aa7:9ab8:: with SMTP id x24mr4282300pfi.98.1565859692466; Thu, 15 Aug 2019 02:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859692; cv=none; d=google.com; s=arc-20160816; b=LGftlA90F5fOmSsIApN+NAVH2SSEOyg3LBZnGGvOn0bTFbVOpSdvjI8SfBF/qs8ZNW /K9mr798lx94vdVKM9Gd4APFoi3tKMoGOoH2eItMNvr4K7q0W2Xi6qCEhA9IwMp8fgge g8TCLgHy+zmqB53RTtvJNyYZz7pUFACOePnBZeNLfo5+Q1PJJ9pq9E3lgcGUgzijcN6U /HhYKMx4tq7ETxucg1Rx0qBSd8hWtnRsz7A2fBbzsGvZXYvS3Rp+g3zaO2jkHPxcyR/m X5MyFFG8RLgmWvO2aKmzWXNMm63sF/MDm+x7w2MesyxT8u2+djYMc0H8yURsK39sfz8c jkOw== 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=Er+86N+2cIZoohxTF9t6iACtueSxaqn6lRZ33S62JII=; b=zfbcgBU87qkFf1PBUdXIvQPcF9jvqtRIwKanK63rxfGqJs5PBX1ueH80ZxH90rUJ2C dz7wO7OBbDwGq0XV9o4Y5VffpFHL1gf9dtFOfw9Mf4a8Z19w3Bd0r5HsAx7xJh2Kl6G/ NnKa+PecalewNEO2YsL9b78d9i9sKUQOEmKfBz1T3y93ry62s66btSbm13h0JD1fkyhs vXSG3W6leZCqkwgbtChz70E9gWmEoT81YyPQDQzHGJ72rnUSZlsdiYiVAn9x8TlR+kHF 9XbQQ+EtdZmsdn60jd/IG3EDySfo7KzOWAxHCd+Ki+u2h2WjxwEgL0w15DIy3TqjViDH Ln2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kwL3DwGm; 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.32; Thu, 15 Aug 2019 02:01:32 -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=kwL3DwGm; 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 S1730787AbfHOJBb (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:31 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39189 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730775AbfHOJBb (ORCPT ); Thu, 15 Aug 2019 05:01:31 -0400 Received: by mail-wm1-f67.google.com with SMTP id i63so676043wmg.4 for ; Thu, 15 Aug 2019 02:01:29 -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=Er+86N+2cIZoohxTF9t6iACtueSxaqn6lRZ33S62JII=; b=kwL3DwGmEiYfTPsqBIEpCPTFvQxO2oS+c5ZwwQKE/bi1v9nndMErM3vAXZ15Ndaa/x w69jA9loiu+jMhVHiXkLG00NPXsZznelGbaAYp0n+cvFED3p5wFw/5J9Aod73/V9tyYD U2wbmC6Z2TQziCK9+LzDNaG7u4FIzroRIg+lzmEK607L8FfPnqWwSC6YJU0eVlTlPZZI 5Doq+YOYJ8OyOqokdd/6J2fUGgB51vvdvT0IazwKM0L9/HU0cS9EaMgl+80ZHb432OzV u7nGAtQu8qdc9R4xqG0COuFVvd0xYNRWQOBWZh2U9hPX9MVo53IsTm6QSX1Wz1yBoI4R PXTA== 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=Er+86N+2cIZoohxTF9t6iACtueSxaqn6lRZ33S62JII=; b=UOMfOQPDeuQDpti70AlaBA/SFvGB8hVJlIeaxh05kI6yQOT4zzFZsLAFB3T1nwg6iI bS5uUmQPoXMHZLBkAiF3Y+B76g/rMoAeYE9mpz0HYpBtnHS6FaXbAL8vriJaCM8N/P0c njJeGEpUo1iPsXZH2Y8shclar2Ow704RJuMr9kL5VJkNObjVoqMTq3GmrpyHYA0Iparl nwN1j6FNFt7uIWpyKybO9Nx7sG1hakB7tfvBu6aqHcj7aiym44Zg41v7+tSXeaPG+35f 9NzruIuHZKyRbCOeCeEXooPZK6lXVcr7M+3JoH2ZnBWWTsMbQNk9az/tOw8Ba+UTnql6 3K5Q== X-Gm-Message-State: APjAAAWIz7JK/WzIIUjKb5xtWie+B8ICisuUrALRC2z0p8VuZMl55gz7 cOc57iyIbJr9u7DLecq7tu7TA96HUFNduMC6 X-Received: by 2002:a7b:c157:: with SMTP id z23mr1696307wmi.104.1565859688695; Thu, 15 Aug 2019 02:01:28 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:28 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 03/30] crypto: sparc/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:45 +0300 Message-Id: <20190815090112.9377-4-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 Switch to the refactored DES key verification routines. While at it, rename the DES encrypt/decrypt routines so they will not conflict with the DES library later on. Signed-off-by: Ard Biesheuvel --- arch/sparc/crypto/des_glue.c | 37 +++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/arch/sparc/crypto/des_glue.c b/arch/sparc/crypto/des_glue.c index 281448f72c90..db6010b4e52e 100644 --- a/arch/sparc/crypto/des_glue.c +++ b/arch/sparc/crypto/des_glue.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -45,19 +45,15 @@ static int des_set_key(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; - u32 tmp[DES_EXPKEY_WORDS]; - int ret; + int err; /* Even though we have special instructions for key expansion, - * we call des_ekey() so that we don't have to write our own + * we call des_verify_key() so that we don't have to write our own * weak key detection code. */ - ret = des_ekey(tmp, key); - if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + err = crypto_des_verify_key(tfm, key); + if (err) + return err; des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]); encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]); @@ -68,7 +64,7 @@ static int des_set_key(struct crypto_tfm *tfm, const u8 *key, extern void des_sparc64_crypt(const u64 *key, const u64 *input, u64 *output); -static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); const u64 *K = ctx->encrypt_expkey; @@ -76,7 +72,7 @@ static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); } -static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); const u64 *K = ctx->decrypt_expkey; @@ -202,14 +198,13 @@ static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; u64 k1[DES_EXPKEY_WORDS / 2]; u64 k2[DES_EXPKEY_WORDS / 2]; u64 k3[DES_EXPKEY_WORDS / 2]; int err; - err = __des3_verify_key(flags, key); - if (unlikely(err)) + err = crypto_des3_ede_verify_key(tfm, key); + if (err) return err; des_sparc64_key_expand((const u32 *)key, k1); @@ -235,7 +230,7 @@ static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key, extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input, u64 *output); -static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); const u64 *K = ctx->encrypt_expkey; @@ -243,7 +238,7 @@ static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); } -static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); const u64 *K = ctx->decrypt_expkey; @@ -390,8 +385,8 @@ static struct crypto_alg algs[] = { { .cia_min_keysize = DES_KEY_SIZE, .cia_max_keysize = DES_KEY_SIZE, .cia_setkey = des_set_key, - .cia_encrypt = des_encrypt, - .cia_decrypt = des_decrypt + .cia_encrypt = sparc_des_encrypt, + .cia_decrypt = sparc_des_decrypt } } }, { @@ -447,8 +442,8 @@ static struct crypto_alg algs[] = { { .cia_min_keysize = DES3_EDE_KEY_SIZE, .cia_max_keysize = DES3_EDE_KEY_SIZE, .cia_setkey = des3_ede_set_key, - .cia_encrypt = des3_ede_encrypt, - .cia_decrypt = des3_ede_decrypt + .cia_encrypt = sparc_des3_ede_encrypt, + .cia_decrypt = sparc_des3_ede_decrypt } } }, { From patchwork Thu Aug 15 09:00:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171404 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1917918ily; Thu, 15 Aug 2019 02:01:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwO7zFj1+lpSkMvp7zKpUfzdr7ItxZCg7Qpe1NfKaPxCr+e7HtDAjBKoYi1FS4UcdmmDLHE X-Received: by 2002:a63:c84d:: with SMTP id l13mr2728718pgi.154.1565859694046; Thu, 15 Aug 2019 02:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859694; cv=none; d=google.com; s=arc-20160816; b=OKI2KqTIkQ35rAv4pfiNZeoiGmV4JOvOGxJ1W9o2a/Wnf0ylkSs4gItAx5yoh4pGFZ uC766j4LIjMw9mkUJKfLGhs5UecZP2nlvjfD7R5lOl80reHeAiO97c3i0vXoUrPmjSOm AYTWUwdT8bRD+sbFRBD1fxl5hsScnBhUqZI5vL1yhaDDLYr47VDj0+2OfZTrqy7aFS4v O5WHaln7MoeiJKySC2evaKzMhUQkqvzM0ONskkM7eyeoT5v54E+ipK243jaBbOp6BqGI zBmhDxmC5mj6FpMMlugziRSlYf4DcpFDItM3UxXWfn+OzFgs7a96msGMWNeI7MTXJJne tJgQ== 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=rdyePxh79O5cxOEfR+t7TLBYxhR+49UWEAWghHr6ZEw=; b=Tmc6Bkh0jgKGRUdq87z5Kooqh6hI9AP2xHgYHDx63S22ujy/AIkQAyfEtadgjgyn0x lQmQ/JjrX4Vhbzp8ulNXut2UN/VORsEmHeRyNYwsUlSnDzlfY58sLjG3TbOuTO0ucHLN yauL8mHTgTqDZ9Md+cA+RnxzU+Ac/YqOpFub+wKmg2A5ndMbg+2ZPLGLdYOkfVEDoVsF oLgz5blXUWwsIXdCmnqhIhdG4v2F6ndUADSitcOPqEmEV9/Q2IXalLZueEIfF0mEEKWZ 4JTMUto1ozZwwGAbz2ZUHSUYIdVuhKNar8Qnw8Ey8/QzdocqbZQeJFh9Nn4wWMox4gar dZcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rVFgaPdx; 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.33; Thu, 15 Aug 2019 02:01:34 -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=rVFgaPdx; 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 S1730789AbfHOJBd (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:33 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36272 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730786AbfHOJBd (ORCPT ); Thu, 15 Aug 2019 05:01:33 -0400 Received: by mail-wr1-f67.google.com with SMTP id r3so1598039wrt.3 for ; Thu, 15 Aug 2019 02:01:31 -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=rdyePxh79O5cxOEfR+t7TLBYxhR+49UWEAWghHr6ZEw=; b=rVFgaPdx5jR/vH2Y8Q+hpDquwPjUatdPmd33Q88NnIHRtzOZY/gradDoPlbaaJzJkq Yxwfaw7I0NP3F3a3t37wwcQr6mpHX3xeL+dpakXYILjmRXYhjfPNX0ma/j2Wt+Fc5v1L jaJhYD09MFAtVBwuxByo/AoIgcO7E7PELP8yeziMJDTGRv63aiftpJX+QHdL7XHHPB46 FK5csTBPvtt5hBa3qAV4lm913/SX0RIkQrRLIAWKxH9o+zdtEoRpA0XR2wNI2Hls/qvj MeMKe29BH68imRAF1uPrCqAPGC++jM2gxO2NNolaMvF9vRtbTVhCiPtyguFLUtZ2Ee/x qJSw== 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=rdyePxh79O5cxOEfR+t7TLBYxhR+49UWEAWghHr6ZEw=; b=LGWjDHPZUrjfD45V3PeHot6GJ/+X529cYKHdaJT7dCpIieHYostPHgNLSqtBN0rDNG FcV6RCczdEBZ6bTo5fU96/ofnnhXE4qVxvP2aB7fNcQshM3DBaI9rihEy+hRmiui3OUc FKpiROV9fbyw+Zb9Gvk8VyQxVLI0AOvNcS8DCp4i88LQ6blaac9Ko+kA1RpkE6nNEGkH xyDgDYblspgMDHLF7Ll3x5ZuY2gmvP4KauNh358/zjf1Kt8/2qEJbctrC9fAChQQbsUk pHpMGOH/azA8ppl+M3JmYT/NoPTm8Hn4j2aotT7zOHjCQ2FJWXVpi5D8/iI549JmlvW8 f1AA== X-Gm-Message-State: APjAAAWqNBpJNhYi/AjCWPB3Xjjid6+2eVfWpiPBFVs8QeQFIMmR7jyi UHCRsMM1l7HlfHi6z0OW9rZBIFxfPnkKQsB1 X-Received: by 2002:adf:dc03:: with SMTP id t3mr4127450wri.80.1565859690772; Thu, 15 Aug 2019 02:01:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:29 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 04/30] crypto: atmel/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:46 +0300 Message-Id: <20190815090112.9377-5-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/atmel-tdes.c | 28 +++++--------------- 1 file changed, 7 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c index 6256883a89ed..1a6c86ae6148 100644 --- a/drivers/crypto/atmel-tdes.c +++ b/drivers/crypto/atmel-tdes.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -773,22 +773,12 @@ static void atmel_tdes_dma_cleanup(struct atmel_tdes_dev *dd) static int atmel_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; - int err; - struct crypto_tfm *ctfm = crypto_ablkcipher_tfm(tfm); - struct atmel_tdes_ctx *ctx = crypto_ablkcipher_ctx(tfm); + int err; - if (keylen != DES_KEY_SIZE) { - crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } - - err = des_ekey(tmp, key); - if (err == 0 && (ctfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - ctfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + err = verify_ablkcipher_des_key(tfm, key); + if (err) + return err; memcpy(ctx->key, key, keylen); ctx->keylen = keylen; @@ -800,15 +790,11 @@ static int atmel_tdes_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen) { struct atmel_tdes_ctx *ctx = crypto_ablkcipher_ctx(tfm); - 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); + err = verify_ablkcipher_des3_key(tfm, key); + if (err) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen; From patchwork Thu Aug 15 09:00:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171405 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1917958ily; Thu, 15 Aug 2019 02:01:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4yOVhyEK8Id3MZVqAcltAhuqPB7kFxTAO/O53iM2kM9clBYLQsloO+1hge/3PFwhUHfMB X-Received: by 2002:a63:c44c:: with SMTP id m12mr2651668pgg.396.1565859696064; Thu, 15 Aug 2019 02:01:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859696; cv=none; d=google.com; s=arc-20160816; b=uA2OiJwTv1pJBhm21i0mVeE3lkwBwYfVKOb49Dtfhq2nl3IdpGfvlNFJd0ac0Qogxn o0vhlGFF5Wej0+7ckgbYsrcK5eJ9kAxDwpY7JY5x7ovjhqZ2An1tJze8lsru6d3sLEK6 LNj4i1Lzy0/Hnt/JozCMbYRcyuRppcYVzKhrITc+nl+c5TFeZMfJDSNi6TLhbZNODoP2 F0dz8OziRHdKK1SYaXD6Tg54QPOvmd2pCyFtnMu3JtGq9B9F0hJ8hv48nVYs3Qm38t1A 4hYJL5YdhGWpoAMka5/5ktRcpnWzXBRdrSDz1u4eBgKoNOkcDlzP+hD7J+zu1LJeq+15 0TlA== 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=ycLlab3IQyS0WLy8fOsxcrFStN9eKVE/xTtX4RGLwls=; b=wLB+Mu+x5QxJg3gQgHyvgCflrWk2M1mr4njkJfLhZ/sG3FX25U+AvBbxWlQd0pySPa yMFYFlzECiRYnqA97qRSJwAS6Znk6Q4g/Kj3+GcqtcRu3XnYPUnRaF75EK+TCU44DGi+ KCHxN4w6dgw/r1RhSaXYZU1fZ5AgseesC5Ri5fX+IhVjqN2D5Fk6y02JUYg6VhmoVATD NXtYv6GWw5Z97IQsSbKZztTHfwROp1dq12VBiQJAOXwwaUqCv+GjFjd4unx1zQ/dVqXT Rl8meiAV7X59Y0SCoRIIeGeu/oSq2+BqNbZ+tcdEztlsmS/gECIMNo9fwfh7q3Nof5Nm vJSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zOPR7zma; 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.35; Thu, 15 Aug 2019 02:01:36 -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=zOPR7zma; 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 S1730792AbfHOJBf (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:35 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40035 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730786AbfHOJBf (ORCPT ); Thu, 15 Aug 2019 05:01:35 -0400 Received: by mail-wm1-f65.google.com with SMTP id v19so673711wmj.5 for ; Thu, 15 Aug 2019 02:01:33 -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=ycLlab3IQyS0WLy8fOsxcrFStN9eKVE/xTtX4RGLwls=; b=zOPR7zmazEa3IlB5ICwrAAJAzqjQnvWGCJzPRaHG1yS4f4yYE6+qn7GV+md6T1dOQ6 surM/TQNDSoPZgvf80fM5q7AMOVwumM+lJAREEtmyhfIG63GJmaSQZHLfmpv6rBHDyX5 STQAPWuTHG5pQb3RLMzJoxbHGA7ukO7wa32pnl9HNx7lsVnHHSyUN6OLWxnsccoLehSv T1ZYIyXowVYHLoToTPmYU9PZYO7zeyU6dvBhJM663YeCoiPoIzD3t9Czvz/m4qRbKmtk eURFvlIt9bF4umuhXKXavrgMCVLjCFidx3jIHNXE4v6Fnsq4ZsQu90j8EUUKqt11vZ9l T3qg== 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=ycLlab3IQyS0WLy8fOsxcrFStN9eKVE/xTtX4RGLwls=; b=JOicpdksfkvmtIOh2wWqeLd3qzuUUWW6GSSXJCMuFzGqtul7JtCLp/ZYjtDwIBjKnB Y7zbrtIkuVuQ4gByOsgxE86q8ZetkzHsecJClxAzO630deC2yucIO2JnaKq/fobe83Gr jVPiAlhLRkm3WZM+g38enjsY5mRHYlNRb5jQOmPWWrYi7T/EQsQX9oYLf2js5Gib6USZ 4sj1TSZ8krIVr00yTxW7KKwVZKyDaYlLen8LTo06qlxMfnU0BCT1ffmTUz2Dh4LRvqZh nOnDnPxajqXzx0z2Xc/JM3tDs1+l/IDmcFZ741T8MRD3Tow6KV2X2lwH85BKKfCnHauD XVEw== X-Gm-Message-State: APjAAAX8LoEGiogZJvN7a1yP/aSySyOg4BRXITnfehiIjjVVJgorORZf KhmFOpcrPuldbWxs3Z7r+6iQKsDZwVbbzZTp X-Received: by 2002:a1c:a852:: with SMTP id r79mr1640031wme.36.1565859692936; Thu, 15 Aug 2019 02:01:32 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:32 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 05/30] crypto: bcm/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:47 +0300 Message-Id: <20190815090112.9377-6-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/bcm/cipher.c | 79 +++++--------------- 1 file changed, 17 insertions(+), 62 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c index 1c23e452700b..f85356a48e7e 100644 --- a/drivers/crypto/bcm/cipher.c +++ b/drivers/crypto/bcm/cipher.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -1802,24 +1802,13 @@ static int des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher); - u32 tmp[DES_EXPKEY_WORDS]; - - if (keylen == DES_KEY_SIZE) { - if (des_ekey(tmp, key) == 0) { - if (crypto_ablkcipher_get_flags(cipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) { - u32 flags = CRYPTO_TFM_RES_WEAK_KEY; + int err; - crypto_ablkcipher_set_flags(cipher, flags); - return -EINVAL; - } - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; - ctx->cipher_type = CIPHER_TYPE_DES; - } else { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } + ctx->cipher_type = CIPHER_TYPE_DES; return 0; } @@ -1827,23 +1816,13 @@ static int threedes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct iproc_ctx_s *ctx = crypto_ablkcipher_ctx(cipher); + int err; - if (keylen == (DES_KEY_SIZE * 3)) { - u32 flags; - int ret; - - flags = crypto_ablkcipher_get_flags(cipher); - ret = __des3_verify_key(&flags, key); - if (unlikely(ret)) { - crypto_ablkcipher_set_flags(cipher, flags); - return ret; - } + err = verify_ablkcipher_des3_key(cipher, key); + if (err) + return err; - ctx->cipher_type = CIPHER_TYPE_3DES; - } else { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } + ctx->cipher_type = CIPHER_TYPE_3DES; return 0; } @@ -2868,40 +2847,16 @@ static int aead_authenc_setkey(struct crypto_aead *cipher, switch (ctx->alg->cipher_info.alg) { case CIPHER_ALG_DES: - if (ctx->enckeylen == DES_KEY_SIZE) { - u32 tmp[DES_EXPKEY_WORDS]; - u32 flags = CRYPTO_TFM_RES_WEAK_KEY; - - if (des_ekey(tmp, keys.enckey) == 0) { - if (crypto_aead_get_flags(cipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) { - crypto_aead_set_flags(cipher, flags); - return -EINVAL; - } - } + if (verify_aead_des_key(cipher, keys.enckey, keys.enckeylen)) + return -EINVAL; - ctx->cipher_type = CIPHER_TYPE_DES; - } else { - goto badkey; - } + ctx->cipher_type = CIPHER_TYPE_DES; break; case CIPHER_ALG_3DES: - if (ctx->enckeylen == (DES_KEY_SIZE * 3)) { - u32 flags; - - flags = crypto_aead_get_flags(cipher); - ret = __des3_verify_key(&flags, keys.enckey); - if (unlikely(ret)) { - crypto_aead_set_flags(cipher, flags); - return ret; - } - - ctx->cipher_type = CIPHER_TYPE_3DES; - } else { - crypto_aead_set_flags(cipher, - CRYPTO_TFM_RES_BAD_KEY_LEN); + if (verify_aead_des3_key(cipher, keys.enckey, keys.enckeylen)) return -EINVAL; - } + + ctx->cipher_type = CIPHER_TYPE_3DES; break; case CIPHER_ALG_AES: switch (ctx->enckeylen) { From patchwork Thu Aug 15 09:00:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171406 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918002ily; Thu, 15 Aug 2019 02:01:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTrs25CMQp3w//gXjSHG09RL2U3DNue+H8CZv2IaCwHghdATB6mNys083d1DKC5zSnYao9 X-Received: by 2002:a17:90a:be06:: with SMTP id a6mr1309851pjs.92.1565859699874; Thu, 15 Aug 2019 02:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859699; cv=none; d=google.com; s=arc-20160816; b=J+wNAXLY05OVzVUXY4A22nHiUKwiZluCO7uAtJ8I54v4FfN+7HQb9/tkpHfiY/IcDH NuE8kWQz5gfjLMMmG6tRBj85S1ets8qk8hdhPmBWu/atITbrs41b6xbvXTul0j8xlU5h dVPC6iN7bQmmIReXZy7issgU1ntcq1uzUkb5YiOlfZyxsdJ/rg0xTzjQFeFTudHEVjg9 SJ7gtYOszdVRo/lnBE7q/eXGqSFZ+D1HRLs0XaKwv3lFBfwpLwYFT3SxjnFJtqiGv9pU nUFBUBFTHtjFkGeRmumVI3KQwulpZw5vJJ0M2FcxNpr8YVza5+IhPfFXcRCu7x0RYZiO VgWQ== 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=OyPLTRp7SD/P3UDM/yCJek9q3VCge2ponsh/WCLUGJA=; b=fUcU9irKcOduucghNDUST+5xrrVDxVN3e4RaOsikE6Ksvt/PFX5zek2Ar8jGSrqMuX 63LhkKSdS1CpbjRFl8cOi4ClevvLDYF2ZY+TS3x7x9B0ac51rifQ/8nozVL/ED+ktRte FOa8N/L2XFnulag73LKWQdafHsUn1iH8JHeKBFpsBBXn1Akl4QvgiYs/jUsX6KJzFvsl yqKY0v8r0/qLrgxljB+jbnAS3xiLUnPbTsJudMTPPcWYUYkNvig6C9ueH+OQtDEhetSG C5i91PfVkw4oZ7YeG/6Xv4ArmQb8XzbpKdnmrJfDT5AnowcHDH1fy/rJ3/YhIxV5AkMc RUWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H3SVR/0O"; 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.39; Thu, 15 Aug 2019 02:01:39 -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="H3SVR/0O"; 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 S1730768AbfHOJBj (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:39 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54480 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730786AbfHOJBi (ORCPT ); Thu, 15 Aug 2019 05:01:38 -0400 Received: by mail-wm1-f68.google.com with SMTP id p74so676850wme.4 for ; Thu, 15 Aug 2019 02:01:36 -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=OyPLTRp7SD/P3UDM/yCJek9q3VCge2ponsh/WCLUGJA=; b=H3SVR/0OmMet5MikolGAKkVhKuOiI6R7SSRrG8Gh7zx1Z3hYadvOh1rWVJnPl2yBvf TyxDYATF+BNU3D/OnGzkgnIvKVb/XNCbswWQ6q091Aj4s4IOjB/zPdDOpkVtU1QSotOU TIHF99l3Z1bndtSSgy3UDAUUJ4w8HsnHsoHc9HfngC6QPIxslP6ZG3mxgDQmSJ3C7jdZ 8E2f5Uvdaiwi9ShRXfh5Al0+qrH0Iz27aXHmFE0xtRcmNRLb1ubNGIL7A3Sby7/Z/zwk ogjLaKEk5LVvzh+Bx0sVWbujEAKtVz3ZMemFPhBbtTqkiCu2DGuqOX+hIpBJpNlxs0qw xw4A== 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=OyPLTRp7SD/P3UDM/yCJek9q3VCge2ponsh/WCLUGJA=; b=QrljstHgscUgXuuPZlXuj29GMuIT+rckkXy0Y6U9I6hq0LvMzI8VbOB/+WzJm3cZXi ZiP0Md7ZdYTevFe9m/BQPLnnwgrxiThizwZUpDCmv0foDkjepQ1xwBBPqbFLB2HP3Drp Bb7h/eJaNx71z06p8T5mjwjdEiw9mp+5rk0vdbr30KzfxCtswc0uYvWrW3jZYrvMf28a qm9StrxLsAfyzbsnt8hU7Es0Exi7eI17jSR9Dg7YZCmIvhF7gTs3DiBvJSl6g7ObnkSg PjeWordKvReHmsG2OG6PKGjY+oKVTytKQct84z7sCnkbHqubYwZmmPcaaawVQyLzDIWk Y6+A== X-Gm-Message-State: APjAAAUhJZCxfYU3w7faV6NG9NxXe/X/8kxCH/qcDJ+Btt/ZCXurfWmY yYFg3VQYBLzzEsut54lMk5XMBdVIWblj6Vca X-Received: by 2002:a7b:ca54:: with SMTP id m20mr705434wml.102.1565859695217; Thu, 15 Aug 2019 02:01:35 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:34 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Horia Geanta Subject: [PATCH v5 06/30] crypto: caam/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:48 +0300 Message-Id: <20190815090112.9377-7-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 Cc: Horia Geanta Signed-off-by: Ard Biesheuvel --- drivers/crypto/caam/caamalg.c | 49 ++++++-------------- drivers/crypto/caam/caamalg_qi.c | 36 +++----------- drivers/crypto/caam/caamalg_qi2.c | 36 +++++--------- drivers/crypto/caam/compat.h | 2 +- 4 files changed, 31 insertions(+), 92 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 947ba8ef487a..3e2662cda9fd 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -628,33 +628,17 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_authenc_keys keys; - u32 flags; int err; err = crypto_authenc_extractkeys(&keys, key, keylen); if (unlikely(err)) - goto badkey; - - err = -EINVAL; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; - - flags = crypto_aead_get_flags(aead); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(aead, flags); - goto out; - } + return err; - err = aead_setkey(aead, key, keylen); + err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?: + aead_setkey(aead, key, keylen); -out: memzero_explicit(&keys, sizeof(keys)); return err; - -badkey: - crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); - goto out; } static int gcm_setkey(struct crypto_aead *aead, @@ -843,22 +827,15 @@ static int arc4_skcipher_setkey(struct crypto_skcipher *skcipher, static int des_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen) { - u32 tmp[DES3_EDE_EXPKEY_WORDS]; - struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher); - - if (keylen == DES3_EDE_KEY_SIZE && - __des3_ede_setkey(tmp, &tfm->crt_flags, key, DES3_EDE_KEY_SIZE)) { - return -EINVAL; - } - - if (!des_ekey(tmp, key) && (crypto_skcipher_get_flags(skcipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - crypto_skcipher_set_flags(skcipher, - CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } + return verify_skcipher_des_key(skcipher, key) ?: + skcipher_setkey(skcipher, key, keylen, 0); +} - return skcipher_setkey(skcipher, key, keylen, 0); +static int des3_skcipher_setkey(struct crypto_skcipher *skcipher, + const u8 *key, unsigned int keylen) +{ + return verify_skcipher_des3_key(skcipher, key) ?: + skcipher_setkey(skcipher, key, keylen, 0); } static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, @@ -1954,7 +1931,7 @@ static struct caam_skcipher_alg driver_algs[] = { .cra_driver_name = "cbc-3des-caam", .cra_blocksize = DES3_EDE_BLOCK_SIZE, }, - .setkey = des_skcipher_setkey, + .setkey = des3_skcipher_setkey, .encrypt = skcipher_encrypt, .decrypt = skcipher_decrypt, .min_keysize = DES3_EDE_KEY_SIZE, @@ -2073,7 +2050,7 @@ static struct caam_skcipher_alg driver_algs[] = { .cra_driver_name = "ecb-des3-caam", .cra_blocksize = DES3_EDE_BLOCK_SIZE, }, - .setkey = des_skcipher_setkey, + .setkey = des3_skcipher_setkey, .encrypt = skcipher_encrypt, .decrypt = skcipher_decrypt, .min_keysize = DES3_EDE_KEY_SIZE, diff --git a/drivers/crypto/caam/caamalg_qi.c b/drivers/crypto/caam/caamalg_qi.c index 59b59f5e9550..23dfdbc1d30f 100644 --- a/drivers/crypto/caam/caamalg_qi.c +++ b/drivers/crypto/caam/caamalg_qi.c @@ -278,33 +278,17 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_authenc_keys keys; - u32 flags; int err; err = crypto_authenc_extractkeys(&keys, key, keylen); if (unlikely(err)) - goto badkey; - - err = -EINVAL; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; - - flags = crypto_aead_get_flags(aead); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(aead, flags); - goto out; - } + return err; - err = aead_setkey(aead, key, keylen); + err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?: + aead_setkey(aead, key, keylen); -out: memzero_explicit(&keys, sizeof(keys)); return err; - -badkey: - crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); - goto out; } static int gcm_set_sh_desc(struct crypto_aead *aead) @@ -745,23 +729,15 @@ static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher, static int des3_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(skcipher, key)) ?: + return verify_skcipher_des3_key(skcipher, key) ?: skcipher_setkey(skcipher, key, keylen, 0); } static int des_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen) { - u32 tmp[DES_EXPKEY_WORDS]; - - if (!des_ekey(tmp, key) && (crypto_skcipher_get_flags(skcipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - crypto_skcipher_set_flags(skcipher, - CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } - - return skcipher_setkey(skcipher, key, keylen, 0); + return verify_skcipher_des_key(skcipher, key) ?: + skcipher_setkey(skcipher, key, keylen, 0); } static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, diff --git a/drivers/crypto/caam/caamalg_qi2.c b/drivers/crypto/caam/caamalg_qi2.c index bd01bcd799e8..3443f6d6dd83 100644 --- a/drivers/crypto/caam/caamalg_qi2.c +++ b/drivers/crypto/caam/caamalg_qi2.c @@ -322,7 +322,6 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_authenc_keys keys; - u32 flags; int err; err = crypto_authenc_extractkeys(&keys, key, keylen); @@ -333,14 +332,8 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, if (keys.enckeylen != DES3_EDE_KEY_SIZE) goto badkey; - flags = crypto_aead_get_flags(aead); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(aead, flags); - goto out; - } - - err = aead_setkey(aead, key, keylen); + err = crypto_des3_ede_verify_key(crypto_aead_tfm(aead), keys.enckey) ?: + aead_setkey(aead, key, keylen); out: memzero_explicit(&keys, sizeof(keys)); @@ -1070,22 +1063,15 @@ static int chacha20_skcipher_setkey(struct crypto_skcipher *skcipher, static int des_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, unsigned int keylen) { - u32 tmp[DES3_EDE_EXPKEY_WORDS]; - struct crypto_tfm *tfm = crypto_skcipher_tfm(skcipher); - - if (keylen == DES3_EDE_KEY_SIZE && - __des3_ede_setkey(tmp, &tfm->crt_flags, key, DES3_EDE_KEY_SIZE)) { - return -EINVAL; - } - - if (!des_ekey(tmp, key) && (crypto_skcipher_get_flags(skcipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - crypto_skcipher_set_flags(skcipher, - CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; - } + return verify_skcipher_des_key(skcipher, key) ?: + skcipher_setkey(skcipher, key, keylen, 0); +} - return skcipher_setkey(skcipher, key, keylen, 0); +static int des3_skcipher_setkey(struct crypto_skcipher *skcipher, + const u8 *key, unsigned int keylen) +{ + return verify_skcipher_des3_key(skcipher, key) ?: + skcipher_setkey(skcipher, key, keylen, 0); } static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, @@ -1634,7 +1620,7 @@ static struct caam_skcipher_alg driver_algs[] = { .cra_driver_name = "cbc-3des-caam-qi2", .cra_blocksize = DES3_EDE_BLOCK_SIZE, }, - .setkey = des_skcipher_setkey, + .setkey = des3_skcipher_setkey, .encrypt = skcipher_encrypt, .decrypt = skcipher_decrypt, .min_keysize = DES3_EDE_KEY_SIZE, diff --git a/drivers/crypto/caam/compat.h b/drivers/crypto/caam/compat.h index 8639b2df0371..60e2a54c19f1 100644 --- a/drivers/crypto/caam/compat.h +++ b/drivers/crypto/caam/compat.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include From patchwork Thu Aug 15 09:00:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171407 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918016ily; Thu, 15 Aug 2019 02:01:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEcSANek8PFRKIr1HrQWtNEHyELXsnOAm/ZeE/bIPvB8cPy3GsdnLWWb9+X/L+gzINhaVY X-Received: by 2002:a17:90a:23c5:: with SMTP id g63mr1285149pje.124.1565859700764; Thu, 15 Aug 2019 02:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859700; cv=none; d=google.com; s=arc-20160816; b=RIZjP6biQPcGmmdeyhX9NsQzsTUSyUp0PhmzxxvEUZjPJsMDyPlKaTKYXhC2LV/udp TRMKVjilQ+H126WDVkdovZ6wFMKDy3APJXfrxdpapYzVVrW4GEr4bxOdouzbs92U3oHO 2D6SXocoZS67uS6avTOIL4Nbz9Qn1Tv9Q1Vg70ngtATvm/ycSpVuwBdl5tN/YxZseuGn BQhpzGNjLvPHfzjrYvP4DSg2bh54GZRCTVVUWaRb6gOVffBXG8BoOqYsMs22kCYGX5hG YvFokHLZPMp+gPtsULPuznz06x1PT0UoXrMtVP3rKbIuxN4FQZpDDsS2XJtTdu9GEGcU 79hg== 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=BOt7PVw9lWqBCV/+RL+9xpeVpvumzg35vFF4tN3Fxn0=; b=qfIHBYoS2kI9T5TDvNEt0+EF3ZMfGm9enisBfNQRTFdd36ZQbCaknrGgve9Y2b6if6 lozHvLypcxT08HTMO52FmrqV1fwKcBbIDtDGUqFEvBv5CifIGicdT8h1QyNRsJXnHAEV JHWNAX1uknhi1s0JkJNwZW0h/XzijRLpOmglMG7bTpbSGdEKEQ82Prr7nlRsBOTDAKlk IiCnW533k1//XhkBn7pzsfM1Mh3d0Lhik816IEk7K2OyFkhyNE6CLQN8l/8xjp89krlW kkSrFvrmFoiTSoy+O7CxxWdkt9GEe8tCe+g1RbECHj6J+wZOmJygp7MJkBMqvsbgOvu+ /rFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q1hGRZPa; 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.40; Thu, 15 Aug 2019 02:01:40 -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=Q1hGRZPa; 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 S1730774AbfHOJBk (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:40 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33064 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBj (ORCPT ); Thu, 15 Aug 2019 05:01:39 -0400 Received: by mail-wm1-f68.google.com with SMTP id p77so591983wme.0 for ; Thu, 15 Aug 2019 02:01:38 -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=BOt7PVw9lWqBCV/+RL+9xpeVpvumzg35vFF4tN3Fxn0=; b=Q1hGRZPa6MRZjoPqKHWUGdpI7Q5tqXwYt0eUeNtFXgtbmAP+3ZtZs9IejBKZZtwBG4 w2YnHDcj2Kl/htWCg5En5YEgXSC1dT/iv4r3wmMD3kUFHRKAZX2txkAGMpQBQJpOK2J1 eBSQkYVVh8Q37ZJiQoMrbX3UNzlVGfetZ7CALx6+xLxOi9Al49CF+jNXii6/0bVFLu2e /KPQBQsiAiU3JStCN9am/r7Ce8kGLNGULdYHHjaDkovis63wHi4wrAGPrdzmKeOWAhqp 23Ug43NOxQPs98WFtq76VVholamwkwtzbMz7VUe1yb2LZMg+rVOnGSlKCbnC7EtNp8Ig LlbQ== 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=BOt7PVw9lWqBCV/+RL+9xpeVpvumzg35vFF4tN3Fxn0=; b=nHn0M4CO1YH47KlloVganH+/wDohngGTjmHhh4Fg1j23oK24QjOmUAQy1O64g3CTKY g5QZK+rhRxHTxVpE6AHraqVRvsUEQbhXS0OpoNjj1y5xJZ3Shw/GcHjyfnWZ91w+MZyl fRr5ZMd8R3TwQ3axuTPOBxP6LfN9MmtfjR/V69pUF173nxh9QhLnflNrgWu86emSA/3k B1wxufeVCOqEt8Cg1PcsVSt1dW4AScV/Pd/Z35tQf8MO8oqmlNNCMTd21Xr9BfJQngxa Woa+Kmh6LoDlftia9YdiJWlEU3lGjzkCX9UmrCagUBUIG1UP3g9sOXKnmzL4yfO2bswk /gEA== X-Gm-Message-State: APjAAAV4jtKYLoC400aAmuDX7qZVFM/7rcLcTTe4x3GmmFQDrDVGqNWA 6lV/znZRiCPC6EatbMGOcjhJnIpP7nWUTbCz X-Received: by 2002:a7b:c157:: with SMTP id z23mr1696966wmi.104.1565859697490; Thu, 15 Aug 2019 02:01:37 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:36 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 07/30] crypto: cpt/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:49 +0300 Message-Id: <20190815090112.9377-8-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/cavium/cpt/cptvf_algs.c | 26 ++++---------------- 1 file changed, 5 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/cavium/cpt/cptvf_algs.c b/drivers/crypto/cavium/cpt/cptvf_algs.c index ff3cb1f8f2b6..596ce28b957d 100644 --- a/drivers/crypto/cavium/cpt/cptvf_algs.c +++ b/drivers/crypto/cavium/cpt/cptvf_algs.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -322,31 +322,15 @@ static int cvm_cfb_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, static int cvm_cbc_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, u32 keylen) { - u32 flags = crypto_ablkcipher_get_flags(cipher); - int err; - - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); - return err; - } - - return cvm_setkey(cipher, key, keylen, DES3_CBC); + return verify_ablkcipher_des3_key(cipher, key) ?: + cvm_setkey(cipher, key, keylen, DES3_CBC); } static int cvm_ecb_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, u32 keylen) { - u32 flags = crypto_ablkcipher_get_flags(cipher); - int err; - - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); - return err; - } - - return cvm_setkey(cipher, key, keylen, DES3_ECB); + return verify_ablkcipher_des3_key(cipher, key) ?: + cvm_setkey(cipher, key, keylen, DES3_ECB); } static int cvm_enc_dec_init(struct crypto_tfm *tfm) From patchwork Thu Aug 15 09:00:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171408 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918036ily; Thu, 15 Aug 2019 02:01:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEscU2acJ4aX9w6cvsJwOkyELb5Rw0FM4pIQXUUT31ASjhhxNgbp/8fYZGzyeSXq2p9t9e X-Received: by 2002:a63:b11:: with SMTP id 17mr2610375pgl.283.1565859702076; Thu, 15 Aug 2019 02:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859702; cv=none; d=google.com; s=arc-20160816; b=mFy4DzPz8ppbjDbpRn+R+O0bORz2/hmGytxT1/Mf5K90xFXSokWAxryP7H8gdOw+cW GeJxIP5KjtLfva0qelf6DMmTQ8tuNe9jRV38Prisk79YrRJp4tYDgafvbgzxA3g/kbdS oQ3BsWSGxvz11p62iqBByb8U1T2Dz6/hTAlDJuIVVEsW6K7onezc0OtS6A786d0blsEN knTCBcV4iPicvben8H8y4HKn4r/e9IRWfDo2Gqkn5dvkZEeIpshMdKi6jWvpkzwWVuK1 fr7T544KP5GPNROX0eeLQ82y884rsTTCJpLQTqYNizf3gpyma8YBapRfuZDP0bfxrlfQ n+Gg== 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=R/dzAswTxDJO+r8Mbwq2UP3hHo6TATLahJ6svsPcZRM=; b=s2/1xKiQRODKfWnfFdpg0/gRqjs/ElEm/YVgpJV9y4GAdrMCz0sFQAK+JicvkHVloP LLGo08RLzVdg+A9fj67KfGA1qm4QZdvlVxfIFZkgauOookDuls3tL/AYfXojzzMlLvCC wJOwBErH0MMdHp664cb4EIgF0FMwMfWAzU/3BAQjQSrt1I6PtHSRr1icI10ujveMMcaP ya3PYgh0ZZqxVOOjS0GDB5t7PcTFHLloJodgfS/GgpYzxSmaoRCEuMKDC7V+JQvZ/bMQ 2pBCHQU23mzKltzpvew+PSxz6nOkip3VcKU50fZRzSufYZL16QIPNLbB3uYco0vMhzo9 O6DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f4UvRqf4; 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.41; Thu, 15 Aug 2019 02:01: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=f4UvRqf4; 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 S1730786AbfHOJBl (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:41 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35678 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730760AbfHOJBk (ORCPT ); Thu, 15 Aug 2019 05:01:40 -0400 Received: by mail-wm1-f66.google.com with SMTP id l2so684297wmg.0 for ; Thu, 15 Aug 2019 02:01: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; bh=R/dzAswTxDJO+r8Mbwq2UP3hHo6TATLahJ6svsPcZRM=; b=f4UvRqf4+mjlADq2VxXANUTyDi5GrfIcG7c4f+rAhM7Dr1CUb2up6E7xokErP3ybxz BKPTTshAW5JM4FncbNS97X4IBsJo1CTscysjrswleBA50xJt0zidkf6spTf0RXZ1vUbU 5U9zji5FZA2OUksccM0PpcNEne4c2NxQ+W88yoJpBTF0eyFCz4Dt0LpGvrf6rr8dYQUB XFnWjUb8cPX0jtvsrRECXyfRbOG7Dk3n/ywI9aT56AyQzOabK5Il49S1OzNF52qLbCeT 98wsgUxpcoemlvkJVT6qos8flcMQWeOtboWR/PfSXJk3ZBYv8dwo3v6ow906t8v9HWMe MgKg== 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=R/dzAswTxDJO+r8Mbwq2UP3hHo6TATLahJ6svsPcZRM=; b=NW09pFjqLCpSjV6lzLKUSEuVL7fG3KErHvasnT+O4IownAB637hqUO8HpIvs+RLEYt LNK+tvPRvWt0PeWNSKhfJ0J1k3HeZdR7RQIThkaW9AsAgvw0cEEMvkS0TtiXro3KAUyn sTwM/8O7ALgcJHdHj35k3t+jfLt3FchzsmnNb+jPVoG5qiIwkmzTcb8MD7dCv47EUH3h Rm4I95WVuURhBWUyEZO9n6n5phkBA/hkwGXdevab0TEKHO97wSu87US9Ju8lYd36gtX/ vKbaVvpi10I6XI6yzRqCrdWkUxOyzEnUAGwnl2eyNKZOwoCzjebl72nJxxxBEp5ZGNTu NwuA== X-Gm-Message-State: APjAAAUWf7SoknoAm+EMLZ5N6REuHmtb/3p/wKS+VWkHMF90u9mUBBBv mIig/C5edLAseyp2t/ezjYnXCnSNXzmrgdsf X-Received: by 2002:a1c:2ec6:: with SMTP id u189mr1654567wmu.67.1565859698755; Thu, 15 Aug 2019 02:01:38 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:38 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 08/30] crypto: nitrox/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:50 +0300 Message-Id: <20190815090112.9377-9-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/cavium/nitrox/nitrox_skcipher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/cavium/nitrox/nitrox_skcipher.c b/drivers/crypto/cavium/nitrox/nitrox_skcipher.c index 7e4a5e69085e..3cdce1f0f257 100644 --- a/drivers/crypto/cavium/nitrox/nitrox_skcipher.c +++ b/drivers/crypto/cavium/nitrox/nitrox_skcipher.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "nitrox_dev.h" @@ -257,7 +257,7 @@ static int nitrox_aes_decrypt(struct skcipher_request *skreq) static int nitrox_3des_setkey(struct crypto_skcipher *cipher, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(cipher, key)) ?: + return verify_skcipher_des3_key(cipher, key) ?: nitrox_skcipher_setkey(cipher, 0, key, keylen); } From patchwork Thu Aug 15 09:00:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171409 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918066ily; Thu, 15 Aug 2019 02:01:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqziOk0I147+wd73Is2/PHXwh1zqtjQZRpGiomLeDjyV9hyVg5qVxVo4fWZqWCzkiBhGp0wk X-Received: by 2002:aa7:96dc:: with SMTP id h28mr4401344pfq.86.1565859703611; Thu, 15 Aug 2019 02:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859703; cv=none; d=google.com; s=arc-20160816; b=ANEah0FqFidth2apztdscVJUsp1c4kNgdeT5WNDqmCm3SuWhQzd2ml20mfT9/QRpK6 NIKpLk/n3QKixVsCHw+RWsapdGhRY0rCD1H86FjvjJOeQrzz496lR9WSwKnGLYie0MWh 6VXSlSo90SxaD5HXyKD8JGqntm8RZcvz6/3/96GMSE/xN9XVfzhfAGgAeRx2HFmnVtDt 0XodA/XxNyXUQt//hpqAWZTtopUalET3GDsJgzOAN5ICMftpy8VJmC5imhObX9wx1ETK vUMWFE3f4F8Z05jy4KJGm5yYprqnPqiwm9s2WfxHGi0fVE9df4tvMpvtAykXjIZKN1gY Qo1Q== 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=HhUKouWNp9h+l5wh7+WhctAuQYAkznLninjkXL0AAyY=; b=cVcbVhDPLx4Uce5wsFHcVLXChEk5TfWkNMW2louUKEV96z9NDFx14FpXHPWy1H5e5L pyUzxZkF6L0pNjCDN2ZVmGEQFQ9PnghvvnA6b1jC850V44hkVzXSxdyKTWtETHBnK8Xa A4K7mdzgKKC+qIuGCm9mUjx9H1OzEyR9hW9u3gaV4zXQOX31E5ynskZxPXq4HHOIlAW4 VaCiHl6aQhePSGdVTSXqcw0Lz0u+Xg92WuulrKijfH06h6RsdxV4wMOgPJ5o/TOONYrn dH4KBUvVBKY6qYWfzwNR67hSjQay8dBxgp9QEIlHz3Ka1EQ+H6BT804Uc9qzzqOK6y7y 5zkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IEp159/Y"; 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.43; Thu, 15 Aug 2019 02:01:43 -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="IEp159/Y"; 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 S1730775AbfHOJBm (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:42 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40047 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBm (ORCPT ); Thu, 15 Aug 2019 05:01:42 -0400 Received: by mail-wr1-f65.google.com with SMTP id c3so1585145wrd.7 for ; Thu, 15 Aug 2019 02:01:41 -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=HhUKouWNp9h+l5wh7+WhctAuQYAkznLninjkXL0AAyY=; b=IEp159/Y7J/EXvoFz1s9k/NwH0TYmv3D0I3GC759SfNO7UosM8Y4YZXjmQ8bOLNQdx 9nBAGlhpKa99mySwcy4AAYmKfr49cmk6Zskug7+ixwbZzBXdi7ZEpkZmiLms0JPkDEVM Munb7WTAqVcj+QLoU7ps9pA7HZfpkZZmPJF8OHrKOhcg7UAUvlSmb8Hd9PDwwvm7m6tM nsh+T9B0YlEcJOKBs49beYXjnNc1QqPcFfB4j0K4RN/awK3EYeckyRjrBCLNS+MJ+7td tFFsKoECpm/Q/fbaNPzpKZT84G0YKGH7wcHxAvmkBi2MhLy7HiQPTspCITctZ1OOBGiE DztA== 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=HhUKouWNp9h+l5wh7+WhctAuQYAkznLninjkXL0AAyY=; b=IDS8CI22Wa09fasKCAFzaI4LmPb1XKGXe7mYJi7HXzygmV0M1obCrM6qggoR/kKU7M FAfEfIhuJqUVzoPs2NgrOERAgQTMmDeH6WvqHy4zTbGn/bq/tCB1TJQLWIlt1q+60Tap lyAmhxWgubhcDC0hmng6pvh3WeMD0H+ntHpNQx1o2Gnv6qq2GAQHreDMitsAwrLbJoXZ ag0tnJpypUAdoHhVlNjxXQpY8iCXgtQ3xxzw1TyMv6X+QpbdJM7RTvFijnc1xDD0gbXp diTkuK8qLGlbUGHpOUGr7DeMSbHjJG7sSJYqUgpQ7zKvQyuV5JbjAOwbfd0OowW7Sx5U pGrw== X-Gm-Message-State: APjAAAUPhcWluroa1tke2DjPMbZC02PmuvyHQHmn7EagAY2k53jkCKGm VCNqMhwUFJTzws2d+/PNXrwzirutlFuUgV0l X-Received: by 2002:adf:fc81:: with SMTP id g1mr4243087wrr.78.1565859700422; Thu, 15 Aug 2019 02:01:40 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:39 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 09/30] crypto: ccp/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:51 +0300 Message-Id: <20190815090112.9377-10-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/ccp/ccp-crypto-des3.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ccp/ccp-crypto-des3.c b/drivers/crypto/ccp/ccp-crypto-des3.c index 5f05f834c7cd..d2c49b2f0323 100644 --- a/drivers/crypto/ccp/ccp-crypto-des3.c +++ b/drivers/crypto/ccp/ccp-crypto-des3.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "ccp-crypto.h" @@ -39,11 +39,10 @@ static int ccp_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key, struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ablkcipher_tfm(tfm)); struct ccp_crypto_ablkcipher_alg *alg = ccp_crypto_ablkcipher_alg(crypto_ablkcipher_tfm(tfm)); - u32 *flags = &tfm->base.crt_flags; int err; - err = __des3_verify_key(flags, key); - if (unlikely(err)) + err = verify_ablkcipher_des3_key(tfm, key); + if (err) return err; /* It's not clear that there is any support for a keysize of 112. From patchwork Thu Aug 15 09:00:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171410 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918113ily; Thu, 15 Aug 2019 02:01:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMmQjzgazR2KK2ScRn0wk/NpWcFLewSq/QvWijglzifSzkIx6jCKfkna1j/NzNK8ZfoQNv X-Received: by 2002:a63:ff0c:: with SMTP id k12mr2610870pgi.186.1565859705899; Thu, 15 Aug 2019 02:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859705; cv=none; d=google.com; s=arc-20160816; b=ineBWiCyfvfVw+pCh/22YSXgrJK7PULNJMJXL64zQRibMMEHbp/p46jc3qz+bn6Dv4 9AqDtvYAAdplLJokwjxnZglxy04oYfmOIdQGNndNmyPpWlRfMES1zErXL3rRz/EzGSfS EUlLt6dicmMpSqHhKYTvYbClNjc2vBPRvdBMmQ8VMhpyTEtqvp4rZ8NY6IMXYhqHO3pd g1k9nU/fz1KjoDYYtOUC9f52S4WfcV0aoqubrv2qkBMPtPPvL4VrC0lPB1Ek3d3eWIp/ IPZ/lAc97MhBX3IP7u+BlmnLCWrLZ54t1LCY9vHdkNQtfbo57xO+8B6DpMz/p6U3/V8V vPBA== 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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=nZvrzjTAO2pcGFdh2htDMV+gZd+Hf6EeO0X8PPrR12o7oUZkPpMR3gLjGtZv2IrCY3 90eX3Gs80Sj/uXr0q1zpfP0Ah5yzprmlfajiqDXBLI8GqY/7/J/5E1ISi87/L26pjwVd ZAazwSiDYsfFlBLRWY2G88cnIQhHcSVkOiy3FOQRz55JLrWqRhPFcXwJXKuWyYs0+XD9 IyNcLxr7kKVQruNROh4Rx5pfWftdGnlAbEZRvk92IFDP2rvaRhfBePJFUCtUTTZTyCI/ rx/WdrAVT7dXfAZy+Ywv96KAxqfK1TVw7LUenEG9QzXAl1ghemz7r+zR4za/ujHUKCYl zzVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zxx4WGbI; 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.45; Thu, 15 Aug 2019 02:01:45 -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=zxx4WGbI; 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 S1730760AbfHOJBp (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:45 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44440 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBp (ORCPT ); Thu, 15 Aug 2019 05:01:45 -0400 Received: by mail-wr1-f68.google.com with SMTP id p17so1562952wrf.11 for ; Thu, 15 Aug 2019 02:01:43 -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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=zxx4WGbIdT6+v94U7dIhYd9lERYrChqa0Wfpl6qPST7cp34Zu/yL/MjXIbJrhGPWAz MM0Eqs5Ym1JnKJQMl0fnaHgsT4JNRfq3aXD1K0XEq9zBxzeR2Yk6vFLdXJtC5N7NzeQF /LCgUNf5i9LCyMWmPkcaugC+P39z+9js3RM/9tNHTEg3iMZn505zrSGVOHB2mXOIdkiP NGoZJF4IA5tZ5U/kkXmXLNTtXua8c3iYp+Ej0PseOBQ0PH88jhL3V6Zw+6p03TViP169 jboiUO55vJ/8QL6IQ0e0QcFy2dprJSlecXys6PLgp8+7RCvPSw6kB8lHnwrMCWmPnSil rfXw== 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=hjScT+0+NYfp5aidkWeFYVYHJ6rSMaKSveRxE97FOLw=; b=Uunwbc3L+mzrVsvVsvm1W7w6nGXdy+r3h1jgs1lbSKnDP+2fGGwONJSf46zo3q2O3e EXsDgA1zO0H/M26ySFmYzn8sIaZQDbjh+k5ok7IqdDXW8mWQcjfl3LoX6IVjcbRJf4l4 eOjT7T1RAOYiRsob8i6gibGqJHsaIQKibRm3LKzbTus2QU/GdApk9HzoleEh0I0UkhU/ tzUvfjIl3aYuf4VXABFy1YxlHHRxe5dQ+B0+CMPT7PulrTe4sXnHy4yoog4sfPURUr4Y YgCQ5sPeN3uxoXGR5Rsz5/OAPnk6finiit2mViLhuFq0xlFzBLkrKgrU7dlzccfSCjAk I9VA== X-Gm-Message-State: APjAAAW9d2bqQNgo5kX6d5fzqEcpC1Tx2KB1DHZpo6PLOfRxQdmpR2Pm 7QZptonn84FEKnAO41ClWMHQD0O413M4e6SX X-Received: by 2002:adf:e504:: with SMTP id j4mr4157939wrm.222.1565859702930; Thu, 15 Aug 2019 02:01:42 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:42 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 10/30] crypto: ccree/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:52 +0300 Message-Id: <20190815090112.9377-11-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/ccree/cc_aead.c | 24 ++++---------------- drivers/crypto/ccree/cc_cipher.c | 15 ++++-------- 2 files changed, 8 insertions(+), 31 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ccree/cc_aead.c b/drivers/crypto/ccree/cc_aead.c index a9779a212b18..d3e8faa03f15 100644 --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include "cc_driver.h" #include "cc_buffer_mgr.h" @@ -649,33 +649,17 @@ static int cc_des3_aead_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_authenc_keys keys; - u32 flags; int err; err = crypto_authenc_extractkeys(&keys, key, keylen); if (unlikely(err)) - goto badkey; - - err = -EINVAL; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; + return err; - flags = crypto_aead_get_flags(aead); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(aead, flags); - goto out; - } + err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?: + cc_aead_setkey(aead, key, keylen); - err = cc_aead_setkey(aead, key, keylen); - -out: memzero_explicit(&keys, sizeof(keys)); return err; - -badkey: - crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); - goto out; } static int cc_rfc4309_ccm_setkey(struct crypto_aead *tfm, const u8 *key, diff --git a/drivers/crypto/ccree/cc_cipher.c b/drivers/crypto/ccree/cc_cipher.c index 5b58226ea24d..c7ec20e90fc0 100644 --- a/drivers/crypto/ccree/cc_cipher.c +++ b/drivers/crypto/ccree/cc_cipher.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -411,16 +411,9 @@ static int cc_cipher_setkey(struct crypto_skcipher *sktfm, const u8 *key, * HW does the expansion on its own. */ if (ctx_p->flow_mode == S_DIN_to_DES) { - u32 tmp[DES3_EDE_EXPKEY_WORDS]; - if (keylen == DES3_EDE_KEY_SIZE && - __des3_ede_setkey(tmp, &tfm->crt_flags, key, - DES3_EDE_KEY_SIZE)) { - dev_dbg(dev, "weak 3DES key"); - return -EINVAL; - } else if (!des_ekey(tmp, key) && - (crypto_tfm_get_flags(tfm) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; + if ((keylen == DES3_EDE_KEY_SIZE && + verify_skcipher_des3_key(sktfm, key)) || + verify_skcipher_des_key(sktfm, key)) { dev_dbg(dev, "weak DES key"); return -EINVAL; } From patchwork Thu Aug 15 09:00: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: 171411 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918141ily; Thu, 15 Aug 2019 02:01:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkR9Ag5i9k8CCMz01sSguBQTr2n3dmmZfnuL789F5xE7x1CuXQPJRX8Fylv5ac2Yy5srWx X-Received: by 2002:a17:902:8d91:: with SMTP id v17mr3495896plo.88.1565859707535; Thu, 15 Aug 2019 02:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859707; cv=none; d=google.com; s=arc-20160816; b=MkNCo10gU5y2/0a7617HLiLN1ieFehawbjs98CvS1evQ1UKoSXWHqBLaqwtk26Peuj lsXGiaSh7mWyVCd/MGIfIMHnZLsGTABO4NJ+3OT76ohcLbsPEWgLrQuh7EuT+RVFgDmI buvjDoeCx9FvMOw/2hVmab6EgQ7yWH7B7Laf+TTr9JE1nGASVfmDOSgqS9alfwSuLLiH A8Jo7UWH97WUNp5uszricN9VJE8gOcqq+fWtW2rhR3EQ4oEmXdaxX8Kejs5R5tQs+PcW jjyuBhbe4nbOqeyGWhIQXDjtPEIPJSzOauYZdpqKux8UduZz/OcrmnCjlhBZFMagkfUZ X8Gg== 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=LHJbGYYVd9anPfjjvOncYFmF6xF/5unBiz7afWnI4fY=; b=wkRiDUYVvxjK6bH74Qd0KHDVJuUovUb1zZA6IzkSKXjjecuylpzRPEn7pZ9h/+8lMy B9irwlTBP/lf3BLSfNjTTSe+FxeWxHPAMuf6OcgF8ewYHuEKVISZgqVIr1xZoq2bTElT YN0GMiCILKlf87cZYIRNw/C6Zx8FUCpkGuupxcAoOb7ncYfZsMfkM0VYrpm2ELdHgOKA zhwCau1c07bCJOm8ckeWP/pwvJ2C565lPG1sJPWhrjSe06r4JQvf9e/MrXjg+lvMyYI8 2Si2xzKpIfaSdSfZh18YDMUO4XLQLSd+jw64lm0zlpzodYJsVUrbcC+HDZMbwtglaDGZ C0kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fv/qAauV"; 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.47; Thu, 15 Aug 2019 02:01:47 -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="Fv/qAauV"; 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 S1730795AbfHOJBq (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:46 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41175 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBq (ORCPT ); Thu, 15 Aug 2019 05:01:46 -0400 Received: by mail-wr1-f66.google.com with SMTP id j16so1577876wrr.8 for ; Thu, 15 Aug 2019 02:01:45 -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=LHJbGYYVd9anPfjjvOncYFmF6xF/5unBiz7afWnI4fY=; b=Fv/qAauVGznLCjxaHU1DlupK80IufloW7FEmG0b2QwK+vEM566prg2y7wNmNF7nDz1 XEX0KtMAEPc5RHIiAVcykpmAOdTqXyxoI3vdDorPaXURnnO8NZVri9/BXqmbOxxUiGd6 B4nixoybCPftkf685DXwqffd2apiYml4i1TPHwpf36x9+IK9EMG3CTIXcDKYFFyPO46e sARtFffmB13EmgcMXx2vQXJt1cM84u2AxwoQdXdQ9HWyQVLPcqMOCidcJLVVBoxLuolp sUPu39IecsAP2q6UZv23k432poHNbB2ROmoCnMCkMWUjOKR0mZWtMQi0ugzv0l0ZMhmE M+PQ== 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=LHJbGYYVd9anPfjjvOncYFmF6xF/5unBiz7afWnI4fY=; b=lpIiILnLvAouoY1CgGy16i0yr251NkBWiI84eTRt8R0+DoFxBXF6k6l/Xul2FODbrW ERbBu521DCOZbzy5FG9Aom8sy5XL63CXFJeMG2a2tjNxhzIDjBXfBPQZ1MG9qw3D+o7S bJRRI4te3Mmv3jS7c3jCMXk0beYAKw0p6YD6i8skW835uyZPopgI1/GG+1GFXmDLVfpj kx2Xx8labpr6sO0nJF3dAZBWn0Hn+3OKScgdUtWkH7S9usVuOhyX8VUwB8fZfA9OcgBG Ta4dPGSgjNpwXRKo2Yr8OFUgoeOKOc7X04+rhnJOXwSUmDSGQzMITEQn4B2bdRPjbPXk QHag== X-Gm-Message-State: APjAAAW1ZOH72uHX/0nCb/rJeBSM7s9HDxbn9PMlywjb6ngpHfFatLrn Dzl1hpmS1hkuEw7OgNjuVLJLNteHcrnNpyPY X-Received: by 2002:adf:f6d2:: with SMTP id y18mr4228361wrp.102.1565859704608; Thu, 15 Aug 2019 02:01:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:43 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 11/30] crypto: hifn/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:53 +0300 Message-Id: <20190815090112.9377-12-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/hifn_795x.c | 32 +++++--------------- 1 file changed, 8 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c index 5c3f02e4aece..a18e62df68d9 100644 --- a/drivers/crypto/hifn_795x.c +++ b/drivers/crypto/hifn_795x.c @@ -21,7 +21,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); @@ -1939,25 +1939,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_context *ctx = crypto_ablkcipher_ctx(cipher); 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 = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; dev->flags &= ~HIFN_FLAG_OLD_KEY; @@ -1972,15 +1960,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 = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } dev->flags &= ~HIFN_FLAG_OLD_KEY; From patchwork Thu Aug 15 09:00:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171412 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918167ily; Thu, 15 Aug 2019 02:01:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhj6NyL0GODnwLvGJfL9aB44b7bz/gyuZL+qUK3gUv+pF5PY1G5sD5LawdaS9eMWN1O8NT X-Received: by 2002:a17:902:f082:: with SMTP id go2mr3558801plb.25.1565859709119; Thu, 15 Aug 2019 02:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859709; cv=none; d=google.com; s=arc-20160816; b=JUNnEe3XEfa0bGdQfVvxteBmw6e4bKnfhhR2uhIJ/2MLnJJoqUHHwMg9N9h3BueC6J qRpc99rO9Scc9S7cPMn2MNbDc8zwDCTXk1skjLj2HnTkRUhfsjUQ8hTUm5lHHYKjDz0d mw5T9o37DKwCjss15OVLhbSPbtqWJgo2cvmVP/wnJyFKM77Ip5kDd9EbFg4YjyP8B35l vNc9FUoYR6V7ycjNbM0n1jrsbAq8pSNEpClrFBl3UIso6YjTpi0Y2VBpt/msAJwWT+dX b6GTWEDqzcraZ8P7jKngfjTUByHDg+szqKvVFzJ7hP0B62dRnoVEgKFekasjjQG6zTnH z7cw== 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=gMw1TSRrolAnfbeQ/pAAvmgP6ZTYCAswbG5wAAMeaMQ=; b=wCfL/fgBfW0lPjZe4WlXNQdpHOrxV2gL14N5t/JpBy479b9mlyDpW9XesIhafoJB2t HFgPKOwJp2wA/NZM+NU56DlOW+P5KIaKGKDPFR4QhogNuAL4g8IcS64JVeVhNiyp2G6H E4/hdGxgTVXZlvhN38aWPkBAPYxTX6juj8pk1lBfaY0oswl25877BxexnyleGH6WNxdH 8Gr6jsBlg4p52NKrTX3xW3a8bSe8bH/EXz8d5C0NnYTzyI4PMV9MwWpiVF2wYlYf8Lt8 dExX+pUF1vnfrgKQsIIe3korWOE1PdZ07iMG+KNAlCP3e3ldCGa4zR2t4TMYQ9j4hSu/ OLeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uGAWG73A; 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.48; Thu, 15 Aug 2019 02:01:49 -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=uGAWG73A; 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 S1726008AbfHOJBs (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39216 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730793AbfHOJBs (ORCPT ); Thu, 15 Aug 2019 05:01:48 -0400 Received: by mail-wm1-f67.google.com with SMTP id i63so676743wmg.4 for ; Thu, 15 Aug 2019 02:01:46 -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=gMw1TSRrolAnfbeQ/pAAvmgP6ZTYCAswbG5wAAMeaMQ=; b=uGAWG73AY2khDOPO4pabFiwxsoz4Oo/oJENgw3mZgUg0b3WCor7L9hof8k286AEA9j zo13vQ65/X2UIclncpj8BPOSSYQGHL0+8giCf5QWdZfKhWH6jSKSzTQ6GskQvMqJmhGw ahgjK2rj9d3BSD2L2B9y4+IY66iO5D/3cbNV3m4BVOhwdiIRNy1O2bjb1GAmKod9Z9IP wrDgiwIG7AuFMWUGGyEUPHbhbTtOEWHzJ+l5+E1scQ/32hJirOtlFKTdstWg2vxBUDf6 0aBa39gBdHzaIdMwe3DXJiCc3VFzPrAQP602f5ToqZ8pfth1EVRDhoUvoaEGlffBMR9y pIlA== 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=gMw1TSRrolAnfbeQ/pAAvmgP6ZTYCAswbG5wAAMeaMQ=; b=sSGKAe+zbFus7zmgNjucL0vlT4IdYAy8VRoajxJclAqtpkjtvg2QuPciQWaz2TS7Kh aHQ9Wnhnug5GifKPpOd4oyhwTUVdZhgl4ltpjUiE/nS5ii3q4kQZJ7heOw6bhVWVTN4z WaxkOuCkj0hm+IzxrPV/x2AGuDTmxbSy056uCfGKD8zEvewS92sez8dpmHtTNX9/QIyy +d6nb3/q/6SPpaSCyscgWqN644Z5RjiTS/fPWS/PfIRBN6VSvq2h/skvF0j6Ptz8UQNZ nIZalpzbRErYR2eFnM9vKzG96hvR8vl8idsTrUeclDpwla2WhCSm7JHjWOgio6Iwko1u 3pQg== X-Gm-Message-State: APjAAAWviQj/jgfwOA5nrjP2LCrnmoeO5G5o3F90Qv/PBci2dLJB68An VPqL5JEkWteTt/+5a0K5dk9JY80UcRLrCaXp X-Received: by 2002:a05:600c:114e:: with SMTP id z14mr1593976wmz.161.1565859705931; Thu, 15 Aug 2019 02:01:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:45 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 12/30] crypto: hisilicon/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:54 +0300 Message-Id: <20190815090112.9377-13-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/hisilicon/sec/sec_algs.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/hisilicon/sec/sec_algs.c b/drivers/crypto/hisilicon/sec/sec_algs.c index 02768af0dccd..e0508ea160f1 100644 --- a/drivers/crypto/hisilicon/sec/sec_algs.c +++ b/drivers/crypto/hisilicon/sec/sec_algs.c @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -347,25 +347,21 @@ static int sec_alg_skcipher_setkey_aes_xts(struct crypto_skcipher *tfm, static int sec_alg_skcipher_setkey_des_ecb(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - if (keylen != DES_KEY_SIZE) - return -EINVAL; - - return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64); + return verify_skcipher_des_key(tfm, key) ?: + sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64); } static int sec_alg_skcipher_setkey_des_cbc(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - if (keylen != DES_KEY_SIZE) - return -EINVAL; - - return sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64); + return verify_skcipher_des_key(tfm, key) ?: + sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64); } static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(tfm, key)) ?: + return verify_skcipher_des3_key(tfm, key) ?: sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_3DES_ECB_192_3KEY); } @@ -373,7 +369,7 @@ static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm, static int sec_alg_skcipher_setkey_3des_cbc(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { - return unlikely(des3_verify_key(tfm, key)) ?: + return verify_skcipher_des3_key(tfm, key) ?: sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_3DES_CBC_192_3KEY); } 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 */ From patchwork Thu Aug 15 09:00:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171414 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918222ily; Thu, 15 Aug 2019 02:01:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5SmEZ/aAX/zvUPhI42mTvZCU+CiSZQV6M+jsuYZcSTpy+2ZNrcyCVdU+AsZqY8b0BHCpS X-Received: by 2002:aa7:81d4:: with SMTP id c20mr4343266pfn.235.1565859712190; Thu, 15 Aug 2019 02:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859712; cv=none; d=google.com; s=arc-20160816; b=EmHZAF+jz5lVc9+na/ziLGdtHO7D/fHXDv0uTGMFYGAPBx1lHAjECguugepfUf53wS 2Q9fM2jqzJCfBnnCOnoy3U6lRVzfiSUBxCeWt3ST5SrZN1b1/0WLMIGpqVyGWlagMvP+ D1BEjqGiF/Njt12mc4fc31U0ZCKIgdqPuZrNbqz8xXiGtse9XRV+x41ySD0lo1dX8XFc 0GyqEU2uBpziOdmBuzRWOrFZ4rOc4eAM22msS9zSwYuriyOPUX+Y5tANYNUprEW5GIfS ZG6kvKEK768faJqu3sVAJ7fWkGvUDF4zRz9KzhX6oBDpMfC6jua9jo7qUfygOh7TB+L3 KdNA== 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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=UeCWijh6nivmf+cdScOxMyqZ5BlENfmYzLHGvtX1CY2c53L+dTKXRw80K0W35ZAKMn SSGHR6Q0fh6RjfEXq9qYCO1mOR+6e+pgK/RwHzq4I/oTXkaGw0APonIvUHRud47HQ+6d YkSa56R8R3fwHKgtMGp7Be2AAgHtW/tUHGlSX4x49H6mAaiP4EC7Mw2fzz7BEFzYD6Zb cvpD8cFXfznFf/Nh8qKIOhqV/2QGqojl/AD36vJLffQfux9NlXfTY8tShiu2rOlICVGs hZLHpNx6+GXSqlDwz6MDFQ2MvBGYDLFJVjcj00Czuuh3EJ21VTKY4SsCAYlnFyFeb14C H6vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r5tONMdJ; 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.51; Thu, 15 Aug 2019 02:01:52 -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=r5tONMdJ; 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 S1730798AbfHOJBv (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:51 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40060 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730793AbfHOJBv (ORCPT ); Thu, 15 Aug 2019 05:01:51 -0400 Received: by mail-wm1-f66.google.com with SMTP id v19so674327wmj.5 for ; Thu, 15 Aug 2019 02:01:49 -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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=r5tONMdJ0NxxlvsctrofXLbL0C4JjABzo02ffFe+aDQ/6b1crHkcbt5r+vgPoVIYv9 O8v0i//+SXVjgwBrX94dNLYvXlnlfdjpeVRGLxFOGtmy+WK937HWR4glJhYX2nrGtga1 T/vAnfKuO142T0CXMVPRJOui+PtjmYcu56b+HpkyFjcfQCaji+1p0kpus2WApT7dMQV6 vDmqwnwfc6TFZRqe8Upl7aDtua53zfgO5Luh05KKAPHXL3u66pk55poIkFtXwy4CpmbH nL085NI7y7kiCM4lZiJdX4GAawOKd81/eJW0OM+IB4BRNJVOEnPxGfV4ekbrXoq+fXSK iWMg== 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=YDi2S78kIoJe4bcEd09atrBhNAeLpe4eGoRIgiaftJs=; b=ryU4N1e9LZpqocvrADxT986gb5VNUr1WSR1aoBGq4/JQ8+7bcNpcOMHCgoE1xbZmjW MzbbbCq/TV6ZRlmVDSKwFi0O0u/yuuipoYNpSVpEvCpQXgpsnWP3rO8yRolSezkDWqlh 9h+/bKSbWYqGQHnBum/AnKOghNHx4+yOZdi+theRXmZRqjl3erlpXlRxTjhwmFHgv9i+ OVkaycfHTmdqQ712hJ3B16vfJKmfyv6g10VToKKB7uaECSHBjvw2cjGvf0WPEgaSnWoP I6UvdUZGVY57bLvfCZemPHN288gEVO85KJl2Dvhw1yVuvVTYThsvaOaWPXzceFuTKfmV qeOw== X-Gm-Message-State: APjAAAXiMnMHseqQD+S96xPF6nnUQ9jkhO0OgWi7XULkiOatpvXS4u0S bxO/e63V701mztFpPIOP34xuUgqCH+H0i4f6 X-Received: by 2002:a1c:b146:: with SMTP id a67mr1688118wmf.124.1565859708821; Thu, 15 Aug 2019 02:01:48 -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.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:47 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 14/30] crypto: ixp4xx/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:56 +0300 Message-Id: <20190815090112.9377-15-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/ixp4xx_crypto.c | 27 +++++--------------- 1 file changed, 6 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c index acedafe3fa98..f3c81bdffaf0 100644 --- a/drivers/crypto/ixp4xx_crypto.c +++ b/drivers/crypto/ixp4xx_crypto.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -756,10 +756,7 @@ static int setup_cipher(struct crypto_tfm *tfm, int encrypt, } cipher_cfg |= keylen_cfg; } else { - u32 tmp[DES_EXPKEY_WORDS]; - if (des_ekey(tmp, key) == 0) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - } + crypto_des_verify_key(tfm, key, key_len); } /* write cfg word to cryptinfo */ *(u32*)cinfo = cpu_to_be32(cipher_cfg); @@ -851,14 +848,8 @@ static int ablk_setkey(struct crypto_ablkcipher *tfm, const u8 *key, static int ablk_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int key_len) { - u32 flags = crypto_ablkcipher_get_flags(tfm); - int err; - - err = __des3_verify_key(&flags, key); - if (unlikely(err)) - crypto_ablkcipher_set_flags(tfm, flags); - - return ablk_setkey(tfm, key, key_len); + return verify_ablkcipher_des3_key(tfm, key) ?: + ablk_setkey(tfm, key, key_len); } static int ablk_rfc3686_setkey(struct crypto_ablkcipher *tfm, const u8 *key, @@ -1181,7 +1172,6 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) { struct ixp_ctx *ctx = crypto_aead_ctx(tfm); - u32 flags = CRYPTO_TFM_RES_BAD_KEY_LEN; struct crypto_authenc_keys keys; int err; @@ -1193,12 +1183,8 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, if (keys.authkeylen > sizeof(ctx->authkey)) goto badkey; - if (keys.enckeylen != DES3_EDE_KEY_SIZE) - goto badkey; - - flags = crypto_aead_get_flags(tfm); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) + err = verify_aead_des3_key(tfm, keys.enckey, keys.enckeylen); + if (err) goto badkey; memcpy(ctx->authkey, keys.authkey, keys.authkeylen); @@ -1209,7 +1195,6 @@ static int des3_aead_setkey(struct crypto_aead *tfm, const u8 *key, memzero_explicit(&keys, sizeof(keys)); return aead_setup(tfm, crypto_aead_authsize(tfm)); badkey: - crypto_aead_set_flags(tfm, flags); memzero_explicit(&keys, sizeof(keys)); return err; } From patchwork Thu Aug 15 09:00:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171415 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918245ily; Thu, 15 Aug 2019 02:01:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5laPzNeASe/EtAwMU7qjp7F5JqP+5FAdtPwkXeGGgwjb6fmFvU10uL39djT7q6/WWNgr+ X-Received: by 2002:a63:2cd4:: with SMTP id s203mr2542426pgs.19.1565859713533; Thu, 15 Aug 2019 02:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859713; cv=none; d=google.com; s=arc-20160816; b=N28WYtF2mngR7YZBHByve+bLBlV3T4Dkitas0O/rhPySo81S1vjc9rh+193qXyi6kk 1QOnqOfHhydy28txJYcpdZkoV9ma0xZRzDd2qMEVFbGNbtdM6t4DN3vrC1IPE3XcsHIF GtADFyYdxgErpzwsKSeLEgcSucTCXWXla8tAAc1NZqrk8vbDpa1mG9PKTbm86mIaIGNu VVLlV2lQQIbnFQWW+r61AscS7S7NFZYIzVGPvlsAgFmyfhtSdAW+qqvQwFkDNx0O/aFb GhfXT2bKpAqSagTAzPOVFa50P4QKQrvWTrwsw7S5nD2vZipTtZMcbEFFZO+Noi9s59ur e7XQ== 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=tzS9LGpq6ZYGPr0TCVhTbC0UKoF/48plVxVUkivfzi8=; b=RLultn7RVf+DI3t+519Vm1vIl40RNstY2jozFF/asNARCANUF+gUX1miWaWmMgCQaA 2q+5ZhpCH+Up4Qq5xmablDCGeO3eDj0p37tmAh9oTspG/d/0PQC7DsCf2Yfrnqoh9YuZ bCqFigbCHk7bae6EiJLyf0MMJvpeRci0psYujSYLLsrdGkcEK7stRK1ooo9UKSLpMlXM rXQcOCYNlSzEoJHHbtjqPjC4dByJrk4AGqzAzBvg14wqakyQx1rEBXMWByvJdtslimCv Qgsz69Me7nJcVAuc/F/PelCDj7P3r1SIAyPj90gNOh0yIAt0CiiBYgLMiu9UuZGXUS05 l4Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xDReowXW; 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.53; Thu, 15 Aug 2019 02:01:53 -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=xDReowXW; 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 S1730793AbfHOJBw (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:52 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55958 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBw (ORCPT ); Thu, 15 Aug 2019 05:01:52 -0400 Received: by mail-wm1-f68.google.com with SMTP id f72so673500wmf.5 for ; Thu, 15 Aug 2019 02:01:51 -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=tzS9LGpq6ZYGPr0TCVhTbC0UKoF/48plVxVUkivfzi8=; b=xDReowXWvAHMKgAX26p+WjLOlTeUj3+QhLfKzEve2e3YZasi7clWMcSEBNGiT6k41q 1E16c9DmCHlUcrW/m/fvpzxfaFihfJMdrd/hFhuV13/u1gggXpYdZfMNcI1CEvR2O00r 9PAHdS9mBMv74GyivxORGOxGb5hmBHMrnoMpzZRERjZXFGhsqCRd4I0hZDc0dstdLOSl GBpyn2Ah1wsry1EdfAIDHy+yGZ8jAw6W8AN6R3OkplcrfCt3O6eXTFpyTH+UtFuv2QE0 swR5ah5suCeE3Q4wQNcufx5BRyenNaaWHdbLKO6ry9WLOn0KdrcLS99Gr33DmB3dl/4G h5Qg== 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=tzS9LGpq6ZYGPr0TCVhTbC0UKoF/48plVxVUkivfzi8=; b=ns6LLclGaxMGxNrqu9AOi9t8i8bbwtkFpUi+7I1QEsRFRcZgbhOCedcr4n4hNWmqK/ Wz+Yv6s94rdGot89zj54iO2lNUFmL2yuPSY+B4VQh953GLHcv0OYzsrW4n0C9Ufcr2Au xqvv/51dYY7O+QrLMYFzZ/KfBUpvdAJIzc8JFSkkEUVT4v85/qtGxUm3cR5BNQuQ6KFV IvS4bafPfaAsi0HZOnfs0C/hg0QjdEZpiZNw9pX+88mZqVn2W/coOOGW3Rnia7glF13V v6LibUOoqi29AvIAGib3t7yWU3SMjRSr43RZcstpYi8pl3CpUzhpsOQ8SpJO3kkfRnVK NgfA== X-Gm-Message-State: APjAAAU1ibdbi6E6mPcxA7rsWIafpHu3eNTgroW4wEZVgLXSphTGUubg o4OvzlP7aGoiRAeP7Kk7qAJLa8gKD4lBzDpm X-Received: by 2002:a1c:a852:: with SMTP id r79mr1641225wme.36.1565859710358; Thu, 15 Aug 2019 02:01:50 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:49 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 15/30] crypto: cesa/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:57 +0300 Message-Id: <20190815090112.9377-16-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/marvell/cipher.c | 25 +++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/marvell/cipher.c b/drivers/crypto/marvell/cipher.c index fa1997e70b63..84ceddfee76b 100644 --- a/drivers/crypto/marvell/cipher.c +++ b/drivers/crypto/marvell/cipher.c @@ -10,7 +10,7 @@ */ #include -#include +#include #include "cesa.h" @@ -272,21 +272,12 @@ static int mv_cesa_aes_setkey(struct crypto_skcipher *cipher, const u8 *key, static int mv_cesa_des_setkey(struct crypto_skcipher *cipher, const u8 *key, unsigned int len) { - struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher); - struct mv_cesa_des_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; - int ret; - - if (len != DES_KEY_SIZE) { - crypto_skcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } + struct mv_cesa_des_ctx *ctx = crypto_skcipher_ctx(cipher); + int err; - 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; - } + err = verify_skcipher_des_key(cipher, key); + if (err) + return err; memcpy(ctx->key, key, DES_KEY_SIZE); @@ -299,8 +290,8 @@ static int mv_cesa_des3_ede_setkey(struct crypto_skcipher *cipher, struct mv_cesa_des_ctx *ctx = crypto_skcipher_ctx(cipher); int err; - err = des3_verify_key(cipher, key); - if (unlikely(err)) + err = verify_skcipher_des3_key(cipher, key); + if (err) return err; memcpy(ctx->key, key, DES3_EDE_KEY_SIZE); From patchwork Thu Aug 15 09:00:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171416 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918288ily; Thu, 15 Aug 2019 02:01:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqWJzNdsbgVjmofUYNU9cVtyRhQcn+pOwZ4gAcYXovj+S5u4Nqenj+6Vfa01biulGu8UPN X-Received: by 2002:a65:4c4d:: with SMTP id l13mr2681158pgr.156.1565859715986; Thu, 15 Aug 2019 02:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859715; cv=none; d=google.com; s=arc-20160816; b=LfN6hbqNBryQFxRQQY954Ud002HB1S/PBSNREhTraFf+9CrEbV5mUo6hobbZO5pdcb 2MKkRo8cyL5CEyZDDevnS9rUN3yqLRR+C4BxeCEQQlihduty0BW0DAsKqX3bipcieJNL npAxKjK5vXvpAPi9nQgTKLwQUY/qfGjQ/SymDg5ylYhoJvU0XLMsxp5cu+IsKY1iUAuZ Szczgk3gLCnjppw1jQJkSezXgNI4OR6Ccha6MbE0mkksmjappodmqsBXOtkzelFwIyfI eFv07OlwikKfRCWmNhKxZQWNGiP10grGWNja2ZhgYNdHgUrC8UuFYPbxKdS7GWHlZuhf H/5w== 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=J7UX2XGzxWe3m3OUYUOwz7PyEEOQmjxp5jPkPEdXR2Q=; b=Y2bhOb4hHq6yvMGWy9gf50guzHTgTIPajfI0zn6lMDZa8g8mg+PRybiPynwWGSPwmE NCPgXj3uWYHF6l0IhpQUuOi09QoenWPPVasW5BfkpIOrcwk9BRV1oRSoghzZKi1LpG10 0u+hxw3tZG6xVkjm/rbBm+QV02bpXc8sbw49jryq526QeC8mQRuXvlJGDD09QUaHT6TE NJA2Xy0rXvsYY0qv/5jqmVI8PkEs6uHIIS5rMqlhQp64wGJPyqdjndTelIlHiUsLRip4 l8FH4UzlyRdMEjTtDvZqeaCCfSVQESfYHuKAPBJD5kee7Mf6G0zKz/UXx0h2IfRQhyU3 QopQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="lwdPUe/g"; 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.55; Thu, 15 Aug 2019 02:01:55 -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="lwdPUe/g"; 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 S1730800AbfHOJBz (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:55 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35700 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJBz (ORCPT ); Thu, 15 Aug 2019 05:01:55 -0400 Received: by mail-wm1-f65.google.com with SMTP id l2so684872wmg.0 for ; Thu, 15 Aug 2019 02:01:53 -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=J7UX2XGzxWe3m3OUYUOwz7PyEEOQmjxp5jPkPEdXR2Q=; b=lwdPUe/gijOIrR3ckJmpvUAAvjkspyEacuIvTqd4h8m2oC+kIGVCkbaksQIci0Xlr1 XCqUUjqfY1FsrtCaW7Ag+9MZ9bFJs4doisLJAt+Pvih4fQZBnMOVWfNoSFMxGq/X2Y7i 7coHqNJDdFwMePIsblq3f+Osih5/7t46yyeAwLVLScUri0lwmxei15lMAzT7vw+o6twr lXbxuyv3/DXen2/5ud7gCSxOkwrYq2IVv+GSWU4nAm+7C/tf0TLR+RaZLZYZqTPN+InN kDuA4Kc/QvwmLIDc6z4xG2Q7SmvGFvWXgPYnzcYq7RgymaC+/EFgZ9T1WHrug78CFAFE k3aw== 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=J7UX2XGzxWe3m3OUYUOwz7PyEEOQmjxp5jPkPEdXR2Q=; b=FReYssn0BHuJyqwwv0LMVJ3eKEuFLERkWf137J5d50wupN1SFJsWqEnnViIzlPU0GR 0FuiRMkj8uZ7IbK2S0grKmIrFuAMzw6h31n2agxODkxmq5z2Qk/fyIL3eZCnP4wZGDZa ZpNqRwadEuifOOm7YFosOnVOxgUlr8opvls8XPPAySHoNJ27P6eZgbRPe0gKFmaS8gIM e9sDPA6YezIyCRdgCqwBF/6Ts8z1Cv/PXCjspszEAiaGykpwgpNN1ohNEAVxuxKTAfhA s3pjAO6yRtXXVlibbN8tEcUJsAxHLOEeejmNBbqjmLddEBqXTci02z5Yt+6jCVJFxJWU BLhg== X-Gm-Message-State: APjAAAVQr3C9ZdJ0VuHMyR/e1D3DSuxDvg+v3h6qMjuVbMbJ8rpma91v SqJph3Nv+9juz+3hnzGZJ6UgQAxy6gORlSY/ X-Received: by 2002:a1c:6c01:: with SMTP id h1mr1700638wmc.30.1565859712659; Thu, 15 Aug 2019 02:01:52 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:51 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 16/30] crypto: n2/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:58 +0300 Message-Id: <20190815090112.9377-17-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/n2_core.c | 32 ++++++-------------- 1 file changed, 9 insertions(+), 23 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c index 760e72a5893b..4765163df6be 100644 --- a/drivers/crypto/n2_core.c +++ b/drivers/crypto/n2_core.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -757,24 +757,15 @@ static int n2_aes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, static int n2_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); - struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm); + struct n2_cipher_context *ctx = crypto_ablkcipher_ctx(cipher); struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm); - u32 tmp[DES_EXPKEY_WORDS]; int err; - ctx->enc_type = n2alg->enc_type; - - if (keylen != DES_KEY_SIZE) { - crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; - err = des_ekey(tmp, key); - if (err == 0 && (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + ctx->enc_type = n2alg->enc_type; ctx->key_len = keylen; memcpy(ctx->key.des, key, keylen); @@ -784,18 +775,13 @@ static int n2_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, static int n2_3des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); - struct n2_cipher_context *ctx = crypto_tfm_ctx(tfm); + struct n2_cipher_context *ctx = crypto_ablkcipher_ctx(cipher); struct n2_cipher_alg *n2alg = n2_cipher_alg(tfm); - 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 = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } ctx->enc_type = n2alg->enc_type; From patchwork Thu Aug 15 09:00:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171417 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918321ily; Thu, 15 Aug 2019 02:01:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyACxB+UOpCntLOci8ZxxRjeynEGEYVzxI81zXmea3tl4771sSbcXwsOocCUahWnQ8CvpCA X-Received: by 2002:a63:a35c:: with SMTP id v28mr2754260pgn.144.1565859717681; Thu, 15 Aug 2019 02:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859717; cv=none; d=google.com; s=arc-20160816; b=lURwsfJXe5RyLlNeY4ZNu6AkbzaknFYMJhJK1PgySlluYfD0OFoOUsbLKk+5pu52EN kGz0iJFRwcoeCDdJMJY0IpIyzq/tqJAY0w8VHjhFHqtUnR6Sypsxo/puFWdYt86Uy7Mk iC+aMKYiqHfA3MMqYwbxK04MEzuJIx1dYtsSF/atkZ/C+RJrsCqK8IL9t3IJL0k04vTd aAJXJAeHKPWB6K9CS5jWoOivMAyn92R3CJ5Dxm1RPT9e4SWzOLGcDfY74fvAznEh2H/s 3AUt2cfv6ZNY41vr/3WuRH+LzDYwUmxzOmND/uZP1QECfP5k4yWYVChEkBBOeIZUTCHV WOEw== 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=+kgpUivqCm6iG3E/0kf20tMpbngNNZjTQte9WULnO08=; b=dGcCrvS6JmMkbX5+y8fq7oWlDvuSX0fBUkfRb/ipsQgiMdx4Vo+CEjec14BioQ/DF5 yoON3zsAc1qzXN5D+Ua/LJAnVAiI21sWVm6odvuweyMDJzdPjukjHnF2HgETbWko8QSH PHs98LH8EK9IpIXmezXQ+/+db9YJugEWEOGqvjXYg4SBL3m2ziZetzXkvf4DLIKUk22m IE5T8H+i43oivlYQrDR3YhpQK/PcZfpECDQbr22hq3gg7e6abxVkNGnbBO2dxC0RGJlX 7zj59gXHRl7reUJNYtVYYfmbjTKWfyJ7Hv2/ZZSf+fawqKO8epS3SWzBWtONGNpG+wVX HbOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e96FvNtn; 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.57; Thu, 15 Aug 2019 02:01:57 -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=e96FvNtn; 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 S1730767AbfHOJB5 (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:57 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34574 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJB4 (ORCPT ); Thu, 15 Aug 2019 05:01:56 -0400 Received: by mail-wm1-f66.google.com with SMTP id e8so589724wme.1 for ; Thu, 15 Aug 2019 02:01:55 -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=+kgpUivqCm6iG3E/0kf20tMpbngNNZjTQte9WULnO08=; b=e96FvNtns/NJo1MXRUb+181SdySwSU6p807OfAMxX+rlEgkbWWyuYRTER06B+6i+B+ vwOlY53Z2GZBOGBmDSRFKuZSEBNkCKiFVweR6/QoxCt31AQlNLlpu8yQ2DqnQhENNcff BMWZTnQjUpgX4wDDcXm5GPLvM4k3IZogxlUltvFIjqolA3SIS//yySXU7AltFFF5Fm8M 3emdZNyOiTZCV3Zw/6Joz36itzKyy769jPDd7cCGvsH7OIC/aCEp9yLJI5vGg+tH3VpJ zR3p0KCy3c+P9Ktv7P9Ij2b/4/pPBrWeCHw8QIczj7e6vuGf+fHv9OYKvI1jwky1/vZq ec2w== 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=+kgpUivqCm6iG3E/0kf20tMpbngNNZjTQte9WULnO08=; b=lzlc3u7GkSVk48LpZBRz0JpZBeQ/GOboJdTJyRA834CK13M5wiBTJaMrtl17qrBsWa I+bi17Jp3Cmli4AcqXqzmqx+yrgRKQm/UCrlC27S/uSsFQrD0WSpGIa7nJqLQSQVbTlS qjAH0+CGy/6x8WUFlKCtNh13jygaXL+OtcNcftLw9f/3jn1J60JIcxeB7qWF/Ynm2GBU TmmqD4K7Iw0X3xfmUCI7oENpvLnXaAKnA6wJ4yPj99V0CQMaC7T5RC9ox/KClQ9o6DsO Pw6GPZN/TIrU5ZozFtom+s6i6dQ/x6hef+P/bY6wIH5b95h4KgoVj73USAwhuKUgGh8/ +uWQ== X-Gm-Message-State: APjAAAWypV3lM7qiE8AQYOYviRNjNLzlNtrTXpAK1NFzRDarJjjNGFv0 DQu0fDnNBPfCbc4pEZYfMJxPxZb9sAhKcnnJ X-Received: by 2002:a05:600c:114e:: with SMTP id z14mr1594557wmz.161.1565859714739; Thu, 15 Aug 2019 02:01:54 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:54 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 17/30] crypto: omap/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:00:59 +0300 Message-Id: <20190815090112.9377-18-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/omap-des.c | 27 ++++++-------------- 1 file changed, 8 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c index 484a693122af..b19d7e5d55ec 100644 --- a/drivers/crypto/omap-des.c +++ b/drivers/crypto/omap-des.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include @@ -650,20 +650,13 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(cipher); - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); + int err; pr_debug("enter, keylen: %d\n", keylen); - /* Do we need to test against weak key? */ - if (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) { - u32 tmp[DES_EXPKEY_WORDS]; - int ret = des_ekey(tmp, key); - - if (!ret) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; memcpy(ctx->key, key, keylen); ctx->keylen = keylen; @@ -672,20 +665,16 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, } static int omap_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, - unsigned int keylen) + unsigned int keylen) { struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(cipher); - u32 flags; int err; pr_debug("enter, keylen: %d\n", keylen); - flags = crypto_ablkcipher_get_flags(cipher); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); + err = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen; From patchwork Thu Aug 15 09:01:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171418 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918334ily; Thu, 15 Aug 2019 02:01:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqHITK1cUQvhOpl6lwyB6h8RVPvK0NIC70HlH/eF5wzlzxghFZSPHICvOUvqZhqAD8QmMG X-Received: by 2002:a17:902:7d84:: with SMTP id a4mr3342438plm.90.1565859719095; Thu, 15 Aug 2019 02:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859719; cv=none; d=google.com; s=arc-20160816; b=PBubzN6zjSqDKdebX+XYnCu0OWtBB+4P9wJn2bfqzOrn3gmw8IclWEKnxQVio2Mpsg jK0o+nLvSrzexYxzyWCNnn5YRhhJA2xCH0IKkG94oZHNbrLU590ZxGTqtPB7Am3YVlOl LejLU1UhcPsPbR0TctTJf+JretnrAQvzR2IW2aXpDo7maGdYxWaSFEWMpluX65HadfS7 hHEplCazqaNecTmquLeSj/kwi6h4TdibJpZJDl72eitb/yYjyQJ6dJbip4KYWOckJNse sK2zkglJAUF9SomYmxa7ouhZgymviv8zTuAO4NIhD6qQjbN1ADwph17gVcbrBU/ORQNI P+wQ== 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=ya+ibHRHBdIQl7M6OE87Hqu8AxrbcNkQvqsyCSV7+xk=; b=1APn0qV6Rpx2rBQhjHXjMpJnTbdpLZKJjOgi+l6xc90SzRSveV/6q5IJQ3Irf6ncsp MnQHxSVHW2aLimQ+KeyeXOvZ7UKbo2ZhZNUxH0TLySQvNJqsJZOe0aUfNwV50KQX2PMT XLn1rY4xrnwuU3D5mq9pF+RHcLpVlAZzS166eg5dIigdDz0cDmUHEuPk4e8qkrrQiPDQ oR71zu5HbWT2UzDcT8gse/4NN/AiIq2XlIUuxRQnycL1xl0gFGKFjlT1S0s0bgaSGhb6 kLuNhzTQZYRedRmSNgvtSqcNNrPysBqQtC/XfLZxDapnsh+/P4g02kZSKipknTG3mP7Y ubhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MMVlsP3w; 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.58; Thu, 15 Aug 2019 02:01: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=MMVlsP3w; 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 S1730805AbfHOJB6 (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:58 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36000 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJB6 (ORCPT ); Thu, 15 Aug 2019 05:01:58 -0400 Received: by mail-wm1-f67.google.com with SMTP id g67so682146wme.1 for ; Thu, 15 Aug 2019 02:01:57 -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=ya+ibHRHBdIQl7M6OE87Hqu8AxrbcNkQvqsyCSV7+xk=; b=MMVlsP3wQM1fAvXZbm8M0UMNRgoqbNZKjdfvb59f4jqEVYxqAtfnrXDSIbfOAfg8Uc kAXnmocvONZYKBx8lhUvUrq8Zx+8IjBKOg1Q8wqVtxUF6UtJBHD+Cb6/JXFKaUPCSi4X IL2ciJ6wcn5vYKL+gosC+vI387u5mA+seDBH1rlP1rMhbxKEJ3FhUvjWdNULDQ/z/NS2 UHNGs95vqNtl1+O9wTKnVDEQ+r9IJURA6knuupQ/NTDeB56J/+1vZghzSO8MoPX2oGVp /Linik3X6FB3CddQRpV4oI1Wp57PlQVL7JNufcDVSunC7Qrdm75MsiW4qWPmd3Wn66oC KtHw== 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=ya+ibHRHBdIQl7M6OE87Hqu8AxrbcNkQvqsyCSV7+xk=; b=p1dDCcXO3781vKqAdLYorewTJ0AiIHgCe/Mx7aTOlfWjqSINay7kRPw/m8dPprjKBV x6U6KQ9476k2GKqCpmewJfADu/KzF7lW+My791L5hO9Yg9nzSUsmczLxjWNMmMkNnfzk HzHmYgzhYgVr5wj3Dma2LMB2R74XFqdAWb/IVhxCEt0XOokxh4WFayzr1UiuRM0XOFaT 2O0e0/4QOsNK9NYHgm46u3AzyZTeYUeZh4LIeAmizGD32EK2lVLrQeBOwSy93IJYBb/O clRZKmzWdXz5Ecl/yZEPjcGKyywDDzxXqfC4Sy3V4hnlSgwYKSWr/OqsxHQ92+5WgCdJ XoBQ== X-Gm-Message-State: APjAAAV31qdWOzj7Rl61w22ucpPj5zLPpGwi+faoKQRWz7ExtcjwJKI2 lAWyPhVeePWS+9y/BFV1TaVHRzrBjAm/B+0y X-Received: by 2002:a1c:80d0:: with SMTP id b199mr1660742wmd.31.1565859716118; Thu, 15 Aug 2019 02:01:56 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:55 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 18/30] crypto: picoxcell/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:00 +0300 Message-Id: <20190815090112.9377-19-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/picoxcell_crypto.c | 24 +++++++------------- 1 file changed, 8 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/picoxcell_crypto.c b/drivers/crypto/picoxcell_crypto.c index 9a939b4fd32f..3cbefb41b099 100644 --- a/drivers/crypto/picoxcell_crypto.c +++ b/drivers/crypto/picoxcell_crypto.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -736,16 +736,12 @@ static void spacc_aead_cra_exit(struct crypto_aead *tfm) static int spacc_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int len) { - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); - struct spacc_ablk_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; + struct spacc_ablk_ctx *ctx = crypto_ablkcipher_ctx(cipher); + int err; - if (unlikely(!des_ekey(tmp, key)) && - (crypto_ablkcipher_get_flags(cipher) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; memcpy(ctx->key, key, len); ctx->key_len = len; @@ -761,15 +757,11 @@ static int spacc_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int len) { struct spacc_ablk_ctx *ctx = crypto_ablkcipher_ctx(cipher); - 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 = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } memcpy(ctx->key, key, len); ctx->key_len = len; From patchwork Thu Aug 15 09:01:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171419 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918365ily; Thu, 15 Aug 2019 02:02:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLnxpV93q5cHWE/blM926dqZWZq8tobAYg0tdvugJ5kAI7TW63La5TOYGubpMMI0cga/KO X-Received: by 2002:aa7:96dc:: with SMTP id h28mr4402577pfq.86.1565859720563; Thu, 15 Aug 2019 02:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859720; cv=none; d=google.com; s=arc-20160816; b=JaVXsaz99I4c7lZFUTWSY/ZEWLc8iv/Dhx6WOSHPai3a4aHfvc2dfFvAf7pnrXTpj8 XnZ2rML5rNbzZwjdJ3Nv9i0kwqL3EpaMB0BW7i7epbS5IFH+OrtPuJI7fUDSqdXyUcYM pPvv0OATVHpFGRAmjbdw1+TrPWUVi+P8plT4Q+Kv2DK4sSbG4RVhMYMz09Yh1J3X0yTm OUIgOhRpZIwANTpNdXyy4psO6ugG98+3AyU3/dfWCiMWPVfQOUsJdwa0NtSqSgomv6gt wJaw69+h9ZdY5ABcKu7Qd7ktgetGpRWgR6iJA3OnWMJVdRt4TIpZRFDVkjv/khYE8YpQ 8WUg== 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=oDHNJUSdNPqpSjf/F+ShbODkMMvSncr+A96YTCBGPY0=; b=hinC/G/8xBLnp5Ku3DPEPbUbirlFD02TcD/bGCjD9oviAvm+A1sAd+3o1s3q56dMmR OI4dg+imLHSt3RN1c/J4YUFjyhqbY1xFIcrndnkXWJSufQkyYefhBJwtMqI/TWu793Vc Ci4t8Th0/XamkZ8yFaNM61T9fIn73Y4d62dvvxGPZUAjRoOBvRtBFqqEm+gkoNgHVutH zVvArDl6dgP+MC6Udz51G/QM9bI3F+2ayp2+LPArFpVcMfdcgB7J2tAcVkGITdVTXwJN Wz6QWkgWeSabIGVNizCf/MOPqqb8kSxprlbrT1it9+0BwaRXtvI/sPsx/aSjia0nPbKW 0wmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qc9NeIxw; 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.02.00; Thu, 15 Aug 2019 02:02:00 -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=qc9NeIxw; 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 S1730801AbfHOJB7 (ORCPT + 3 others); Thu, 15 Aug 2019 05:01:59 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40074 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfHOJB7 (ORCPT ); Thu, 15 Aug 2019 05:01:59 -0400 Received: by mail-wm1-f67.google.com with SMTP id v19so674699wmj.5 for ; Thu, 15 Aug 2019 02:01:58 -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=oDHNJUSdNPqpSjf/F+ShbODkMMvSncr+A96YTCBGPY0=; b=qc9NeIxwzioPaFkaKkT3fVDcnGY3Fgrc+Vxc5idgsbqDUdnVU/RcGxbYyYJPaiecXO /5rjUmoM22ds59uL8XVIB4e+i8R9g5DeRFTC4KIhihzEcUUpjQPwlEz0albFDx5U2PmA OIGsJNpIe8an0jIQytcvt5UiK0oV1smRL10iI6nyLuOO9Xwq26XWLnNYeSxJPVGJh0Is cnkYtaUMgh2GsefAE2gmIept4mKR/UZm1BSHhFReIgbswY7KdFJDvt4uuCJvUZpJavMp UAouVGaL71Bb9k0Ia9sUTPguDnFVlWOJv0qnTm2TsJkFq0s5pnJVGbnzv1/oWVpP38i7 bPEQ== 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=oDHNJUSdNPqpSjf/F+ShbODkMMvSncr+A96YTCBGPY0=; b=LPL6QzBRvoEJt2WKppfg6qtT+S0sZLJ8hFi+vL3ec8pK8ib0mgsAen7h/35TSCEUUv T4TCs3xJ6hRrAsw8sFxf2fIGaQfLXncNEG0x3SaggNzeE0MV6EKHHfRtkOLzJb8pUwGO tIQp1Z1pTOmVhLqypdjJAmPGjzSEcJyNwizP48Oei5pfA3FAeLj8a8daNIFUYx1nFKE3 4Z0gk9r7SYpysRVKMsGA+QIYdBZU9EPVAfNC+qDY1Pgj21poAqop94hN2BuG0p8WF1QY 8mUjKvL27wbqJNwGGAH/swrl5PBoivdaEtVdaLtScO4SiOKB9/ZSIqbbmQuiKic0f93t QmMg== X-Gm-Message-State: APjAAAWi7hjxlXfY6vRJ4s/x4tZ1/f/awaGLBjL2aspC+zj0b0vZFUrC 5pYNVedppRqaWS8emY2JKHIxdBrLOICu30wD X-Received: by 2002:a1c:2ec6:: with SMTP id u189mr1655823wmu.67.1565859717581; Thu, 15 Aug 2019 02:01:57 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:56 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 19/30] crypto: qce/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:01 +0300 Message-Id: <20190815090112.9377-20-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/qce/ablkcipher.c | 55 ++++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/qce/ablkcipher.c b/drivers/crypto/qce/ablkcipher.c index a976210ba41c..7a98bf5cc967 100644 --- a/drivers/crypto/qce/ablkcipher.c +++ b/drivers/crypto/qce/ablkcipher.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "cipher.h" @@ -154,27 +154,17 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, { struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); - unsigned long flags = to_cipher_tmpl(tfm)->alg_flags; int ret; if (!key || !keylen) return -EINVAL; - if (IS_AES(flags)) { - switch (keylen) { - case AES_KEYSIZE_128: - case AES_KEYSIZE_256: - break; - default: - goto fallback; - } - } else if (IS_DES(flags)) { - u32 tmp[DES_EXPKEY_WORDS]; - - ret = des_ekey(tmp, key); - if (!ret && (crypto_ablkcipher_get_flags(ablk) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) - goto weakkey; + switch (keylen) { + case AES_KEYSIZE_128: + case AES_KEYSIZE_256: + break; + default: + goto fallback; } ctx->enc_keylen = keylen; @@ -185,24 +175,32 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, if (!ret) ctx->enc_keylen = keylen; return ret; -weakkey: - crypto_ablkcipher_set_flags(ablk, CRYPTO_TFM_RES_WEAK_KEY); - return -EINVAL; +} + +static int qce_des_setkey(struct crypto_ablkcipher *ablk, const u8 *key, + unsigned int keylen) +{ + struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); + int err; + + err = verify_ablkcipher_des_key(ablk, key); + if (err) + return err; + + ctx->enc_keylen = keylen; + memcpy(ctx->enc_key, key, keylen); + return 0; } static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, unsigned int keylen) { struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); - u32 flags; int err; - flags = crypto_ablkcipher_get_flags(ablk); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(ablk, flags); + err = verify_ablkcipher_des3_key(ablk, key); + if (err) return err; - } ctx->enc_keylen = keylen; memcpy(ctx->enc_key, key, keylen); @@ -374,8 +372,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def, alg->cra_ablkcipher.ivsize = def->ivsize; alg->cra_ablkcipher.min_keysize = def->min_keysize; alg->cra_ablkcipher.max_keysize = def->max_keysize; - alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? - qce_des3_setkey : qce_ablkcipher_setkey; + alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? qce_des3_setkey : + IS_DES(def->flags) ? qce_des_setkey : + qce_ablkcipher_setkey; alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; From patchwork Thu Aug 15 09:01:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171420 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918390ily; Thu, 15 Aug 2019 02:02:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeBz893c5opMDv4cstlPnwa7unzLr+PWJV5f9Sa7bue7IWgnm8EvfZVhOEr23lvkbkOcYH X-Received: by 2002:aa7:9638:: with SMTP id r24mr4200150pfg.68.1565859722203; Thu, 15 Aug 2019 02:02:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859722; cv=none; d=google.com; s=arc-20160816; b=TKZBR+IdK6Aaq9la9XMDqyJTRT5/G1H3jiWKZvKQvVOThZKQ7PAErJrHI4rKE5+r7/ 3tZEJsB+eItUBM64g8VhhnL64rCGTk2QMbfN7J51Xm7j2MzlrZs+lPh8zj04jHaLFNZF hjBiZpOwA2ysKaLJZ3X3uIyWcoLSvvS8qqC0Pec+xodKrVzHyEMotXGMwX5SE4sLJyzW 6bDtm4r00HKicylSpUjFre+5fyFq0GZWE6F9mDZxMK7X6AWycpKn+sQ1tQ/KotgntjMI IB68VczPS3zLZgakfpdMbH+1dOiRxt5BN6I6g44iQ5ZZi1IqO7/EKd+c75Pc6CdNQGb+ 1CIw== 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=778hfxXDi1a/ED/3zsXr54rfRhlsz4uqHXQp8Y8p7z0=; b=Uhw4Aoyq/E5veG4JdPNSGR+sfX0OS6mBnn2QD/K0P2tG9oRVLWM5elWtffXZoiBTp1 aaz+WO6h80mT7ESdervFy9O9WpJIIwy9sRqWy5Pj6rh813BGebfOtvcvWEq9LAiF8qV/ pn0xE1VRR3JQkF+nrf9/uMM0QCh3LAKAIK1zpx043G3tBKxnSnuqcvRSwSLVgp5VKSIb QyFiV5qRZo4p6Xj865tR2lBdJW6dQbepv4I4ZkW57SACKievHpxPALR4v4r2mQE3CZJz V/t8UIdN9s80OmVgA5FzDnapSaSQEkynKaLlj7QGtPVfdCz6TUFMpIqJvqaeqxNS30YB 8iHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qgtO7cCM; 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.02.01; Thu, 15 Aug 2019 02:02:02 -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=qgtO7cCM; 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 S1730808AbfHOJCB (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:01 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53445 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfHOJCB (ORCPT ); Thu, 15 Aug 2019 05:02:01 -0400 Received: by mail-wm1-f65.google.com with SMTP id 10so680562wmp.3 for ; Thu, 15 Aug 2019 02:01:59 -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=778hfxXDi1a/ED/3zsXr54rfRhlsz4uqHXQp8Y8p7z0=; b=qgtO7cCMgFqe7yoxE5EcOEeZm3bOuxQAXQz8DvCiciHXoXsquLAsfb0y0lIpwHOaI/ Yqyxe5NtrPX86K6YdD1wSDT/6zzZRbwiDJ1NMmpHow6nP+A2/xINrsTMtalqnFWgP4DA YpaxhkV6u5jzxGnT4MBrNDPwDAl774aH5RX+JZeLSle1i4rTHFxYfynypj9GObR6zWFx 9ZnuV2bVfeK1Fbao6gq3CEjJK9wFSXjKFuivDKSNSvdg9D3SYrEfauK5T3NUVAa6eCSn plTLmJNEnNWRFWiKzfJ5saWbt0yV9JHbEF2QkXaotW5iDcH6Qqq3lcCaHhw0KkuOzwX+ q5Xw== 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=778hfxXDi1a/ED/3zsXr54rfRhlsz4uqHXQp8Y8p7z0=; b=RX9P5TK6MkvFmr1gbBC6EBuzGasG9htQEn5t8cXOxEb+7f0gzJ0CWRFNNuTBnvYKQS cCnSP1FAaMZzM9vVTn76blU0In44Suz6q32TWrX6TAjoGcMOT5l5ytR3mrLqsQBaCyE/ kZ0jgF+UBdHdhFp6BhMRpPgAgGtWXKVE2ixewGPwuK1bsctnG83A+m3so7h+2cPuV0Li q1+rxw1K8a31U284tBSyeiy8Vx4pjJaHvSRNS/sX5/gsub0bv8VoqBPdWAPA+4tx902S WSuesl31v7ndIvuZB9Ru2STM8BzUmUzFAHgtHp4udWMDQKf5+EIS2FPrw/4GEx9lOf6f /rxQ== X-Gm-Message-State: APjAAAU6EGxexNV512n2a8Zt5vPrL5Kyn8AkkPTUkoYQi57s3IILsjaI CKjN8XX8WjRegnfaGA1q96tKpGUtv8lFx+d5 X-Received: by 2002:a1c:3945:: with SMTP id g66mr1620772wma.139.1565859718954; Thu, 15 Aug 2019 02:01:58 -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.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:58 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 20/30] crypto: rk3288/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:02 +0300 Message-Id: <20190815090112.9377-21-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/rockchip/rk3288_crypto.h | 2 +- drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 21 +++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/rockchip/rk3288_crypto.h b/drivers/crypto/rockchip/rk3288_crypto.h index 54ee5b3ed9db..18e2b3f29336 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.h +++ b/drivers/crypto/rockchip/rk3288_crypto.h @@ -3,7 +3,7 @@ #define __RK3288_CRYPTO_H__ #include -#include +#include #include #include #include diff --git a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c index 96078aaa2098..d0f4b2d18059 100644 --- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c +++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c @@ -46,15 +46,12 @@ static int rk_aes_setkey(struct crypto_ablkcipher *cipher, static int rk_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); - struct rk_cipher_ctx *ctx = crypto_tfm_ctx(tfm); - u32 tmp[DES_EXPKEY_WORDS]; + struct rk_cipher_ctx *ctx = crypto_ablkcipher_ctx(cipher); + int err; - if (!des_ekey(tmp, key) && - (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; ctx->keylen = keylen; memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, key, keylen); @@ -65,15 +62,11 @@ static int rk_tdes_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct rk_cipher_ctx *ctx = crypto_ablkcipher_ctx(cipher); - 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 = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } ctx->keylen = keylen; memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, key, keylen); From patchwork Thu Aug 15 09:01:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171421 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918416ily; Thu, 15 Aug 2019 02:02:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8OwyJ/eh+TEwL0azpEiyHpGa3bY2c/Wx4MZNxTJMaF2tI3ntjDkqnAJETvi/21aEB//hl X-Received: by 2002:a17:902:d90a:: with SMTP id c10mr3315323plz.208.1565859723932; Thu, 15 Aug 2019 02:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859723; cv=none; d=google.com; s=arc-20160816; b=0ILJdiQ8K1Q6W31tBzXArlDHu0FfvQKRt8f0swDhI1iqvfw3WiZLhreVcmNYBGr68X iSeX9BApnH1vjZT9Ut1UNwOBQ+NdMn77bW9Xjmxu/PSYN7IEK2EDB/naCLZvQx4tSY0E 5LqL/P8bR8ME1szygPLJ9/tuu0e9gY+qXy49KxYxVjVmc4o9/O01tiBrMRssiVWFAmdk MB72cPMqalE0/n1fVHKO6FDlSl3OIuYqDSXdoZhCS9ZztOEMnjw1ZZRCGQf5f8fYsqut FbjHQ2E6gtszEr0utaflW+9ghvfwRqngyGChePszNb0L9qVIQhlDKPjvmkrDbFfyBj06 QR5A== 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=aK500irIOyWCZfK/24qo1jK8JNVXK4wIKJej8ysCy/c=; b=S/ITbR5NhqwsRxaLehGmYHtYUQZW2eDmgqMBEDY+oFPazrMxBOWsZ2G0+LCCqO2oXL frf+FOvXntWGTbUqgfUtoFZ2NfGLjAvphoIarRucy55NOI5/pQhfhMbkjx2+lZnWcyVl w8JoaloJ39jIs0hAQhaeUBK9zbImPCunqAc1P1b6HLxQglL8zWZ5znmMYSqHkWCc5MkC yq7mA8eYVAud2CNnQ5HcVghMy83I07yqf3wWzIB9f18a9j7ePJ1mULZzZDgILWlJ3LQG 5hjadH7r023fwQCX0//lSzZgO5T+FADCVcr1t+JooRrwmZbv/2FTjFVXSQfVd422QYom Q7Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zwz1i9rI; 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.02.03; Thu, 15 Aug 2019 02:02:03 -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=zwz1i9rI; 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 S1726120AbfHOJCD (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:03 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53449 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfHOJCD (ORCPT ); Thu, 15 Aug 2019 05:02:03 -0400 Received: by mail-wm1-f66.google.com with SMTP id 10so680627wmp.3 for ; Thu, 15 Aug 2019 02:02:01 -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=aK500irIOyWCZfK/24qo1jK8JNVXK4wIKJej8ysCy/c=; b=zwz1i9rIMzQzz4hNhkdPgRVfX+8Zx6QYhRurULthi6GqEs5NjcF5k52jjSdoTFFbTx yKJNq6gjNd/R1pgQ+ANfKrjrZ1KIsivwcRX10Qa4IWiINZz6PjBpOcJR5mm+l2mx/oMZ NhjXgQz9ys/aabQiN6fWYZ6Obp2CKSH5yxr1kzZEcKmLKKGjomBxYjQQSqKpNc+P7t/O I18ueMEoSLobQkJvG77NxowGTklkCpV4llzpbSWY6fdG90DlWWW6JWhAtGhzu3b9qLxe OzGDPkFSJb9yh1l5FSwkFINHknQM9nnw7ssT2QeIs+e7agBf1QV0KttnHm1e6TcmN+C0 URyw== 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=aK500irIOyWCZfK/24qo1jK8JNVXK4wIKJej8ysCy/c=; b=KMVEwOpVR4ImyeiZb9ou4LYLs3KgsV+HOqbtHVw2EscIi9w09B5FMI+/Qf7hkD23Bi aOFRG+EoeGAg6WCK12LZAYKmnlR8p+/TyR/OwH+MbX/RUK9wEfSBkRpV/UhJg78nmUbR IxdcnjfWg74yAjK4kK5G0PJ9bHjy8Nnmy5kWVSNJuO2fcYRf8EzlXa8l2Ovtb7gtNErK 3nMEBaXbRrqUIq+3SMqT+VLJTD/hp1YLy9C+rt8cuFAlTIsEoCPPN+f7kk3eIrznwbZw 4Q7DJpqZSHGqXB9L/A60Ui02wac1WDhAHbz8TcizeXnNf/IEsOMx/8llY+ASVmXPkoEa fn/w== X-Gm-Message-State: APjAAAXV2ycFJqvXEc8DWzpZLIXjKcFnMns8z6QnxJ6oVpOGDgrBGGCi LV9pgJZrgUOxNXNG6w1AlYVEejswYdjOgp7W X-Received: by 2002:a1c:5a56:: with SMTP id o83mr1663958wmb.103.1565859720430; Thu, 15 Aug 2019 02:02:00 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:01:59 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 21/30] crypto: stm32/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:03 +0300 Message-Id: <20190815090112.9377-22-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/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 5cf6679da580..ba5ea6434f9c 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 verify_ablkcipher_des_key(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 verify_ablkcipher_des3_key(tfm, key) ?: + stm32_cryp_setkey(tfm, key, keylen); } static int stm32_cryp_aes_aead_setkey(struct crypto_aead *tfm, const u8 *key, From patchwork Thu Aug 15 09:01:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171422 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918455ily; Thu, 15 Aug 2019 02:02:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzzPZiRp28BMomKNTRlUWGrZfqyn0jt7yXdcM2WadFR4vUohvYqM3qkN7U51OuXExzrjwR/ X-Received: by 2002:a65:4c4d:: with SMTP id l13mr2681733pgr.156.1565859725950; Thu, 15 Aug 2019 02:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859725; cv=none; d=google.com; s=arc-20160816; b=GZ0DxjMY92mh9TAAfc9cxM4eZiEnh20wa6uMNB2d4UuNkM9fKk3GOV1YWVJllSr+iX me7WEaVw3xJoa2H6exTuf8jeYBM9SUZsXs2nh2J4cqz8nTbQZYEKjd4xxi80k5biC/16 L3Z3bYUC8S9AUk9GovAMkhWs+RXaL2Y8t+28V2VNOofU2prdolhqara3QnzbL/SSKHuc hxWhCFwx9vf5n2eKdzG05rWJBp9jjihZ7zvvxmziGyrJpaGPhqVZ9+6w8YZQwYzI/Qat yZw0af2EXXPWyxIOJyFI2bo4Bh1dICSUowEBFOwMEu25D+lX+heyRe9iLjmYngmKBJLm PM9Q== 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=XLJnIIvmW4SzkEyV1uIEA40FVVu0pdhDcedX5nqwoBk=; b=DkG+wMNjCiVC07BusBpaNiwOvKEjnzCSlZqeF5gWCYRQCr/bhD95tYSCNWSdAyvxrW u8LUlqxJH2hbVAA8kbwv9CFawvnG3xkD8Af5Gh04MppOQ09cArnT2TNylFL2KyV5QX5b hEJAQvg6ZCWcRrC2WOI4IHYHOz+TnAuERDGrUygxEECwxL2kYhZ6eYrCP3Q6LaaSPfUA CObvqlUCmoMamfIcI/JLbKhx9CweOKX78Qic1wfCurlyv/fP6tPKNs0+CQqPGjdjEpDB 0c6VGWvZz7eK1viK+rGOHTuxiYaEPJD1oeQcnY8Ov9hOwkw+XfcdMhgyji8gwwhNvwfV 6AmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ouTa8Jts; 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.02.05; Thu, 15 Aug 2019 02:02:05 -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=ouTa8Jts; 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 S1730811AbfHOJCF (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:05 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34583 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfHOJCE (ORCPT ); Thu, 15 Aug 2019 05:02:04 -0400 Received: by mail-wm1-f68.google.com with SMTP id e8so589920wme.1 for ; Thu, 15 Aug 2019 02:02:03 -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=XLJnIIvmW4SzkEyV1uIEA40FVVu0pdhDcedX5nqwoBk=; b=ouTa8JtsfJZaISvVI6BDVEtCiXUWdEm76zb+FfXH0X1oW/RjIVMnu+kPsDdLHgtjH7 cThk2l+89bjCGW41VLvEbnZDIs4jRm39njIFF2e+K8OrmVDeto9JP/wdXktqO2bZmVO2 loxvAwtk/AA+McxxLWFfZnHEwLNiGFR1I+BO6ObJKkLAvubjX1dPrtP2FaD4AaN/GTk8 fIEQUFqUbZ9PxNfcxjk3FhAbuqWeeNLjlbe2SYELV2YEmU76r27T8Lbx4SOZEXv1Ixjk QOwltCNYLFNQBGCBzx3rdWhbqkuzq8dF5zxT8f1U41gAEHzJAWwVvYK585wB2phY6S00 IVjQ== 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=XLJnIIvmW4SzkEyV1uIEA40FVVu0pdhDcedX5nqwoBk=; b=TATZ9jfhPH1NMYAcg3ne3RyAgsOxMramsgQdKVKwR/CkBmp+A/mo7Grik8vtr8ZtCp BVCdEa2XSwv/WH2wKZXkVMDhTHEaijvc7z2m7X4jxkRnvGzpV0EAf8uC6w1adbY0+Lo3 c2vNJd2pXwf0DxjSJ65DnLwshYbOKTDLqikiSwtj0RNzpiu3S6KqnGcU5+mJ95YwswNh 0Vne9Jb0uFd895GNv6tnuCgERoOgiV3qJ5PRw3ktkjvIBNb2Ynq9v102T2A4gbDKI+hP u3hJqeNV5sbEupjkosNjKTIIDZxG8Gv6pjAYv+7p+rAxvy8Xy1EXyCbmT02kmvem9Sfs HMuQ== X-Gm-Message-State: APjAAAW/I9t8S8Pqhyvuk/1NfXI4VcL+Z3ZWUiBm7LYKIE1I/iS46oc/ qXw7jS3cheQ/KcYrgbXwdKVQrQPcOvKhKrOD X-Received: by 2002:a1c:ed06:: with SMTP id l6mr1646070wmh.128.1565859722865; Thu, 15 Aug 2019 02:02:02 -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.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:02 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Corentin Labbe Subject: [PATCH v5 22/30] crypto: sun4i/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:04 +0300 Message-Id: <20190815090112.9377-23-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 Cc: Corentin Labbe Acked-by: Corentin Labbe Signed-off-by: Ard Biesheuvel --- drivers/crypto/sunxi-ss/sun4i-ss-cipher.c | 26 +++++--------------- drivers/crypto/sunxi-ss/sun4i-ss.h | 2 +- 2 files changed, 7 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c index 6f7cbf6c2b55..6536fd4bee65 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c +++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c @@ -542,25 +542,11 @@ int sun4i_ss_des_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) { struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm); - struct sun4i_ss_ctx *ss = op->ss; - u32 flags; - u32 tmp[DES_EXPKEY_WORDS]; - int ret; - - if (unlikely(keylen != DES_KEY_SIZE)) { - dev_err(ss->dev, "Invalid keylen %u\n", keylen); - crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); - return -EINVAL; - } - - flags = crypto_skcipher_get_flags(tfm); + int err; - ret = des_ekey(tmp, key); - if (unlikely(!ret) && (flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); - dev_dbg(ss->dev, "Weak key %u\n", keylen); - return -EINVAL; - } + err = verify_skcipher_des_key(tfm, key); + if (err) + return err; op->keylen = keylen; memcpy(op->key, key, keylen); @@ -578,8 +564,8 @@ int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key, struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm); int err; - err = des3_verify_key(tfm, key); - if (unlikely(err)) + err = verify_skcipher_des3_key(tfm, key); + if (err) return err; op->keylen = keylen; diff --git a/drivers/crypto/sunxi-ss/sun4i-ss.h b/drivers/crypto/sunxi-ss/sun4i-ss.h index 8654d48aedc0..35a27a7145f8 100644 --- a/drivers/crypto/sunxi-ss/sun4i-ss.h +++ b/drivers/crypto/sunxi-ss/sun4i-ss.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include From patchwork Thu Aug 15 09:01: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: 171423 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918511ily; Thu, 15 Aug 2019 02:02:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvvkYvpP85RdpIrsN2MQPs9dRLBmWWrdkKHjr68pJIAOJRSXizncoh+q/QI2MGLTgLCyxj X-Received: by 2002:a63:1918:: with SMTP id z24mr2623301pgl.94.1565859728347; Thu, 15 Aug 2019 02:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859728; cv=none; d=google.com; s=arc-20160816; b=ERXsRyNnaTmva96SjimlK6Z0bYJUkQEy/ekyGuN9CK2SEFMoEvbqZdvZByF73Dn0Mj icGqfpIrn4ACJ0hiZZGWrv0lKRBb/WyJbmZeNCtD564hv/OCToc/+XGrAl1aPwdKcdI5 3P8BdJsTZs9wfGQ+TOpY5/naGN07banyFh/yL8DspJqvCWFWkguDg+sVoxvAUXIY1kwq PrB3yfNqe8bsT1szf+el1lma5OFhYgsJ6PE8zm5z82ecLKCgF3v06auBJ20GPLp/0PHA XDBof880Yv80QYyMxI/YYi4VK6KWOGTuqOOoJCiuDB8LxXmudMXhq8tqERtOteVbIiMn iX0A== 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=w4DLwdf0vNkcjK1oUYPJMOwRT6FQjUNCaxQ0VkHOdYY=; b=Gekqm5A4rYnuQ0c3p3HMxpJE3GNPfIq4EmQyEFE+B81xoSwYglOgMfMKhnQPXWjMh/ yzrRfYyAfNnyVZLC3IkI0ZYk5xpsGV8ZfKI7Hp/VmeMehBQdAlf51Dj1PIzH9AmlGzKI +mXoBsHaxpGHc9uIKQ4qvgJ7KFbf0n9ys3x/QdC0XBaaWqK4s3fokIyw9vm+BzyOv9yi CN35gGiEI9IRXqQttf+xkaDLl1VKg5VQv31dbXKjZvJ3zeiqdNH86ErynjTbpFHoMF9R YGuB2ID7a3K2I/DaymK+SkMKzbM2Pmm2RXtni0HYQu3t5mtM78qMlsV01brYcJ/LeX63 MWSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KdXNwkVe; 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.02.08; Thu, 15 Aug 2019 02:02:08 -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=KdXNwkVe; 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 S1730815AbfHOJCH (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:07 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44478 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfHOJCH (ORCPT ); Thu, 15 Aug 2019 05:02:07 -0400 Received: by mail-wr1-f68.google.com with SMTP id p17so1563909wrf.11 for ; Thu, 15 Aug 2019 02:02:05 -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=w4DLwdf0vNkcjK1oUYPJMOwRT6FQjUNCaxQ0VkHOdYY=; b=KdXNwkVeoBib8xSjJPulcNiB/FgALn1BQj+LmHP09bdsN1d33d1VIb20tqVLDomkrz rvzM+h4qhmy+8IdHi2XgQHCliThwE0H8XBo1M1+7ntEIjlv9fKhYzncBeuCNnO8ROfTU HoVRIloSyBv/s8+wEWhdiMQNQPQ1LsWBStijTQi+dQDmec0WmUibaRPASYx4BdmDdUfN o6+Gh9WcIagnlMQDqDOTi+wSsWGIekiiAnLmAIuROvPvG8a+uCKbaocRJ5fQc1GLANag 3E2fkabbCHmkPOqx/M3mf2eDZbT1GH6mE7JfRyQYKAx+qtqglAHRAphKD+HnX32I8oG8 jSkg== 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=w4DLwdf0vNkcjK1oUYPJMOwRT6FQjUNCaxQ0VkHOdYY=; b=NfnU/3NCNvoeUAx3E+7FgZXt767PE6KBFDqNnR4eYARcsIOkI6JG/IxajeD8oRsGzL lKTjIhFc3d9qIjK6COrjkPnmp7e/yK2YH3qvS9ftiTsPEi52Nbrxr4cfcfRwdtUDI1oe nOQmOy6nAChkgaWk9Wi3AAwAmcASBN563YxxTkHJiHWkxxWj7Hly2cdEyYF5gHXFv4yt Z8Qz1uf1benqZ1ZIpLHR7fw9J0d8FafcAfM2IBxUSQuFL9N+cOizoFkE7nkrzsGpga7L 39685WggogF6CTONvu/d8qSqvvaLxdi1mmCDdOebU5Ur4zgoWeRM6DC8QCJAapnVVrEF x04A== X-Gm-Message-State: APjAAAWDExB6CbKggjVcRHpy7RpDZazDr0fGS7z8AV9e1hoovUp7U/Rz YicgBC8ht+F9dW1fQjrToUeHLMNmuRzuAndM X-Received: by 2002:a5d:6b11:: with SMTP id v17mr4149576wrw.323.1565859725010; Thu, 15 Aug 2019 02:02:05 -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.02.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:04 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Christophe Leroy Subject: [PATCH v5 23/30] crypto: talitos/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:05 +0300 Message-Id: <20190815090112.9377-24-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 Cc: Christophe Leroy Signed-off-by: Ard Biesheuvel --- drivers/crypto/talitos.c | 37 ++++---------------- 1 file changed, 7 insertions(+), 30 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c index c9d686a0e805..117c831b5ede 100644 --- a/drivers/crypto/talitos.c +++ b/drivers/crypto/talitos.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -936,15 +936,9 @@ 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) - goto badkey; - - flags = crypto_aead_get_flags(authenc); - err = __des3_verify_key(&flags, keys.enckey); - if (unlikely(err)) { - crypto_aead_set_flags(authenc, flags); + err = verify_aead_des3_key(authenc, keys.enckey, keys.enckeylen); + if (err) goto out; - } if (ctx->keylen) dma_unmap_single(dev, ctx->dma_key, ctx->keylen, DMA_TO_DEVICE); @@ -1517,32 +1511,15 @@ 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]; - - 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; - } - - return ablkcipher_setkey(cipher, key, keylen); + return verify_ablkcipher_des_key(cipher, key) ?: + ablkcipher_setkey(cipher, key, keylen); } 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); - return err; - } - - return ablkcipher_setkey(cipher, key, keylen); + return verify_ablkcipher_des3_key(cipher, key) ?: + ablkcipher_setkey(cipher, key, keylen); } static int ablkcipher_aes_setkey(struct crypto_ablkcipher *cipher, From patchwork Thu Aug 15 09:01:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171424 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918537ily; Thu, 15 Aug 2019 02:02:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjs8WBsXUnpSfX00FstW09vVMV7JPSK8El7F+g7Bfd/me4dtaOVjr4YNOF4CSQa5xqqE/L X-Received: by 2002:a17:902:f087:: with SMTP id go7mr3407387plb.330.1565859729628; Thu, 15 Aug 2019 02:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859729; cv=none; d=google.com; s=arc-20160816; b=Rt+/EBBpVircmNqraSn0QaLxqk5PzPNr37GxqfJdxX8vMYxxS9UlW+Vtn7HFl+XGi4 IWqrtWaYIthyqkHG+gW87m9aRyKWYGSnPZvfG4kEqobS4/2A+8MF9o1Y1k/jGc37HW8d ZXUbi2Y9pmE9hJcZD5VzJeCbOfA2HKPxtMz8dBt67cPntBr0x0MSrl+qcexvI/mG4mZQ m9d3PUbPGY2Q3MLoPS+BbyEKI5Z+lNiDtoS/6EYVmPEjvNEvVL8yZIr3buMeVz3QNpOm YmCQLHLzvFOG/fbLCQQ/N5qEhtix4UCuMa0RzzA/9Wx+0bD2Hc/QuCRAF5TFrAGuqk4x rTyw== 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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=Icr9wXNNsQ01eFioStCvnfCK0xMouKds/r816eZ8dBiZJJdY4fItMco1FcgqFwHpyj MYBudVyMVao9s5wjBNVH26OOYJU5WpRxEWh3gI8U8C/tXeU1H0E0MtVo2jhW1/z3u72x Tup8SkmXWl1u7ViTqw46uwMW/J1pZkDNaOARJYaqkFXCVGMRQLGGpJAgoASzuloQcJiZ BkSLuXKdCyejrC5gKOyYhEBNvegrG1Q4t022ZfdE+n65qNd4KQzq5ICOs1P5ZwGTtzw9 qv2H5VrEUKLIcMJKfSXPzpeXwvNGi8Yk5tUoI80yCALDYTyp+I7a3r/3Ee5dvibH/B+V 0Sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVqmOF1q; 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.02.09; Thu, 15 Aug 2019 02:02:09 -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=hVqmOF1q; 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 S1730806AbfHOJCJ (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:09 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33096 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730812AbfHOJCI (ORCPT ); Thu, 15 Aug 2019 05:02:08 -0400 Received: by mail-wm1-f65.google.com with SMTP id p77so592734wme.0 for ; Thu, 15 Aug 2019 02:02:07 -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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=hVqmOF1qu+II6tfY1zd1ybrlI9y2D9MSn93KwiDis2+WcuqorSMuQtbT1uLXWF3TIO e2f9UbNNN4WVMhtOV9Xd/mhOCZjDv3x5kPi2cMnC+WlBr4V1OlPerlxr1vkX4H7cdHAH 1qzgZdatL4CXvv/pPEypzuKNjz51GVpMtg7uBndVdD3yz9KAoARJZYebXFqZMboO5+wM kYffU97K8UeQ4f+t0HxaB2g1AA4WLunEY73296dOIoWAQuVfIwy3DTm8g6wOHnJTC9Az q5WT+eJVRmnh+tpyCIbqfx4KRzaCEPMzOkdfmQgWBcoGXywsYKF+HkNfx9jAPVgR09bQ Zv6A== 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=sFD6/mvXD8MMx71MGNXO6jdjD0BYk/bg6JkcVmcj0vo=; b=pCJMZa+eBWLVDu0YmOTYM32Mxw/9hcfr87FmgPLzAvwOyN7R+i+7xe6rK6lm/0Z7Sa bSSqoLPeJUFqKkz1VxvN+5cbnhMGTJyYZdAqH7SOCYteNx9y4OvLtFQzfI5VOACDgPpM 3UCy2UKWotT/tohrrUuvYZO//ob8tvq7h1B0V5m+OaCIT+IpnfUZOTk1blK38UDIwdHm qzhf8CK9aJHIglbQgU/jKcDpBfzwSvJOqjBhLkg2rFpERJcz9HhfA5chK9dHLlJiynYj gHccpmj5dx9pBIYhKtzM+hlB5Kvn9zvqfhvbdVD7wXDCJpdH77g0X4vDXsg21UOB5LZn oSaA== X-Gm-Message-State: APjAAAVFbTn7M3nTWu7NxeJ24iMouygLOOJpzeQcddxxgCSwIg0CPWSS GdXqYRY7YW3clgo635FRSV5zoW/MJHpzIbe1 X-Received: by 2002:a1c:b146:: with SMTP id a67mr1689392wmf.124.1565859726346; Thu, 15 Aug 2019 02:02:06 -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.02.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:05 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 24/30] crypto: ux500/des - switch to new verification routines Date: Thu, 15 Aug 2019 12:01:06 +0300 Message-Id: <20190815090112.9377-25-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/ux500/cryp/cryp_core.c | 31 +++++--------------- 1 file changed, 7 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c index b4beb54c0dbe..e966e9a64501 100644 --- a/drivers/crypto/ux500/cryp/cryp_core.c +++ b/drivers/crypto/ux500/cryp/cryp_core.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -987,26 +987,13 @@ static int des_ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher); - u32 *flags = &cipher->base.crt_flags; - u32 tmp[DES_EXPKEY_WORDS]; - int ret; + int err; pr_debug(DEV_DBG_NAME " [%s]", __func__); - if (keylen != DES_KEY_SIZE) { - *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; - pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_BAD_KEY_LEN", - __func__); - return -EINVAL; - } - ret = des_ekey(tmp, key); - if (unlikely(ret == 0) && - (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - pr_debug(DEV_DBG_NAME " [%s]: CRYPTO_TFM_RES_WEAK_KEY", - __func__); - return -EINVAL; - } + err = verify_ablkcipher_des_key(cipher, key); + if (err) + return err; memcpy(ctx->key, key, keylen); ctx->keylen = keylen; @@ -1019,17 +1006,13 @@ static int des3_ablkcipher_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { struct cryp_ctx *ctx = crypto_ablkcipher_ctx(cipher); - u32 flags; int err; pr_debug(DEV_DBG_NAME " [%s]", __func__); - flags = crypto_ablkcipher_get_flags(cipher); - err = __des3_verify_key(&flags, key); - if (unlikely(err)) { - crypto_ablkcipher_set_flags(cipher, flags); + err = verify_ablkcipher_des3_key(cipher, key); + if (err) return err; - } memcpy(ctx->key, key, keylen); ctx->keylen = keylen; From patchwork Thu Aug 15 09:01:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171425 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918553ily; Thu, 15 Aug 2019 02:02:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkXan4HgDWzCFQG5SFkf56GR6L8C94zY9G8qgbnA0Ullr+5xcCjMctoKiGcW0UJjLEq/Yg X-Received: by 2002:a65:4c4d:: with SMTP id l13mr2681998pgr.156.1565859730501; Thu, 15 Aug 2019 02:02:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859730; cv=none; d=google.com; s=arc-20160816; b=nnV2XALoPdmG6RQjeqDKG3qqmXV8yqusFAss6qd12Mv0T6bCmxzczLcgqnKh9AASlB 3vMFCw+0sGZd6UxldF9fu6abBrsXMuV0oDfCgvSIuzCd/2nQkQvkm+siRV9ABWJvQqh/ vJwl8KldsUYmXe0nqQXzRh7GUcTGkyIrESQ/e25AJ1JUl1wXz0TVRwZN5owcqGS6/oqb BznY9MIgNND2r5/iZ69CYRceocW7Wb7x7sf1XGdlKYB8OgDlRf18TPyUcTZ6nI5xNZj3 ThRFvSYo0y20PeMIMHDKP6SUE4wAlqHfguOzQG1CnFDFNfPrA8AF1hf0t7ZqUVbBwPQv cN7Q== 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=yCESPLK8PsPxTY0h56e7rMqRQ6UHxShhjY396ceo/NE=; b=hpohwY+gge34VcUgwQwSUT10IEjGwcDnqGNIwa51C2n37s2vyyjRjmoAB1+lc8/vf/ dVAMlR0o+pbM1GwanhM2xFBHMZUw/vG/OomKxrnxuMXfaRN0Mv/cVR/+fVRjQzIP/Ece zD3zeuh+KIh1yiFI2QBDnbBw5clJoRYFH16M6B+VRArTnz3P+fabJa9iwPZ24X+giPUw 8VVl4dTAbOl3lCqhTx8OSWB/nC27Ltm/j563RGMOMD60/W5OzLdIHLgSIkyts7cYjVeQ xX/FWtIcVp0/4Y4bIgCd04TwpYKwcOTI8w+DpblZ6mV3vxWM2oi4wo+RSYgYk2su1zlz OPpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L6O8XAd5; 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.02.10; Thu, 15 Aug 2019 02:02:10 -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=L6O8XAd5; 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 S1730812AbfHOJCJ (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:09 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40089 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730559AbfHOJCJ (ORCPT ); Thu, 15 Aug 2019 05:02:09 -0400 Received: by mail-wr1-f66.google.com with SMTP id c3so1586270wrd.7 for ; Thu, 15 Aug 2019 02:02:08 -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=yCESPLK8PsPxTY0h56e7rMqRQ6UHxShhjY396ceo/NE=; b=L6O8XAd5mt7jKpY4cPiwdBmabAPEOW4TR4TLxBMzhZsp5WsCm+Do/lj7nMJGtqT5Jy 1Ek6PT3ZitfbxBzJTuxouP8nqkv2+wqaXnXMOZ8hdvYuaXbmP1v6Mxs3Nnh1tyCv69fO zi3Cds2t2atcffWQkEv0K0MCWtXGUJVFJYdpfbJGYU0bIpoiXRimV0/B9JMy00XWaw4b hAPTp8uQKoORavnFZaQd6yeEbqsI0aGNwfqezCRCN9H7dYdH4+7ffHpkw1Qv21OHdVMK jzQzmoBMubEOo/Kc6IG1JbfbYcraS4GO+pKPEuBF1ZhF5RSKU14+8vW6jjZyCAOkC5xc THxQ== 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=yCESPLK8PsPxTY0h56e7rMqRQ6UHxShhjY396ceo/NE=; b=VSIhIZ9UuvTD7wFf0FGA7ZSSunbf4vv7FAm9qoI5vnYGz3NF6NIUFqItZpLfd5EL5B NU7I0LWDrCR+dpIWdfwHChJFA68e8cOhiqd0EyfFUKDEUe599TV9IZwcQpWM5R9p6Y47 ICuPIw4x9EqPeuMrNMyxhN051z5ZYNrCdIa3DXHUbgsrCj1bYDVzKiGNF2S2lkycW5Tn LhsgmJL5SFP3HrWEBARHb1DrQmdWGQ0iNwQY8LYS76SPM/aelOW2yg4oxkDZlAEWvnDm SYSBDJzVwZRS4Qdisw21DpWexv3hzGwQ6uAEwZiHldn0MO6HVZWEUyl98DBHg+uVAUEl RBPA== X-Gm-Message-State: APjAAAWQgaU0rj2xhMnWBoveh6hiVTWI0838dY60oIZouLmDHrw+tQZc azMffTUwAkqwdYQHp/CNxRyQLUMvBwy/aLEW X-Received: by 2002:adf:a2cd:: with SMTP id t13mr3989590wra.251.1565859727693; Thu, 15 Aug 2019 02:02:07 -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.02.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:07 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 25/30] crypto: 3des - move verification out of exported routine Date: Thu, 15 Aug 2019 12:01:07 +0300 Message-Id: <20190815090112.9377-26-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 In preparation of moving the shared key expansion routine into the DES library, move the verification done by __des3_ede_setkey() into its callers. Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/des3_ede_glue.c | 4 ++++ crypto/des_generic.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index 968386c21ef4..ec608babc22b 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -348,6 +348,10 @@ static int des3_ede_x86_setkey(struct crypto_tfm *tfm, const u8 *key, u32 i, j, tmp; int err; + err = crypto_des3_ede_verify_key(tfm, key); + if (err) + return err; + /* Generate encryption context using generic implementation. */ err = __des3_ede_setkey(ctx->enc_expkey, &tfm->crt_flags, key, keylen); if (err < 0) diff --git a/crypto/des_generic.c b/crypto/des_generic.c index c4d8ecda4ddf..f15ae7660f1b 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -846,10 +846,6 @@ int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, { int err; - err = __des3_verify_key(flags, key); - if (unlikely(err)) - return err; - des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; des_ekey(expkey, key); @@ -862,8 +858,12 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; u32 *expkey = dctx->expkey; + int err; + + err = crypto_des3_ede_verify_key(tfm, key); + if (err) + return err; return __des3_ede_setkey(expkey, flags, key, keylen); } From patchwork Thu Aug 15 09:01:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171426 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918593ily; Thu, 15 Aug 2019 02:02:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNuGXhyY1d+EhkQGl072Uik7qUn2pAer8D+5QjVJE1Ghq/UVDA76iv2DX4ZXb6dT4luNnt X-Received: by 2002:a17:902:5a1:: with SMTP id f30mr3486943plf.64.1565859732812; Thu, 15 Aug 2019 02:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859732; cv=none; d=google.com; s=arc-20160816; b=rpmNUp1TWGl2Rs4Mo4UPyoSDlR7nbBZf0XwWEuUzAi8NGVcHjDprzJSMffzMjKSPvD 9Z5XTrvFFvDSxT7yW9S0VLGKjceyd2dX90/AE1dE1/IAX6dv/uNTR/IlzkYiP7IonHE6 LrK0KvPTTpAGzQGKoUQ2zvtP68hhmT8VuqSY4ds+PyefpSk4ItZP0Syyws6ykpqOUhs1 o9chZR0BB/ldhEqOjRk6HZEUJGkNzMfzmzdluQbtJ4ORBYBWSYqPpOJJl+2g9Ehu2Sdq ybVeHGhpz/R0P1bh1fKTLXZy3HClNBl2BFW2mbNinAHWKAUN/YXnazFcObSEZEsIxSVc YWHw== 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=pe1t6EIo+yRXqpRd0fashi/U/Hk4eqLBq4nJecNCty0=; b=NpWJZYTCpacPAjbuSKaupA4pD32bgtiYYiGmYo/3RXAFWm/Svq5VFoqyT15w5qCNIS xwko1JtwKhK9lAShBV++vkFxZQRyhPS2k7ij/VC5SHLh3viu1XoyRu3D4geuFRGrqZ8k 51jtw7znphob7sdtkEbH/O5zdw0D1Boz6isZdvSc1EmFLnqKX9bogoFcdhJjl3n3T8Ia r4813KxoACmI4GfGBaMm3hLQiIT1HBisgfWJidcxvzjBc7xwhJp9+NZ8l3oR/x5RoHH/ XiU2yUxZ3Fxkr+U3Th6g0tHsP6lC5gki3rddIWSqnBMjInfT4haLX/Bk6C+ryFqN2KTA Eylw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/ovov2u"; 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.02.12; Thu, 15 Aug 2019 02:02: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="W/ovov2u"; 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 S1730816AbfHOJCM (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:12 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52610 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730559AbfHOJCL (ORCPT ); Thu, 15 Aug 2019 05:02:11 -0400 Received: by mail-wm1-f68.google.com with SMTP id o4so678926wmh.2 for ; Thu, 15 Aug 2019 02:02:10 -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=pe1t6EIo+yRXqpRd0fashi/U/Hk4eqLBq4nJecNCty0=; b=W/ovov2u3wtU15EPm5SECrUm13XhWagQwor2qxMXuxW2Ikx/vrfjdS3x8rOzxRru72 AwYscZrWdSKOYXDE8E0pWfOc9Wo70FX/G3xID3avY+Iygb5oE9uQfNqF1rK36YOWqojg nbVoFWUJjIevv2JZeQASw5S2uvte2VaQ/5qRcK7YT3ZUbQ6HEpRmx0o/4h+5PmM79OKU o81pwwgolqTNZv+USmnL1de8R4dkQjRWOIPP9Z2gM5glU39Th1lWsc+PIElFxIqnsEgq exudf3z8toOtSfYBprmuunk2kAJOAeEiq20/EHuhWuPYthENxr2sUMrlm+uINXpj7tbC L+DA== 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=pe1t6EIo+yRXqpRd0fashi/U/Hk4eqLBq4nJecNCty0=; b=boTYDGxyEahQ+bONIsqU0mCp07aBiPUrqxQKmNo2HQYEwgBsbGm9XCHlr9/5hPhbuu Ee6sV9B+35z6JeRkr7GcdWlj/lbUePavV3EnwmTG2mdLEtnlbiL6FozjHYztoN8PMBGy kqqNmCN2yE5c2ShIilfghG2bjfrlG0YhCSZlJH87kHTjt5i/OuhzKeNUfeaYwJ8SfzjF F856g4bbyrFd7sxVgR8VRKr0jIeGiPjVWbtws5fP0KvBgcIvpAY9URAw7AZtjYP+dmvv Uk7jedMbG6dUKUi1a56HXUR+vEQMr9hSMZZMziaQ+5lzKbQCtQ6oY8k6guzwUzWVi27s j6eg== X-Gm-Message-State: APjAAAUTRLoTHk5Ut8qeCymHJx6JQFYFW5msuptf8K2b3vPEgOFaSmA7 f9AxfvS28PlrHjx2NA/kuifwJo2Ri5oWZzQC X-Received: by 2002:a1c:5a56:: with SMTP id o83mr1664675wmb.103.1565859729783; Thu, 15 Aug 2019 02:02:09 -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.02.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:09 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 26/30] crypto: des - remove unused function Date: Thu, 15 Aug 2019 12:01:08 +0300 Message-Id: <20190815090112.9377-27-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 Remove the old DES3 verification functions that are no longer used. Signed-off-by: Ard Biesheuvel --- include/crypto/des.h | 41 -------------------- 1 file changed, 41 deletions(-) -- 2.17.1 diff --git a/include/crypto/des.h b/include/crypto/des.h index 72c7c8e5a5a7..31b04ba835b1 100644 --- a/include/crypto/des.h +++ b/include/crypto/des.h @@ -19,47 +19,6 @@ #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE -static inline int __des3_verify_key(u32 *flags, const u8 *key) -{ - int err = -EINVAL; - u32 K[6]; - - memcpy(K, key, DES3_EDE_KEY_SIZE); - - if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || - !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && - (fips_enabled || - (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS))) - goto bad; - - if (unlikely(!((K[0] ^ K[4]) | (K[1] ^ K[5]))) && fips_enabled) - goto bad; - - err = 0; - -out: - memzero_explicit(K, DES3_EDE_KEY_SIZE); - - return err; - -bad: - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - goto out; -} - -static inline int des3_verify_key(struct crypto_skcipher *tfm, const u8 *key) -{ - u32 flags; - int err; - - flags = crypto_skcipher_get_flags(tfm); - err = __des3_verify_key(&flags, key); - crypto_skcipher_set_flags(tfm, flags); - return err; -} - -extern unsigned long des_ekey(u32 *pe, const u8 *k); - extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, unsigned int keylen); From patchwork Thu Aug 15 09:01:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171430 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918812ily; Thu, 15 Aug 2019 02:02:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZRgm/LUgDe5+NuTrLrbChN20HvdHJT3IpG/ypfLjemrXIMmeYIG2bBwjofklePRz1nbX3 X-Received: by 2002:a65:6891:: with SMTP id e17mr2751272pgt.305.1565859743136; Thu, 15 Aug 2019 02:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859743; cv=none; d=google.com; s=arc-20160816; b=bOF2L7OuA+8WJB0RhP/L+q/R1AYaOC1omOq0qOjCUVn4hD/pmxsrpYiqCdUxb0Vxvp zLJLtbumO/HDLZMT837iuj08ZcU8SlV0QNM0Qwtr/HkUpGVDH+mp5axxaF4JMkZLuZ67 jRg2nb+O87UEsKN+M9owYc03PW2oBbz1rIlTqTWuqi6F2Vie7thTfpZ3Tp5jvoYLzHgJ 8gRelFQPWprBGz3bP2Wn6djeSAz8GkN3+ygbFbfqpJFaBQwEIbja2tQp97PANaF6FzvW iKe11K5Wb52PY6tELf/0sdgS1h9r4/jwV2m+T8WeaFi9PRROSBnnklOeJ71a2O4l4HjG Hh1A== 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=EQD3Yz4/E/hQa6m3ot8YrbybVAaA2KIMFOZXweyBf7Q=; b=gmgYvwzD9QwwcWSdDLtGP4gYFeZBuHO1KEq6TPPy56Rk+ZLsDYiS73p2vR8aAQftLf POR7KzlhS+5v9G1GGqGCT+UvZ3xiZ0XiY/SQhyKkw+3IHAkKEd9i++h7X1BX0qioJx/S W+wM+xVH6jGZ5T2AbaDmNUXRLCf713cbsw+t+8J/s7rvKWGOW04r/fH6750C/WEcPAdk pEEvNDFOHkBTOndryP0Iqo9atPR926ugfUPGIgHO2nJ/zobXy+6x6NCkhwJ0kANNQohA 0kCMDqH5U4YUFWv5NbWnmpBKWWcPnGBB2aREv4vH2gFthS/P80A6B50zWCOthS9Wq0XE 5WYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=moGsEtFE; 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 k11si1650459pfi.3.2019.08.15.02.02.22; Thu, 15 Aug 2019 02:02:23 -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=moGsEtFE; 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 S1730559AbfHOJCW (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:22 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40106 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730822AbfHOJCV (ORCPT ); Thu, 15 Aug 2019 05:02:21 -0400 Received: by mail-wr1-f65.google.com with SMTP id c3so1586715wrd.7 for ; Thu, 15 Aug 2019 02:02:16 -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=EQD3Yz4/E/hQa6m3ot8YrbybVAaA2KIMFOZXweyBf7Q=; b=moGsEtFEoDDfDOOAyEnKBXMBanpzvbN+N89CCLBz56SCnHsgDlQh3sSgW5dOuvc2Pn /URF3Pa5Bv3pLYXYQ9Rq5bdbf15WNi/zkB2D/b+nLMjKw+TjIbJSgAuF0nt5HUsGNnGG O2tG8ostalyEiEztNjbSWBWyZ4cqpY2X30JwwL2GXzhJItsIXiNT8Kzw4+UVcT1cCRkH 28Ygs2RGs9J1kyrq4Sm9LBcRbu2fM6v3opS+rhiYZAHbCE4AycjdY04FRRw3vLDwWUWP BCrG5HjnyMDM/ekUpN8iXNfOGe6yd1S4QKv6a8S7iYWkttTLSuizDn/pMCX2Mll/zxEo AOgg== 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=EQD3Yz4/E/hQa6m3ot8YrbybVAaA2KIMFOZXweyBf7Q=; b=atmgxYrBLCSu8H7NmNCoX3eJYKj+OLWjB3S6pAP71s9pxxCIQh/PrO1B4QnLzbapFx FdpLRgHlCYFGK9/jG66NRHUpXYw5MYlpD3hT1Q0SOYltq72RGiBQXoF2FtgY7l08nbLb 8Ya5a010vJ1cjNL2hWyHd8sBRvIhvp7621pHIWXdTR0/nk2Ezzl/Imf7jIgJdqXbFkEj mT1nQOQBwOwSNDhUjlQ6VBlx00+QwnApK65qwnxjxlxcf3ztMkJww3t2bDritp41JbJ3 Qw6n5N0fP3XEy1yY7vFl3Zz9GuBteQV4r/o6jOSy2LX8Z1lZb3DYTYwHzT93mdh0Y1aN AXCQ== X-Gm-Message-State: APjAAAWZfZxZDDFwsDCES2Tgrz4PO/2BZJ3lLaB0/gwR4PWb9CQvQInm eTkdY8Hj7Bn6uk8YH6TY1jsQLvhuzGWds0Je X-Received: by 2002:a5d:4108:: with SMTP id l8mr4201135wrp.113.1565859734018; Thu, 15 Aug 2019 02:02:14 -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.02.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:13 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 27/30] crypto: des - split off DES library from generic DES cipher driver Date: Thu, 15 Aug 2019 12:01:09 +0300 Message-Id: <20190815090112.9377-28-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 Another one for the cipher museum: split off DES core processing into a separate module so other drivers (mostly for crypto accelerators) can reuse the code without pulling in the generic DES cipher itself. This will also permit the cipher interface to be made private to the crypto API itself once we move the only user in the kernel (CIFS) to this library interface. Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/des3_ede_glue.c | 2 +- crypto/Kconfig | 8 +- crypto/des_generic.c | 917 +------------------- drivers/crypto/Kconfig | 28 +- drivers/crypto/caam/Kconfig | 2 +- drivers/crypto/cavium/nitrox/Kconfig | 2 +- drivers/crypto/inside-secure/safexcel_cipher.c | 2 +- drivers/crypto/stm32/Kconfig | 2 +- drivers/crypto/ux500/Kconfig | 2 +- include/crypto/des.h | 43 +- include/crypto/internal/des.h | 69 +- lib/crypto/Makefile | 3 + lib/crypto/des.c | 902 +++++++++++++++++++ 13 files changed, 1053 insertions(+), 929 deletions(-) -- 2.17.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index ec608babc22b..f730a312ce35 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include #include diff --git a/crypto/Kconfig b/crypto/Kconfig index 8880c1fc51d8..6e01525edad3 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -1301,9 +1301,13 @@ config CRYPTO_CAST6_AVX_X86_64 This module provides the Cast6 cipher algorithm that processes eight blocks parallel using the AVX instruction set. +config CRYPTO_LIB_DES + tristate + config CRYPTO_DES tristate "DES and Triple DES EDE cipher algorithms" select CRYPTO_ALGAPI + select CRYPTO_LIB_DES help DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3). @@ -1311,7 +1315,7 @@ config CRYPTO_DES_SPARC64 tristate "DES and Triple DES EDE cipher algorithms (SPARC64)" depends on SPARC64 select CRYPTO_ALGAPI - select CRYPTO_DES + select CRYPTO_LIB_DES help DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3), optimized using SPARC64 crypto opcodes. @@ -1320,7 +1324,7 @@ config CRYPTO_DES3_EDE_X86_64 tristate "Triple DES EDE cipher algorithm (x86-64)" depends on X86 && 64BIT select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES help Triple DES EDE (FIPS 46-3) algorithm. diff --git a/crypto/des_generic.c b/crypto/des_generic.c index f15ae7660f1b..e021a321f584 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -13,832 +13,42 @@ #include #include #include -#include -#include - -#define ROL(x, r) ((x) = rol32((x), (r))) -#define ROR(x, r) ((x) = ror32((x), (r))) - -struct des_ctx { - u32 expkey[DES_EXPKEY_WORDS]; -}; - -struct des3_ede_ctx { - u32 expkey[DES3_EDE_EXPKEY_WORDS]; -}; - -/* Lookup tables for key expansion */ - -static const u8 pc1[256] = { - 0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14, - 0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54, - 0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16, - 0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56, - 0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c, - 0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c, - 0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e, - 0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e, - 0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34, - 0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74, - 0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36, - 0x26, 0x62, 0x66, 0x66, 0x36, 0x72, 0x76, 0x76, - 0xa0, 0x28, 0xe0, 0x2c, 0xb0, 0x38, 0xf0, 0x3c, - 0xa4, 0x68, 0xe4, 0x6c, 0xb4, 0x78, 0xf4, 0x7c, - 0xa2, 0x2a, 0xe2, 0x2e, 0xb2, 0x3a, 0xf2, 0x3e, - 0xa6, 0x6a, 0xe6, 0x6e, 0xb6, 0x7a, 0xf6, 0x7e, - 0x08, 0x80, 0x48, 0x84, 0x18, 0x90, 0x58, 0x94, - 0x0c, 0xc0, 0x4c, 0xc4, 0x1c, 0xd0, 0x5c, 0xd4, - 0x0a, 0x82, 0x4a, 0x86, 0x1a, 0x92, 0x5a, 0x96, - 0x0e, 0xc2, 0x4e, 0xc6, 0x1e, 0xd2, 0x5e, 0xd6, - 0x88, 0x88, 0xc8, 0x8c, 0x98, 0x98, 0xd8, 0x9c, - 0x8c, 0xc8, 0xcc, 0xcc, 0x9c, 0xd8, 0xdc, 0xdc, - 0x8a, 0x8a, 0xca, 0x8e, 0x9a, 0x9a, 0xda, 0x9e, - 0x8e, 0xca, 0xce, 0xce, 0x9e, 0xda, 0xde, 0xde, - 0x28, 0xa0, 0x68, 0xa4, 0x38, 0xb0, 0x78, 0xb4, - 0x2c, 0xe0, 0x6c, 0xe4, 0x3c, 0xf0, 0x7c, 0xf4, - 0x2a, 0xa2, 0x6a, 0xa6, 0x3a, 0xb2, 0x7a, 0xb6, - 0x2e, 0xe2, 0x6e, 0xe6, 0x3e, 0xf2, 0x7e, 0xf6, - 0xa8, 0xa8, 0xe8, 0xac, 0xb8, 0xb8, 0xf8, 0xbc, - 0xac, 0xe8, 0xec, 0xec, 0xbc, 0xf8, 0xfc, 0xfc, - 0xaa, 0xaa, 0xea, 0xae, 0xba, 0xba, 0xfa, 0xbe, - 0xae, 0xea, 0xee, 0xee, 0xbe, 0xfa, 0xfe, 0xfe -}; - -static const u8 rs[256] = { - 0x00, 0x00, 0x80, 0x80, 0x02, 0x02, 0x82, 0x82, - 0x04, 0x04, 0x84, 0x84, 0x06, 0x06, 0x86, 0x86, - 0x08, 0x08, 0x88, 0x88, 0x0a, 0x0a, 0x8a, 0x8a, - 0x0c, 0x0c, 0x8c, 0x8c, 0x0e, 0x0e, 0x8e, 0x8e, - 0x10, 0x10, 0x90, 0x90, 0x12, 0x12, 0x92, 0x92, - 0x14, 0x14, 0x94, 0x94, 0x16, 0x16, 0x96, 0x96, - 0x18, 0x18, 0x98, 0x98, 0x1a, 0x1a, 0x9a, 0x9a, - 0x1c, 0x1c, 0x9c, 0x9c, 0x1e, 0x1e, 0x9e, 0x9e, - 0x20, 0x20, 0xa0, 0xa0, 0x22, 0x22, 0xa2, 0xa2, - 0x24, 0x24, 0xa4, 0xa4, 0x26, 0x26, 0xa6, 0xa6, - 0x28, 0x28, 0xa8, 0xa8, 0x2a, 0x2a, 0xaa, 0xaa, - 0x2c, 0x2c, 0xac, 0xac, 0x2e, 0x2e, 0xae, 0xae, - 0x30, 0x30, 0xb0, 0xb0, 0x32, 0x32, 0xb2, 0xb2, - 0x34, 0x34, 0xb4, 0xb4, 0x36, 0x36, 0xb6, 0xb6, - 0x38, 0x38, 0xb8, 0xb8, 0x3a, 0x3a, 0xba, 0xba, - 0x3c, 0x3c, 0xbc, 0xbc, 0x3e, 0x3e, 0xbe, 0xbe, - 0x40, 0x40, 0xc0, 0xc0, 0x42, 0x42, 0xc2, 0xc2, - 0x44, 0x44, 0xc4, 0xc4, 0x46, 0x46, 0xc6, 0xc6, - 0x48, 0x48, 0xc8, 0xc8, 0x4a, 0x4a, 0xca, 0xca, - 0x4c, 0x4c, 0xcc, 0xcc, 0x4e, 0x4e, 0xce, 0xce, - 0x50, 0x50, 0xd0, 0xd0, 0x52, 0x52, 0xd2, 0xd2, - 0x54, 0x54, 0xd4, 0xd4, 0x56, 0x56, 0xd6, 0xd6, - 0x58, 0x58, 0xd8, 0xd8, 0x5a, 0x5a, 0xda, 0xda, - 0x5c, 0x5c, 0xdc, 0xdc, 0x5e, 0x5e, 0xde, 0xde, - 0x60, 0x60, 0xe0, 0xe0, 0x62, 0x62, 0xe2, 0xe2, - 0x64, 0x64, 0xe4, 0xe4, 0x66, 0x66, 0xe6, 0xe6, - 0x68, 0x68, 0xe8, 0xe8, 0x6a, 0x6a, 0xea, 0xea, - 0x6c, 0x6c, 0xec, 0xec, 0x6e, 0x6e, 0xee, 0xee, - 0x70, 0x70, 0xf0, 0xf0, 0x72, 0x72, 0xf2, 0xf2, - 0x74, 0x74, 0xf4, 0xf4, 0x76, 0x76, 0xf6, 0xf6, - 0x78, 0x78, 0xf8, 0xf8, 0x7a, 0x7a, 0xfa, 0xfa, - 0x7c, 0x7c, 0xfc, 0xfc, 0x7e, 0x7e, 0xfe, 0xfe -}; - -static const u32 pc2[1024] = { - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00040000, 0x00000000, 0x04000000, 0x00100000, - 0x00400000, 0x00000008, 0x00000800, 0x40000000, - 0x00440000, 0x00000008, 0x04000800, 0x40100000, - 0x00000400, 0x00000020, 0x08000000, 0x00000100, - 0x00040400, 0x00000020, 0x0c000000, 0x00100100, - 0x00400400, 0x00000028, 0x08000800, 0x40000100, - 0x00440400, 0x00000028, 0x0c000800, 0x40100100, - 0x80000000, 0x00000010, 0x00000000, 0x00800000, - 0x80040000, 0x00000010, 0x04000000, 0x00900000, - 0x80400000, 0x00000018, 0x00000800, 0x40800000, - 0x80440000, 0x00000018, 0x04000800, 0x40900000, - 0x80000400, 0x00000030, 0x08000000, 0x00800100, - 0x80040400, 0x00000030, 0x0c000000, 0x00900100, - 0x80400400, 0x00000038, 0x08000800, 0x40800100, - 0x80440400, 0x00000038, 0x0c000800, 0x40900100, - 0x10000000, 0x00000000, 0x00200000, 0x00001000, - 0x10040000, 0x00000000, 0x04200000, 0x00101000, - 0x10400000, 0x00000008, 0x00200800, 0x40001000, - 0x10440000, 0x00000008, 0x04200800, 0x40101000, - 0x10000400, 0x00000020, 0x08200000, 0x00001100, - 0x10040400, 0x00000020, 0x0c200000, 0x00101100, - 0x10400400, 0x00000028, 0x08200800, 0x40001100, - 0x10440400, 0x00000028, 0x0c200800, 0x40101100, - 0x90000000, 0x00000010, 0x00200000, 0x00801000, - 0x90040000, 0x00000010, 0x04200000, 0x00901000, - 0x90400000, 0x00000018, 0x00200800, 0x40801000, - 0x90440000, 0x00000018, 0x04200800, 0x40901000, - 0x90000400, 0x00000030, 0x08200000, 0x00801100, - 0x90040400, 0x00000030, 0x0c200000, 0x00901100, - 0x90400400, 0x00000038, 0x08200800, 0x40801100, - 0x90440400, 0x00000038, 0x0c200800, 0x40901100, - 0x00000200, 0x00080000, 0x00000000, 0x00000004, - 0x00040200, 0x00080000, 0x04000000, 0x00100004, - 0x00400200, 0x00080008, 0x00000800, 0x40000004, - 0x00440200, 0x00080008, 0x04000800, 0x40100004, - 0x00000600, 0x00080020, 0x08000000, 0x00000104, - 0x00040600, 0x00080020, 0x0c000000, 0x00100104, - 0x00400600, 0x00080028, 0x08000800, 0x40000104, - 0x00440600, 0x00080028, 0x0c000800, 0x40100104, - 0x80000200, 0x00080010, 0x00000000, 0x00800004, - 0x80040200, 0x00080010, 0x04000000, 0x00900004, - 0x80400200, 0x00080018, 0x00000800, 0x40800004, - 0x80440200, 0x00080018, 0x04000800, 0x40900004, - 0x80000600, 0x00080030, 0x08000000, 0x00800104, - 0x80040600, 0x00080030, 0x0c000000, 0x00900104, - 0x80400600, 0x00080038, 0x08000800, 0x40800104, - 0x80440600, 0x00080038, 0x0c000800, 0x40900104, - 0x10000200, 0x00080000, 0x00200000, 0x00001004, - 0x10040200, 0x00080000, 0x04200000, 0x00101004, - 0x10400200, 0x00080008, 0x00200800, 0x40001004, - 0x10440200, 0x00080008, 0x04200800, 0x40101004, - 0x10000600, 0x00080020, 0x08200000, 0x00001104, - 0x10040600, 0x00080020, 0x0c200000, 0x00101104, - 0x10400600, 0x00080028, 0x08200800, 0x40001104, - 0x10440600, 0x00080028, 0x0c200800, 0x40101104, - 0x90000200, 0x00080010, 0x00200000, 0x00801004, - 0x90040200, 0x00080010, 0x04200000, 0x00901004, - 0x90400200, 0x00080018, 0x00200800, 0x40801004, - 0x90440200, 0x00080018, 0x04200800, 0x40901004, - 0x90000600, 0x00080030, 0x08200000, 0x00801104, - 0x90040600, 0x00080030, 0x0c200000, 0x00901104, - 0x90400600, 0x00080038, 0x08200800, 0x40801104, - 0x90440600, 0x00080038, 0x0c200800, 0x40901104, - 0x00000002, 0x00002000, 0x20000000, 0x00000001, - 0x00040002, 0x00002000, 0x24000000, 0x00100001, - 0x00400002, 0x00002008, 0x20000800, 0x40000001, - 0x00440002, 0x00002008, 0x24000800, 0x40100001, - 0x00000402, 0x00002020, 0x28000000, 0x00000101, - 0x00040402, 0x00002020, 0x2c000000, 0x00100101, - 0x00400402, 0x00002028, 0x28000800, 0x40000101, - 0x00440402, 0x00002028, 0x2c000800, 0x40100101, - 0x80000002, 0x00002010, 0x20000000, 0x00800001, - 0x80040002, 0x00002010, 0x24000000, 0x00900001, - 0x80400002, 0x00002018, 0x20000800, 0x40800001, - 0x80440002, 0x00002018, 0x24000800, 0x40900001, - 0x80000402, 0x00002030, 0x28000000, 0x00800101, - 0x80040402, 0x00002030, 0x2c000000, 0x00900101, - 0x80400402, 0x00002038, 0x28000800, 0x40800101, - 0x80440402, 0x00002038, 0x2c000800, 0x40900101, - 0x10000002, 0x00002000, 0x20200000, 0x00001001, - 0x10040002, 0x00002000, 0x24200000, 0x00101001, - 0x10400002, 0x00002008, 0x20200800, 0x40001001, - 0x10440002, 0x00002008, 0x24200800, 0x40101001, - 0x10000402, 0x00002020, 0x28200000, 0x00001101, - 0x10040402, 0x00002020, 0x2c200000, 0x00101101, - 0x10400402, 0x00002028, 0x28200800, 0x40001101, - 0x10440402, 0x00002028, 0x2c200800, 0x40101101, - 0x90000002, 0x00002010, 0x20200000, 0x00801001, - 0x90040002, 0x00002010, 0x24200000, 0x00901001, - 0x90400002, 0x00002018, 0x20200800, 0x40801001, - 0x90440002, 0x00002018, 0x24200800, 0x40901001, - 0x90000402, 0x00002030, 0x28200000, 0x00801101, - 0x90040402, 0x00002030, 0x2c200000, 0x00901101, - 0x90400402, 0x00002038, 0x28200800, 0x40801101, - 0x90440402, 0x00002038, 0x2c200800, 0x40901101, - 0x00000202, 0x00082000, 0x20000000, 0x00000005, - 0x00040202, 0x00082000, 0x24000000, 0x00100005, - 0x00400202, 0x00082008, 0x20000800, 0x40000005, - 0x00440202, 0x00082008, 0x24000800, 0x40100005, - 0x00000602, 0x00082020, 0x28000000, 0x00000105, - 0x00040602, 0x00082020, 0x2c000000, 0x00100105, - 0x00400602, 0x00082028, 0x28000800, 0x40000105, - 0x00440602, 0x00082028, 0x2c000800, 0x40100105, - 0x80000202, 0x00082010, 0x20000000, 0x00800005, - 0x80040202, 0x00082010, 0x24000000, 0x00900005, - 0x80400202, 0x00082018, 0x20000800, 0x40800005, - 0x80440202, 0x00082018, 0x24000800, 0x40900005, - 0x80000602, 0x00082030, 0x28000000, 0x00800105, - 0x80040602, 0x00082030, 0x2c000000, 0x00900105, - 0x80400602, 0x00082038, 0x28000800, 0x40800105, - 0x80440602, 0x00082038, 0x2c000800, 0x40900105, - 0x10000202, 0x00082000, 0x20200000, 0x00001005, - 0x10040202, 0x00082000, 0x24200000, 0x00101005, - 0x10400202, 0x00082008, 0x20200800, 0x40001005, - 0x10440202, 0x00082008, 0x24200800, 0x40101005, - 0x10000602, 0x00082020, 0x28200000, 0x00001105, - 0x10040602, 0x00082020, 0x2c200000, 0x00101105, - 0x10400602, 0x00082028, 0x28200800, 0x40001105, - 0x10440602, 0x00082028, 0x2c200800, 0x40101105, - 0x90000202, 0x00082010, 0x20200000, 0x00801005, - 0x90040202, 0x00082010, 0x24200000, 0x00901005, - 0x90400202, 0x00082018, 0x20200800, 0x40801005, - 0x90440202, 0x00082018, 0x24200800, 0x40901005, - 0x90000602, 0x00082030, 0x28200000, 0x00801105, - 0x90040602, 0x00082030, 0x2c200000, 0x00901105, - 0x90400602, 0x00082038, 0x28200800, 0x40801105, - 0x90440602, 0x00082038, 0x2c200800, 0x40901105, - - 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000008, 0x00080000, 0x10000000, - 0x02000000, 0x00000000, 0x00000080, 0x00001000, - 0x02000000, 0x00000008, 0x00080080, 0x10001000, - 0x00004000, 0x00000000, 0x00000040, 0x00040000, - 0x00004000, 0x00000008, 0x00080040, 0x10040000, - 0x02004000, 0x00000000, 0x000000c0, 0x00041000, - 0x02004000, 0x00000008, 0x000800c0, 0x10041000, - 0x00020000, 0x00008000, 0x08000000, 0x00200000, - 0x00020000, 0x00008008, 0x08080000, 0x10200000, - 0x02020000, 0x00008000, 0x08000080, 0x00201000, - 0x02020000, 0x00008008, 0x08080080, 0x10201000, - 0x00024000, 0x00008000, 0x08000040, 0x00240000, - 0x00024000, 0x00008008, 0x08080040, 0x10240000, - 0x02024000, 0x00008000, 0x080000c0, 0x00241000, - 0x02024000, 0x00008008, 0x080800c0, 0x10241000, - 0x00000000, 0x01000000, 0x00002000, 0x00000020, - 0x00000000, 0x01000008, 0x00082000, 0x10000020, - 0x02000000, 0x01000000, 0x00002080, 0x00001020, - 0x02000000, 0x01000008, 0x00082080, 0x10001020, - 0x00004000, 0x01000000, 0x00002040, 0x00040020, - 0x00004000, 0x01000008, 0x00082040, 0x10040020, - 0x02004000, 0x01000000, 0x000020c0, 0x00041020, - 0x02004000, 0x01000008, 0x000820c0, 0x10041020, - 0x00020000, 0x01008000, 0x08002000, 0x00200020, - 0x00020000, 0x01008008, 0x08082000, 0x10200020, - 0x02020000, 0x01008000, 0x08002080, 0x00201020, - 0x02020000, 0x01008008, 0x08082080, 0x10201020, - 0x00024000, 0x01008000, 0x08002040, 0x00240020, - 0x00024000, 0x01008008, 0x08082040, 0x10240020, - 0x02024000, 0x01008000, 0x080020c0, 0x00241020, - 0x02024000, 0x01008008, 0x080820c0, 0x10241020, - 0x00000400, 0x04000000, 0x00100000, 0x00000004, - 0x00000400, 0x04000008, 0x00180000, 0x10000004, - 0x02000400, 0x04000000, 0x00100080, 0x00001004, - 0x02000400, 0x04000008, 0x00180080, 0x10001004, - 0x00004400, 0x04000000, 0x00100040, 0x00040004, - 0x00004400, 0x04000008, 0x00180040, 0x10040004, - 0x02004400, 0x04000000, 0x001000c0, 0x00041004, - 0x02004400, 0x04000008, 0x001800c0, 0x10041004, - 0x00020400, 0x04008000, 0x08100000, 0x00200004, - 0x00020400, 0x04008008, 0x08180000, 0x10200004, - 0x02020400, 0x04008000, 0x08100080, 0x00201004, - 0x02020400, 0x04008008, 0x08180080, 0x10201004, - 0x00024400, 0x04008000, 0x08100040, 0x00240004, - 0x00024400, 0x04008008, 0x08180040, 0x10240004, - 0x02024400, 0x04008000, 0x081000c0, 0x00241004, - 0x02024400, 0x04008008, 0x081800c0, 0x10241004, - 0x00000400, 0x05000000, 0x00102000, 0x00000024, - 0x00000400, 0x05000008, 0x00182000, 0x10000024, - 0x02000400, 0x05000000, 0x00102080, 0x00001024, - 0x02000400, 0x05000008, 0x00182080, 0x10001024, - 0x00004400, 0x05000000, 0x00102040, 0x00040024, - 0x00004400, 0x05000008, 0x00182040, 0x10040024, - 0x02004400, 0x05000000, 0x001020c0, 0x00041024, - 0x02004400, 0x05000008, 0x001820c0, 0x10041024, - 0x00020400, 0x05008000, 0x08102000, 0x00200024, - 0x00020400, 0x05008008, 0x08182000, 0x10200024, - 0x02020400, 0x05008000, 0x08102080, 0x00201024, - 0x02020400, 0x05008008, 0x08182080, 0x10201024, - 0x00024400, 0x05008000, 0x08102040, 0x00240024, - 0x00024400, 0x05008008, 0x08182040, 0x10240024, - 0x02024400, 0x05008000, 0x081020c0, 0x00241024, - 0x02024400, 0x05008008, 0x081820c0, 0x10241024, - 0x00000800, 0x00010000, 0x20000000, 0x00000010, - 0x00000800, 0x00010008, 0x20080000, 0x10000010, - 0x02000800, 0x00010000, 0x20000080, 0x00001010, - 0x02000800, 0x00010008, 0x20080080, 0x10001010, - 0x00004800, 0x00010000, 0x20000040, 0x00040010, - 0x00004800, 0x00010008, 0x20080040, 0x10040010, - 0x02004800, 0x00010000, 0x200000c0, 0x00041010, - 0x02004800, 0x00010008, 0x200800c0, 0x10041010, - 0x00020800, 0x00018000, 0x28000000, 0x00200010, - 0x00020800, 0x00018008, 0x28080000, 0x10200010, - 0x02020800, 0x00018000, 0x28000080, 0x00201010, - 0x02020800, 0x00018008, 0x28080080, 0x10201010, - 0x00024800, 0x00018000, 0x28000040, 0x00240010, - 0x00024800, 0x00018008, 0x28080040, 0x10240010, - 0x02024800, 0x00018000, 0x280000c0, 0x00241010, - 0x02024800, 0x00018008, 0x280800c0, 0x10241010, - 0x00000800, 0x01010000, 0x20002000, 0x00000030, - 0x00000800, 0x01010008, 0x20082000, 0x10000030, - 0x02000800, 0x01010000, 0x20002080, 0x00001030, - 0x02000800, 0x01010008, 0x20082080, 0x10001030, - 0x00004800, 0x01010000, 0x20002040, 0x00040030, - 0x00004800, 0x01010008, 0x20082040, 0x10040030, - 0x02004800, 0x01010000, 0x200020c0, 0x00041030, - 0x02004800, 0x01010008, 0x200820c0, 0x10041030, - 0x00020800, 0x01018000, 0x28002000, 0x00200030, - 0x00020800, 0x01018008, 0x28082000, 0x10200030, - 0x02020800, 0x01018000, 0x28002080, 0x00201030, - 0x02020800, 0x01018008, 0x28082080, 0x10201030, - 0x00024800, 0x01018000, 0x28002040, 0x00240030, - 0x00024800, 0x01018008, 0x28082040, 0x10240030, - 0x02024800, 0x01018000, 0x280020c0, 0x00241030, - 0x02024800, 0x01018008, 0x280820c0, 0x10241030, - 0x00000c00, 0x04010000, 0x20100000, 0x00000014, - 0x00000c00, 0x04010008, 0x20180000, 0x10000014, - 0x02000c00, 0x04010000, 0x20100080, 0x00001014, - 0x02000c00, 0x04010008, 0x20180080, 0x10001014, - 0x00004c00, 0x04010000, 0x20100040, 0x00040014, - 0x00004c00, 0x04010008, 0x20180040, 0x10040014, - 0x02004c00, 0x04010000, 0x201000c0, 0x00041014, - 0x02004c00, 0x04010008, 0x201800c0, 0x10041014, - 0x00020c00, 0x04018000, 0x28100000, 0x00200014, - 0x00020c00, 0x04018008, 0x28180000, 0x10200014, - 0x02020c00, 0x04018000, 0x28100080, 0x00201014, - 0x02020c00, 0x04018008, 0x28180080, 0x10201014, - 0x00024c00, 0x04018000, 0x28100040, 0x00240014, - 0x00024c00, 0x04018008, 0x28180040, 0x10240014, - 0x02024c00, 0x04018000, 0x281000c0, 0x00241014, - 0x02024c00, 0x04018008, 0x281800c0, 0x10241014, - 0x00000c00, 0x05010000, 0x20102000, 0x00000034, - 0x00000c00, 0x05010008, 0x20182000, 0x10000034, - 0x02000c00, 0x05010000, 0x20102080, 0x00001034, - 0x02000c00, 0x05010008, 0x20182080, 0x10001034, - 0x00004c00, 0x05010000, 0x20102040, 0x00040034, - 0x00004c00, 0x05010008, 0x20182040, 0x10040034, - 0x02004c00, 0x05010000, 0x201020c0, 0x00041034, - 0x02004c00, 0x05010008, 0x201820c0, 0x10041034, - 0x00020c00, 0x05018000, 0x28102000, 0x00200034, - 0x00020c00, 0x05018008, 0x28182000, 0x10200034, - 0x02020c00, 0x05018000, 0x28102080, 0x00201034, - 0x02020c00, 0x05018008, 0x28182080, 0x10201034, - 0x00024c00, 0x05018000, 0x28102040, 0x00240034, - 0x00024c00, 0x05018008, 0x28182040, 0x10240034, - 0x02024c00, 0x05018000, 0x281020c0, 0x00241034, - 0x02024c00, 0x05018008, 0x281820c0, 0x10241034 -}; - -/* S-box lookup tables */ - -static const u32 S1[64] = { - 0x01010400, 0x00000000, 0x00010000, 0x01010404, - 0x01010004, 0x00010404, 0x00000004, 0x00010000, - 0x00000400, 0x01010400, 0x01010404, 0x00000400, - 0x01000404, 0x01010004, 0x01000000, 0x00000004, - 0x00000404, 0x01000400, 0x01000400, 0x00010400, - 0x00010400, 0x01010000, 0x01010000, 0x01000404, - 0x00010004, 0x01000004, 0x01000004, 0x00010004, - 0x00000000, 0x00000404, 0x00010404, 0x01000000, - 0x00010000, 0x01010404, 0x00000004, 0x01010000, - 0x01010400, 0x01000000, 0x01000000, 0x00000400, - 0x01010004, 0x00010000, 0x00010400, 0x01000004, - 0x00000400, 0x00000004, 0x01000404, 0x00010404, - 0x01010404, 0x00010004, 0x01010000, 0x01000404, - 0x01000004, 0x00000404, 0x00010404, 0x01010400, - 0x00000404, 0x01000400, 0x01000400, 0x00000000, - 0x00010004, 0x00010400, 0x00000000, 0x01010004 -}; - -static const u32 S2[64] = { - 0x80108020, 0x80008000, 0x00008000, 0x00108020, - 0x00100000, 0x00000020, 0x80100020, 0x80008020, - 0x80000020, 0x80108020, 0x80108000, 0x80000000, - 0x80008000, 0x00100000, 0x00000020, 0x80100020, - 0x00108000, 0x00100020, 0x80008020, 0x00000000, - 0x80000000, 0x00008000, 0x00108020, 0x80100000, - 0x00100020, 0x80000020, 0x00000000, 0x00108000, - 0x00008020, 0x80108000, 0x80100000, 0x00008020, - 0x00000000, 0x00108020, 0x80100020, 0x00100000, - 0x80008020, 0x80100000, 0x80108000, 0x00008000, - 0x80100000, 0x80008000, 0x00000020, 0x80108020, - 0x00108020, 0x00000020, 0x00008000, 0x80000000, - 0x00008020, 0x80108000, 0x00100000, 0x80000020, - 0x00100020, 0x80008020, 0x80000020, 0x00100020, - 0x00108000, 0x00000000, 0x80008000, 0x00008020, - 0x80000000, 0x80100020, 0x80108020, 0x00108000 -}; - -static const u32 S3[64] = { - 0x00000208, 0x08020200, 0x00000000, 0x08020008, - 0x08000200, 0x00000000, 0x00020208, 0x08000200, - 0x00020008, 0x08000008, 0x08000008, 0x00020000, - 0x08020208, 0x00020008, 0x08020000, 0x00000208, - 0x08000000, 0x00000008, 0x08020200, 0x00000200, - 0x00020200, 0x08020000, 0x08020008, 0x00020208, - 0x08000208, 0x00020200, 0x00020000, 0x08000208, - 0x00000008, 0x08020208, 0x00000200, 0x08000000, - 0x08020200, 0x08000000, 0x00020008, 0x00000208, - 0x00020000, 0x08020200, 0x08000200, 0x00000000, - 0x00000200, 0x00020008, 0x08020208, 0x08000200, - 0x08000008, 0x00000200, 0x00000000, 0x08020008, - 0x08000208, 0x00020000, 0x08000000, 0x08020208, - 0x00000008, 0x00020208, 0x00020200, 0x08000008, - 0x08020000, 0x08000208, 0x00000208, 0x08020000, - 0x00020208, 0x00000008, 0x08020008, 0x00020200 -}; - -static const u32 S4[64] = { - 0x00802001, 0x00002081, 0x00002081, 0x00000080, - 0x00802080, 0x00800081, 0x00800001, 0x00002001, - 0x00000000, 0x00802000, 0x00802000, 0x00802081, - 0x00000081, 0x00000000, 0x00800080, 0x00800001, - 0x00000001, 0x00002000, 0x00800000, 0x00802001, - 0x00000080, 0x00800000, 0x00002001, 0x00002080, - 0x00800081, 0x00000001, 0x00002080, 0x00800080, - 0x00002000, 0x00802080, 0x00802081, 0x00000081, - 0x00800080, 0x00800001, 0x00802000, 0x00802081, - 0x00000081, 0x00000000, 0x00000000, 0x00802000, - 0x00002080, 0x00800080, 0x00800081, 0x00000001, - 0x00802001, 0x00002081, 0x00002081, 0x00000080, - 0x00802081, 0x00000081, 0x00000001, 0x00002000, - 0x00800001, 0x00002001, 0x00802080, 0x00800081, - 0x00002001, 0x00002080, 0x00800000, 0x00802001, - 0x00000080, 0x00800000, 0x00002000, 0x00802080 -}; - -static const u32 S5[64] = { - 0x00000100, 0x02080100, 0x02080000, 0x42000100, - 0x00080000, 0x00000100, 0x40000000, 0x02080000, - 0x40080100, 0x00080000, 0x02000100, 0x40080100, - 0x42000100, 0x42080000, 0x00080100, 0x40000000, - 0x02000000, 0x40080000, 0x40080000, 0x00000000, - 0x40000100, 0x42080100, 0x42080100, 0x02000100, - 0x42080000, 0x40000100, 0x00000000, 0x42000000, - 0x02080100, 0x02000000, 0x42000000, 0x00080100, - 0x00080000, 0x42000100, 0x00000100, 0x02000000, - 0x40000000, 0x02080000, 0x42000100, 0x40080100, - 0x02000100, 0x40000000, 0x42080000, 0x02080100, - 0x40080100, 0x00000100, 0x02000000, 0x42080000, - 0x42080100, 0x00080100, 0x42000000, 0x42080100, - 0x02080000, 0x00000000, 0x40080000, 0x42000000, - 0x00080100, 0x02000100, 0x40000100, 0x00080000, - 0x00000000, 0x40080000, 0x02080100, 0x40000100 -}; - -static const u32 S6[64] = { - 0x20000010, 0x20400000, 0x00004000, 0x20404010, - 0x20400000, 0x00000010, 0x20404010, 0x00400000, - 0x20004000, 0x00404010, 0x00400000, 0x20000010, - 0x00400010, 0x20004000, 0x20000000, 0x00004010, - 0x00000000, 0x00400010, 0x20004010, 0x00004000, - 0x00404000, 0x20004010, 0x00000010, 0x20400010, - 0x20400010, 0x00000000, 0x00404010, 0x20404000, - 0x00004010, 0x00404000, 0x20404000, 0x20000000, - 0x20004000, 0x00000010, 0x20400010, 0x00404000, - 0x20404010, 0x00400000, 0x00004010, 0x20000010, - 0x00400000, 0x20004000, 0x20000000, 0x00004010, - 0x20000010, 0x20404010, 0x00404000, 0x20400000, - 0x00404010, 0x20404000, 0x00000000, 0x20400010, - 0x00000010, 0x00004000, 0x20400000, 0x00404010, - 0x00004000, 0x00400010, 0x20004010, 0x00000000, - 0x20404000, 0x20000000, 0x00400010, 0x20004010 -}; - -static const u32 S7[64] = { - 0x00200000, 0x04200002, 0x04000802, 0x00000000, - 0x00000800, 0x04000802, 0x00200802, 0x04200800, - 0x04200802, 0x00200000, 0x00000000, 0x04000002, - 0x00000002, 0x04000000, 0x04200002, 0x00000802, - 0x04000800, 0x00200802, 0x00200002, 0x04000800, - 0x04000002, 0x04200000, 0x04200800, 0x00200002, - 0x04200000, 0x00000800, 0x00000802, 0x04200802, - 0x00200800, 0x00000002, 0x04000000, 0x00200800, - 0x04000000, 0x00200800, 0x00200000, 0x04000802, - 0x04000802, 0x04200002, 0x04200002, 0x00000002, - 0x00200002, 0x04000000, 0x04000800, 0x00200000, - 0x04200800, 0x00000802, 0x00200802, 0x04200800, - 0x00000802, 0x04000002, 0x04200802, 0x04200000, - 0x00200800, 0x00000000, 0x00000002, 0x04200802, - 0x00000000, 0x00200802, 0x04200000, 0x00000800, - 0x04000002, 0x04000800, 0x00000800, 0x00200002 -}; - -static const u32 S8[64] = { - 0x10001040, 0x00001000, 0x00040000, 0x10041040, - 0x10000000, 0x10001040, 0x00000040, 0x10000000, - 0x00040040, 0x10040000, 0x10041040, 0x00041000, - 0x10041000, 0x00041040, 0x00001000, 0x00000040, - 0x10040000, 0x10000040, 0x10001000, 0x00001040, - 0x00041000, 0x00040040, 0x10040040, 0x10041000, - 0x00001040, 0x00000000, 0x00000000, 0x10040040, - 0x10000040, 0x10001000, 0x00041040, 0x00040000, - 0x00041040, 0x00040000, 0x10041000, 0x00001000, - 0x00000040, 0x10040040, 0x00001000, 0x00041040, - 0x10001000, 0x00000040, 0x10000040, 0x10040000, - 0x10040040, 0x10000000, 0x00040000, 0x10001040, - 0x00000000, 0x10041040, 0x00040040, 0x10000040, - 0x10040000, 0x10001000, 0x10001040, 0x00000000, - 0x10041040, 0x00041000, 0x00041000, 0x00001040, - 0x00001040, 0x00040040, 0x10000000, 0x10041000 -}; - -/* Encryption components: IP, FP, and round function */ - -#define IP(L, R, T) \ - ROL(R, 4); \ - T = L; \ - L ^= R; \ - L &= 0xf0f0f0f0; \ - R ^= L; \ - L ^= T; \ - ROL(R, 12); \ - T = L; \ - L ^= R; \ - L &= 0xffff0000; \ - R ^= L; \ - L ^= T; \ - ROR(R, 14); \ - T = L; \ - L ^= R; \ - L &= 0xcccccccc; \ - R ^= L; \ - L ^= T; \ - ROL(R, 6); \ - T = L; \ - L ^= R; \ - L &= 0xff00ff00; \ - R ^= L; \ - L ^= T; \ - ROR(R, 7); \ - T = L; \ - L ^= R; \ - L &= 0xaaaaaaaa; \ - R ^= L; \ - L ^= T; \ - ROL(L, 1); - -#define FP(L, R, T) \ - ROR(L, 1); \ - T = L; \ - L ^= R; \ - L &= 0xaaaaaaaa; \ - R ^= L; \ - L ^= T; \ - ROL(R, 7); \ - T = L; \ - L ^= R; \ - L &= 0xff00ff00; \ - R ^= L; \ - L ^= T; \ - ROR(R, 6); \ - T = L; \ - L ^= R; \ - L &= 0xcccccccc; \ - R ^= L; \ - L ^= T; \ - ROL(R, 14); \ - T = L; \ - L ^= R; \ - L &= 0xffff0000; \ - R ^= L; \ - L ^= T; \ - ROR(R, 12); \ - T = L; \ - L ^= R; \ - L &= 0xf0f0f0f0; \ - R ^= L; \ - L ^= T; \ - ROR(R, 4); - -#define ROUND(L, R, A, B, K, d) \ - B = K[0]; A = K[1]; K += d; \ - B ^= R; A ^= R; \ - B &= 0x3f3f3f3f; ROR(A, 4); \ - L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \ - L ^= S6[0xff & (B >> 8)]; B >>= 16; \ - L ^= S7[0xff & A]; \ - L ^= S5[0xff & (A >> 8)]; A >>= 16; \ - L ^= S4[0xff & B]; \ - L ^= S2[0xff & (B >> 8)]; \ - L ^= S3[0xff & A]; \ - L ^= S1[0xff & (A >> 8)]; - -/* - * PC2 lookup tables are organized as 2 consecutive sets of 4 interleaved - * tables of 128 elements. One set is for C_i and the other for D_i, while - * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i. - * - * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i - * or D_i in bits 7-1 (bit 0 being the least significant). - */ - -#define T1(x) pt[2 * (x) + 0] -#define T2(x) pt[2 * (x) + 1] -#define T3(x) pt[2 * (x) + 2] -#define T4(x) pt[2 * (x) + 3] - -#define DES_PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a)) - -/* - * Encryption key expansion - * - * RFC2451: Weak key checks SHOULD be performed. - * - * FIPS 74: - * - * Keys having duals are keys which produce all zeros, all ones, or - * alternating zero-one patterns in the C and D registers after Permuted - * Choice 1 has operated on the key. - * - */ -unsigned long des_ekey(u32 *pe, const u8 *k) -{ - /* K&R: long is at least 32 bits */ - unsigned long a, b, c, d, w; - const u32 *pt = pc2; - - d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; - c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; - b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; - a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; - - pe[15 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; - pe[14 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[13 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[12 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[11 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[10 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 9 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 8 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; - pe[ 7 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 6 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 5 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 4 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 3 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 2 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 1 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; - pe[ 0 * 2 + 0] = DES_PC2(b, c, d, a); - - /* Check if first half is weak */ - w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); - - /* Skip to next table set */ - pt += 512; - - d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; - c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; - b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; - a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; - - /* Check if second half is weak */ - w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); - - pe[15 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; - pe[14 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[13 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[12 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[11 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[10 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 9 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 8 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; - pe[ 7 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 6 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 5 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 4 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 3 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 2 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[ 1 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; - pe[ 0 * 2 + 1] = DES_PC2(b, c, d, a); - - /* Fixup: 2413 5768 -> 1357 2468 */ - for (d = 0; d < 16; ++d) { - a = pe[2 * d]; - b = pe[2 * d + 1]; - c = a ^ b; - c &= 0xffff0000; - a ^= c; - b ^= c; - ROL(b, 18); - pe[2 * d] = a; - pe[2 * d + 1] = b; - } - - /* Zero if weak key */ - return w; -} -EXPORT_SYMBOL_GPL(des_ekey); - -/* - * Decryption key expansion - * - * No weak key checking is performed, as this is only used by triple DES - * - */ -static void dkey(u32 *pe, const u8 *k) -{ - /* K&R: long is at least 32 bits */ - unsigned long a, b, c, d; - const u32 *pt = pc2; - - d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; - c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; - b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; - a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; - - pe[ 0 * 2] = DES_PC2(a, b, c, d); d = rs[d]; - pe[ 1 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 2 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 3 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 4 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 5 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 6 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 7 * 2] = DES_PC2(d, a, b, c); c = rs[c]; - pe[ 8 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 9 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[10 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[11 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[12 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[13 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[14 * 2] = DES_PC2(c, d, a, b); b = rs[b]; - pe[15 * 2] = DES_PC2(b, c, d, a); - - /* Skip to next table set */ - pt += 512; - - d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; - c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; - b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; - a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; - - pe[ 0 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; - pe[ 1 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 2 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 3 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 4 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 5 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; - pe[ 6 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; - pe[ 7 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; - pe[ 8 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[ 9 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[10 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[11 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[12 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; - pe[13 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; - pe[14 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; - pe[15 * 2 + 1] = DES_PC2(b, c, d, a); - - /* Fixup: 2413 5768 -> 1357 2468 */ - for (d = 0; d < 16; ++d) { - a = pe[2 * d]; - b = pe[2 * d + 1]; - c = a ^ b; - c &= 0xffff0000; - a ^= c; - b ^= c; - ROL(b, 18); - pe[2 * d] = a; - pe[2 * d + 1] = b; - } -} +#include static int des_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *flags = &tfm->crt_flags; - u32 tmp[DES_EXPKEY_WORDS]; - int ret; - - /* Expand to tmp */ - ret = des_ekey(tmp, key); + int err; - if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { - *flags |= CRYPTO_TFM_RES_WEAK_KEY; - return -EINVAL; + err = des_expand_key(dctx, key, keylen); + if (err == -ENOKEY) { + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) + err = -EINVAL; + else + err = 0; } - /* Copy to output */ - memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); - - return 0; + if (err) { + memset(dctx, 0, sizeof(*dctx)); + crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); + } + return err; } -static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void crypto_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { - struct des_ctx *ctx = crypto_tfm_ctx(tfm); - const u32 *K = ctx->expkey; - const __le32 *s = (const __le32 *)src; - __le32 *d = (__le32 *)dst; - u32 L, R, A, B; - int i; - - L = le32_to_cpu(s[0]); - R = le32_to_cpu(s[1]); - - IP(L, R, A); - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, 2); - ROUND(R, L, A, B, K, 2); - } - FP(R, L, A); + const struct des_ctx *dctx = crypto_tfm_ctx(tfm); - d[0] = cpu_to_le32(R); - d[1] = cpu_to_le32(L); + des_encrypt(dctx, dst, src); } -static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void crypto_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { - struct des_ctx *ctx = crypto_tfm_ctx(tfm); - const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2; - const __le32 *s = (const __le32 *)src; - __le32 *d = (__le32 *)dst; - u32 L, R, A, B; - int i; - - L = le32_to_cpu(s[0]); - R = le32_to_cpu(s[1]); + const struct des_ctx *dctx = crypto_tfm_ctx(tfm); - IP(L, R, A); - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, -2); - ROUND(R, L, A, B, K, -2); - } - FP(R, L, A); - - d[0] = cpu_to_le32(R); - d[1] = cpu_to_le32(L); + des_decrypt(dctx, dst, src); } int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, @@ -858,76 +68,37 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - u32 *expkey = dctx->expkey; int err; - err = crypto_des3_ede_verify_key(tfm, key); - if (err) - return err; + err = des3_ede_expand_key(dctx, key, keylen); + if (err == -ENOKEY) { + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) + err = -EINVAL; + else + err = 0; + } - return __des3_ede_setkey(expkey, flags, key, keylen); + if (err) { + memset(dctx, 0, sizeof(*dctx)); + crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); + } + return err; } -static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void crypto_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, + const u8 *src) { - struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - const u32 *K = dctx->expkey; - const __le32 *s = (const __le32 *)src; - __le32 *d = (__le32 *)dst; - u32 L, R, A, B; - int i; - - L = le32_to_cpu(s[0]); - R = le32_to_cpu(s[1]); + const struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - IP(L, R, A); - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, 2); - ROUND(R, L, A, B, K, 2); - } - for (i = 0; i < 8; i++) { - ROUND(R, L, A, B, K, 2); - ROUND(L, R, A, B, K, 2); - } - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, 2); - ROUND(R, L, A, B, K, 2); - } - FP(R, L, A); - - d[0] = cpu_to_le32(R); - d[1] = cpu_to_le32(L); + des3_ede_encrypt(dctx, dst, src); } -static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) +static void crypto_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, + const u8 *src) { - struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; - const __le32 *s = (const __le32 *)src; - __le32 *d = (__le32 *)dst; - u32 L, R, A, B; - int i; - - L = le32_to_cpu(s[0]); - R = le32_to_cpu(s[1]); - - IP(L, R, A); - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, -2); - ROUND(R, L, A, B, K, -2); - } - for (i = 0; i < 8; i++) { - ROUND(R, L, A, B, K, -2); - ROUND(L, R, A, B, K, -2); - } - for (i = 0; i < 8; i++) { - ROUND(L, R, A, B, K, -2); - ROUND(R, L, A, B, K, -2); - } - FP(R, L, A); + const struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); - d[0] = cpu_to_le32(R); - d[1] = cpu_to_le32(L); + des3_ede_decrypt(dctx, dst, src); } static struct crypto_alg des_algs[2] = { { @@ -938,13 +109,12 @@ static struct crypto_alg des_algs[2] = { { .cra_blocksize = DES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct des_ctx), .cra_module = THIS_MODULE, - .cra_alignmask = 3, .cra_u = { .cipher = { .cia_min_keysize = DES_KEY_SIZE, .cia_max_keysize = DES_KEY_SIZE, .cia_setkey = des_setkey, - .cia_encrypt = des_encrypt, - .cia_decrypt = des_decrypt } } + .cia_encrypt = crypto_des_encrypt, + .cia_decrypt = crypto_des_decrypt } } }, { .cra_name = "des3_ede", .cra_driver_name = "des3_ede-generic", @@ -953,13 +123,12 @@ static struct crypto_alg des_algs[2] = { { .cra_blocksize = DES3_EDE_BLOCK_SIZE, .cra_ctxsize = sizeof(struct des3_ede_ctx), .cra_module = THIS_MODULE, - .cra_alignmask = 3, .cra_u = { .cipher = { .cia_min_keysize = DES3_EDE_KEY_SIZE, .cia_max_keysize = DES3_EDE_KEY_SIZE, .cia_setkey = des3_ede_setkey, - .cia_encrypt = des3_ede_encrypt, - .cia_decrypt = des3_ede_decrypt } } + .cia_encrypt = crypto_des3_ede_encrypt, + .cia_decrypt = crypto_des3_ede_decrypt } } } }; static int __init des_generic_mod_init(void) diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig index b8c50871f11b..5cd6e3d12bac 100644 --- a/drivers/crypto/Kconfig +++ b/drivers/crypto/Kconfig @@ -150,7 +150,7 @@ config CRYPTO_DES_S390 depends on S390 select CRYPTO_ALGAPI select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES help This is the s390 hardware accelerated implementation of the DES cipher algorithm (FIPS 46-2), and Triple DES EDE (FIPS 46-3). @@ -215,7 +215,7 @@ config CRYPTO_DEV_MARVELL_CESA tristate "Marvell's Cryptographic Engine driver" depends on PLAT_ORION || ARCH_MVEBU select CRYPTO_LIB_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER select CRYPTO_HASH select SRAM @@ -227,7 +227,7 @@ config CRYPTO_DEV_MARVELL_CESA config CRYPTO_DEV_NIAGARA2 tristate "Niagara2 Stream Processing Unit driver" - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER select CRYPTO_HASH select CRYPTO_MD5 @@ -244,7 +244,7 @@ config CRYPTO_DEV_NIAGARA2 config CRYPTO_DEV_HIFN_795X tristate "Driver HIFN 795x crypto accelerator chips" - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER select HW_RANDOM if CRYPTO_DEV_HIFN_795X_RNG depends on PCI @@ -300,7 +300,7 @@ config CRYPTO_DEV_TALITOS2 config CRYPTO_DEV_IXP4XX tristate "Driver for IXP4xx crypto hardware acceleration" depends on ARCH_IXP4XX && IXP4XX_QMGR && IXP4XX_NPE - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_AEAD select CRYPTO_AUTHENC select CRYPTO_BLKCIPHER @@ -366,7 +366,7 @@ config CRYPTO_DEV_OMAP_AES config CRYPTO_DEV_OMAP_DES tristate "Support for OMAP DES/3DES hw engine" depends on ARCH_OMAP2PLUS - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER select CRYPTO_ENGINE help @@ -384,7 +384,7 @@ config CRYPTO_DEV_PICOXCELL select CRYPTO_AES select CRYPTO_AUTHENC select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_CBC select CRYPTO_ECB select CRYPTO_SEQIV @@ -497,7 +497,7 @@ config CRYPTO_DEV_ATMEL_AES config CRYPTO_DEV_ATMEL_TDES tristate "Support for Atmel DES/TDES hw accelerator" depends on ARCH_AT91 || COMPILE_TEST - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER help Some Atmel processors have DES/TDES hw accelerator. @@ -595,7 +595,7 @@ config CRYPTO_DEV_QCE depends on ARCH_QCOM || COMPILE_TEST depends on HAS_IOMEM select CRYPTO_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_ECB select CRYPTO_CBC select CRYPTO_XTS @@ -643,7 +643,7 @@ config CRYPTO_DEV_SUN4I_SS select CRYPTO_MD5 select CRYPTO_SHA1 select CRYPTO_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_BLKCIPHER help Some Allwinner SoC have a crypto accelerator named @@ -666,7 +666,7 @@ config CRYPTO_DEV_ROCKCHIP tristate "Rockchip's Cryptographic Engine driver" depends on OF && ARCH_ROCKCHIP select CRYPTO_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_MD5 select CRYPTO_SHA1 select CRYPTO_SHA256 @@ -703,7 +703,7 @@ config CRYPTO_DEV_BCM_SPU depends on MAILBOX default m select CRYPTO_AUTHENC - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_MD5 select CRYPTO_SHA1 select CRYPTO_SHA256 @@ -722,7 +722,7 @@ config CRYPTO_DEV_SAFEXCEL select CRYPTO_LIB_AES select CRYPTO_AUTHENC select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_HASH select CRYPTO_HMAC select CRYPTO_MD5 @@ -760,7 +760,7 @@ config CRYPTO_DEV_CCREE default n select CRYPTO_HASH select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES select CRYPTO_AEAD select CRYPTO_AUTHENC select CRYPTO_SHA1 diff --git a/drivers/crypto/caam/Kconfig b/drivers/crypto/caam/Kconfig index e4fdf545ac90..137ed3df0c74 100644 --- a/drivers/crypto/caam/Kconfig +++ b/drivers/crypto/caam/Kconfig @@ -98,7 +98,7 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API select CRYPTO_AEAD select CRYPTO_AUTHENC select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES help Selecting this will offload crypto for users of the scatterlist crypto API (such as the linux native IPSec diff --git a/drivers/crypto/cavium/nitrox/Kconfig b/drivers/crypto/cavium/nitrox/Kconfig index dab162af41b8..7b1e751bb9cd 100644 --- a/drivers/crypto/cavium/nitrox/Kconfig +++ b/drivers/crypto/cavium/nitrox/Kconfig @@ -6,7 +6,7 @@ config CRYPTO_DEV_NITROX tristate select CRYPTO_BLKCIPHER select CRYPTO_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select FW_LOADER config CRYPTO_DEV_NITROX_CNN55XX diff --git a/drivers/crypto/inside-secure/safexcel_cipher.c b/drivers/crypto/inside-secure/safexcel_cipher.c index 16c4d5460334..b68b6a7c0a32 100644 --- a/drivers/crypto/inside-secure/safexcel_cipher.c +++ b/drivers/crypto/inside-secure/safexcel_cipher.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/crypto/stm32/Kconfig b/drivers/crypto/stm32/Kconfig index d6576280fc9b..1aba9372cd23 100644 --- a/drivers/crypto/stm32/Kconfig +++ b/drivers/crypto/stm32/Kconfig @@ -25,7 +25,7 @@ config CRYPTO_DEV_STM32_CRYP depends on ARCH_STM32 select CRYPTO_HASH select CRYPTO_ENGINE - select CRYPTO_DES + select CRYPTO_LIB_DES help This enables support for the CRYP (AES/DES/TDES) hw accelerator which can be found on STMicroelectronics STM32 SOC. diff --git a/drivers/crypto/ux500/Kconfig b/drivers/crypto/ux500/Kconfig index 349d34eaac13..b1c6f739f77b 100644 --- a/drivers/crypto/ux500/Kconfig +++ b/drivers/crypto/ux500/Kconfig @@ -9,7 +9,7 @@ config CRYPTO_DEV_UX500_CRYP depends on CRYPTO_DEV_UX500 select CRYPTO_ALGAPI select CRYPTO_BLKCIPHER - select CRYPTO_DES + select CRYPTO_LIB_DES help This selects the crypto driver for the UX500_CRYP hardware. It supports AES-ECB, CBC and CTR with keys sizes of 128, 192 and 256 bit sizes. diff --git a/include/crypto/des.h b/include/crypto/des.h index 31b04ba835b1..2c864a4e6707 100644 --- a/include/crypto/des.h +++ b/include/crypto/des.h @@ -6,10 +6,7 @@ #ifndef __CRYPTO_DES_H #define __CRYPTO_DES_H -#include -#include -#include -#include +#include #define DES_KEY_SIZE 8 #define DES_EXPKEY_WORDS 32 @@ -19,6 +16,44 @@ #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE +struct des_ctx { + u32 expkey[DES_EXPKEY_WORDS]; +}; + +struct des3_ede_ctx { + u32 expkey[DES3_EDE_EXPKEY_WORDS]; +}; + +void des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src); +void des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src); + +void des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src); +void des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src); + +/** + * des_expand_key - Expand a DES input key into a key schedule + * @ctx: the key schedule + * @key: buffer containing the input key + * @len: size of the buffer contents + * + * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if + * the key is accepted but has been found to be weak. + */ +int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen); + +/** + * des3_ede_expand_key - Expand a triple DES input key into a key schedule + * @ctx: the key schedule + * @key: buffer containing the input key + * @len: size of the buffer contents + * + * Returns 0 on success, -EINVAL if the input key is rejected and -ENOKEY if + * the key is accepted but has been found to be weak. Note that weak keys will + * be rejected (and -EINVAL will be returned) when running in FIPS mode. + */ +int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key, + unsigned int keylen); + extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, unsigned int keylen); diff --git a/include/crypto/internal/des.h b/include/crypto/internal/des.h index f5d2e696522e..81ea1a425e9c 100644 --- a/include/crypto/internal/des.h +++ b/include/crypto/internal/des.h @@ -25,18 +25,21 @@ */ static inline int crypto_des_verify_key(struct crypto_tfm *tfm, const u8 *key) { - u32 tmp[DES_EXPKEY_WORDS]; - int err = 0; - - if (!(crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) - return 0; + struct des_ctx tmp; + int err; + + err = des_expand_key(&tmp, key, DES_KEY_SIZE); + if (err == -ENOKEY) { + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) + err = -EINVAL; + else + err = 0; + } - if (!des_ekey(tmp, key)) { + if (err) crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); - err = -EINVAL; - } - memzero_explicit(tmp, sizeof(tmp)); + memzero_explicit(&tmp, sizeof(tmp)); return err; } @@ -53,6 +56,28 @@ static inline int crypto_des_verify_key(struct crypto_tfm *tfm, const u8 *key) * property. * */ +static inline int des3_ede_verify_key(const u8 *key, unsigned int key_len, + bool check_weak) +{ + int ret = fips_enabled ? -EINVAL : -ENOKEY; + u32 K[6]; + + memcpy(K, key, DES3_EDE_KEY_SIZE); + + if ((!((K[0] ^ K[2]) | (K[1] ^ K[3])) || + !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && + (fips_enabled || check_weak)) + goto bad; + + if ((!((K[0] ^ K[4]) | (K[1] ^ K[5]))) && fips_enabled) + goto bad; + + ret = 0; +bad: + memzero_explicit(K, DES3_EDE_KEY_SIZE); + + return ret; +} /** * crypto_des3_ede_verify_key - Check whether a DES3-EDE key is weak @@ -70,28 +95,14 @@ static inline int crypto_des_verify_key(struct crypto_tfm *tfm, const u8 *key) static inline int crypto_des3_ede_verify_key(struct crypto_tfm *tfm, const u8 *key) { - int err = -EINVAL; - u32 K[6]; - - memcpy(K, key, DES3_EDE_KEY_SIZE); - - if ((!((K[0] ^ K[2]) | (K[1] ^ K[3])) || - !((K[2] ^ K[4]) | (K[3] ^ K[5]))) && - (fips_enabled || (crypto_tfm_get_flags(tfm) & - CRYPTO_TFM_REQ_FORBID_WEAK_KEYS))) - goto bad; - - if ((!((K[0] ^ K[4]) | (K[1] ^ K[5]))) && fips_enabled) - goto bad; + int err; - err = 0; -out: - memzero_explicit(K, DES3_EDE_KEY_SIZE); + err = des3_ede_verify_key(key, DES3_EDE_KEY_SIZE, + crypto_tfm_get_flags(tfm) & + CRYPTO_TFM_REQ_FORBID_WEAK_KEYS); + if (err) + crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); return err; - -bad: - crypto_tfm_set_flags(tfm, CRYPTO_TFM_RES_WEAK_KEY); - goto out; } static inline int verify_skcipher_des_key(struct crypto_skcipher *tfm, diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 42a91c62d96d..101a321b8a99 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -5,3 +5,6 @@ libaes-y := aes.o obj-$(CONFIG_CRYPTO_LIB_ARC4) += libarc4.o libarc4-y := arc4.o + +obj-$(CONFIG_CRYPTO_LIB_DES) += libdes.o +libdes-y := des.o diff --git a/lib/crypto/des.c b/lib/crypto/des.c new file mode 100644 index 000000000000..ef5bb8822aba --- /dev/null +++ b/lib/crypto/des.c @@ -0,0 +1,902 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Cryptographic API. + * + * DES & Triple DES EDE Cipher Algorithms. + * + * Copyright (c) 2005 Dag Arne Osvik + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#define ROL(x, r) ((x) = rol32((x), (r))) +#define ROR(x, r) ((x) = ror32((x), (r))) + +/* Lookup tables for key expansion */ + +static const u8 pc1[256] = { + 0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14, + 0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54, + 0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16, + 0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56, + 0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c, + 0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c, + 0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e, + 0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e, + 0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34, + 0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74, + 0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36, + 0x26, 0x62, 0x66, 0x66, 0x36, 0x72, 0x76, 0x76, + 0xa0, 0x28, 0xe0, 0x2c, 0xb0, 0x38, 0xf0, 0x3c, + 0xa4, 0x68, 0xe4, 0x6c, 0xb4, 0x78, 0xf4, 0x7c, + 0xa2, 0x2a, 0xe2, 0x2e, 0xb2, 0x3a, 0xf2, 0x3e, + 0xa6, 0x6a, 0xe6, 0x6e, 0xb6, 0x7a, 0xf6, 0x7e, + 0x08, 0x80, 0x48, 0x84, 0x18, 0x90, 0x58, 0x94, + 0x0c, 0xc0, 0x4c, 0xc4, 0x1c, 0xd0, 0x5c, 0xd4, + 0x0a, 0x82, 0x4a, 0x86, 0x1a, 0x92, 0x5a, 0x96, + 0x0e, 0xc2, 0x4e, 0xc6, 0x1e, 0xd2, 0x5e, 0xd6, + 0x88, 0x88, 0xc8, 0x8c, 0x98, 0x98, 0xd8, 0x9c, + 0x8c, 0xc8, 0xcc, 0xcc, 0x9c, 0xd8, 0xdc, 0xdc, + 0x8a, 0x8a, 0xca, 0x8e, 0x9a, 0x9a, 0xda, 0x9e, + 0x8e, 0xca, 0xce, 0xce, 0x9e, 0xda, 0xde, 0xde, + 0x28, 0xa0, 0x68, 0xa4, 0x38, 0xb0, 0x78, 0xb4, + 0x2c, 0xe0, 0x6c, 0xe4, 0x3c, 0xf0, 0x7c, 0xf4, + 0x2a, 0xa2, 0x6a, 0xa6, 0x3a, 0xb2, 0x7a, 0xb6, + 0x2e, 0xe2, 0x6e, 0xe6, 0x3e, 0xf2, 0x7e, 0xf6, + 0xa8, 0xa8, 0xe8, 0xac, 0xb8, 0xb8, 0xf8, 0xbc, + 0xac, 0xe8, 0xec, 0xec, 0xbc, 0xf8, 0xfc, 0xfc, + 0xaa, 0xaa, 0xea, 0xae, 0xba, 0xba, 0xfa, 0xbe, + 0xae, 0xea, 0xee, 0xee, 0xbe, 0xfa, 0xfe, 0xfe +}; + +static const u8 rs[256] = { + 0x00, 0x00, 0x80, 0x80, 0x02, 0x02, 0x82, 0x82, + 0x04, 0x04, 0x84, 0x84, 0x06, 0x06, 0x86, 0x86, + 0x08, 0x08, 0x88, 0x88, 0x0a, 0x0a, 0x8a, 0x8a, + 0x0c, 0x0c, 0x8c, 0x8c, 0x0e, 0x0e, 0x8e, 0x8e, + 0x10, 0x10, 0x90, 0x90, 0x12, 0x12, 0x92, 0x92, + 0x14, 0x14, 0x94, 0x94, 0x16, 0x16, 0x96, 0x96, + 0x18, 0x18, 0x98, 0x98, 0x1a, 0x1a, 0x9a, 0x9a, + 0x1c, 0x1c, 0x9c, 0x9c, 0x1e, 0x1e, 0x9e, 0x9e, + 0x20, 0x20, 0xa0, 0xa0, 0x22, 0x22, 0xa2, 0xa2, + 0x24, 0x24, 0xa4, 0xa4, 0x26, 0x26, 0xa6, 0xa6, + 0x28, 0x28, 0xa8, 0xa8, 0x2a, 0x2a, 0xaa, 0xaa, + 0x2c, 0x2c, 0xac, 0xac, 0x2e, 0x2e, 0xae, 0xae, + 0x30, 0x30, 0xb0, 0xb0, 0x32, 0x32, 0xb2, 0xb2, + 0x34, 0x34, 0xb4, 0xb4, 0x36, 0x36, 0xb6, 0xb6, + 0x38, 0x38, 0xb8, 0xb8, 0x3a, 0x3a, 0xba, 0xba, + 0x3c, 0x3c, 0xbc, 0xbc, 0x3e, 0x3e, 0xbe, 0xbe, + 0x40, 0x40, 0xc0, 0xc0, 0x42, 0x42, 0xc2, 0xc2, + 0x44, 0x44, 0xc4, 0xc4, 0x46, 0x46, 0xc6, 0xc6, + 0x48, 0x48, 0xc8, 0xc8, 0x4a, 0x4a, 0xca, 0xca, + 0x4c, 0x4c, 0xcc, 0xcc, 0x4e, 0x4e, 0xce, 0xce, + 0x50, 0x50, 0xd0, 0xd0, 0x52, 0x52, 0xd2, 0xd2, + 0x54, 0x54, 0xd4, 0xd4, 0x56, 0x56, 0xd6, 0xd6, + 0x58, 0x58, 0xd8, 0xd8, 0x5a, 0x5a, 0xda, 0xda, + 0x5c, 0x5c, 0xdc, 0xdc, 0x5e, 0x5e, 0xde, 0xde, + 0x60, 0x60, 0xe0, 0xe0, 0x62, 0x62, 0xe2, 0xe2, + 0x64, 0x64, 0xe4, 0xe4, 0x66, 0x66, 0xe6, 0xe6, + 0x68, 0x68, 0xe8, 0xe8, 0x6a, 0x6a, 0xea, 0xea, + 0x6c, 0x6c, 0xec, 0xec, 0x6e, 0x6e, 0xee, 0xee, + 0x70, 0x70, 0xf0, 0xf0, 0x72, 0x72, 0xf2, 0xf2, + 0x74, 0x74, 0xf4, 0xf4, 0x76, 0x76, 0xf6, 0xf6, + 0x78, 0x78, 0xf8, 0xf8, 0x7a, 0x7a, 0xfa, 0xfa, + 0x7c, 0x7c, 0xfc, 0xfc, 0x7e, 0x7e, 0xfe, 0xfe +}; + +static const u32 pc2[1024] = { + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00040000, 0x00000000, 0x04000000, 0x00100000, + 0x00400000, 0x00000008, 0x00000800, 0x40000000, + 0x00440000, 0x00000008, 0x04000800, 0x40100000, + 0x00000400, 0x00000020, 0x08000000, 0x00000100, + 0x00040400, 0x00000020, 0x0c000000, 0x00100100, + 0x00400400, 0x00000028, 0x08000800, 0x40000100, + 0x00440400, 0x00000028, 0x0c000800, 0x40100100, + 0x80000000, 0x00000010, 0x00000000, 0x00800000, + 0x80040000, 0x00000010, 0x04000000, 0x00900000, + 0x80400000, 0x00000018, 0x00000800, 0x40800000, + 0x80440000, 0x00000018, 0x04000800, 0x40900000, + 0x80000400, 0x00000030, 0x08000000, 0x00800100, + 0x80040400, 0x00000030, 0x0c000000, 0x00900100, + 0x80400400, 0x00000038, 0x08000800, 0x40800100, + 0x80440400, 0x00000038, 0x0c000800, 0x40900100, + 0x10000000, 0x00000000, 0x00200000, 0x00001000, + 0x10040000, 0x00000000, 0x04200000, 0x00101000, + 0x10400000, 0x00000008, 0x00200800, 0x40001000, + 0x10440000, 0x00000008, 0x04200800, 0x40101000, + 0x10000400, 0x00000020, 0x08200000, 0x00001100, + 0x10040400, 0x00000020, 0x0c200000, 0x00101100, + 0x10400400, 0x00000028, 0x08200800, 0x40001100, + 0x10440400, 0x00000028, 0x0c200800, 0x40101100, + 0x90000000, 0x00000010, 0x00200000, 0x00801000, + 0x90040000, 0x00000010, 0x04200000, 0x00901000, + 0x90400000, 0x00000018, 0x00200800, 0x40801000, + 0x90440000, 0x00000018, 0x04200800, 0x40901000, + 0x90000400, 0x00000030, 0x08200000, 0x00801100, + 0x90040400, 0x00000030, 0x0c200000, 0x00901100, + 0x90400400, 0x00000038, 0x08200800, 0x40801100, + 0x90440400, 0x00000038, 0x0c200800, 0x40901100, + 0x00000200, 0x00080000, 0x00000000, 0x00000004, + 0x00040200, 0x00080000, 0x04000000, 0x00100004, + 0x00400200, 0x00080008, 0x00000800, 0x40000004, + 0x00440200, 0x00080008, 0x04000800, 0x40100004, + 0x00000600, 0x00080020, 0x08000000, 0x00000104, + 0x00040600, 0x00080020, 0x0c000000, 0x00100104, + 0x00400600, 0x00080028, 0x08000800, 0x40000104, + 0x00440600, 0x00080028, 0x0c000800, 0x40100104, + 0x80000200, 0x00080010, 0x00000000, 0x00800004, + 0x80040200, 0x00080010, 0x04000000, 0x00900004, + 0x80400200, 0x00080018, 0x00000800, 0x40800004, + 0x80440200, 0x00080018, 0x04000800, 0x40900004, + 0x80000600, 0x00080030, 0x08000000, 0x00800104, + 0x80040600, 0x00080030, 0x0c000000, 0x00900104, + 0x80400600, 0x00080038, 0x08000800, 0x40800104, + 0x80440600, 0x00080038, 0x0c000800, 0x40900104, + 0x10000200, 0x00080000, 0x00200000, 0x00001004, + 0x10040200, 0x00080000, 0x04200000, 0x00101004, + 0x10400200, 0x00080008, 0x00200800, 0x40001004, + 0x10440200, 0x00080008, 0x04200800, 0x40101004, + 0x10000600, 0x00080020, 0x08200000, 0x00001104, + 0x10040600, 0x00080020, 0x0c200000, 0x00101104, + 0x10400600, 0x00080028, 0x08200800, 0x40001104, + 0x10440600, 0x00080028, 0x0c200800, 0x40101104, + 0x90000200, 0x00080010, 0x00200000, 0x00801004, + 0x90040200, 0x00080010, 0x04200000, 0x00901004, + 0x90400200, 0x00080018, 0x00200800, 0x40801004, + 0x90440200, 0x00080018, 0x04200800, 0x40901004, + 0x90000600, 0x00080030, 0x08200000, 0x00801104, + 0x90040600, 0x00080030, 0x0c200000, 0x00901104, + 0x90400600, 0x00080038, 0x08200800, 0x40801104, + 0x90440600, 0x00080038, 0x0c200800, 0x40901104, + 0x00000002, 0x00002000, 0x20000000, 0x00000001, + 0x00040002, 0x00002000, 0x24000000, 0x00100001, + 0x00400002, 0x00002008, 0x20000800, 0x40000001, + 0x00440002, 0x00002008, 0x24000800, 0x40100001, + 0x00000402, 0x00002020, 0x28000000, 0x00000101, + 0x00040402, 0x00002020, 0x2c000000, 0x00100101, + 0x00400402, 0x00002028, 0x28000800, 0x40000101, + 0x00440402, 0x00002028, 0x2c000800, 0x40100101, + 0x80000002, 0x00002010, 0x20000000, 0x00800001, + 0x80040002, 0x00002010, 0x24000000, 0x00900001, + 0x80400002, 0x00002018, 0x20000800, 0x40800001, + 0x80440002, 0x00002018, 0x24000800, 0x40900001, + 0x80000402, 0x00002030, 0x28000000, 0x00800101, + 0x80040402, 0x00002030, 0x2c000000, 0x00900101, + 0x80400402, 0x00002038, 0x28000800, 0x40800101, + 0x80440402, 0x00002038, 0x2c000800, 0x40900101, + 0x10000002, 0x00002000, 0x20200000, 0x00001001, + 0x10040002, 0x00002000, 0x24200000, 0x00101001, + 0x10400002, 0x00002008, 0x20200800, 0x40001001, + 0x10440002, 0x00002008, 0x24200800, 0x40101001, + 0x10000402, 0x00002020, 0x28200000, 0x00001101, + 0x10040402, 0x00002020, 0x2c200000, 0x00101101, + 0x10400402, 0x00002028, 0x28200800, 0x40001101, + 0x10440402, 0x00002028, 0x2c200800, 0x40101101, + 0x90000002, 0x00002010, 0x20200000, 0x00801001, + 0x90040002, 0x00002010, 0x24200000, 0x00901001, + 0x90400002, 0x00002018, 0x20200800, 0x40801001, + 0x90440002, 0x00002018, 0x24200800, 0x40901001, + 0x90000402, 0x00002030, 0x28200000, 0x00801101, + 0x90040402, 0x00002030, 0x2c200000, 0x00901101, + 0x90400402, 0x00002038, 0x28200800, 0x40801101, + 0x90440402, 0x00002038, 0x2c200800, 0x40901101, + 0x00000202, 0x00082000, 0x20000000, 0x00000005, + 0x00040202, 0x00082000, 0x24000000, 0x00100005, + 0x00400202, 0x00082008, 0x20000800, 0x40000005, + 0x00440202, 0x00082008, 0x24000800, 0x40100005, + 0x00000602, 0x00082020, 0x28000000, 0x00000105, + 0x00040602, 0x00082020, 0x2c000000, 0x00100105, + 0x00400602, 0x00082028, 0x28000800, 0x40000105, + 0x00440602, 0x00082028, 0x2c000800, 0x40100105, + 0x80000202, 0x00082010, 0x20000000, 0x00800005, + 0x80040202, 0x00082010, 0x24000000, 0x00900005, + 0x80400202, 0x00082018, 0x20000800, 0x40800005, + 0x80440202, 0x00082018, 0x24000800, 0x40900005, + 0x80000602, 0x00082030, 0x28000000, 0x00800105, + 0x80040602, 0x00082030, 0x2c000000, 0x00900105, + 0x80400602, 0x00082038, 0x28000800, 0x40800105, + 0x80440602, 0x00082038, 0x2c000800, 0x40900105, + 0x10000202, 0x00082000, 0x20200000, 0x00001005, + 0x10040202, 0x00082000, 0x24200000, 0x00101005, + 0x10400202, 0x00082008, 0x20200800, 0x40001005, + 0x10440202, 0x00082008, 0x24200800, 0x40101005, + 0x10000602, 0x00082020, 0x28200000, 0x00001105, + 0x10040602, 0x00082020, 0x2c200000, 0x00101105, + 0x10400602, 0x00082028, 0x28200800, 0x40001105, + 0x10440602, 0x00082028, 0x2c200800, 0x40101105, + 0x90000202, 0x00082010, 0x20200000, 0x00801005, + 0x90040202, 0x00082010, 0x24200000, 0x00901005, + 0x90400202, 0x00082018, 0x20200800, 0x40801005, + 0x90440202, 0x00082018, 0x24200800, 0x40901005, + 0x90000602, 0x00082030, 0x28200000, 0x00801105, + 0x90040602, 0x00082030, 0x2c200000, 0x00901105, + 0x90400602, 0x00082038, 0x28200800, 0x40801105, + 0x90440602, 0x00082038, 0x2c200800, 0x40901105, + + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000008, 0x00080000, 0x10000000, + 0x02000000, 0x00000000, 0x00000080, 0x00001000, + 0x02000000, 0x00000008, 0x00080080, 0x10001000, + 0x00004000, 0x00000000, 0x00000040, 0x00040000, + 0x00004000, 0x00000008, 0x00080040, 0x10040000, + 0x02004000, 0x00000000, 0x000000c0, 0x00041000, + 0x02004000, 0x00000008, 0x000800c0, 0x10041000, + 0x00020000, 0x00008000, 0x08000000, 0x00200000, + 0x00020000, 0x00008008, 0x08080000, 0x10200000, + 0x02020000, 0x00008000, 0x08000080, 0x00201000, + 0x02020000, 0x00008008, 0x08080080, 0x10201000, + 0x00024000, 0x00008000, 0x08000040, 0x00240000, + 0x00024000, 0x00008008, 0x08080040, 0x10240000, + 0x02024000, 0x00008000, 0x080000c0, 0x00241000, + 0x02024000, 0x00008008, 0x080800c0, 0x10241000, + 0x00000000, 0x01000000, 0x00002000, 0x00000020, + 0x00000000, 0x01000008, 0x00082000, 0x10000020, + 0x02000000, 0x01000000, 0x00002080, 0x00001020, + 0x02000000, 0x01000008, 0x00082080, 0x10001020, + 0x00004000, 0x01000000, 0x00002040, 0x00040020, + 0x00004000, 0x01000008, 0x00082040, 0x10040020, + 0x02004000, 0x01000000, 0x000020c0, 0x00041020, + 0x02004000, 0x01000008, 0x000820c0, 0x10041020, + 0x00020000, 0x01008000, 0x08002000, 0x00200020, + 0x00020000, 0x01008008, 0x08082000, 0x10200020, + 0x02020000, 0x01008000, 0x08002080, 0x00201020, + 0x02020000, 0x01008008, 0x08082080, 0x10201020, + 0x00024000, 0x01008000, 0x08002040, 0x00240020, + 0x00024000, 0x01008008, 0x08082040, 0x10240020, + 0x02024000, 0x01008000, 0x080020c0, 0x00241020, + 0x02024000, 0x01008008, 0x080820c0, 0x10241020, + 0x00000400, 0x04000000, 0x00100000, 0x00000004, + 0x00000400, 0x04000008, 0x00180000, 0x10000004, + 0x02000400, 0x04000000, 0x00100080, 0x00001004, + 0x02000400, 0x04000008, 0x00180080, 0x10001004, + 0x00004400, 0x04000000, 0x00100040, 0x00040004, + 0x00004400, 0x04000008, 0x00180040, 0x10040004, + 0x02004400, 0x04000000, 0x001000c0, 0x00041004, + 0x02004400, 0x04000008, 0x001800c0, 0x10041004, + 0x00020400, 0x04008000, 0x08100000, 0x00200004, + 0x00020400, 0x04008008, 0x08180000, 0x10200004, + 0x02020400, 0x04008000, 0x08100080, 0x00201004, + 0x02020400, 0x04008008, 0x08180080, 0x10201004, + 0x00024400, 0x04008000, 0x08100040, 0x00240004, + 0x00024400, 0x04008008, 0x08180040, 0x10240004, + 0x02024400, 0x04008000, 0x081000c0, 0x00241004, + 0x02024400, 0x04008008, 0x081800c0, 0x10241004, + 0x00000400, 0x05000000, 0x00102000, 0x00000024, + 0x00000400, 0x05000008, 0x00182000, 0x10000024, + 0x02000400, 0x05000000, 0x00102080, 0x00001024, + 0x02000400, 0x05000008, 0x00182080, 0x10001024, + 0x00004400, 0x05000000, 0x00102040, 0x00040024, + 0x00004400, 0x05000008, 0x00182040, 0x10040024, + 0x02004400, 0x05000000, 0x001020c0, 0x00041024, + 0x02004400, 0x05000008, 0x001820c0, 0x10041024, + 0x00020400, 0x05008000, 0x08102000, 0x00200024, + 0x00020400, 0x05008008, 0x08182000, 0x10200024, + 0x02020400, 0x05008000, 0x08102080, 0x00201024, + 0x02020400, 0x05008008, 0x08182080, 0x10201024, + 0x00024400, 0x05008000, 0x08102040, 0x00240024, + 0x00024400, 0x05008008, 0x08182040, 0x10240024, + 0x02024400, 0x05008000, 0x081020c0, 0x00241024, + 0x02024400, 0x05008008, 0x081820c0, 0x10241024, + 0x00000800, 0x00010000, 0x20000000, 0x00000010, + 0x00000800, 0x00010008, 0x20080000, 0x10000010, + 0x02000800, 0x00010000, 0x20000080, 0x00001010, + 0x02000800, 0x00010008, 0x20080080, 0x10001010, + 0x00004800, 0x00010000, 0x20000040, 0x00040010, + 0x00004800, 0x00010008, 0x20080040, 0x10040010, + 0x02004800, 0x00010000, 0x200000c0, 0x00041010, + 0x02004800, 0x00010008, 0x200800c0, 0x10041010, + 0x00020800, 0x00018000, 0x28000000, 0x00200010, + 0x00020800, 0x00018008, 0x28080000, 0x10200010, + 0x02020800, 0x00018000, 0x28000080, 0x00201010, + 0x02020800, 0x00018008, 0x28080080, 0x10201010, + 0x00024800, 0x00018000, 0x28000040, 0x00240010, + 0x00024800, 0x00018008, 0x28080040, 0x10240010, + 0x02024800, 0x00018000, 0x280000c0, 0x00241010, + 0x02024800, 0x00018008, 0x280800c0, 0x10241010, + 0x00000800, 0x01010000, 0x20002000, 0x00000030, + 0x00000800, 0x01010008, 0x20082000, 0x10000030, + 0x02000800, 0x01010000, 0x20002080, 0x00001030, + 0x02000800, 0x01010008, 0x20082080, 0x10001030, + 0x00004800, 0x01010000, 0x20002040, 0x00040030, + 0x00004800, 0x01010008, 0x20082040, 0x10040030, + 0x02004800, 0x01010000, 0x200020c0, 0x00041030, + 0x02004800, 0x01010008, 0x200820c0, 0x10041030, + 0x00020800, 0x01018000, 0x28002000, 0x00200030, + 0x00020800, 0x01018008, 0x28082000, 0x10200030, + 0x02020800, 0x01018000, 0x28002080, 0x00201030, + 0x02020800, 0x01018008, 0x28082080, 0x10201030, + 0x00024800, 0x01018000, 0x28002040, 0x00240030, + 0x00024800, 0x01018008, 0x28082040, 0x10240030, + 0x02024800, 0x01018000, 0x280020c0, 0x00241030, + 0x02024800, 0x01018008, 0x280820c0, 0x10241030, + 0x00000c00, 0x04010000, 0x20100000, 0x00000014, + 0x00000c00, 0x04010008, 0x20180000, 0x10000014, + 0x02000c00, 0x04010000, 0x20100080, 0x00001014, + 0x02000c00, 0x04010008, 0x20180080, 0x10001014, + 0x00004c00, 0x04010000, 0x20100040, 0x00040014, + 0x00004c00, 0x04010008, 0x20180040, 0x10040014, + 0x02004c00, 0x04010000, 0x201000c0, 0x00041014, + 0x02004c00, 0x04010008, 0x201800c0, 0x10041014, + 0x00020c00, 0x04018000, 0x28100000, 0x00200014, + 0x00020c00, 0x04018008, 0x28180000, 0x10200014, + 0x02020c00, 0x04018000, 0x28100080, 0x00201014, + 0x02020c00, 0x04018008, 0x28180080, 0x10201014, + 0x00024c00, 0x04018000, 0x28100040, 0x00240014, + 0x00024c00, 0x04018008, 0x28180040, 0x10240014, + 0x02024c00, 0x04018000, 0x281000c0, 0x00241014, + 0x02024c00, 0x04018008, 0x281800c0, 0x10241014, + 0x00000c00, 0x05010000, 0x20102000, 0x00000034, + 0x00000c00, 0x05010008, 0x20182000, 0x10000034, + 0x02000c00, 0x05010000, 0x20102080, 0x00001034, + 0x02000c00, 0x05010008, 0x20182080, 0x10001034, + 0x00004c00, 0x05010000, 0x20102040, 0x00040034, + 0x00004c00, 0x05010008, 0x20182040, 0x10040034, + 0x02004c00, 0x05010000, 0x201020c0, 0x00041034, + 0x02004c00, 0x05010008, 0x201820c0, 0x10041034, + 0x00020c00, 0x05018000, 0x28102000, 0x00200034, + 0x00020c00, 0x05018008, 0x28182000, 0x10200034, + 0x02020c00, 0x05018000, 0x28102080, 0x00201034, + 0x02020c00, 0x05018008, 0x28182080, 0x10201034, + 0x00024c00, 0x05018000, 0x28102040, 0x00240034, + 0x00024c00, 0x05018008, 0x28182040, 0x10240034, + 0x02024c00, 0x05018000, 0x281020c0, 0x00241034, + 0x02024c00, 0x05018008, 0x281820c0, 0x10241034 +}; + +/* S-box lookup tables */ + +static const u32 S1[64] = { + 0x01010400, 0x00000000, 0x00010000, 0x01010404, + 0x01010004, 0x00010404, 0x00000004, 0x00010000, + 0x00000400, 0x01010400, 0x01010404, 0x00000400, + 0x01000404, 0x01010004, 0x01000000, 0x00000004, + 0x00000404, 0x01000400, 0x01000400, 0x00010400, + 0x00010400, 0x01010000, 0x01010000, 0x01000404, + 0x00010004, 0x01000004, 0x01000004, 0x00010004, + 0x00000000, 0x00000404, 0x00010404, 0x01000000, + 0x00010000, 0x01010404, 0x00000004, 0x01010000, + 0x01010400, 0x01000000, 0x01000000, 0x00000400, + 0x01010004, 0x00010000, 0x00010400, 0x01000004, + 0x00000400, 0x00000004, 0x01000404, 0x00010404, + 0x01010404, 0x00010004, 0x01010000, 0x01000404, + 0x01000004, 0x00000404, 0x00010404, 0x01010400, + 0x00000404, 0x01000400, 0x01000400, 0x00000000, + 0x00010004, 0x00010400, 0x00000000, 0x01010004 +}; + +static const u32 S2[64] = { + 0x80108020, 0x80008000, 0x00008000, 0x00108020, + 0x00100000, 0x00000020, 0x80100020, 0x80008020, + 0x80000020, 0x80108020, 0x80108000, 0x80000000, + 0x80008000, 0x00100000, 0x00000020, 0x80100020, + 0x00108000, 0x00100020, 0x80008020, 0x00000000, + 0x80000000, 0x00008000, 0x00108020, 0x80100000, + 0x00100020, 0x80000020, 0x00000000, 0x00108000, + 0x00008020, 0x80108000, 0x80100000, 0x00008020, + 0x00000000, 0x00108020, 0x80100020, 0x00100000, + 0x80008020, 0x80100000, 0x80108000, 0x00008000, + 0x80100000, 0x80008000, 0x00000020, 0x80108020, + 0x00108020, 0x00000020, 0x00008000, 0x80000000, + 0x00008020, 0x80108000, 0x00100000, 0x80000020, + 0x00100020, 0x80008020, 0x80000020, 0x00100020, + 0x00108000, 0x00000000, 0x80008000, 0x00008020, + 0x80000000, 0x80100020, 0x80108020, 0x00108000 +}; + +static const u32 S3[64] = { + 0x00000208, 0x08020200, 0x00000000, 0x08020008, + 0x08000200, 0x00000000, 0x00020208, 0x08000200, + 0x00020008, 0x08000008, 0x08000008, 0x00020000, + 0x08020208, 0x00020008, 0x08020000, 0x00000208, + 0x08000000, 0x00000008, 0x08020200, 0x00000200, + 0x00020200, 0x08020000, 0x08020008, 0x00020208, + 0x08000208, 0x00020200, 0x00020000, 0x08000208, + 0x00000008, 0x08020208, 0x00000200, 0x08000000, + 0x08020200, 0x08000000, 0x00020008, 0x00000208, + 0x00020000, 0x08020200, 0x08000200, 0x00000000, + 0x00000200, 0x00020008, 0x08020208, 0x08000200, + 0x08000008, 0x00000200, 0x00000000, 0x08020008, + 0x08000208, 0x00020000, 0x08000000, 0x08020208, + 0x00000008, 0x00020208, 0x00020200, 0x08000008, + 0x08020000, 0x08000208, 0x00000208, 0x08020000, + 0x00020208, 0x00000008, 0x08020008, 0x00020200 +}; + +static const u32 S4[64] = { + 0x00802001, 0x00002081, 0x00002081, 0x00000080, + 0x00802080, 0x00800081, 0x00800001, 0x00002001, + 0x00000000, 0x00802000, 0x00802000, 0x00802081, + 0x00000081, 0x00000000, 0x00800080, 0x00800001, + 0x00000001, 0x00002000, 0x00800000, 0x00802001, + 0x00000080, 0x00800000, 0x00002001, 0x00002080, + 0x00800081, 0x00000001, 0x00002080, 0x00800080, + 0x00002000, 0x00802080, 0x00802081, 0x00000081, + 0x00800080, 0x00800001, 0x00802000, 0x00802081, + 0x00000081, 0x00000000, 0x00000000, 0x00802000, + 0x00002080, 0x00800080, 0x00800081, 0x00000001, + 0x00802001, 0x00002081, 0x00002081, 0x00000080, + 0x00802081, 0x00000081, 0x00000001, 0x00002000, + 0x00800001, 0x00002001, 0x00802080, 0x00800081, + 0x00002001, 0x00002080, 0x00800000, 0x00802001, + 0x00000080, 0x00800000, 0x00002000, 0x00802080 +}; + +static const u32 S5[64] = { + 0x00000100, 0x02080100, 0x02080000, 0x42000100, + 0x00080000, 0x00000100, 0x40000000, 0x02080000, + 0x40080100, 0x00080000, 0x02000100, 0x40080100, + 0x42000100, 0x42080000, 0x00080100, 0x40000000, + 0x02000000, 0x40080000, 0x40080000, 0x00000000, + 0x40000100, 0x42080100, 0x42080100, 0x02000100, + 0x42080000, 0x40000100, 0x00000000, 0x42000000, + 0x02080100, 0x02000000, 0x42000000, 0x00080100, + 0x00080000, 0x42000100, 0x00000100, 0x02000000, + 0x40000000, 0x02080000, 0x42000100, 0x40080100, + 0x02000100, 0x40000000, 0x42080000, 0x02080100, + 0x40080100, 0x00000100, 0x02000000, 0x42080000, + 0x42080100, 0x00080100, 0x42000000, 0x42080100, + 0x02080000, 0x00000000, 0x40080000, 0x42000000, + 0x00080100, 0x02000100, 0x40000100, 0x00080000, + 0x00000000, 0x40080000, 0x02080100, 0x40000100 +}; + +static const u32 S6[64] = { + 0x20000010, 0x20400000, 0x00004000, 0x20404010, + 0x20400000, 0x00000010, 0x20404010, 0x00400000, + 0x20004000, 0x00404010, 0x00400000, 0x20000010, + 0x00400010, 0x20004000, 0x20000000, 0x00004010, + 0x00000000, 0x00400010, 0x20004010, 0x00004000, + 0x00404000, 0x20004010, 0x00000010, 0x20400010, + 0x20400010, 0x00000000, 0x00404010, 0x20404000, + 0x00004010, 0x00404000, 0x20404000, 0x20000000, + 0x20004000, 0x00000010, 0x20400010, 0x00404000, + 0x20404010, 0x00400000, 0x00004010, 0x20000010, + 0x00400000, 0x20004000, 0x20000000, 0x00004010, + 0x20000010, 0x20404010, 0x00404000, 0x20400000, + 0x00404010, 0x20404000, 0x00000000, 0x20400010, + 0x00000010, 0x00004000, 0x20400000, 0x00404010, + 0x00004000, 0x00400010, 0x20004010, 0x00000000, + 0x20404000, 0x20000000, 0x00400010, 0x20004010 +}; + +static const u32 S7[64] = { + 0x00200000, 0x04200002, 0x04000802, 0x00000000, + 0x00000800, 0x04000802, 0x00200802, 0x04200800, + 0x04200802, 0x00200000, 0x00000000, 0x04000002, + 0x00000002, 0x04000000, 0x04200002, 0x00000802, + 0x04000800, 0x00200802, 0x00200002, 0x04000800, + 0x04000002, 0x04200000, 0x04200800, 0x00200002, + 0x04200000, 0x00000800, 0x00000802, 0x04200802, + 0x00200800, 0x00000002, 0x04000000, 0x00200800, + 0x04000000, 0x00200800, 0x00200000, 0x04000802, + 0x04000802, 0x04200002, 0x04200002, 0x00000002, + 0x00200002, 0x04000000, 0x04000800, 0x00200000, + 0x04200800, 0x00000802, 0x00200802, 0x04200800, + 0x00000802, 0x04000002, 0x04200802, 0x04200000, + 0x00200800, 0x00000000, 0x00000002, 0x04200802, + 0x00000000, 0x00200802, 0x04200000, 0x00000800, + 0x04000002, 0x04000800, 0x00000800, 0x00200002 +}; + +static const u32 S8[64] = { + 0x10001040, 0x00001000, 0x00040000, 0x10041040, + 0x10000000, 0x10001040, 0x00000040, 0x10000000, + 0x00040040, 0x10040000, 0x10041040, 0x00041000, + 0x10041000, 0x00041040, 0x00001000, 0x00000040, + 0x10040000, 0x10000040, 0x10001000, 0x00001040, + 0x00041000, 0x00040040, 0x10040040, 0x10041000, + 0x00001040, 0x00000000, 0x00000000, 0x10040040, + 0x10000040, 0x10001000, 0x00041040, 0x00040000, + 0x00041040, 0x00040000, 0x10041000, 0x00001000, + 0x00000040, 0x10040040, 0x00001000, 0x00041040, + 0x10001000, 0x00000040, 0x10000040, 0x10040000, + 0x10040040, 0x10000000, 0x00040000, 0x10001040, + 0x00000000, 0x10041040, 0x00040040, 0x10000040, + 0x10040000, 0x10001000, 0x10001040, 0x00000000, + 0x10041040, 0x00041000, 0x00041000, 0x00001040, + 0x00001040, 0x00040040, 0x10000000, 0x10041000 +}; + +/* Encryption components: IP, FP, and round function */ + +#define IP(L, R, T) \ + ROL(R, 4); \ + T = L; \ + L ^= R; \ + L &= 0xf0f0f0f0; \ + R ^= L; \ + L ^= T; \ + ROL(R, 12); \ + T = L; \ + L ^= R; \ + L &= 0xffff0000; \ + R ^= L; \ + L ^= T; \ + ROR(R, 14); \ + T = L; \ + L ^= R; \ + L &= 0xcccccccc; \ + R ^= L; \ + L ^= T; \ + ROL(R, 6); \ + T = L; \ + L ^= R; \ + L &= 0xff00ff00; \ + R ^= L; \ + L ^= T; \ + ROR(R, 7); \ + T = L; \ + L ^= R; \ + L &= 0xaaaaaaaa; \ + R ^= L; \ + L ^= T; \ + ROL(L, 1); + +#define FP(L, R, T) \ + ROR(L, 1); \ + T = L; \ + L ^= R; \ + L &= 0xaaaaaaaa; \ + R ^= L; \ + L ^= T; \ + ROL(R, 7); \ + T = L; \ + L ^= R; \ + L &= 0xff00ff00; \ + R ^= L; \ + L ^= T; \ + ROR(R, 6); \ + T = L; \ + L ^= R; \ + L &= 0xcccccccc; \ + R ^= L; \ + L ^= T; \ + ROL(R, 14); \ + T = L; \ + L ^= R; \ + L &= 0xffff0000; \ + R ^= L; \ + L ^= T; \ + ROR(R, 12); \ + T = L; \ + L ^= R; \ + L &= 0xf0f0f0f0; \ + R ^= L; \ + L ^= T; \ + ROR(R, 4); + +#define ROUND(L, R, A, B, K, d) \ + B = K[0]; A = K[1]; K += d; \ + B ^= R; A ^= R; \ + B &= 0x3f3f3f3f; ROR(A, 4); \ + L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \ + L ^= S6[0xff & (B >> 8)]; B >>= 16; \ + L ^= S7[0xff & A]; \ + L ^= S5[0xff & (A >> 8)]; A >>= 16; \ + L ^= S4[0xff & B]; \ + L ^= S2[0xff & (B >> 8)]; \ + L ^= S3[0xff & A]; \ + L ^= S1[0xff & (A >> 8)]; + +/* + * PC2 lookup tables are organized as 2 consecutive sets of 4 interleaved + * tables of 128 elements. One set is for C_i and the other for D_i, while + * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i. + * + * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i + * or D_i in bits 7-1 (bit 0 being the least significant). + */ + +#define T1(x) pt[2 * (x) + 0] +#define T2(x) pt[2 * (x) + 1] +#define T3(x) pt[2 * (x) + 2] +#define T4(x) pt[2 * (x) + 3] + +#define DES_PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a)) + +/* + * Encryption key expansion + * + * RFC2451: Weak key checks SHOULD be performed. + * + * FIPS 74: + * + * Keys having duals are keys which produce all zeros, all ones, or + * alternating zero-one patterns in the C and D registers after Permuted + * Choice 1 has operated on the key. + * + */ +static unsigned long des_ekey(u32 *pe, const u8 *k) +{ + /* K&R: long is at least 32 bits */ + unsigned long a, b, c, d, w; + const u32 *pt = pc2; + + d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; + c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; + b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; + a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; + + pe[15 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; + pe[14 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[13 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[12 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[11 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[10 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 9 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 8 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; + pe[ 7 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 6 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 5 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 4 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 3 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 2 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 1 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; + pe[ 0 * 2 + 0] = DES_PC2(b, c, d, a); + + /* Check if first half is weak */ + w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); + + /* Skip to next table set */ + pt += 512; + + d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; + c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; + b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; + a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; + + /* Check if second half is weak */ + w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); + + pe[15 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; + pe[14 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[13 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[12 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[11 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[10 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 9 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 8 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; + pe[ 7 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 6 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 5 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 4 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 3 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 2 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[ 1 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; + pe[ 0 * 2 + 1] = DES_PC2(b, c, d, a); + + /* Fixup: 2413 5768 -> 1357 2468 */ + for (d = 0; d < 16; ++d) { + a = pe[2 * d]; + b = pe[2 * d + 1]; + c = a ^ b; + c &= 0xffff0000; + a ^= c; + b ^= c; + ROL(b, 18); + pe[2 * d] = a; + pe[2 * d + 1] = b; + } + + /* Zero if weak key */ + return w; +} + +int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen) +{ + if (keylen != DES_KEY_SIZE) + return -EINVAL; + + return des_ekey(ctx->expkey, key) ? 0 : -ENOKEY; +} +EXPORT_SYMBOL_GPL(des_expand_key); + +/* + * Decryption key expansion + * + * No weak key checking is performed, as this is only used by triple DES + * + */ +static void dkey(u32 *pe, const u8 *k) +{ + /* K&R: long is at least 32 bits */ + unsigned long a, b, c, d; + const u32 *pt = pc2; + + d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; + c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; + b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; + a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; + + pe[ 0 * 2] = DES_PC2(a, b, c, d); d = rs[d]; + pe[ 1 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 2 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 3 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 4 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 5 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 6 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 7 * 2] = DES_PC2(d, a, b, c); c = rs[c]; + pe[ 8 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 9 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[10 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[11 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[12 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[13 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[14 * 2] = DES_PC2(c, d, a, b); b = rs[b]; + pe[15 * 2] = DES_PC2(b, c, d, a); + + /* Skip to next table set */ + pt += 512; + + d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; + c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; + b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; + a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; + + pe[ 0 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; + pe[ 1 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 2 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 3 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 4 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 5 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; + pe[ 6 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; + pe[ 7 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; + pe[ 8 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[ 9 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[10 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[11 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[12 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; + pe[13 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; + pe[14 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; + pe[15 * 2 + 1] = DES_PC2(b, c, d, a); + + /* Fixup: 2413 5768 -> 1357 2468 */ + for (d = 0; d < 16; ++d) { + a = pe[2 * d]; + b = pe[2 * d + 1]; + c = a ^ b; + c &= 0xffff0000; + a ^= c; + b ^= c; + ROL(b, 18); + pe[2 * d] = a; + pe[2 * d + 1] = b; + } +} + +void des_encrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src) +{ + const u32 *K = ctx->expkey; + u32 L, R, A, B; + int i; + + L = get_unaligned_le32(src); + R = get_unaligned_le32(src + 4); + + IP(L, R, A); + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, 2); + ROUND(R, L, A, B, K, 2); + } + FP(R, L, A); + + put_unaligned_le32(R, dst); + put_unaligned_le32(L, dst + 4); +} +EXPORT_SYMBOL_GPL(des_encrypt); + +void des_decrypt(const struct des_ctx *ctx, u8 *dst, const u8 *src) +{ + const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2; + u32 L, R, A, B; + int i; + + L = get_unaligned_le32(src); + R = get_unaligned_le32(src + 4); + + IP(L, R, A); + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, -2); + ROUND(R, L, A, B, K, -2); + } + FP(R, L, A); + + put_unaligned_le32(R, dst); + put_unaligned_le32(L, dst + 4); +} +EXPORT_SYMBOL_GPL(des_decrypt); + +int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key, + unsigned int keylen) +{ + u32 *pe = ctx->expkey; + int err; + + if (keylen != DES3_EDE_KEY_SIZE) + return -EINVAL; + + err = des3_ede_verify_key(key, keylen, true); + if (err && err != -ENOKEY) + return err; + + des_ekey(pe, key); pe += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; + dkey(pe, key); pe += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; + des_ekey(pe, key); + + return err; +} +EXPORT_SYMBOL_GPL(des3_ede_expand_key); + +void des3_ede_encrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src) +{ + const u32 *K = dctx->expkey; + u32 L, R, A, B; + int i; + + L = get_unaligned_le32(src); + R = get_unaligned_le32(src + 4); + + IP(L, R, A); + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, 2); + ROUND(R, L, A, B, K, 2); + } + for (i = 0; i < 8; i++) { + ROUND(R, L, A, B, K, 2); + ROUND(L, R, A, B, K, 2); + } + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, 2); + ROUND(R, L, A, B, K, 2); + } + FP(R, L, A); + + put_unaligned_le32(R, dst); + put_unaligned_le32(L, dst + 4); +} +EXPORT_SYMBOL_GPL(des3_ede_encrypt); + +void des3_ede_decrypt(const struct des3_ede_ctx *dctx, u8 *dst, const u8 *src) +{ + const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; + u32 L, R, A, B; + int i; + + L = get_unaligned_le32(src); + R = get_unaligned_le32(src + 4); + + IP(L, R, A); + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, -2); + ROUND(R, L, A, B, K, -2); + } + for (i = 0; i < 8; i++) { + ROUND(R, L, A, B, K, -2); + ROUND(L, R, A, B, K, -2); + } + for (i = 0; i < 8; i++) { + ROUND(L, R, A, B, K, -2); + ROUND(R, L, A, B, K, -2); + } + FP(R, L, A); + + put_unaligned_le32(R, dst); + put_unaligned_le32(L, dst + 4); +} +EXPORT_SYMBOL_GPL(des3_ede_decrypt); + +MODULE_LICENSE("GPL"); From patchwork Thu Aug 15 09:01:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171427 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918743ily; Thu, 15 Aug 2019 02:02:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxk/QYRz/sUeLLggJWsybmFt+EuZ8rk02XucRIcZmXeQ9ddOM+b61vtJPudFOJa1OFvxL2 X-Received: by 2002:a17:90a:3ad0:: with SMTP id b74mr1257268pjc.79.1565859740339; Thu, 15 Aug 2019 02:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859740; cv=none; d=google.com; s=arc-20160816; b=s+6OHrEXPi0K+bCaMdFo88cduXvb25XvGwuKs/cZOwf9mPJUKF4XLlBwekHjtYJ1rx hzoxffXvHXN8WUYX68YERDwNFr6hx3GXLbQLmOSOkwdlYPUStpiZxiU64eXYdSUjaCEm KfhCMh6E4WJAz4p+7FdoQQCXoZo/aoi0dSkj2QMJ6wcYH4HyjqF148wT7J55ZvBVg4IV 9DVe1cKW4l6k8O0/u44XyTuWsr2qbfX6cm7SUt6aNd/a/lUcNTfw5jp0lYHEbrHZS+ih xzJYuwLCPFEVO+VvSA/7tSlC0hnlt2mE96Er7Hc1bVifPsmupW1uP7hv2GByDmDV/w4N MDRw== 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=uMoPWG7ZtNqmAOxM6E+qCA9KIAAzgWl56JeFS/8CuPA=; b=omgfAX+5jrtbuNaE9TsOpn1l9WwdrxxKkOPAVQRgSOksht6b//wGZNqFydxUp+wPVv AbmjunCGyYFhaMkVc1WVnqwTcJ5+s++Q7yIOLc2jdnwQd8q1fw/KytlODhpHcqIK0jv7 srmmQ2keBaYdqpZenc6WhJBzzKPglaBzpV0+BrSaECfjm0V8ODf6xB8OhiOIGqZrCv4r dbIyN9Kz/f4GeicvgGTXBQWmH9DaPCnm2ODTBk1nq9S6MzWlGCLGvcSA7dkUDb0pC30P ge2IgX/8jZ+gOqRMrI0hkfvC9aYNGWf3dNRIeBv95etCCbmwRlbi5rflki61lfjznwUH r7AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F441Umy/"; 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 k11si1650459pfi.3.2019.08.15.02.02.20; Thu, 15 Aug 2019 02:02:20 -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="F441Umy/"; 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 S1730862AbfHOJCS (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:18 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:33104 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730823AbfHOJCS (ORCPT ); Thu, 15 Aug 2019 05:02:18 -0400 Received: by mail-wm1-f67.google.com with SMTP id p77so592948wme.0 for ; Thu, 15 Aug 2019 02:02:17 -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=uMoPWG7ZtNqmAOxM6E+qCA9KIAAzgWl56JeFS/8CuPA=; b=F441Umy/1KJ6iJyvfwZoAuD8zpROKzYiD0r0+XQQiL48PNrrojPbbLSaFEcn7jnyBD CcEKgpvvWc+2sLCSTb24PokyQHKybx4OxD9eJ/b1F9OkzE4cmOf7PKXk5IQL9i2gui2A ZIdGaAdUPq+i9C4o2lpp7SWCelAg0pE5WR2EVRPF76r7KxuCNpWD8Np34U26Z6trTVpE 8c3ZtE/cf02jcoaCZCHdKb64wFv76enxWSe1Ux5LRDlkUK+7EPM4CFRw/Zq6QrPW6Ji2 5GTK/MyT9kmdcYKxWylf4tW9BnPDHQUiVF7RnaCqka/J1i42xWmkyz7q9QzWMoH0Fnlu 6/5g== 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=uMoPWG7ZtNqmAOxM6E+qCA9KIAAzgWl56JeFS/8CuPA=; b=Kt7MvvexbgmkS1XNXf8EXD1OLJdw9CLRz7aO7NptrZ9lfN+6IN8Y6kP9fDakpKB/0I cuqnV/vX0bgH/8GSH1Azw6ABpGZ4mwxFFSEzuaMQjc3Cle/TynhzSNcs48fMTxWBz6WQ P7qZKSgtStihp9woXQNJiryv9c6vgTLVBmAA5ZoRcughe51fysiP5FOGTPJRIxFpOK5I J5j/v+H32+biRqGf0Ewu2jaLGbCdpdLu8x2aq9fCI3ue3Vel1hYfJn9OUAGIrmdm4XiO eTaaVkDHCPyAFKU9HrG83HSjZzwR6qLuIQJzlcDw/iaNaNa6BFK6xqLC0OXoAYXLfah/ pyVA== X-Gm-Message-State: APjAAAVbYFrIDZ00f/wj9dbuVk38VVA36C9zR32EJAJSp76CPtClf4JZ DOkw+U5aBiKEIohL5NARiJV6kTutNGFrLcoh X-Received: by 2002:a7b:ca5a:: with SMTP id m26mr1600238wml.134.1565859736265; Thu, 15 Aug 2019 02:02:16 -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.02.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:15 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 28/30] crypto: x86/des - switch to library interface Date: Thu, 15 Aug 2019 12:01:10 +0300 Message-Id: <20190815090112.9377-29-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 --- arch/x86/crypto/des3_ede_glue.c | 42 +++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/arch/x86/crypto/des3_ede_glue.c b/arch/x86/crypto/des3_ede_glue.c index f730a312ce35..89830e531350 100644 --- a/arch/x86/crypto/des3_ede_glue.c +++ b/arch/x86/crypto/des3_ede_glue.c @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include #include @@ -19,8 +19,8 @@ #include struct des3_ede_x86_ctx { - u32 enc_expkey[DES3_EDE_EXPKEY_WORDS]; - u32 dec_expkey[DES3_EDE_EXPKEY_WORDS]; + struct des3_ede_ctx enc; + struct des3_ede_ctx dec; }; /* regular block cipher functions */ @@ -34,7 +34,7 @@ asmlinkage void des3_ede_x86_64_crypt_blk_3way(const u32 *expkey, u8 *dst, static inline void des3_ede_enc_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, const u8 *src) { - u32 *enc_ctx = ctx->enc_expkey; + u32 *enc_ctx = ctx->enc.expkey; des3_ede_x86_64_crypt_blk(enc_ctx, dst, src); } @@ -42,7 +42,7 @@ static inline void des3_ede_enc_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, static inline void des3_ede_dec_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, const u8 *src) { - u32 *dec_ctx = ctx->dec_expkey; + u32 *dec_ctx = ctx->dec.expkey; des3_ede_x86_64_crypt_blk(dec_ctx, dst, src); } @@ -50,7 +50,7 @@ static inline void des3_ede_dec_blk(struct des3_ede_x86_ctx *ctx, u8 *dst, static inline void des3_ede_enc_blk_3way(struct des3_ede_x86_ctx *ctx, u8 *dst, const u8 *src) { - u32 *enc_ctx = ctx->enc_expkey; + u32 *enc_ctx = ctx->enc.expkey; des3_ede_x86_64_crypt_blk_3way(enc_ctx, dst, src); } @@ -58,7 +58,7 @@ static inline void des3_ede_enc_blk_3way(struct des3_ede_x86_ctx *ctx, u8 *dst, static inline void des3_ede_dec_blk_3way(struct des3_ede_x86_ctx *ctx, u8 *dst, const u8 *src) { - u32 *dec_ctx = ctx->dec_expkey; + u32 *dec_ctx = ctx->dec.expkey; des3_ede_x86_64_crypt_blk_3way(dec_ctx, dst, src); } @@ -122,7 +122,7 @@ static int ecb_encrypt(struct skcipher_request *req) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct des3_ede_x86_ctx *ctx = crypto_skcipher_ctx(tfm); - return ecb_crypt(req, ctx->enc_expkey); + return ecb_crypt(req, ctx->enc.expkey); } static int ecb_decrypt(struct skcipher_request *req) @@ -130,7 +130,7 @@ static int ecb_decrypt(struct skcipher_request *req) struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct des3_ede_x86_ctx *ctx = crypto_skcipher_ctx(tfm); - return ecb_crypt(req, ctx->dec_expkey); + return ecb_crypt(req, ctx->dec.expkey); } static unsigned int __cbc_encrypt(struct des3_ede_x86_ctx *ctx, @@ -348,24 +348,28 @@ static int des3_ede_x86_setkey(struct crypto_tfm *tfm, const u8 *key, u32 i, j, tmp; int err; - err = crypto_des3_ede_verify_key(tfm, key); - if (err) - return err; + err = des3_ede_expand_key(&ctx->enc, key, keylen); + if (err == -ENOKEY) { + if (crypto_tfm_get_flags(tfm) & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) + err = -EINVAL; + else + err = 0; + } - /* Generate encryption context using generic implementation. */ - err = __des3_ede_setkey(ctx->enc_expkey, &tfm->crt_flags, key, keylen); - if (err < 0) + if (err) { + memset(ctx, 0, sizeof(*ctx)); return err; + } /* Fix encryption context for this implementation and form decryption * context. */ j = DES3_EDE_EXPKEY_WORDS - 2; for (i = 0; i < DES3_EDE_EXPKEY_WORDS; i += 2, j -= 2) { - tmp = ror32(ctx->enc_expkey[i + 1], 4); - ctx->enc_expkey[i + 1] = tmp; + tmp = ror32(ctx->enc.expkey[i + 1], 4); + ctx->enc.expkey[i + 1] = tmp; - ctx->dec_expkey[j + 0] = ctx->enc_expkey[i + 0]; - ctx->dec_expkey[j + 1] = tmp; + ctx->dec.expkey[j + 0] = ctx->enc.expkey[i + 0]; + ctx->dec.expkey[j + 1] = tmp; } return 0; From patchwork Thu Aug 15 09:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171428 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918763ily; Thu, 15 Aug 2019 02:02:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+OPV0jZnkrYPYCg2tulyFX9Ilj6aLS/wBbmsapQci3z1MuUOgYZbzkK2KdgEC9Gfj+nPV X-Received: by 2002:a17:90a:71ca:: with SMTP id m10mr1312252pjs.27.1565859741079; Thu, 15 Aug 2019 02:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859741; cv=none; d=google.com; s=arc-20160816; b=w8y5kf2+tgrpeHL4EJiw7q3UQyEDuBkek9Xi7brpmxcOJp4xGcEVDjG1LshhW62lgJ XOAedZ14CoaMhsC1+8R2KpcakxUgn5ttdwFoXUMmO3TC/UChC3bw5sGx4EVmCcjOTaji eJPthZP4JlCl8I74taoTEPhKmz1GEhdPT1CSlM9XQ2pMewAVojCC3Ljs1XsrCwhVydXT aOa+3sOHEBoB0mH8mdGd91I70GLw6TBSIHJmgA9b4Xd6eMJx0jfbcjpw8PbtoeZv1Biz FFprq1GUqAc+d/0rxdEzltL48TGq6d82wZTBYnMKEpjKxen9LoHMsTLsaMC2pbsV2zK+ 0coQ== 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=6OhjbF2M4HRdeN0EH1XAkAXt0Z8G30cJBFEK1XTbAV0=; b=nBO9cPZuGdpOnsSWrtfiCNEZD2nN5OJ+dFWPMquA0B8vN72h+z62GNaqQ8D8uHbQyj 2scuII1gDyCFlJ9ZUkDpPNz7RqyWVC5Su7JUnDsuZ52V6Uwqac5VjCQWYh4YNQkQS1FN VcYCS2YMS8srOQRy4H8jQshr4jQp7Gfp4ehb7Np1qAWGwJwpgrr0Qas8hbK71bODkiUj //pDHXB7AA2J/BafsIKx/yNIhINKjaw0xRaQo/I3Zsb5qaqLM/fXWjGO9dy8RsWPgKMj COF3ETf696rvA3BvbZ/TqJWSxteBTIGEwhqteBQZ1fcb3AxnVtXm2PI4wTMSglzDJl+7 ia0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dYD58Uvi; 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 k11si1650459pfi.3.2019.08.15.02.02.20; Thu, 15 Aug 2019 02:02:21 -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=dYD58Uvi; 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 S1730867AbfHOJCU (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:20 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39266 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730213AbfHOJCT (ORCPT ); Thu, 15 Aug 2019 05:02:19 -0400 Received: by mail-wm1-f66.google.com with SMTP id i63so678112wmg.4 for ; Thu, 15 Aug 2019 02:02:18 -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=6OhjbF2M4HRdeN0EH1XAkAXt0Z8G30cJBFEK1XTbAV0=; b=dYD58UviyQoaqUX0Ufh5LH392urYuVBmdfTxlfeu4vZIhEPoJieDnCAHjViHnMA96Q 1LFZ+a9mTb30FunM54tEir8xdwB6AxzpZrS0YuF1wZNyQAuYvlUYbOwvXy5nMS1hdxNW gek5jdntD6WcQbQgLS0TfLeP2sA6YH7ModgaZ9y/BWS3YxiWUq65wQ2R9XkOgXPidsGX F4/3shClIptKCYbkurnxGkGxgpufK04bT+UHDkqfOAGfaPncGJHOBEZTaoJT7Pm1+NJB gZm5OPLJMuKDRlxU/qaBQfXHPOQDlvU/pmKRJ0rHoXqJgDq2NBmtsbojCvxDjIKC7oEy iWRQ== 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=6OhjbF2M4HRdeN0EH1XAkAXt0Z8G30cJBFEK1XTbAV0=; b=BKYTSyF/bP3A5SwIRUbJS98j/qlnBif7nUnTWmIFYcXe7PxRANQ3Q1rxQkDiYMe+Of YprmIcE8sXEeEitBZiJ6hCMPa6sOoopgUHXvnWFINpQNiICHJ7Ps6SEoHajUY6HxMd6o SGPxqfHVizrGOx8BewNOB9si22HkmvSdrUURJliyPLHWtGHA+QakyEaPjeYc2MOzu5t3 pYc7l9et5yjrwYaEG9XS9P9ztGPtRLCZnb467WVIaHebJe2QUFqubFnQzex+TAtjncbS 6gxEuRP2Hubb/fm1AI+OKtEc8IAcI++Ns5oNeoMDAterZCfBCaFFGJFUGnFAncA4WXJp B0og== X-Gm-Message-State: APjAAAUMPpnD0p3a9G0Z2ghfSawGC33EeAfuUesgi/LEMosXF6wgytR7 U3uOAo7g9Lcy5nfxX8vOMBEU0FWG6gILJzt6 X-Received: by 2002:a7b:c157:: with SMTP id z23mr1699974wmi.104.1565859737719; Thu, 15 Aug 2019 02:02:17 -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.02.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:17 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 29/30] crypto: des - remove now unused __des3_ede_setkey() Date: Thu, 15 Aug 2019 12:01:11 +0300 Message-Id: <20190815090112.9377-30-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 --- crypto/des_generic.c | 13 ------------- include/crypto/des.h | 3 --- 2 files changed, 16 deletions(-) -- 2.17.1 diff --git a/crypto/des_generic.c b/crypto/des_generic.c index e021a321f584..6e13a4a29ecb 100644 --- a/crypto/des_generic.c +++ b/crypto/des_generic.c @@ -51,19 +51,6 @@ static void crypto_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) des_decrypt(dctx, dst, src); } -int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, - unsigned int keylen) -{ - int err; - - des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; - dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; - des_ekey(expkey, key); - - return 0; -} -EXPORT_SYMBOL_GPL(__des3_ede_setkey); - static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) { diff --git a/include/crypto/des.h b/include/crypto/des.h index 2c864a4e6707..7812b4331ae4 100644 --- a/include/crypto/des.h +++ b/include/crypto/des.h @@ -54,7 +54,4 @@ int des_expand_key(struct des_ctx *ctx, const u8 *key, unsigned int keylen); int des3_ede_expand_key(struct des3_ede_ctx *ctx, const u8 *key, unsigned int keylen); -extern int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, - unsigned int keylen); - #endif /* __CRYPTO_DES_H */ From patchwork Thu Aug 15 09:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 171429 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp1918789ily; Thu, 15 Aug 2019 02:02:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj+H66tYgqCoUnfrM9bGCJu5KCrkAj9zb+JLK1s3lxYgql4DFQQ/6EGkV0/X3YwIzuBbgw X-Received: by 2002:a17:902:2aab:: with SMTP id j40mr3267098plb.76.1565859742327; Thu, 15 Aug 2019 02:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565859742; cv=none; d=google.com; s=arc-20160816; b=wVPx4kjFfar5JNEVBvHEBgC3cczVMLbvlvN669r15P7gP3h65cRtE3pRlpIK+Et0KD xzubqKD3OOvCiekqqjNKFWCzNd2AKbcOQw2250fBETMfSSPaUM29FNiabYaRyRvcTvSG serVRNFqZnDFNwykv00h0xuAw0YNXyRhSO40yDOvpzEiVQRBbpg2b4QjyunaUQFU6Kad mksJf9BJSl1S96Zx4UujDUkX1NwUPFyY/e7QbdWeYE851mQexu2w6Bq9TVYemYLP9Plu Lv5GK75zfwXTrH5R8cbEo+/ZzMvysRkxnVqZC0uSXZ8laXgkLhVTNylk3wkXH+kHGe25 hzdw== 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=BotHPKD3g+g+mUZQ/dtkowLHJlOQtGFVF7+kbySZOcU=; b=OT53KmNGYjofS6eZKXX1D2NUYHW/4cawfrLTR6cTJ3sD5yORrz0ugTSBLOWynv9pD1 6Yr0iLPiyB+OMrGsKOP4PB13DfuX7eZgU/aA74LKgd8zJgQu70+tKcYz3J5nO+lyh9ev t87xp9tGReHw1chrFnAtUqsZV/Th1eg/GoxFSuZv0wyb+w8lNdxD6AYDua2/LqR2JceO km/IWB15+Sh6auYZdlfP502gPSpom5jsAMtugRY/tUlcmbKnK1pBE+LDBuMBapZaVUzR rrmYSVriL66jcejEz3YBGsiuXxvG2UfONUDeNUg+vohK8kgeyIGmzSugypyRiPTMacU6 sM+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=whv+LhAh; 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 k11si1650459pfi.3.2019.08.15.02.02.22; Thu, 15 Aug 2019 02:02:22 -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=whv+LhAh; 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 S1730213AbfHOJCV (ORCPT + 3 others); Thu, 15 Aug 2019 05:02:21 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:56002 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730823AbfHOJCV (ORCPT ); Thu, 15 Aug 2019 05:02:21 -0400 Received: by mail-wm1-f67.google.com with SMTP id f72so674667wmf.5 for ; Thu, 15 Aug 2019 02:02:20 -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=BotHPKD3g+g+mUZQ/dtkowLHJlOQtGFVF7+kbySZOcU=; b=whv+LhAhxs1dUKQOELKk0+c9ufyVLY04ilRm4Xr/A3joJ+etHGyyoDTbsisvPcFm1b hqFntJVU38lK/9tlFHSPFxW5putYTbXeMuNadA4os9moVI1ktBNzzyo2WUhryYMAGhQx r56uPTE+wCR/UIdyngOuDCktneeoxFL/hipPlKgqXtHg2oob1vOkpKX+Z/dLhNmqx/WO e1XejR5fP7q4a+WIGiKAKFDTDNy4u6WdUonPFjo8v3jBMt+JrIaHOztze1S0Bx/gdCrd 1c6jfWFFb9RmFb0aTbQJ0Redfvmy3XFTjLoupJN8cTuaIRmVBt5u8mp7iXWnKrnZrCFR T2GA== 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=BotHPKD3g+g+mUZQ/dtkowLHJlOQtGFVF7+kbySZOcU=; b=KyjjiGikWEg72e1AxdMqlWhGOc/HWwsIM8+9duKRw9inDVUYFSN8RJpsY3M1dgI2oq 0Rc43oxsnOZYk2VABNvC5xdOuk5BGQsyr+uOcITpfJYunffpQoMEBjtCDlCUqsqxPcb3 Bj65WkxBzTjnFk14r+r4Oc6lMefaRVRz1QVQG6NrjigpKo826zpH1kj/70MHR7LzPVV+ uez8i0xdegp+kfqzVMhDfr10+FdbxFU75o6QqW+55RGitWyaIVybD9wRgYmP10hxWp2R uKJnM9ep09HXzWUmc7Iv4g6nWLXPiaaJHHiMEM2KTwFx5hTq888jSqbrwgfXWec48SbU z6sA== X-Gm-Message-State: APjAAAW08Ju6Ap/AWlxpF4rYBt8yO/f8S3JuHJ96nJu80A7xc82+K2Hp VLxjv8aoxzje+5RAOT5z6jAPjK157FL6cJ3z X-Received: by 2002:a1c:3945:: with SMTP id g66mr1622342wma.139.1565859739008; Thu, 15 Aug 2019 02:02:19 -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.02.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2019 02:02:18 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel Subject: [PATCH v5 30/30] fs: cifs: move from the crypto cipher API to the new DES library interface Date: Thu, 15 Aug 2019 12:01:12 +0300 Message-Id: <20190815090112.9377-31-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 Some legacy code in the CIFS driver uses single DES to calculate some password hash, and uses the crypto cipher API to do so. Given that there is no point in invoking an accelerated cipher for doing 56-bit symmetric encryption on a single 8-byte block of input, the flexibility of the crypto cipher API does not add much value here, and so we're much better off using a library call into the generic C implementation. Signed-off-by: Ard Biesheuvel --- fs/cifs/Kconfig | 2 +- fs/cifs/cifsfs.c | 1 - fs/cifs/smbencrypt.c | 18 +++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index b16219e5dac9..350bc3061656 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig @@ -16,7 +16,7 @@ config CIFS select CRYPTO_GCM select CRYPTO_ECB select CRYPTO_AES - select CRYPTO_DES + select CRYPTO_LIB_DES select KEYS help This is the client VFS module for the SMB3 family of NAS protocols, diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 3289b566463f..4e2f74894e9b 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1601,7 +1601,6 @@ MODULE_DESCRIPTION ("VFS to access SMB3 servers e.g. Samba, Macs, Azure and Windows (and " "also older servers complying with the SNIA CIFS Specification)"); MODULE_VERSION(CIFS_VERSION); -MODULE_SOFTDEP("pre: des"); MODULE_SOFTDEP("pre: ecb"); MODULE_SOFTDEP("pre: hmac"); MODULE_SOFTDEP("pre: md4"); diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c index 2b6d87bfdf8e..39a938443e3e 100644 --- a/fs/cifs/smbencrypt.c +++ b/fs/cifs/smbencrypt.c @@ -11,13 +11,14 @@ */ -#include #include #include +#include #include #include #include #include +#include #include "cifs_fs_sb.h" #include "cifs_unicode.h" #include "cifspdu.h" @@ -58,19 +59,18 @@ static int smbhash(unsigned char *out, const unsigned char *in, unsigned char *key) { unsigned char key2[8]; - struct crypto_cipher *tfm_des; + struct des_ctx ctx; str_to_key(key, key2); - tfm_des = crypto_alloc_cipher("des", 0, 0); - if (IS_ERR(tfm_des)) { - cifs_dbg(VFS, "could not allocate des crypto API\n"); - return PTR_ERR(tfm_des); + if (fips_enabled) { + cifs_dbg(VFS, "FIPS compliance enabled: DES not permitted\n"); + return -ENOENT; } - crypto_cipher_setkey(tfm_des, key2, 8); - crypto_cipher_encrypt_one(tfm_des, out, in); - crypto_free_cipher(tfm_des); + des_expand_key(&ctx, key2, DES_KEY_SIZE); + des_encrypt(&ctx, out, in); + memzero_explicit(&ctx, sizeof(ctx)); return 0; }