Blame view
net/mac80211/aes_cmac.c
1.59 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
765cb46a3 mac80211: 802.11w... |
2 3 4 |
/* * AES-128-CMAC with TLen 16 for IEEE 802.11w BIP * Copyright 2008, Jouni Malinen <j@w1.fi> |
765cb46a3 mac80211: 802.11w... |
5 6 7 8 9 |
*/ #include <linux/kernel.h> #include <linux/types.h> #include <linux/crypto.h> |
4afebd636 mac80211: include... |
10 |
#include <linux/export.h> |
765cb46a3 mac80211: 802.11w... |
11 |
#include <linux/err.h> |
0cd20a278 mac80211: use AES... |
12 |
#include <crypto/aes.h> |
765cb46a3 mac80211: 802.11w... |
13 14 15 16 |
#include <net/mac80211.h> #include "key.h" #include "aes_cmac.h" |
765cb46a3 mac80211: 802.11w... |
17 |
#define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */ |
56c52da2d mac80111: Add BIP... |
18 |
#define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */ |
765cb46a3 mac80211: 802.11w... |
19 |
#define AAD_LEN 20 |
26717828b mac80211: aes-cma... |
20 |
static const u8 zero[CMAC_TLEN_256]; |
765cb46a3 mac80211: 802.11w... |
21 |
|
26717828b mac80211: aes-cma... |
22 |
void ieee80211_aes_cmac(struct crypto_shash *tfm, const u8 *aad, |
765cb46a3 mac80211: 802.11w... |
23 24 |
const u8 *data, size_t data_len, u8 *mic) { |
26717828b mac80211: aes-cma... |
25 26 |
SHASH_DESC_ON_STACK(desc, tfm); u8 out[AES_BLOCK_SIZE]; |
765cb46a3 mac80211: 802.11w... |
27 |
|
26717828b mac80211: aes-cma... |
28 |
desc->tfm = tfm; |
765cb46a3 mac80211: 802.11w... |
29 |
|
26717828b mac80211: aes-cma... |
30 31 32 33 34 35 |
crypto_shash_init(desc); crypto_shash_update(desc, aad, AAD_LEN); crypto_shash_update(desc, data, data_len - CMAC_TLEN); crypto_shash_finup(desc, zero, CMAC_TLEN, out); memcpy(mic, out, CMAC_TLEN); |
765cb46a3 mac80211: 802.11w... |
36 |
} |
26717828b mac80211: aes-cma... |
37 |
void ieee80211_aes_cmac_256(struct crypto_shash *tfm, const u8 *aad, |
56c52da2d mac80111: Add BIP... |
38 39 |
const u8 *data, size_t data_len, u8 *mic) { |
26717828b mac80211: aes-cma... |
40 |
SHASH_DESC_ON_STACK(desc, tfm); |
56c52da2d mac80111: Add BIP... |
41 |
|
26717828b mac80211: aes-cma... |
42 |
desc->tfm = tfm; |
56c52da2d mac80111: Add BIP... |
43 |
|
26717828b mac80211: aes-cma... |
44 45 46 47 |
crypto_shash_init(desc); crypto_shash_update(desc, aad, AAD_LEN); crypto_shash_update(desc, data, data_len - CMAC_TLEN_256); crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic); |
56c52da2d mac80111: Add BIP... |
48 |
} |
765cb46a3 mac80211: 802.11w... |
49 |
|
26717828b mac80211: aes-cma... |
50 51 |
struct crypto_shash *ieee80211_aes_cmac_key_setup(const u8 key[], size_t key_len) |
765cb46a3 mac80211: 802.11w... |
52 |
{ |
26717828b mac80211: aes-cma... |
53 |
struct crypto_shash *tfm; |
765cb46a3 mac80211: 802.11w... |
54 |
|
26717828b mac80211: aes-cma... |
55 |
tfm = crypto_alloc_shash("cmac(aes)", 0, 0); |
1ac62ba7c mac80211: Don't s... |
56 |
if (!IS_ERR(tfm)) |
26717828b mac80211: aes-cma... |
57 |
crypto_shash_setkey(tfm, key, key_len); |
765cb46a3 mac80211: 802.11w... |
58 59 60 |
return tfm; } |
26717828b mac80211: aes-cma... |
61 |
void ieee80211_aes_cmac_key_free(struct crypto_shash *tfm) |
765cb46a3 mac80211: 802.11w... |
62 |
{ |
26717828b mac80211: aes-cma... |
63 |
crypto_free_shash(tfm); |
765cb46a3 mac80211: 802.11w... |
64 |
} |