#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)
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;
}
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[],
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;
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);
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;
#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[],
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,