| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AES-128-CMAC with TLen 16 for IEEE 802.11w BIP |
|---|
| 3 | 4 | * Copyright 2008, Jouni Malinen <j@w1.fi> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | 5 | */ |
|---|
| 9 | 6 | |
|---|
| 10 | 7 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 29 | 26 | { |
|---|
| 30 | 27 | SHASH_DESC_ON_STACK(desc, tfm); |
|---|
| 31 | 28 | u8 out[AES_BLOCK_SIZE]; |
|---|
| 29 | + const __le16 *fc; |
|---|
| 32 | 30 | |
|---|
| 33 | 31 | desc->tfm = tfm; |
|---|
| 34 | 32 | |
|---|
| 35 | 33 | crypto_shash_init(desc); |
|---|
| 36 | 34 | crypto_shash_update(desc, aad, AAD_LEN); |
|---|
| 37 | | - crypto_shash_update(desc, data, data_len - CMAC_TLEN); |
|---|
| 35 | + fc = (const __le16 *)aad; |
|---|
| 36 | + if (ieee80211_is_beacon(*fc)) { |
|---|
| 37 | + /* mask Timestamp field to zero */ |
|---|
| 38 | + crypto_shash_update(desc, zero, 8); |
|---|
| 39 | + crypto_shash_update(desc, data + 8, data_len - 8 - CMAC_TLEN); |
|---|
| 40 | + } else { |
|---|
| 41 | + crypto_shash_update(desc, data, data_len - CMAC_TLEN); |
|---|
| 42 | + } |
|---|
| 38 | 43 | crypto_shash_finup(desc, zero, CMAC_TLEN, out); |
|---|
| 39 | 44 | |
|---|
| 40 | 45 | memcpy(mic, out, CMAC_TLEN); |
|---|
| .. | .. |
|---|
| 44 | 49 | const u8 *data, size_t data_len, u8 *mic) |
|---|
| 45 | 50 | { |
|---|
| 46 | 51 | SHASH_DESC_ON_STACK(desc, tfm); |
|---|
| 52 | + const __le16 *fc; |
|---|
| 47 | 53 | |
|---|
| 48 | 54 | desc->tfm = tfm; |
|---|
| 49 | 55 | |
|---|
| 50 | 56 | crypto_shash_init(desc); |
|---|
| 51 | 57 | crypto_shash_update(desc, aad, AAD_LEN); |
|---|
| 52 | | - crypto_shash_update(desc, data, data_len - CMAC_TLEN_256); |
|---|
| 58 | + fc = (const __le16 *)aad; |
|---|
| 59 | + if (ieee80211_is_beacon(*fc)) { |
|---|
| 60 | + /* mask Timestamp field to zero */ |
|---|
| 61 | + crypto_shash_update(desc, zero, 8); |
|---|
| 62 | + crypto_shash_update(desc, data + 8, |
|---|
| 63 | + data_len - 8 - CMAC_TLEN_256); |
|---|
| 64 | + } else { |
|---|
| 65 | + crypto_shash_update(desc, data, data_len - CMAC_TLEN_256); |
|---|
| 66 | + } |
|---|
| 53 | 67 | crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic); |
|---|
| 54 | 68 | } |
|---|
| 55 | 69 | |
|---|