aes_gcm.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef AES_GCM_H
  9. #define AES_GCM_H
  10. #include "aead_api.h"
  11. #define GCM_AAD_LEN 32
  12. static inline int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm,
  13. u8 *j_0, u8 *aad, u8 *data,
  14. size_t data_len, u8 *mic)
  15. {
  16. return aead_encrypt(tfm, j_0, aad + 2,
  17. be16_to_cpup((__be16 *)aad),
  18. data, data_len, mic);
  19. }
  20. static inline int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm,
  21. u8 *j_0, u8 *aad, u8 *data,
  22. size_t data_len, u8 *mic)
  23. {
  24. return aead_decrypt(tfm, j_0, aad + 2,
  25. be16_to_cpup((__be16 *)aad),
  26. data, data_len, mic);
  27. }
  28. static inline struct crypto_aead *
  29. ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
  30. {
  31. return aead_key_setup_encrypt("gcm(aes)", key,
  32. key_len, IEEE80211_GCMP_MIC_LEN);
  33. }
  34. static inline void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
  35. {
  36. return aead_key_free(tfm);
  37. }
  38. #endif /* AES_GCM_H */