From patchwork Tue Jun 11 13:47: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: 166453 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2387830ilk; Tue, 11 Jun 2019 06:48:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxR4hpAY3RAyS6Ov6LuzB/gVGl2EE47yzMG0aQ5J0rIRfVyc8pN9HOZOd5T/KypgTAefgto X-Received: by 2002:a17:90a:9385:: with SMTP id q5mr26507909pjo.126.1560260881706; Tue, 11 Jun 2019 06:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560260881; cv=none; d=google.com; s=arc-20160816; b=Jh9COb2Wl45RZQHZFuq7E8faMkjbuIv7DrUvfNxI2ELdif+6kzR1CdY5fq2GTz5QJS 3XuuynfzozsPBMM1umNHLsp2KtSn0WY6j12EsmaOIdboTUG2u+y5RYG7j8ersmT4WfnO gYNMsw8f/mXJNpAxpB1rAI4lDLIUAeNtjCV3+nofXcIUqmVuttY0fwuRW2/JS+9Ur/Sc y2A8BsQCsKxM3PDdcy0yJozx/rEebYJmzFF8UKal71z8jYFi3oLpyKbTgKeF1KStFWUf UYWjcyoELZhVPjTwI4f3o0qEh3zD629t46y4YsOawevnfLSMs/XVfKYkrwrR4DUG0yf/ 2Dhw== 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=/gY5jF66N0ah9l8UKu613ADNAxCdjTNe2VAUbLEx/sY=; b=Ykt34NmA7FNtKljbhqAHHd5l1nFsZskFBAq5NDzLgzMMV3hhalYPNQMT6+8pRW70VY 1Fm2Tk4aRO7DEjGWMccaMySZ/ZG7J8Q5N5RHgnZJszOsVpteR7CaNl+QXooLPlC6FkcW zPE06Qf2BMy1ioyB/TkEFohOC8q6EL1xqNck2URpu/GbWJdEFJ2XDxaoiPtMf5XiZm/Z gGvY3o5yZpNoAZwtbgKWrdP4cRgIrm1FPUxC/h/7EbggJ/JiI3muURAahthasKHHnr9Q KTXql9sqM8I19CC5a8+wHqKocOQaZFaH/cPH4jDRQOfR4WVB8GxMIJJ9lF4l5QOHmddC 8G8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vCzJ4LFc; 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 w127si14336788pfw.200.2019.06.11.06.48.01; Tue, 11 Jun 2019 06:48:01 -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=vCzJ4LFc; 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 S2389733AbfFKNsA (ORCPT + 3 others); Tue, 11 Jun 2019 09:48:00 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33395 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389298AbfFKNsA (ORCPT ); Tue, 11 Jun 2019 09:48:00 -0400 Received: by mail-wr1-f65.google.com with SMTP id n9so13170215wru.0 for ; Tue, 11 Jun 2019 06:47: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 :mime-version:content-transfer-encoding; bh=/gY5jF66N0ah9l8UKu613ADNAxCdjTNe2VAUbLEx/sY=; b=vCzJ4LFc4W+qqyhi9wcuXopDIPfIUqJwT+fXZe3Pj6hqfe8qAwtPhAc3iWFduFHv9E hKcsJyRemE2dBglJk2k+Qi3jhjhzb3FlOhHwFJsv3tg3GaX/opYgdR9vFhIXKtV7FVu8 nzLwmPtjxZR4Vpjb2i5dMtUHoOmlxWqT7w5nnAtaCiS2djPC9HpMYtXx8d1GyNcvkrXJ BsbnT7/b+b+roVOQ8DnMMShf3362cvQVNAXKAs6xLBLGfJetd28kv5eWQdNB70gXbapD 5OBrtmodGNMRwUh12/Jdu5cAKbgqtdPp5t74Kx9pDInmMtSaUxvSOcnJ9UT0w7d30wQh DuDQ== 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=/gY5jF66N0ah9l8UKu613ADNAxCdjTNe2VAUbLEx/sY=; b=Das76rH7khzvqxhJDNeDehifscTk0eOn16qe8E3IPtHx8hd73xm+l6LDLcCbmw96/Y DwWOPBw1UCpShAOADvR1Pw7Cfz1b+lDp+0WhIIdC+OfwhWG+5g5tHKZ1lgwqGTygyC+I RhQsIN27pRAf27eQ86f7LziQVoaNDdWgMZEiOmpTyxP1efa1CizbBKwp7otaP9jRLuDA 2Nvu9KkGeqcAVenkbS+d/nVAmCShW2+ra6FVE7olvlFZBcYDqievPuLrMnk7Towr7nP7 WWApau4YtSKH9+kom8/FXmKI5fA1YV4a8xS/TS21Wz75EDDLAAReV5y6xUChX/oi6HRk W8/Q== X-Gm-Message-State: APjAAAVou+62UCJdGUub9CqqHn4IF69qpGRRddxjrK1kiImrk/KCkRJA +piY+wsOPTRzGiCqjsAMnodUdh3avBrj1nbk X-Received: by 2002:a5d:5448:: with SMTP id w8mr16959006wrv.180.1560260877993; Tue, 11 Jun 2019 06:47:57 -0700 (PDT) Received: from sudo.home ([2a01:cb1d:112:6f00:24bb:7f31:25fe:43a7]) by smtp.gmail.com with ESMTPSA id o126sm3964305wmo.31.2019.06.11.06.47.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 06:47:57 -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 v3 3/7] net/lib80211: move WEP handling to ARC4 library code Date: Tue, 11 Jun 2019 15:47:46 +0200 Message-Id: <20190611134750.2974-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190611134750.2974-1-ard.biesheuvel@linaro.org> References: <20190611134750.2974-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 | 49 +++++--------------- 2 files changed, 13 insertions(+), 37 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..9a4e4653fe64 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,51 +36,30 @@ 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); } @@ -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;