Re: [RFC PATCH 2/7] staging/rtl8192u: switch to RC4 library interface

2020-07-02 Thread Greg Kroah-Hartman
On Thu, Jul 02, 2020 at 12:19:42PM +0200, Ard Biesheuvel wrote:
> Switch to the ARC4 library interface, to remove the pointless
> dependency on the skcipher API, from which we will hopefully be
> able to drop ecb(arc4) skcipher support.
> 
> Signed-off-by: Ard Biesheuvel 

Acked-by: Greg Kroah-Hartman 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC PATCH 2/7] staging/rtl8192u: switch to RC4 library interface

2020-07-02 Thread Ard Biesheuvel
Switch to the ARC4 library interface, to remove the pointless
dependency on the skcipher API, from which we will hopefully be
able to drop ecb(arc4) skcipher support.

Signed-off-by: Ard Biesheuvel 
---
 drivers/staging/rtl8192u/Kconfig  |  1 +
 drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 82 

 drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c  | 64 +++
 3 files changed, 27 insertions(+), 120 deletions(-)

diff --git a/drivers/staging/rtl8192u/Kconfig b/drivers/staging/rtl8192u/Kconfig
index 1edca5c304fb..ef883d462d3d 100644
--- a/drivers/staging/rtl8192u/Kconfig
+++ b/drivers/staging/rtl8192u/Kconfig
@@ -8,3 +8,4 @@ config RTL8192U
select CRYPTO
select CRYPTO_AES
select CRYPTO_CCM
+   select CRYPTO_LIB_ARC4
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c 
b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
index ffe624ed0c0c..a315133c20db 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2003-2004, Jouni Malinen 
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -17,9 +18,7 @@
 
 #include "ieee80211.h"
 
-#include 
-#include 
-   #include 
+#include 
 #include 
 
 MODULE_AUTHOR("Jouni Malinen");
@@ -49,9 +48,9 @@ struct ieee80211_tkip_data {
 
int key_idx;
 
-   struct crypto_sync_skcipher *rx_tfm_arc4;
+   struct arc4_ctx rx_ctx_arc4;
+   struct arc4_ctx tx_ctx_arc4;
struct crypto_shash *rx_tfm_michael;
-   struct crypto_sync_skcipher *tx_tfm_arc4;
struct crypto_shash *tx_tfm_michael;
 
/* scratch buffers for virt_to_page() (crypto API) */
@@ -62,19 +61,14 @@ static void *ieee80211_tkip_init(int key_idx)
 {
struct ieee80211_tkip_data *priv;
 
+   if (fips_enabled)
+   return NULL;
+
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
goto fail;
priv->key_idx = key_idx;
 
-   priv->tx_tfm_arc4 = crypto_alloc_sync_skcipher("ecb(arc4)", 0, 0);
-   if (IS_ERR(priv->tx_tfm_arc4)) {
-   printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
-   "crypto API arc4\n");
-   priv->tx_tfm_arc4 = NULL;
-   goto fail;
-   }
-
priv->tx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0);
if (IS_ERR(priv->tx_tfm_michael)) {
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -83,14 +77,6 @@ static void *ieee80211_tkip_init(int key_idx)
goto fail;
}
 
-   priv->rx_tfm_arc4 = crypto_alloc_sync_skcipher("ecb(arc4)", 0, 0);
-   if (IS_ERR(priv->rx_tfm_arc4)) {
-   printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
-   "crypto API arc4\n");
-   priv->rx_tfm_arc4 = NULL;
-   goto fail;
-   }
-
priv->rx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0);
if (IS_ERR(priv->rx_tfm_michael)) {
printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate "
@@ -104,9 +90,7 @@ static void *ieee80211_tkip_init(int key_idx)
 fail:
if (priv) {
crypto_free_shash(priv->tx_tfm_michael);
-   crypto_free_sync_skcipher(priv->tx_tfm_arc4);
crypto_free_shash(priv->rx_tfm_michael);
-   crypto_free_sync_skcipher(priv->rx_tfm_arc4);
kfree(priv);
}
 
@@ -120,11 +104,9 @@ static void ieee80211_tkip_deinit(void *priv)
 
if (_priv) {
crypto_free_shash(_priv->tx_tfm_michael);
-   crypto_free_sync_skcipher(_priv->tx_tfm_arc4);
crypto_free_shash(_priv->rx_tfm_michael);
-   crypto_free_sync_skcipher(_priv->rx_tfm_arc4);
}
-   kfree(priv);
+   kzfree(priv);
 }
 
 
@@ -290,10 +272,8 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int 
hdr_len, void *priv)
u8 *pos;
struct rtl_80211_hdr_4addr *hdr;
struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 
MAX_DEV_ADDR_SIZE);
-   int ret = 0;
u8 rc4key[16],  *icv;
u32 crc;
-   struct scatterlist sg;
 
if (skb_headroom(skb) < 8 || skb_tailroom(skb) < 4 ||
skb->len < hdr_len)
@@ -334,21 +314,15 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, 
int hdr_len, void *priv)
*pos++ = (tkey->tx_iv32 >> 24) & 0xff;
 
if (!tcb_desc->bHwSec) {
-   SYNC_SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
-
icv = skb_put(skb, 4);
crc = ~crc32_le(~0, pos, len);
icv[0] = crc;
icv[1] = crc >> 8;
icv[2] = crc >> 16;
icv[3] = crc >> 24;
-   crypto_sync_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
-