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>
This commit is contained in:
Chien Wong
2025-11-13 22:05:09 +08:00
committed by Johannes Berg
parent 4255545a28
commit edf62602fc
4 changed files with 25 additions and 25 deletions

View File

@@ -16,11 +16,9 @@
#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[],

View 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;

View 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[],

View 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,