2 * AES-128-CMAC with TLen 16 for IEEE 802.11w BIP
3 * Copyright 2008, Jouni Malinen <j@w1.fi>
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.
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/crypto.h>
13 #include <linux/export.h>
14 #include <linux/err.h>
15 #include <crypto/aes.h>
17 #include <net/mac80211.h>
21 #define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */
22 #define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */
25 static const u8 zero
[CMAC_TLEN_256
];
27 void ieee80211_aes_cmac(struct crypto_shash
*tfm
, const u8
*aad
,
28 const u8
*data
, size_t data_len
, u8
*mic
)
30 SHASH_DESC_ON_STACK(desc
, tfm
);
31 u8 out
[AES_BLOCK_SIZE
];
35 crypto_shash_init(desc
);
36 crypto_shash_update(desc
, aad
, AAD_LEN
);
37 crypto_shash_update(desc
, data
, data_len
- CMAC_TLEN
);
38 crypto_shash_finup(desc
, zero
, CMAC_TLEN
, out
);
40 memcpy(mic
, out
, CMAC_TLEN
);
43 void ieee80211_aes_cmac_256(struct crypto_shash
*tfm
, const u8
*aad
,
44 const u8
*data
, size_t data_len
, u8
*mic
)
46 SHASH_DESC_ON_STACK(desc
, tfm
);
50 crypto_shash_init(desc
);
51 crypto_shash_update(desc
, aad
, AAD_LEN
);
52 crypto_shash_update(desc
, data
, data_len
- CMAC_TLEN_256
);
53 crypto_shash_finup(desc
, zero
, CMAC_TLEN_256
, mic
);
56 struct crypto_shash
*ieee80211_aes_cmac_key_setup(const u8 key
[],
59 struct crypto_shash
*tfm
;
61 tfm
= crypto_alloc_shash("cmac(aes)", 0, 0);
63 crypto_shash_setkey(tfm
, key
, key_len
);
68 void ieee80211_aes_cmac_key_free(struct crypto_shash
*tfm
)
70 crypto_free_shash(tfm
);