aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00crypto.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-12-02 12:19:48 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-12-05 09:35:50 -0500
commit1ce9cdac482f0dfbbd22ba4b3e5c016a05543a42 (patch)
tree90ffda49f6558137efc2760f4badac6de791c49a /drivers/net/wireless/rt2x00/rt2x00crypto.c
parentaac9207e45b1ec1f36d67e57d94f59ac036d37ee (diff)
rt2x00: Optimize IV/EIV handling
IV and EIV belong to eachother and don't require 2 seperate fields. Instead they can logically be merged into a single array with size 2. With this approach we can simplify the code in rt2x00crypto.c by using a single memcpy() when copying the iv/eiv data. Additionally we can move some code out of if-statements because the if-statement would always be true. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2x00crypto.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00crypto.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00crypto.c b/drivers/net/wireless/rt2x00/rt2x00crypto.c
index 5a858e5106c4..e0fc7c193040 100644
--- a/drivers/net/wireless/rt2x00/rt2x00crypto.c
+++ b/drivers/net/wireless/rt2x00/rt2x00crypto.c
@@ -78,10 +78,7 @@ void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len)
78 return; 78 return;
79 79
80 /* Copy IV/EIV data */ 80 /* Copy IV/EIV data */
81 if (iv_len >= 4) 81 memcpy(skbdesc->iv, skb->data + header_length, iv_len);
82 memcpy(&skbdesc->iv, skb->data + header_length, 4);
83 if (iv_len >= 8)
84 memcpy(&skbdesc->eiv, skb->data + header_length + 4, 4);
85 82
86 /* Move ieee80211 header */ 83 /* Move ieee80211 header */
87 memmove(skb->data + iv_len, skb->data, header_length); 84 memmove(skb->data + iv_len, skb->data, header_length);
@@ -98,7 +95,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
98 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 95 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
99 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb); 96 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
100 const unsigned int iv_len = 97 const unsigned int iv_len =
101 ((!!(skbdesc->iv)) * 4) + ((!!(skbdesc->eiv)) * 4); 98 ((!!(skbdesc->iv[0])) * 4) + ((!!(skbdesc->iv[1])) * 4);
102 99
103 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED)) 100 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED))
104 return; 101 return;
@@ -109,10 +106,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
109 memmove(skb->data, skb->data + iv_len, header_length); 106 memmove(skb->data, skb->data + iv_len, header_length);
110 107
111 /* Copy IV/EIV data */ 108 /* Copy IV/EIV data */
112 if (iv_len >= 4) 109 memcpy(skb->data + header_length, skbdesc->iv, iv_len);
113 memcpy(skb->data + header_length, &skbdesc->iv, 4);
114 if (iv_len >= 8)
115 memcpy(skb->data + header_length + 4, &skbdesc->eiv, 4);
116 110
117 /* IV/EIV data has returned into the frame */ 111 /* IV/EIV data has returned into the frame */
118 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED; 112 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED;
@@ -172,17 +166,9 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
172 header_length); 166 header_length);
173 transfer += header_length; 167 transfer += header_length;
174 168
175 /* Copy IV data */ 169 /* Copy IV/EIV data */
176 if (iv_len >= 4) { 170 memcpy(skb->data + transfer, rxdesc->iv, iv_len);
177 memcpy(skb->data + transfer, &rxdesc->iv, 4); 171 transfer += iv_len;
178 transfer += 4;
179 }
180
181 /* Copy EIV data */
182 if (iv_len >= 8) {
183 memcpy(skb->data + transfer, &rxdesc->eiv, 4);
184 transfer += 4;
185 }
186 172
187 /* Move payload */ 173 /* Move payload */
188 if (align) { 174 if (align) {
@@ -198,16 +184,14 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
198 */ 184 */
199 transfer += payload_len; 185 transfer += payload_len;
200 186
201 /* Copy ICV data */ 187 /*
202 if (icv_len >= 4) { 188 * Copy ICV data
203 memcpy(skb->data + transfer, &rxdesc->icv, 4); 189 * AES appends 8 bytes, we can't fill the upper
204 /* 190 * 4 bytes, but mac80211 doesn't care about what
205 * AES appends 8 bytes, we can't fill the upper 191 * we provide here anyway and strips it immediately.
206 * 4 bytes, but mac80211 doesn't care about what 192 */
207 * we provide here anyway and strips it immediately. 193 memcpy(skb->data + transfer, &rxdesc->icv, 4);
208 */ 194 transfer += icv_len;
209 transfer += icv_len;
210 }
211 195
212 /* IV/EIV/ICV has been inserted into frame */ 196 /* IV/EIV/ICV has been inserted into frame */
213 rxdesc->size = transfer; 197 rxdesc->size = transfer;