d80211: Replace rc4 code with crypto api arc4
Subsystems (2)
PATCH 1/1 d80211: Replace rc4 code with crypto api arc4
Replace rc4 code with crypto api arc4
This patch replaces the rc4 code used in wep.c with crypto api's arc4 cipher. The struct crypto_tfm passing in tkip isn't great, but it'll get fixed when tkip is converted to use crypto api entirely. (michael_mic)
Signed-off-by Michael Wu <[email protected]>
---
net/d80211/Kconfig | 1 net/d80211/ieee80211.c | 10 ++ net/d80211/ieee80211_i.h | 1 net/d80211/tkip.c | 14 ++- net/d80211/tkip.h | 10 +- net/d80211/wep.c | 193 ++++++++++------------------------------------ net/d80211/wep.h | 11 +-- net/d80211/wpa.c | 4 - 8 files changed, 73 insertions(+), 171 deletions(-)
net/d80211/Kconfig +1 -0
@@ -1,6 +1,7 @@ config D80211 tristate "Generic IEEE 802.11 Networking Stack (dscape)" select CRYPTO + select CRYPTO_ARC4 select CRYPTO_AES ---help--- This option enables the hardware independent IEEE 802.11
net/d80211/ieee80211.c +8 -2
@@ -4381,11 +4381,16 @@ int ieee80211_register_hw(struct net_dev goto fail_rate_attrs; } + result =ieee80211_wep_init (local); + +if (result <0 ) { +printk (KERN_DEBUG "%s: Failed to initialize wep\n" , dev->name); + goto fail_rate_attrs; + } +/* TODO: add rtnl locking around device creation and qdisc install */ ieee80211_install_qdisc (dev); -ieee80211_wep_init (local); -/* add one default STA interface */ rtnl_lock (); result =ieee80211_if_add (dev,"wlan%d" ,1 , &sta_dev);
@@ -4502,6 +4507,7 @@ void ieee80211_free_hw(struct net_devicestruct ieee80211_local *local = dev->ieee80211_ptr;free_netdev (dev); +ieee80211_wep_free (local);ieee80211_dev_free (local); }
net/d80211/ieee80211_i.h +1 -0
@@ -396,6 +396,7 @@ #define IEEE80211_IRQSAFE_QUEUE_LIMIT 12int long_retry_limit;/* dot11LongRetryLimit */ int short_preamble;/* use short preamble with IEEE 802.11b */ +struct crypto_tfm *wep_tfm;u32 wep_iv;int key_tx_rx_threshold;/* number of times any key can be used in TX * or RX before generating a rekey
net/d80211/tkip.c +7 -7
@@ -211,8 +211,8 @@ u8 * ieee80211_tkip_add_iv(u8 *pos, stru* headroom of eight octets for IV and Ext. IV and taildroom of four octets * for ICV. @payload_len is the length of payload (_not_ including extra * headroom and tailroom). @ta is the transmitter addresses. */ -void ieee80211_tkip_encrypt_data (struct ieee80211_key *key,u8 *pos, -size_t payload_len,u8 *ta) +void ieee80211_tkip_encrypt_data (struct crypto_tfm *tfm,struct ieee80211_key *key, +u8 *pos,size_t payload_len,u8 *ta) {u8 rc4key[16 ];
@@ -228,7 +228,7 @@ void ieee80211_tkip_encrypt_data(struct key->u.tkip.iv16, rc4key); pos =ieee80211_tkip_add_iv (pos, key, rc4key[0 ], rc4key[1 ], rc4key[2 ]); -ieee80211_wep_encrypt_data (rc4key,16 , pos, payload_len); +ieee80211_wep_encrypt_data (tfm, rc4key,16 , pos, payload_len); }
@@ -236,9 +236,9 @@ void ieee80211_tkip_encrypt_data(struct* beginning of the buffer containing IEEE 802.11 header payload, i.e., * including IV, Ext. IV, real data, Michael MIC, ICV. @payload_len is the * length of payload, including IV, Ext. IV, MIC, ICV. */ -int ieee80211_tkip_decrypt_data (struct ieee80211_key *key,u8 *payload, -size_t payload_len,u8 *ta,int only_iv, -int queue) +int ieee80211_tkip_decrypt_data (struct crypto_tfm *tfm,struct ieee80211_key *key, +u8 *payload,size_t payload_len,u8 *ta, +int only_iv,int queue) {u32 iv32;u32 iv16;
@@ -325,7 +325,7 @@ #ifdef CONFIG_TKIP_DEBUG }#endif /* CONFIG_TKIP_DEBUG */ - res =ieee80211_wep_decrypt_data (rc4key,16 , pos, payload_len -12 ); + res =ieee80211_wep_decrypt_data (tfm, rc4key,16 , pos, payload_len -12 ); done:if (res ==TKIP_DECRYPT_OK ) {/* FIX: these should be updated only after Michael MIC has been
net/d80211/tkip.h +5 -5
@@ -14,16 +14,16 @@ #include "ieee80211_key.h"u8 *ieee80211_tkip_add_iv (u8 *pos,struct ieee80211_key *key,u8 iv0,u8 iv1,u8 iv2); -void ieee80211_tkip_encrypt_data (struct ieee80211_key *key,u8 *pos, -size_t payload_len,u8 *ta); +void ieee80211_tkip_encrypt_data (struct crypto_tfm *tfm,struct ieee80211_key *key, +u8 *pos,size_t payload_len,u8 *ta);enum {TKIP_DECRYPT_OK =0 ,TKIP_DECRYPT_NO_EXT_IV =-1 ,TKIP_DECRYPT_INVALID_KEYIDX =-2 ,TKIP_DECRYPT_REPLAY =-3 , }; -int ieee80211_tkip_decrypt_data (struct ieee80211_key *key,u8 *payload, -size_t payload_len,u8 *ta,int only_iv, -int queue); +int ieee80211_tkip_decrypt_data (struct crypto_tfm *tfm,struct ieee80211_key *key, +u8 *payload,size_t payload_len,u8 *ta, +int only_iv,int queue);#endif /* TKIP_H */
net/d80211/wep.c +43 -150
237 lines not on this page · raw message
net/d80211/wep.h +6 -5
@@ -16,7 +16,8 @@ #include <linux/types.h>#include "ieee80211_i.h" #include "ieee80211_key.h" -void ieee80211_wep_init (struct ieee80211_local *local); +int ieee80211_wep_init (struct ieee80211_local *local); +void ieee80211_wep_free (struct ieee80211_local *local);void ieee80211_wep_get_iv (struct ieee80211_local *local,struct ieee80211_key *key,u8 *iv); u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
@@ -25,10 +26,10 @@ u8 * ieee80211_wep_add_iv(struct ieee802void ieee80211_wep_remove_iv (struct ieee80211_local *local,struct sk_buff *skb,struct ieee80211_key *key); -void ieee80211_wep_encrypt_data (u8 *rc4key,size_t klen,u8 *data, -size_t data_len); -int ieee80211_wep_decrypt_data (u8 *rc4key,size_t klen,u8 *data, -size_t data_len); +void ieee80211_wep_encrypt_data (struct crypto_tfm *tfm,u8 *rc4key,size_t klen, +u8 *data,size_t data_len); +int ieee80211_wep_decrypt_data (struct crypto_tfm *tfm,u8 *rc4key,size_t klen, +u8 *data,size_t data_len);int ieee80211_wep_encrypt (struct ieee80211_local *local,struct sk_buff *skb,struct ieee80211_key *key); int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
net/d80211/wpa.c +2 -2
@@ -355,7 +355,7 @@ #endif /* CONFIG_HOSTAPD_WPA_TESTING */skb_put (skb,TKIP_ICV_LEN ); hdr = (struct ieee80211_hdr *) skb->data; -ieee80211_tkip_encrypt_data (key, pos, len, hdr->addr2); +ieee80211_tkip_encrypt_data (tx->local->wep_tfm, key, pos, len, hdr->addr2);return 0 ; }
@@ -498,7 +498,7 @@ #endif /* CONFIG_HOSTAPD_WPA_TESTING */ hwaccel =1 ; } - res =ieee80211_tkip_decrypt_data (key, skb->data + hdrlen, + res =ieee80211_tkip_decrypt_data (rx->local->wep_tfm, key, skb->data + hdrlen, skb->len - hdrlen, rx->sta->addr, hwaccel, rx->u.rx.queue);if (res !=TKIP_DECRYPT_OK || wpa_test) {
Quoted 3 lines · Michael Wu
This patch replaces the rc4 code used in
wep.cwith crypto api's arc4 cipher. The structcrypto_tfmpassing in tkip isn't great, but it'll get fixed when tkip is converted to use crypto api entirely. (michael_mic)
Great work! Thanks, I'll apply the patch to my tree (there is a minor conflict) and push it to John eventually.
Jiri
Signature · 2 lines
Jiri Benc SUSE Labs