mac80211: update to wireless-testing 2017-10-06
[openwrt/staging/dedeckeh.git] / package / kernel / mac80211 / patches / 100-remove-cryptoapi-dependencies.patch
index 95fea441a4f2d3dffc7ea08d9ce03412d08e352b..0febc57b3f3bea37a06e299d725523b3fd478856 100644 (file)
@@ -6,9 +6,9 @@
        depends on CRYPTO_AES
 -      select BPAUTO_CRYPTO_CCM
 -      depends on CRYPTO_GCM
+       depends on CRYPTO_CMAC
        depends on CRC32
        ---help---
-         This option enables the hardware independent IEEE 802.11
 --- a/net/mac80211/Makefile
 +++ b/net/mac80211/Makefile
 @@ -16,9 +16,7 @@ mac80211-y := \
 -      struct aead_request *aead_req;
 -      int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
 -      u8 *__aad;
--
++      int i;
 -      aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
 -      if (!aead_req)
 -              return -ENOMEM;
--
++      crypto_cipher_encrypt_one(tfm, b, b_0);
 -      __aad = (u8 *)aead_req + reqsize;
 -      memcpy(__aad, aad, CCM_AAD_LEN);
--
++      /* Extra Authenticate-only data (always two AES blocks) */
++      for (i = 0; i < AES_BLOCK_SIZE; i++)
++              aad[i] ^= b[i];
++      crypto_cipher_encrypt_one(tfm, b, aad);
 -      sg_init_table(sg, 3);
 -      sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
 -      sg_set_buf(&sg[1], data, data_len);
 -      sg_set_buf(&sg[2], mic, mic_len);
--
++      aad += AES_BLOCK_SIZE;
 -      aead_request_set_tfm(aead_req, tfm);
 -      aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
 -      aead_request_set_ad(aead_req, sg[0].length);
-+      int i;
--      crypto_aead_encrypt(aead_req);
--      kzfree(aead_req);
-+      crypto_cipher_encrypt_one(tfm, b, b_0);
--      return 0;
-+      /* Extra Authenticate-only data (always two AES blocks) */
-+      for (i = 0; i < AES_BLOCK_SIZE; i++)
-+              aad[i] ^= b[i];
-+      crypto_cipher_encrypt_one(tfm, b, aad);
-+
-+      aad += AES_BLOCK_SIZE;
-+
 +      for (i = 0; i < AES_BLOCK_SIZE; i++)
 +              aad[i] ^= b[i];
 +      crypto_cipher_encrypt_one(tfm, a, aad);
-+
+-      crypto_aead_encrypt(aead_req);
+-      kzfree(aead_req);
 +      /* Mask out bits from auth-only-b_0 */
 +      b_0[0] &= 0x07;
-+
+-      return 0;
 +      /* S_0 is used to encrypt T (= MIC) */
 +      b_0[14] = 0;
 +      b_0[15] = 0;
 +      crypto_cipher_encrypt_one(tfm, s_0, b_0);
-+}
-+
+ }
+-int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
+-                            u8 *data, size_t data_len, u8 *mic,
+-                            size_t mic_len)
 +
 +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
 +                             u8 *data, size_t data_len, u8 *mic,
 +                             size_t mic_len)
-+{
+ {
+-      struct scatterlist sg[3];
+-      struct aead_request *aead_req;
+-      int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
+-      u8 *__aad;
+-      int err;
 +      int i, j, last_len, num_blocks;
 +      u8 b[AES_BLOCK_SIZE];
 +      u8 s_0[AES_BLOCK_SIZE];
 +      u8 e[AES_BLOCK_SIZE];
 +      u8 *pos, *cpos;
-+
+-      if (data_len == 0)
+-              return -EINVAL;
 +      num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
 +      last_len = data_len % AES_BLOCK_SIZE;
 +      aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
-+
+-      aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
+-      if (!aead_req)
+-              return -ENOMEM;
 +      /* Process payload blocks */
 +      pos = data;
 +      cpos = data;
 +      for (j = 1; j <= num_blocks; j++) {
 +              int blen = (j == num_blocks && last_len) ?
 +                      last_len : AES_BLOCK_SIZE;
-+
+-      __aad = (u8 *)aead_req + reqsize;
+-      memcpy(__aad, aad, CCM_AAD_LEN);
 +              /* Authentication followed by encryption */
 +              for (i = 0; i < blen; i++)
 +                      b[i] ^= pos[i];
 +              crypto_cipher_encrypt_one(tfm, b, b);
-+
+-      sg_init_table(sg, 3);
+-      sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
+-      sg_set_buf(&sg[1], data, data_len);
+-      sg_set_buf(&sg[2], mic, mic_len);
 +              b_0[14] = (j >> 8) & 0xff;
 +              b_0[15] = j & 0xff;
 +              crypto_cipher_encrypt_one(tfm, e, b_0);
 +              for (i = 0; i < blen; i++)
 +                      *cpos++ = *pos++ ^ e[i];
 +      }
-+
-+      for (i = 0; i < mic_len; i++)
-+              mic[i] = b[i] ^ s_0[i];
- }
  
--int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
-+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
-                             u8 *data, size_t data_len, u8 *mic,
-                             size_t mic_len)
- {
--      struct scatterlist sg[3];
--      struct aead_request *aead_req;
--      int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
--      u8 *__aad;
--      int err;
--
--      if (data_len == 0)
--              return -EINVAL;
--
--      aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
--      if (!aead_req)
--              return -ENOMEM;
--
--      __aad = (u8 *)aead_req + reqsize;
--      memcpy(__aad, aad, CCM_AAD_LEN);
--
--      sg_init_table(sg, 3);
--      sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
--      sg_set_buf(&sg[1], data, data_len);
--      sg_set_buf(&sg[2], mic, mic_len);
--
 -      aead_request_set_tfm(aead_req, tfm);
 -      aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
 -      aead_request_set_ad(aead_req, sg[0].length);
++      for (i = 0; i < mic_len; i++)
++              mic[i] = b[i] ^ s_0[i];
++}
+-      err = crypto_aead_decrypt(aead_req);
+-      kzfree(aead_req);
++int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
++                            u8 *data, size_t data_len, u8 *mic,
++                            size_t mic_len)
++{
 +      int i, j, last_len, num_blocks;
 +      u8 *pos, *cpos;
 +      u8 a[AES_BLOCK_SIZE];
 +      u8 b[AES_BLOCK_SIZE];
 +      u8 s_0[AES_BLOCK_SIZE];
-+
+-      return err;
 +      num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
 +      last_len = data_len % AES_BLOCK_SIZE;
 +      aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
 +              if ((mic[i] ^ s_0[i]) != a[i])
 +                      return -1;
 +      }
--      err = crypto_aead_decrypt(aead_req);
--      kzfree(aead_req);
--
--      return err;
++
 +      return 0;
  }
  
  {
 -      struct crypto_aead *tfm;
 -      int err;
-+      struct crypto_cipher *tfm;
+-
 -      tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
 -      if (IS_ERR(tfm))
 -              return tfm;
--
++      struct crypto_cipher *tfm;
 -      err = crypto_aead_setkey(tfm, key, key_len);
 -      if (err)
 -              goto free_aead;
                struct {
 --- a/net/mac80211/wpa.c
 +++ b/net/mac80211/wpa.c
-@@ -305,7 +305,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
+@@ -306,7 +306,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
  }
  
  
  {
        __le16 mask_fc;
        int a4_included, mgmt;
-@@ -335,14 +336,8 @@ static void ccmp_special_blocks(struct s
+@@ -336,14 +337,8 @@ static void ccmp_special_blocks(struct s
        else
                qos_tid = 0;
  
  
        /* Nonce: Nonce Flags | A2 | PN
         * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
-@@ -350,6 +345,8 @@ static void ccmp_special_blocks(struct s
+@@ -351,6 +346,8 @@ static void ccmp_special_blocks(struct s
        b_0[1] = qos_tid | (mgmt << 4);
        memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
        memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
  
        /* AAD (extra authenticate-only data) / masked 802.11 header
         * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
-@@ -406,7 +403,7 @@ static int ccmp_encrypt_skb(struct ieee8
+@@ -407,7 +404,7 @@ static int ccmp_encrypt_skb(struct ieee8
        u8 *pos;
        u8 pn[6];
        u64 pn64;
        u8 b_0[AES_BLOCK_SIZE];
  
        if (info->control.hw_key &&
-@@ -461,9 +458,11 @@ static int ccmp_encrypt_skb(struct ieee8
+@@ -462,9 +459,11 @@ static int ccmp_encrypt_skb(struct ieee8
                return 0;
  
        pos += IEEE80211_CCMP_HDR_LEN;
  }
  
  
-@@ -536,7 +535,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
+@@ -537,7 +536,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
                        u8 aad[2 * AES_BLOCK_SIZE];
                        u8 b_0[AES_BLOCK_SIZE];
                        /* hardware didn't decrypt/verify MIC */
  
                        if (ieee80211_aes_ccm_decrypt(
                                    key->u.ccmp.tfm, b_0, aad,
-@@ -638,7 +637,7 @@ static int gcmp_encrypt_skb(struct ieee8
+@@ -639,7 +638,7 @@ static int gcmp_encrypt_skb(struct ieee8
        u8 *pos;
        u8 pn[6];
        u64 pn64;
        u8 j_0[AES_BLOCK_SIZE];
  
        if (info->control.hw_key &&
-@@ -695,8 +694,10 @@ static int gcmp_encrypt_skb(struct ieee8
+@@ -696,8 +695,10 @@ static int gcmp_encrypt_skb(struct ieee8
  
        pos += IEEE80211_GCMP_HDR_LEN;
        gcmp_special_blocks(skb, pn, j_0, aad);
  }
  
  ieee80211_tx_result
-@@ -1120,9 +1121,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
+@@ -1121,9 +1122,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
        struct ieee80211_key *key = tx->key;
        struct ieee80211_mmie_16 *mmie;
        struct ieee80211_hdr *hdr;
  
        if (WARN_ON(skb_queue_len(&tx->skbs) != 1))
                return TX_DROP;
-@@ -1168,7 +1169,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
+@@ -1169,7 +1170,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
        struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
        struct ieee80211_key *key = rx->key;
        struct ieee80211_mmie_16 *mmie;