aes_gcm.h 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2014-2015, Qualcomm Atheros, Inc.
  4. */
  5. #ifndef AES_GCM_H
  6. #define AES_GCM_H
  7. #include "aead_api.h"
  8. #define GCM_AAD_LEN 32
  9. static inline int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm,
  10. u8 *j_0, u8 *aad, u8 *data,
  11. size_t data_len, u8 *mic)
  12. {
  13. return aead_encrypt(tfm, j_0, aad + 2,
  14. be16_to_cpup((__be16 *)aad),
  15. data, data_len, mic);
  16. }
  17. static inline int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm,
  18. u8 *j_0, u8 *aad, u8 *data,
  19. size_t data_len, u8 *mic)
  20. {
  21. return aead_decrypt(tfm, j_0, aad + 2,
  22. be16_to_cpup((__be16 *)aad),
  23. data, data_len, mic);
  24. }
  25. static inline struct crypto_aead *
  26. ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
  27. {
  28. return aead_key_setup_encrypt("gcm(aes)", key,
  29. key_len, IEEE80211_GCMP_MIC_LEN);
  30. }
  31. static inline void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
  32. {
  33. return aead_key_free(tfm);
  34. }
  35. #endif /* AES_GCM_H */