ARM: shmobile: defconfig: Enable reset controller support
[linux/fpc-iii.git] / net / mac80211 / aes_cmac.c
blob2fb65588490c3ddbd7fe69b56ce0e7fb0a8f0312
1 /*
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.
8 */
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>
18 #include "key.h"
19 #include "aes_cmac.h"
21 #define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */
22 #define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */
23 #define AAD_LEN 20
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];
33 desc->tfm = tfm;
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);
48 desc->tfm = 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[],
57 size_t key_len)
59 struct crypto_shash *tfm;
61 tfm = crypto_alloc_shash("cmac(aes)", 0, 0);
62 if (!IS_ERR(tfm))
63 crypto_shash_setkey(tfm, key, key_len);
65 return tfm;
68 void ieee80211_aes_cmac_key_free(struct crypto_shash *tfm)
70 crypto_free_shash(tfm);