From patchwork Tue Jun 11 23:09:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 166499 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2934777ilk; Tue, 11 Jun 2019 16:09:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYo/0iz/1RtUYYdaTiINWaV6b2gamVmf7MKO1QdKXwqFsOoHH9+BSdxfcBIGAIMX6z6uQl X-Received: by 2002:a63:b547:: with SMTP id u7mr22867110pgo.322.1560294593134; Tue, 11 Jun 2019 16:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560294593; cv=none; d=google.com; s=arc-20160816; b=G3+tX2kkgLRBicCIS9rXJrWLarJJXkJVgi0WK9m4BoE7biLizSW59YRCyLSd2JeV2s LlhfL+CMyfhmHAx7s1IDSmb2zD00ogHXzAT3xY/3BLsukw070eeejEK9/vwMBHvvi3an kdUM4jXbvjFghiRKZanQeRqFCjwq/BNLiZNeKxnEb3IL7+WX9bLGBT5BXlr3REY8zDwg ukVibWcyweEpLWGyAw+YkwSIvDGZ642V01sP58+g4gPT1ugZ8Eghopu5tP0sXh2r/bi2 BFU09FgrVVmCFV5zx7RYRNQR9GnQySpQMaTyy6q8SlUr8Y9obw0y6MQIDMvWF23pcVuP BVbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OwqgljQ1B81ow4cCya6JJaWKyb9eZkcUJZbKrShyt74=; b=P2DX6ly+gPiV3GtjMA5wzC8U0EmpeaUcxOjjC3S30pGqUaPLDbd0pxLdtJWFHLze7S 8eg0ggDloXasee6kAkJMN/aa+LbzLkuSl1OOZihiE/4AvD++IGQw2uqBQgn497MMKXJx Zwa27wHC/XyTWSLfIJln/FnzmAqsoXss/b0UcbZgXLC8kKfxVomWNog0pyenzZ36xPGC /m66tRrU0+3aDn9gg2+YTBh/cQ6zsy1In971rnbrcKWSypvWjPOwllfu9VGmZEmDRnWu wOE0lDfFj8fQtTA0bOH2c+CKdmYQMAOUWWMf3GpwPSJ2qkaJHjw7MdhZ8xBtqJ0m4bT9 V1kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ego+R3yL; 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 h21si13653976pgv.266.2019.06.11.16.09.52; Tue, 11 Jun 2019 16:09: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=ego+R3yL; 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 S2407946AbfFKXJw (ORCPT + 3 others); Tue, 11 Jun 2019 19:09:52 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44379 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407944AbfFKXJt (ORCPT ); Tue, 11 Jun 2019 19:09:49 -0400 Received: by mail-wr1-f67.google.com with SMTP id b17so14781735wrq.11 for ; Tue, 11 Jun 2019 16:09: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 :mime-version:content-transfer-encoding; bh=OwqgljQ1B81ow4cCya6JJaWKyb9eZkcUJZbKrShyt74=; b=ego+R3yLJjqYVtyUtNrsfCkWcown+rLk6UiEMaUUHboV16q9o9u6eUIx0pPbTGUl78 s6l9Eu2dLFAUXEJSrIG7rQ61m8dSJTtKMZpGXd9Lgq2sYQ2Hxv0PYjiVM6KiIVw3ZZN9 ID6Vfmj69tmcxnAFhIfTX+OPddLrTow8v5bwRUSP/5Cqn3IW6ovVvxbtFdoYxzWBP4cH yG/1DomuX7SwXvJfGcoN5JZMLi0Y724gkGMCMmvwc6QfJCeClju1uT5MKaO0fU4u9RPS iN2Jd/S/SyT8tgfJtjpnSt4nG99xaUsy3Jodom3iaoq0SzmQlFYjCf/drbf+HQLfQMVz h4gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OwqgljQ1B81ow4cCya6JJaWKyb9eZkcUJZbKrShyt74=; b=W7LiGRXOY/aU+KpkJNiMur3YOrLW7BHV3tvpAeTYfonAX8rBluwC0kBfd+zUn+kHa/ D6dAU54g+TdTwNYvvHO9IkbzSc9pIj9sil6RhcsmpADejEFAsK59zLAKxTE1RR647Snl +G4lWYWBiulCfbqJ9ZjQa1Yqam7HccZ4cp7tS0GF8+Ab3dW4R4cnwrT3j989FT1J/p4H 0nQSlu3zC/NB+A1u9gnIpeKsDsLLVlsFNZvk3C2J6gu60sk8balGB8r4qLRji0hgo6gf 43TJl1PLDCEh0Rk/5ooRzRV3G1D2m/BjneUybZpucyjryRwKc98JsvdrLPZfFIC+ikkn Zkgw== X-Gm-Message-State: APjAAAWPEkP/wDdFTuvVCUFwbdG2jflbe5m1XfTp44Whmub6eaYkZshi OStLcyQtP25fFHT0D8z/2WHWAUsxwDauxmco X-Received: by 2002:a05:6000:1c9:: with SMTP id t9mr26667190wrx.187.1560294587363; Tue, 11 Jun 2019 16:09:47 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:24bb:7f31:25fe:43a7]) by smtp.gmail.com with ESMTPSA id g11sm10827813wrq.89.2019.06.11.16.09.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 16:09:46 -0700 (PDT) From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: Ard Biesheuvel , Herbert Xu , "David S. Miller" , Eric Biggers , Johannes Berg Subject: [PATCH v4 3/7] net/lib80211: move WEP handling to ARC4 library code Date: Wed, 12 Jun 2019 01:09:34 +0200 Message-Id: <20190611230938.19265-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190611230938.19265-1-ard.biesheuvel@linaro.org> References: <20190611230938.19265-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The crypto API abstraction is not very useful for invoking ciphers directly, especially in the case of arc4, which only has a generic implementation in C. So let's invoke the library code directly. Signed-off-by: Ard Biesheuvel --- net/wireless/Kconfig | 1 + net/wireless/lib80211_crypt_wep.c | 51 +++++--------------- 2 files changed, 14 insertions(+), 38 deletions(-) -- 2.20.1 diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig index 6310ddede220..6d9c48cea07e 100644 --- a/net/wireless/Kconfig +++ b/net/wireless/Kconfig @@ -213,6 +213,7 @@ config LIB80211 config LIB80211_CRYPT_WEP tristate + select CRYPTO_LIB_ARC4 config LIB80211_CRYPT_CCMP tristate diff --git a/net/wireless/lib80211_crypt_wep.c b/net/wireless/lib80211_crypt_wep.c index 20c1ad63ad44..04e4d66ea19d 100644 --- a/net/wireless/lib80211_crypt_wep.c +++ b/net/wireless/lib80211_crypt_wep.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -22,7 +23,7 @@ #include -#include +#include #include MODULE_AUTHOR("Jouni Malinen"); @@ -35,52 +36,31 @@ struct lib80211_wep_data { u8 key[WEP_KEY_LEN + 1]; u8 key_len; u8 key_idx; - struct crypto_cipher *tx_tfm; - struct crypto_cipher *rx_tfm; + struct arc4_ctx tx_ctx; + struct arc4_ctx rx_ctx; }; static void *lib80211_wep_init(int keyidx) { struct lib80211_wep_data *priv; + if (fips_enabled) + return NULL; + priv = kzalloc(sizeof(*priv), GFP_ATOMIC); if (priv == NULL) - goto fail; + return NULL; priv->key_idx = keyidx; - priv->tx_tfm = crypto_alloc_cipher("arc4", 0, 0); - if (IS_ERR(priv->tx_tfm)) { - priv->tx_tfm = NULL; - goto fail; - } - - priv->rx_tfm = crypto_alloc_cipher("arc4", 0, 0); - if (IS_ERR(priv->rx_tfm)) { - priv->rx_tfm = NULL; - goto fail; - } /* start WEP IV from a random value */ get_random_bytes(&priv->iv, 4); return priv; - - fail: - if (priv) { - crypto_free_cipher(priv->tx_tfm); - crypto_free_cipher(priv->rx_tfm); - kfree(priv); - } - return NULL; } static void lib80211_wep_deinit(void *priv) { - struct lib80211_wep_data *_priv = priv; - if (_priv) { - crypto_free_cipher(_priv->tx_tfm); - crypto_free_cipher(_priv->rx_tfm); - } - kfree(priv); + kzfree(priv); } /* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */ @@ -132,7 +112,6 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) u32 crc, klen, len; u8 *pos, *icv; u8 key[WEP_KEY_LEN + 3]; - int i; /* other checks are in lib80211_wep_build_iv */ if (skb_tailroom(skb) < 4) @@ -160,10 +139,8 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) icv[2] = crc >> 16; icv[3] = crc >> 24; - crypto_cipher_setkey(wep->tx_tfm, key, klen); - - for (i = 0; i < len + 4; i++) - crypto_cipher_encrypt_one(wep->tx_tfm, pos + i, pos + i); + arc4_setkey(&wep->tx_ctx, key, klen); + arc4_crypt(&wep->tx_ctx, pos, pos, len + 4); return 0; } @@ -181,7 +158,6 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) u32 crc, klen, plen; u8 key[WEP_KEY_LEN + 3]; u8 keyidx, *pos, icv[4]; - int i; if (skb->len < hdr_len + 8) return -1; @@ -202,9 +178,8 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) /* Apply RC4 to data and compute CRC32 over decrypted data */ plen = skb->len - hdr_len - 8; - crypto_cipher_setkey(wep->rx_tfm, key, klen); - for (i = 0; i < plen + 4; i++) - crypto_cipher_decrypt_one(wep->rx_tfm, pos + i, pos + i); + arc4_setkey(&wep->rx_ctx, key, klen); + arc4_crypt(&wep->rx_ctx, pos, pos, plen + 4); crc = ~crc32_le(~0, pos, plen); icv[0] = crc;