blob: d2b09603300922ac9d199a2045e93ed8a3082960 [file] [log] [blame]
Jouni Malinen00b9cfa2015-01-24 19:52:06 +02001/*
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
Xiang Gao4133da72017-10-10 22:31:49 -040012#include "aead_api.h"
Jouni Malinen00b9cfa2015-01-24 19:52:06 +020013
Ard Biesheuvelf4a067f2016-10-17 15:05:33 +010014#define GCM_AAD_LEN 32
15
Xiang Gao4133da72017-10-10 22:31:49 -040016static 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
25static 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
34static inline struct crypto_aead *
35ieee80211_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
41static inline void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
42{
43 return aead_key_free(tfm);
44}
Jouni Malinen00b9cfa2015-01-24 19:52:06 +020045
46#endif /* AES_GCM_H */