]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mac80211: utilize the newly defined CMAC constants
authorChien Wong <m@xv97.com>
Thu, 13 Nov 2025 14:05:09 +0000 (22:05 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Thu, 20 Nov 2025 10:56:19 +0000 (11:56 +0100)
Make use of the added constants to reduce duplication.

Signed-off-by: Chien Wong <m@xv97.com>
Link: https://patch.msgid.link/20251113140511.48658-4-m@xv97.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/aes_cmac.c
net/mac80211/aes_gmac.c
net/mac80211/aes_gmac.h
net/mac80211/wpa.c

index 65989c7dfc680905506fa49bf20bc57e719b0ecb..672ed80ee4ff26cca0d2af4e78e764d6bd39c362 100644 (file)
 #include "key.h"
 #include "aes_cmac.h"
 
-#define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */
-#define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */
 #define AAD_LEN 20
 
-static const u8 zero[CMAC_TLEN_256];
+static const u8 zero[IEEE80211_CMAC_256_MIC_LEN];
 
 int ieee80211_aes_cmac(struct crypto_shash *tfm, const u8 *aad,
                       const u8 *data, size_t data_len, u8 *mic)
@@ -44,20 +42,20 @@ int ieee80211_aes_cmac(struct crypto_shash *tfm, const u8 *aad,
                err = crypto_shash_update(desc, zero, 8);
                if (err)
                        return err;
-               err = crypto_shash_update(desc, data + 8,
-                                         data_len - 8 - CMAC_TLEN);
+               err = crypto_shash_update(desc, data + 8, data_len - 8 -
+                                         IEEE80211_CMAC_128_MIC_LEN);
                if (err)
                        return err;
        } else {
-               err = crypto_shash_update(desc, data,
-                                         data_len - CMAC_TLEN);
+               err = crypto_shash_update(desc, data, data_len -
+                                         IEEE80211_CMAC_128_MIC_LEN);
                if (err)
                        return err;
        }
-       err = crypto_shash_finup(desc, zero, CMAC_TLEN, out);
+       err = crypto_shash_finup(desc, zero, IEEE80211_CMAC_128_MIC_LEN, out);
        if (err)
                return err;
-       memcpy(mic, out, CMAC_TLEN);
+       memcpy(mic, out, IEEE80211_CMAC_128_MIC_LEN);
 
        return 0;
 }
@@ -83,16 +81,17 @@ int ieee80211_aes_cmac_256(struct crypto_shash *tfm, const u8 *aad,
                err = crypto_shash_update(desc, zero, 8);
                if (err)
                        return err;
-               err = crypto_shash_update(desc, data + 8,
-                                         data_len - 8 - CMAC_TLEN_256);
+               err = crypto_shash_update(desc, data + 8, data_len - 8 -
+                                         IEEE80211_CMAC_256_MIC_LEN);
                if (err)
                        return err;
        } else {
-               err = crypto_shash_update(desc, data, data_len - CMAC_TLEN_256);
+               err = crypto_shash_update(desc, data, data_len -
+                                         IEEE80211_CMAC_256_MIC_LEN);
                if (err)
                        return err;
        }
-       return crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic);
+       return crypto_shash_finup(desc, zero, IEEE80211_CMAC_256_MIC_LEN, mic);
 }
 
 struct crypto_shash *ieee80211_aes_cmac_key_setup(const u8 key[],
index 512cab073f2e8ed9ff7bbf5c0d339e5240c77770..811a83d8d5259a83dc4498e0180c2436b5e3639c 100644 (file)
@@ -24,15 +24,16 @@ int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
        const __le16 *fc;
        int ret;
 
-       if (data_len < GMAC_MIC_LEN)
+       if (data_len < IEEE80211_GMAC_MIC_LEN)
                return -EINVAL;
 
-       aead_req = kzalloc(reqsize + GMAC_MIC_LEN + GMAC_AAD_LEN, GFP_ATOMIC);
+       aead_req = kzalloc(reqsize + IEEE80211_GMAC_MIC_LEN + GMAC_AAD_LEN,
+                          GFP_ATOMIC);
        if (!aead_req)
                return -ENOMEM;
 
        zero = (u8 *)aead_req + reqsize;
-       __aad = zero + GMAC_MIC_LEN;
+       __aad = zero + IEEE80211_GMAC_MIC_LEN;
        memcpy(__aad, aad, GMAC_AAD_LEN);
 
        fc = (const __le16 *)aad;
@@ -41,15 +42,16 @@ int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
                sg_init_table(sg, 5);
                sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN);
                sg_set_buf(&sg[1], zero, 8);
-               sg_set_buf(&sg[2], data + 8, data_len - 8 - GMAC_MIC_LEN);
-               sg_set_buf(&sg[3], zero, GMAC_MIC_LEN);
-               sg_set_buf(&sg[4], mic, GMAC_MIC_LEN);
+               sg_set_buf(&sg[2], data + 8,
+                          data_len - 8 - IEEE80211_GMAC_MIC_LEN);
+               sg_set_buf(&sg[3], zero, IEEE80211_GMAC_MIC_LEN);
+               sg_set_buf(&sg[4], mic, IEEE80211_GMAC_MIC_LEN);
        } else {
                sg_init_table(sg, 4);
                sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN);
-               sg_set_buf(&sg[1], data, data_len - GMAC_MIC_LEN);
-               sg_set_buf(&sg[2], zero, GMAC_MIC_LEN);
-               sg_set_buf(&sg[3], mic, GMAC_MIC_LEN);
+               sg_set_buf(&sg[1], data, data_len - IEEE80211_GMAC_MIC_LEN);
+               sg_set_buf(&sg[2], zero, IEEE80211_GMAC_MIC_LEN);
+               sg_set_buf(&sg[3], mic, IEEE80211_GMAC_MIC_LEN);
        }
 
        memcpy(iv, nonce, GMAC_NONCE_LEN);
@@ -78,7 +80,7 @@ struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
 
        err = crypto_aead_setkey(tfm, key, key_len);
        if (!err)
-               err = crypto_aead_setauthsize(tfm, GMAC_MIC_LEN);
+               err = crypto_aead_setauthsize(tfm, IEEE80211_GMAC_MIC_LEN);
        if (!err)
                return tfm;
 
index c739356bae2ad7627683908b7b04858c9334d5df..206136b60bca0f191c5fbfa7bd43324857ae68c6 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/crypto.h>
 
 #define GMAC_AAD_LEN   20
-#define GMAC_MIC_LEN   16
 #define GMAC_NONCE_LEN 12
 
 struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
index bb0fa505cdcaeeca1d1aa846b3eeb560721007f3..3d5efd8c6e2da0f84b26ab5544188ef3b0d9cfac 100644 (file)
@@ -1117,7 +1117,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct ieee80211_rx_data *rx)
                memcpy(nonce, hdr->addr2, ETH_ALEN);
                memcpy(nonce + ETH_ALEN, ipn, 6);
 
-               mic = kmalloc(GMAC_MIC_LEN, GFP_ATOMIC);
+               mic = kmalloc(IEEE80211_GMAC_MIC_LEN, GFP_ATOMIC);
                if (!mic)
                        return RX_DROP_U_OOM;
                if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce,