Commit b802a5d6 authored by Johannes Berg's avatar Johannes Berg

lib80211: don't use skcipher

Using skcipher just makes the code longer, and mac80211
also "open-codes" the WEP encrypt/decrypt.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 1edcfc20
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <net/iw_handler.h> #include <net/iw_handler.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#include <crypto/skcipher.h> #include <linux/crypto.h>
#include <linux/crc32.h> #include <linux/crc32.h>
#include <net/lib80211.h> #include <net/lib80211.h>
...@@ -64,9 +64,9 @@ struct lib80211_tkip_data { ...@@ -64,9 +64,9 @@ struct lib80211_tkip_data {
int key_idx; int key_idx;
struct crypto_skcipher *rx_tfm_arc4; struct crypto_cipher *rx_tfm_arc4;
struct crypto_shash *rx_tfm_michael; struct crypto_shash *rx_tfm_michael;
struct crypto_skcipher *tx_tfm_arc4; struct crypto_cipher *tx_tfm_arc4;
struct crypto_shash *tx_tfm_michael; struct crypto_shash *tx_tfm_michael;
/* scratch buffers for virt_to_page() (crypto API) */ /* scratch buffers for virt_to_page() (crypto API) */
...@@ -99,8 +99,7 @@ static void *lib80211_tkip_init(int key_idx) ...@@ -99,8 +99,7 @@ static void *lib80211_tkip_init(int key_idx)
priv->key_idx = key_idx; priv->key_idx = key_idx;
priv->tx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0, priv->tx_tfm_arc4 = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm_arc4)) { if (IS_ERR(priv->tx_tfm_arc4)) {
priv->tx_tfm_arc4 = NULL; priv->tx_tfm_arc4 = NULL;
goto fail; goto fail;
...@@ -112,8 +111,7 @@ static void *lib80211_tkip_init(int key_idx) ...@@ -112,8 +111,7 @@ static void *lib80211_tkip_init(int key_idx)
goto fail; goto fail;
} }
priv->rx_tfm_arc4 = crypto_alloc_skcipher("ecb(arc4)", 0, priv->rx_tfm_arc4 = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->rx_tfm_arc4)) { if (IS_ERR(priv->rx_tfm_arc4)) {
priv->rx_tfm_arc4 = NULL; priv->rx_tfm_arc4 = NULL;
goto fail; goto fail;
...@@ -130,9 +128,9 @@ static void *lib80211_tkip_init(int key_idx) ...@@ -130,9 +128,9 @@ static void *lib80211_tkip_init(int key_idx)
fail: fail:
if (priv) { if (priv) {
crypto_free_shash(priv->tx_tfm_michael); crypto_free_shash(priv->tx_tfm_michael);
crypto_free_skcipher(priv->tx_tfm_arc4); crypto_free_cipher(priv->tx_tfm_arc4);
crypto_free_shash(priv->rx_tfm_michael); crypto_free_shash(priv->rx_tfm_michael);
crypto_free_skcipher(priv->rx_tfm_arc4); crypto_free_cipher(priv->rx_tfm_arc4);
kfree(priv); kfree(priv);
} }
...@@ -144,9 +142,9 @@ static void lib80211_tkip_deinit(void *priv) ...@@ -144,9 +142,9 @@ static void lib80211_tkip_deinit(void *priv)
struct lib80211_tkip_data *_priv = priv; struct lib80211_tkip_data *_priv = priv;
if (_priv) { if (_priv) {
crypto_free_shash(_priv->tx_tfm_michael); crypto_free_shash(_priv->tx_tfm_michael);
crypto_free_skcipher(_priv->tx_tfm_arc4); crypto_free_cipher(_priv->tx_tfm_arc4);
crypto_free_shash(_priv->rx_tfm_michael); crypto_free_shash(_priv->rx_tfm_michael);
crypto_free_skcipher(_priv->rx_tfm_arc4); crypto_free_cipher(_priv->rx_tfm_arc4);
} }
kfree(priv); kfree(priv);
} }
...@@ -344,12 +342,10 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len, ...@@ -344,12 +342,10 @@ static int lib80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct lib80211_tkip_data *tkey = priv; struct lib80211_tkip_data *tkey = priv;
SKCIPHER_REQUEST_ON_STACK(req, tkey->tx_tfm_arc4);
int len; int len;
u8 rc4key[16], *pos, *icv; u8 rc4key[16], *pos, *icv;
u32 crc; u32 crc;
struct scatterlist sg; int i;
int err;
if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) { if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
...@@ -374,14 +370,10 @@ static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -374,14 +370,10 @@ static int lib80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
icv[2] = crc >> 16; icv[2] = crc >> 16;
icv[3] = crc >> 24; icv[3] = crc >> 24;
crypto_skcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16); crypto_cipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
sg_init_one(&sg, pos, len + 4); for (i = 0; i < len + 4; i++)
skcipher_request_set_tfm(req, tkey->tx_tfm_arc4); crypto_cipher_encrypt_one(tkey->tx_tfm_arc4, pos + i, pos + i);
skcipher_request_set_callback(req, 0, NULL, NULL); return 0;
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
err = crypto_skcipher_encrypt(req);
skcipher_request_zero(req);
return err;
} }
/* /*
...@@ -400,7 +392,6 @@ static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n, ...@@ -400,7 +392,6 @@ static inline int tkip_replay_check(u32 iv32_n, u16 iv16_n,
static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct lib80211_tkip_data *tkey = priv; struct lib80211_tkip_data *tkey = priv;
SKCIPHER_REQUEST_ON_STACK(req, tkey->rx_tfm_arc4);
u8 rc4key[16]; u8 rc4key[16];
u8 keyidx, *pos; u8 keyidx, *pos;
u32 iv32; u32 iv32;
...@@ -408,9 +399,8 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -408,9 +399,8 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
struct ieee80211_hdr *hdr; struct ieee80211_hdr *hdr;
u8 icv[4]; u8 icv[4];
u32 crc; u32 crc;
struct scatterlist sg;
int plen; int plen;
int err; int i;
hdr = (struct ieee80211_hdr *)skb->data; hdr = (struct ieee80211_hdr *)skb->data;
...@@ -463,18 +453,9 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -463,18 +453,9 @@ static int lib80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
plen = skb->len - hdr_len - 12; plen = skb->len - hdr_len - 12;
crypto_skcipher_setkey(tkey->rx_tfm_arc4, rc4key, 16); crypto_cipher_setkey(tkey->rx_tfm_arc4, rc4key, 16);
sg_init_one(&sg, pos, plen + 4); for (i = 0; i < plen + 4; i++)
skcipher_request_set_tfm(req, tkey->rx_tfm_arc4); crypto_cipher_decrypt_one(tkey->rx_tfm_arc4, pos + i, pos + i);
skcipher_request_set_callback(req, 0, NULL, NULL);
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
err = crypto_skcipher_decrypt(req);
skcipher_request_zero(req);
if (err) {
net_dbg_ratelimited("TKIP: failed to decrypt received packet from %pM\n",
hdr->addr2);
return -7;
}
crc = ~crc32_le(~0, pos, plen); crc = ~crc32_le(~0, pos, plen);
icv[0] = crc; icv[0] = crc;
...@@ -660,9 +641,9 @@ static int lib80211_tkip_set_key(void *key, int len, u8 * seq, void *priv) ...@@ -660,9 +641,9 @@ static int lib80211_tkip_set_key(void *key, int len, u8 * seq, void *priv)
struct lib80211_tkip_data *tkey = priv; struct lib80211_tkip_data *tkey = priv;
int keyidx; int keyidx;
struct crypto_shash *tfm = tkey->tx_tfm_michael; struct crypto_shash *tfm = tkey->tx_tfm_michael;
struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4; struct crypto_cipher *tfm2 = tkey->tx_tfm_arc4;
struct crypto_shash *tfm3 = tkey->rx_tfm_michael; struct crypto_shash *tfm3 = tkey->rx_tfm_michael;
struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4; struct crypto_cipher *tfm4 = tkey->rx_tfm_arc4;
keyidx = tkey->key_idx; keyidx = tkey->key_idx;
memset(tkey, 0, sizeof(*tkey)); memset(tkey, 0, sizeof(*tkey));
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <net/lib80211.h> #include <net/lib80211.h>
#include <crypto/skcipher.h> #include <linux/crypto.h>
#include <linux/crc32.h> #include <linux/crc32.h>
MODULE_AUTHOR("Jouni Malinen"); MODULE_AUTHOR("Jouni Malinen");
...@@ -35,8 +35,8 @@ struct lib80211_wep_data { ...@@ -35,8 +35,8 @@ struct lib80211_wep_data {
u8 key[WEP_KEY_LEN + 1]; u8 key[WEP_KEY_LEN + 1];
u8 key_len; u8 key_len;
u8 key_idx; u8 key_idx;
struct crypto_skcipher *tx_tfm; struct crypto_cipher *tx_tfm;
struct crypto_skcipher *rx_tfm; struct crypto_cipher *rx_tfm;
}; };
static void *lib80211_wep_init(int keyidx) static void *lib80211_wep_init(int keyidx)
...@@ -48,13 +48,13 @@ static void *lib80211_wep_init(int keyidx) ...@@ -48,13 +48,13 @@ static void *lib80211_wep_init(int keyidx)
goto fail; goto fail;
priv->key_idx = keyidx; priv->key_idx = keyidx;
priv->tx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); priv->tx_tfm = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm)) { if (IS_ERR(priv->tx_tfm)) {
priv->tx_tfm = NULL; priv->tx_tfm = NULL;
goto fail; goto fail;
} }
priv->rx_tfm = crypto_alloc_skcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); priv->rx_tfm = crypto_alloc_cipher("arc4", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->rx_tfm)) { if (IS_ERR(priv->rx_tfm)) {
priv->rx_tfm = NULL; priv->rx_tfm = NULL;
goto fail; goto fail;
...@@ -66,8 +66,8 @@ static void *lib80211_wep_init(int keyidx) ...@@ -66,8 +66,8 @@ static void *lib80211_wep_init(int keyidx)
fail: fail:
if (priv) { if (priv) {
crypto_free_skcipher(priv->tx_tfm); crypto_free_cipher(priv->tx_tfm);
crypto_free_skcipher(priv->rx_tfm); crypto_free_cipher(priv->rx_tfm);
kfree(priv); kfree(priv);
} }
return NULL; return NULL;
...@@ -77,8 +77,8 @@ static void lib80211_wep_deinit(void *priv) ...@@ -77,8 +77,8 @@ static void lib80211_wep_deinit(void *priv)
{ {
struct lib80211_wep_data *_priv = priv; struct lib80211_wep_data *_priv = priv;
if (_priv) { if (_priv) {
crypto_free_skcipher(_priv->tx_tfm); crypto_free_cipher(_priv->tx_tfm);
crypto_free_skcipher(_priv->rx_tfm); crypto_free_cipher(_priv->rx_tfm);
} }
kfree(priv); kfree(priv);
} }
...@@ -129,12 +129,10 @@ static int lib80211_wep_build_iv(struct sk_buff *skb, int hdr_len, ...@@ -129,12 +129,10 @@ static int lib80211_wep_build_iv(struct sk_buff *skb, int hdr_len,
static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct lib80211_wep_data *wep = priv; struct lib80211_wep_data *wep = priv;
SKCIPHER_REQUEST_ON_STACK(req, wep->tx_tfm);
u32 crc, klen, len; u32 crc, klen, len;
u8 *pos, *icv; u8 *pos, *icv;
struct scatterlist sg;
u8 key[WEP_KEY_LEN + 3]; u8 key[WEP_KEY_LEN + 3];
int err; int i;
/* other checks are in lib80211_wep_build_iv */ /* other checks are in lib80211_wep_build_iv */
if (skb_tailroom(skb) < 4) if (skb_tailroom(skb) < 4)
...@@ -162,14 +160,12 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -162,14 +160,12 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
icv[2] = crc >> 16; icv[2] = crc >> 16;
icv[3] = crc >> 24; icv[3] = crc >> 24;
crypto_skcipher_setkey(wep->tx_tfm, key, klen); crypto_cipher_setkey(wep->tx_tfm, key, klen);
sg_init_one(&sg, pos, len + 4);
skcipher_request_set_tfm(req, wep->tx_tfm); for (i = 0; i < len + 4; i++)
skcipher_request_set_callback(req, 0, NULL, NULL); crypto_cipher_encrypt_one(wep->tx_tfm, pos + i, pos + i);
skcipher_request_set_crypt(req, &sg, &sg, len + 4, NULL);
err = crypto_skcipher_encrypt(req); return 0;
skcipher_request_zero(req);
return err;
} }
/* Perform WEP decryption on given buffer. Buffer includes whole WEP part of /* Perform WEP decryption on given buffer. Buffer includes whole WEP part of
...@@ -182,12 +178,10 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -182,12 +178,10 @@ static int lib80211_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
{ {
struct lib80211_wep_data *wep = priv; struct lib80211_wep_data *wep = priv;
SKCIPHER_REQUEST_ON_STACK(req, wep->rx_tfm);
u32 crc, klen, plen; u32 crc, klen, plen;
u8 key[WEP_KEY_LEN + 3]; u8 key[WEP_KEY_LEN + 3];
u8 keyidx, *pos, icv[4]; u8 keyidx, *pos, icv[4];
struct scatterlist sg; int i;
int err;
if (skb->len < hdr_len + 8) if (skb->len < hdr_len + 8)
return -1; return -1;
...@@ -208,15 +202,9 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -208,15 +202,9 @@ static int lib80211_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
/* Apply RC4 to data and compute CRC32 over decrypted data */ /* Apply RC4 to data and compute CRC32 over decrypted data */
plen = skb->len - hdr_len - 8; plen = skb->len - hdr_len - 8;
crypto_skcipher_setkey(wep->rx_tfm, key, klen); crypto_cipher_setkey(wep->rx_tfm, key, klen);
sg_init_one(&sg, pos, plen + 4); for (i = 0; i < plen + 4; i++)
skcipher_request_set_tfm(req, wep->rx_tfm); crypto_cipher_decrypt_one(wep->rx_tfm, pos + i, pos + i);
skcipher_request_set_callback(req, 0, NULL, NULL);
skcipher_request_set_crypt(req, &sg, &sg, plen + 4, NULL);
err = crypto_skcipher_decrypt(req);
skcipher_request_zero(req);
if (err)
return -7;
crc = ~crc32_le(~0, pos, plen); crc = ~crc32_le(~0, pos, plen);
icv[0] = crc; icv[0] = crc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment