Commit 1ce9cdac authored by Ivo van Doorn's avatar Ivo van Doorn Committed by John W. Linville

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: default avatarIvo van Doorn <IvDoorn@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent aac9207e
...@@ -78,10 +78,7 @@ void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len) ...@@ -78,10 +78,7 @@ void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len)
return; return;
/* Copy IV/EIV data */ /* Copy IV/EIV data */
if (iv_len >= 4) memcpy(skbdesc->iv, skb->data + header_length, iv_len);
memcpy(&skbdesc->iv, skb->data + header_length, 4);
if (iv_len >= 8)
memcpy(&skbdesc->eiv, skb->data + header_length + 4, 4);
/* Move ieee80211 header */ /* Move ieee80211 header */
memmove(skb->data + iv_len, skb->data, header_length); memmove(skb->data + iv_len, skb->data, header_length);
...@@ -98,7 +95,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb) ...@@ -98,7 +95,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb); unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
const unsigned int iv_len = const unsigned int iv_len =
((!!(skbdesc->iv)) * 4) + ((!!(skbdesc->eiv)) * 4); ((!!(skbdesc->iv[0])) * 4) + ((!!(skbdesc->iv[1])) * 4);
if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED)) if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED))
return; return;
...@@ -109,10 +106,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb) ...@@ -109,10 +106,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
memmove(skb->data, skb->data + iv_len, header_length); memmove(skb->data, skb->data + iv_len, header_length);
/* Copy IV/EIV data */ /* Copy IV/EIV data */
if (iv_len >= 4) memcpy(skb->data + header_length, skbdesc->iv, iv_len);
memcpy(skb->data + header_length, &skbdesc->iv, 4);
if (iv_len >= 8)
memcpy(skb->data + header_length + 4, &skbdesc->eiv, 4);
/* IV/EIV data has returned into the frame */ /* IV/EIV data has returned into the frame */
skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED; skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED;
...@@ -172,17 +166,9 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align, ...@@ -172,17 +166,9 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
header_length); header_length);
transfer += header_length; transfer += header_length;
/* Copy IV data */ /* Copy IV/EIV data */
if (iv_len >= 4) { memcpy(skb->data + transfer, rxdesc->iv, iv_len);
memcpy(skb->data + transfer, &rxdesc->iv, 4); transfer += iv_len;
transfer += 4;
}
/* Copy EIV data */
if (iv_len >= 8) {
memcpy(skb->data + transfer, &rxdesc->eiv, 4);
transfer += 4;
}
/* Move payload */ /* Move payload */
if (align) { if (align) {
...@@ -198,16 +184,14 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align, ...@@ -198,16 +184,14 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
*/ */
transfer += payload_len; transfer += payload_len;
/* Copy ICV data */ /*
if (icv_len >= 4) { * Copy ICV data
memcpy(skb->data + transfer, &rxdesc->icv, 4); * AES appends 8 bytes, we can't fill the upper
/* * 4 bytes, but mac80211 doesn't care about what
* AES appends 8 bytes, we can't fill the upper * we provide here anyway and strips it immediately.
* 4 bytes, but mac80211 doesn't care about what */
* we provide here anyway and strips it immediately. memcpy(skb->data + transfer, &rxdesc->icv, 4);
*/ transfer += icv_len;
transfer += icv_len;
}
/* IV/EIV/ICV has been inserted into frame */ /* IV/EIV/ICV has been inserted into frame */
rxdesc->size = transfer; rxdesc->size = transfer;
......
...@@ -109,8 +109,7 @@ enum skb_frame_desc_flags { ...@@ -109,8 +109,7 @@ enum skb_frame_desc_flags {
* @desc: Pointer to descriptor part of the frame. * @desc: Pointer to descriptor part of the frame.
* Note that this pointer could point to something outside * Note that this pointer could point to something outside
* of the scope of the skb->data pointer. * of the scope of the skb->data pointer.
* @iv: IV data used during encryption/decryption. * @iv: IV/EIV data used during encryption/decryption.
* @eiv: EIV data used during encryption/decryption.
* @skb_dma: (PCI-only) the DMA address associated with the sk buffer. * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
* @entry: The entry to which this sk buffer belongs. * @entry: The entry to which this sk buffer belongs.
*/ */
...@@ -123,8 +122,7 @@ struct skb_frame_desc { ...@@ -123,8 +122,7 @@ struct skb_frame_desc {
void *desc; void *desc;
__le32 iv; __le32 iv[2];
__le32 eiv;
dma_addr_t skb_dma; dma_addr_t skb_dma;
...@@ -168,8 +166,7 @@ enum rxdone_entry_desc_flags { ...@@ -168,8 +166,7 @@ enum rxdone_entry_desc_flags {
* @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags). * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
* @cipher: Cipher type used during decryption. * @cipher: Cipher type used during decryption.
* @cipher_status: Decryption status. * @cipher_status: Decryption status.
* @iv: IV data used during decryption. * @iv: IV/EIV data used during decryption.
* @eiv: EIV data used during decryption.
* @icv: ICV data used during decryption. * @icv: ICV data used during decryption.
*/ */
struct rxdone_entry_desc { struct rxdone_entry_desc {
...@@ -182,8 +179,7 @@ struct rxdone_entry_desc { ...@@ -182,8 +179,7 @@ struct rxdone_entry_desc {
u8 cipher; u8 cipher;
u8 cipher_status; u8 cipher_status;
__le32 iv; __le32 iv[2];
__le32 eiv;
__le32 icv; __le32 icv;
}; };
......
...@@ -1778,8 +1778,8 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev, ...@@ -1778,8 +1778,8 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
rt2x00_desc_write(txd, 2, word); rt2x00_desc_write(txd, 2, word);
if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
_rt2x00_desc_write(txd, 3, skbdesc->iv); _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
_rt2x00_desc_write(txd, 4, skbdesc->eiv); _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
} }
rt2x00_desc_read(txd, 5, &word); rt2x00_desc_read(txd, 5, &word);
...@@ -1949,8 +1949,8 @@ static void rt61pci_fill_rxdone(struct queue_entry *entry, ...@@ -1949,8 +1949,8 @@ static void rt61pci_fill_rxdone(struct queue_entry *entry,
} }
if (rxdesc->cipher != CIPHER_NONE) { if (rxdesc->cipher != CIPHER_NONE) {
_rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv); _rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv[0]);
_rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->eiv); _rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->iv[1]);
_rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv); _rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv);
/* /*
......
...@@ -1428,8 +1428,8 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev, ...@@ -1428,8 +1428,8 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
rt2x00_desc_write(txd, 2, word); rt2x00_desc_write(txd, 2, word);
if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
_rt2x00_desc_write(txd, 3, skbdesc->iv); _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
_rt2x00_desc_write(txd, 4, skbdesc->eiv); _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
} }
rt2x00_desc_read(txd, 5, &word); rt2x00_desc_read(txd, 5, &word);
...@@ -1618,8 +1618,8 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry, ...@@ -1618,8 +1618,8 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry,
} }
if (rxdesc->cipher != CIPHER_NONE) { if (rxdesc->cipher != CIPHER_NONE) {
_rt2x00_desc_read(rxd, 2, &rxdesc->iv); _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
_rt2x00_desc_read(rxd, 3, &rxdesc->eiv); _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
_rt2x00_desc_read(rxd, 4, &rxdesc->icv); _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
/* /*
......
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