Merge tag 'v5.3-rc4' into next
[linux/fpc-iii.git] / net / mac80211 / aes_cmac.c
blob57748cab0e2886bcd4560d59a21584889484f557
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * AES-128-CMAC with TLen 16 for IEEE 802.11w BIP
4 * Copyright 2008, Jouni Malinen <j@w1.fi>
5 */
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/crypto.h>
10 #include <linux/export.h>
11 #include <linux/err.h>
12 #include <crypto/aes.h>
14 #include <net/mac80211.h>
15 #include "key.h"
16 #include "aes_cmac.h"
18 #define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */
19 #define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */
20 #define AAD_LEN 20
22 static const u8 zero[CMAC_TLEN_256];
24 void ieee80211_aes_cmac(struct crypto_shash *tfm, const u8 *aad,
25 const u8 *data, size_t data_len, u8 *mic)
27 SHASH_DESC_ON_STACK(desc, tfm);
28 u8 out[AES_BLOCK_SIZE];
30 desc->tfm = tfm;
32 crypto_shash_init(desc);
33 crypto_shash_update(desc, aad, AAD_LEN);
34 crypto_shash_update(desc, data, data_len - CMAC_TLEN);
35 crypto_shash_finup(desc, zero, CMAC_TLEN, out);
37 memcpy(mic, out, CMAC_TLEN);
40 void ieee80211_aes_cmac_256(struct crypto_shash *tfm, const u8 *aad,
41 const u8 *data, size_t data_len, u8 *mic)
43 SHASH_DESC_ON_STACK(desc, tfm);
45 desc->tfm = tfm;
47 crypto_shash_init(desc);
48 crypto_shash_update(desc, aad, AAD_LEN);
49 crypto_shash_update(desc, data, data_len - CMAC_TLEN_256);
50 crypto_shash_finup(desc, zero, CMAC_TLEN_256, mic);
53 struct crypto_shash *ieee80211_aes_cmac_key_setup(const u8 key[],
54 size_t key_len)
56 struct crypto_shash *tfm;
58 tfm = crypto_alloc_shash("cmac(aes)", 0, 0);
59 if (!IS_ERR(tfm))
60 crypto_shash_setkey(tfm, key, key_len);
62 return tfm;
65 void ieee80211_aes_cmac_key_free(struct crypto_shash *tfm)
67 crypto_free_shash(tfm);