FT: Avoid unnecessary allocation for MIC calculation

Use the vector version of omac1_aes_128() to avoid unnecessary memory
allocation for each FTIE MIC calculation.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-03-15 20:18:14 +02:00
parent 18da814be7
commit 8b949804b3

View file

@ -207,8 +207,10 @@ int wpa_ft_mic(const u8 *kck, size_t kck_len, const u8 *sta_addr,
const u8 *rsnie, size_t rsnie_len, const u8 *rsnie, size_t rsnie_len,
const u8 *ric, size_t ric_len, u8 *mic) const u8 *ric, size_t ric_len, u8 *mic)
{ {
u8 *buf, *pos; const u8 *addr[9];
size_t buf_len; size_t len[9];
size_t i, num_elem = 0;
u8 zero_mic[16];
if (kck_len != 16) { if (kck_len != 16) {
wpa_printf(MSG_WARNING, "FT: Unsupported KCK length %u", wpa_printf(MSG_WARNING, "FT: Unsupported KCK length %u",
@ -216,48 +218,58 @@ int wpa_ft_mic(const u8 *kck, size_t kck_len, const u8 *sta_addr,
return -1; return -1;
} }
buf_len = 2 * ETH_ALEN + 1 + mdie_len + ftie_len + rsnie_len + ric_len; addr[num_elem] = sta_addr;
buf = os_malloc(buf_len); len[num_elem] = ETH_ALEN;
if (buf == NULL) num_elem++;
return -1;
addr[num_elem] = ap_addr;
len[num_elem] = ETH_ALEN;
num_elem++;
addr[num_elem] = &transaction_seqnum;
len[num_elem] = 1;
num_elem++;
pos = buf;
os_memcpy(pos, sta_addr, ETH_ALEN);
pos += ETH_ALEN;
os_memcpy(pos, ap_addr, ETH_ALEN);
pos += ETH_ALEN;
*pos++ = transaction_seqnum;
if (rsnie) { if (rsnie) {
os_memcpy(pos, rsnie, rsnie_len); addr[num_elem] = rsnie;
pos += rsnie_len; len[num_elem] = rsnie_len;
num_elem++;
} }
if (mdie) { if (mdie) {
os_memcpy(pos, mdie, mdie_len); addr[num_elem] = mdie;
pos += mdie_len; len[num_elem] = mdie_len;
num_elem++;
} }
if (ftie) { if (ftie) {
struct rsn_ftie *_ftie; if (ftie_len < 2 + sizeof(struct rsn_ftie))
os_memcpy(pos, ftie, ftie_len);
if (ftie_len < 2 + sizeof(*_ftie)) {
os_free(buf);
return -1; return -1;
}
_ftie = (struct rsn_ftie *) (pos + 2); /* IE hdr and mic_control */
os_memset(_ftie->mic, 0, sizeof(_ftie->mic)); addr[num_elem] = ftie;
pos += ftie_len; len[num_elem] = 2 + 2;
num_elem++;
/* MIC field with all zeros */
os_memset(zero_mic, 0, sizeof(zero_mic));
addr[num_elem] = zero_mic;
len[num_elem] = sizeof(zero_mic);
num_elem++;
/* Rest of FTIE */
addr[num_elem] = ftie + 2 + 2 + 16;
len[num_elem] = ftie_len - (2 + 2 + 16);
num_elem++;
} }
if (ric) { if (ric) {
os_memcpy(pos, ric, ric_len); addr[num_elem] = ric;
pos += ric_len; len[num_elem] = ric_len;
num_elem++;
} }
wpa_hexdump(MSG_MSGDUMP, "FT: MIC data", buf, pos - buf); for (i = 0; i < num_elem; i++)
if (omac1_aes_128(kck, buf, pos - buf, mic)) { wpa_hexdump(MSG_MSGDUMP, "FT: MIC data", addr[i], len[i]);
os_free(buf); if (omac1_aes_128_vector(kck, num_elem, addr, len, mic))
return -1; return -1;
}
os_free(buf);
return 0; return 0;
} }