Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: mac80211: utilize the newly defined CMAC constants

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>

authored by

Chien Wong and committed by
Johannes Berg
edf62602 4255545a

+25 -25
+12 -13
net/mac80211/aes_cmac.c
··· 16 16 #include "key.h" 17 17 #include "aes_cmac.h" 18 18 19 - #define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */ 20 - #define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */ 21 19 #define AAD_LEN 20 22 20 23 - static const u8 zero[CMAC_TLEN_256]; 21 + static const u8 zero[IEEE80211_CMAC_256_MIC_LEN]; 24 22 25 23 int ieee80211_aes_cmac(struct crypto_shash *tfm, const u8 *aad, 26 24 const u8 *data, size_t data_len, u8 *mic) ··· 42 44 err = crypto_shash_update(desc, zero, 8); 43 45 if (err) 44 46 return err; 45 - err = crypto_shash_update(desc, data + 8, 46 - data_len - 8 - CMAC_TLEN); 47 + err = crypto_shash_update(desc, data + 8, data_len - 8 - 48 + IEEE80211_CMAC_128_MIC_LEN); 47 49 if (err) 48 50 return err; 49 51 } else { 50 - err = crypto_shash_update(desc, data, 51 - data_len - CMAC_TLEN); 52 + err = crypto_shash_update(desc, data, data_len - 53 + IEEE80211_CMAC_128_MIC_LEN); 52 54 if (err) 53 55 return err; 54 56 } 55 - err = crypto_shash_finup(desc, zero, CMAC_TLEN, out); 57 + err = crypto_shash_finup(desc, zero, IEEE80211_CMAC_128_MIC_LEN, out); 56 58 if (err) 57 59 return err; 58 - memcpy(mic, out, CMAC_TLEN); 60 + memcpy(mic, out, IEEE80211_CMAC_128_MIC_LEN); 59 61 60 62 return 0; 61 63 } ··· 81 83 err = crypto_shash_update(desc, zero, 8); 82 84 if (err) 83 85 return err; 84 - err = crypto_shash_update(desc, data + 8, 85 - data_len - 8 - CMAC_TLEN_256); 86 + err = crypto_shash_update(desc, data + 8, data_len - 8 - 87 + IEEE80211_CMAC_256_MIC_LEN); 86 88 if (err) 87 89 return err; 88 90 } else { 89 - err = crypto_shash_update(desc, data, data_len - CMAC_TLEN_256); 91 + err = crypto_shash_update(desc, data, data_len - 92 + IEEE80211_CMAC_256_MIC_LEN); 90 93 if (err) 91 94 return err; 92 95 } 93 - return crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic); 96 + return crypto_shash_finup(desc, zero, IEEE80211_CMAC_256_MIC_LEN, mic); 94 97 } 95 98 96 99 struct crypto_shash *ieee80211_aes_cmac_key_setup(const u8 key[],
+12 -10
net/mac80211/aes_gmac.c
··· 24 24 const __le16 *fc; 25 25 int ret; 26 26 27 - if (data_len < GMAC_MIC_LEN) 27 + if (data_len < IEEE80211_GMAC_MIC_LEN) 28 28 return -EINVAL; 29 29 30 - aead_req = kzalloc(reqsize + GMAC_MIC_LEN + GMAC_AAD_LEN, GFP_ATOMIC); 30 + aead_req = kzalloc(reqsize + IEEE80211_GMAC_MIC_LEN + GMAC_AAD_LEN, 31 + GFP_ATOMIC); 31 32 if (!aead_req) 32 33 return -ENOMEM; 33 34 34 35 zero = (u8 *)aead_req + reqsize; 35 - __aad = zero + GMAC_MIC_LEN; 36 + __aad = zero + IEEE80211_GMAC_MIC_LEN; 36 37 memcpy(__aad, aad, GMAC_AAD_LEN); 37 38 38 39 fc = (const __le16 *)aad; ··· 42 41 sg_init_table(sg, 5); 43 42 sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN); 44 43 sg_set_buf(&sg[1], zero, 8); 45 - sg_set_buf(&sg[2], data + 8, data_len - 8 - GMAC_MIC_LEN); 46 - sg_set_buf(&sg[3], zero, GMAC_MIC_LEN); 47 - sg_set_buf(&sg[4], mic, GMAC_MIC_LEN); 44 + sg_set_buf(&sg[2], data + 8, 45 + data_len - 8 - IEEE80211_GMAC_MIC_LEN); 46 + sg_set_buf(&sg[3], zero, IEEE80211_GMAC_MIC_LEN); 47 + sg_set_buf(&sg[4], mic, IEEE80211_GMAC_MIC_LEN); 48 48 } else { 49 49 sg_init_table(sg, 4); 50 50 sg_set_buf(&sg[0], __aad, GMAC_AAD_LEN); 51 - sg_set_buf(&sg[1], data, data_len - GMAC_MIC_LEN); 52 - sg_set_buf(&sg[2], zero, GMAC_MIC_LEN); 53 - sg_set_buf(&sg[3], mic, GMAC_MIC_LEN); 51 + sg_set_buf(&sg[1], data, data_len - IEEE80211_GMAC_MIC_LEN); 52 + sg_set_buf(&sg[2], zero, IEEE80211_GMAC_MIC_LEN); 53 + sg_set_buf(&sg[3], mic, IEEE80211_GMAC_MIC_LEN); 54 54 } 55 55 56 56 memcpy(iv, nonce, GMAC_NONCE_LEN); ··· 80 78 81 79 err = crypto_aead_setkey(tfm, key, key_len); 82 80 if (!err) 83 - err = crypto_aead_setauthsize(tfm, GMAC_MIC_LEN); 81 + err = crypto_aead_setauthsize(tfm, IEEE80211_GMAC_MIC_LEN); 84 82 if (!err) 85 83 return tfm; 86 84
-1
net/mac80211/aes_gmac.h
··· 9 9 #include <linux/crypto.h> 10 10 11 11 #define GMAC_AAD_LEN 20 12 - #define GMAC_MIC_LEN 16 13 12 #define GMAC_NONCE_LEN 12 14 13 15 14 struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
+1 -1
net/mac80211/wpa.c
··· 1117 1117 memcpy(nonce, hdr->addr2, ETH_ALEN); 1118 1118 memcpy(nonce + ETH_ALEN, ipn, 6); 1119 1119 1120 - mic = kmalloc(GMAC_MIC_LEN, GFP_ATOMIC); 1120 + mic = kmalloc(IEEE80211_GMAC_MIC_LEN, GFP_ATOMIC); 1121 1121 if (!mic) 1122 1122 return RX_DROP_U_OOM; 1123 1123 if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce,