GNU Linux-libre 4.19.314-gnu1
[releases.git] / net / mac80211 / aes_gcm.h
1 /*
2  * Copyright 2014-2015, Qualcomm Atheros, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #ifndef AES_GCM_H
10 #define AES_GCM_H
11
12 #include "aead_api.h"
13
14 #define GCM_AAD_LEN     32
15
16 static inline int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm,
17                                             u8 *j_0, u8 *aad,  u8 *data,
18                                             size_t data_len, u8 *mic)
19 {
20         return aead_encrypt(tfm, j_0, aad + 2,
21                             be16_to_cpup((__be16 *)aad),
22                             data, data_len, mic);
23 }
24
25 static inline int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm,
26                                             u8 *j_0, u8 *aad, u8 *data,
27                                             size_t data_len, u8 *mic)
28 {
29         return aead_decrypt(tfm, j_0, aad + 2,
30                             be16_to_cpup((__be16 *)aad),
31                             data, data_len, mic);
32 }
33
34 static inline struct crypto_aead *
35 ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
36 {
37         return aead_key_setup_encrypt("gcm(aes)", key,
38                                       key_len, IEEE80211_GCMP_MIC_LEN);
39 }
40
41 static inline void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
42 {
43         return aead_key_free(tfm);
44 }
45
46 #endif /* AES_GCM_H */