key.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2002-2004, Instant802 Networks, Inc.
  4. * Copyright 2005, Devicescape Software, Inc.
  5. * Copyright (C) 2019, 2022-2023 Intel Corporation
  6. */
  7. #ifndef IEEE80211_KEY_H
  8. #define IEEE80211_KEY_H
  9. #include <linux/types.h>
  10. #include <linux/list.h>
  11. #include <linux/crypto.h>
  12. #include <linux/rcupdate.h>
  13. #include <crypto/arc4.h>
  14. #include <net/mac80211.h>
  15. #define NUM_DEFAULT_KEYS 4
  16. #define NUM_DEFAULT_MGMT_KEYS 2
  17. #define NUM_DEFAULT_BEACON_KEYS 2
  18. #define INVALID_PTK_KEYIDX 2 /* Keyidx always pointing to a NULL key for PTK */
  19. struct ieee80211_local;
  20. struct ieee80211_sub_if_data;
  21. struct ieee80211_link_data;
  22. struct sta_info;
  23. /**
  24. * enum ieee80211_internal_key_flags - internal key flags
  25. *
  26. * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
  27. * in the hardware for TX crypto hardware acceleration.
  28. * @KEY_FLAG_TAINTED: Key is tainted and packets should be dropped.
  29. */
  30. enum ieee80211_internal_key_flags {
  31. KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
  32. KEY_FLAG_TAINTED = BIT(1),
  33. };
  34. enum ieee80211_internal_tkip_state {
  35. TKIP_STATE_NOT_INIT,
  36. TKIP_STATE_PHASE1_DONE,
  37. TKIP_STATE_PHASE1_HW_UPLOADED,
  38. };
  39. struct tkip_ctx {
  40. u16 p1k[5]; /* p1k cache */
  41. u32 p1k_iv32; /* iv32 for which p1k computed */
  42. enum ieee80211_internal_tkip_state state;
  43. };
  44. struct tkip_ctx_rx {
  45. struct tkip_ctx ctx;
  46. u32 iv32; /* current iv32 */
  47. u16 iv16; /* current iv16 */
  48. };
  49. struct ieee80211_key {
  50. struct ieee80211_local *local;
  51. struct ieee80211_sub_if_data *sdata;
  52. struct sta_info *sta;
  53. /* for sdata list */
  54. struct list_head list;
  55. /* protected by key mutex */
  56. unsigned int flags;
  57. union {
  58. struct {
  59. /* protects tx context */
  60. spinlock_t txlock;
  61. /* last used TSC */
  62. struct tkip_ctx tx;
  63. /* last received RSC */
  64. struct tkip_ctx_rx rx[IEEE80211_NUM_TIDS];
  65. /* number of mic failures */
  66. u32 mic_failures;
  67. } tkip;
  68. struct {
  69. /*
  70. * Last received packet number. The first
  71. * IEEE80211_NUM_TIDS counters are used with Data
  72. * frames and the last counter is used with Robust
  73. * Management frames.
  74. */
  75. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
  76. struct crypto_aead *tfm;
  77. u32 replays; /* dot11RSNAStatsCCMPReplays */
  78. } ccmp;
  79. struct {
  80. u8 rx_pn[IEEE80211_CMAC_PN_LEN];
  81. struct crypto_shash *tfm;
  82. u32 replays; /* dot11RSNAStatsCMACReplays */
  83. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  84. } aes_cmac;
  85. struct {
  86. u8 rx_pn[IEEE80211_GMAC_PN_LEN];
  87. struct crypto_aead *tfm;
  88. u32 replays; /* dot11RSNAStatsCMACReplays */
  89. u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
  90. } aes_gmac;
  91. struct {
  92. /* Last received packet number. The first
  93. * IEEE80211_NUM_TIDS counters are used with Data
  94. * frames and the last counter is used with Robust
  95. * Management frames.
  96. */
  97. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_GCMP_PN_LEN];
  98. struct crypto_aead *tfm;
  99. u32 replays; /* dot11RSNAStatsGCMPReplays */
  100. } gcmp;
  101. struct {
  102. /* generic cipher scheme */
  103. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_MAX_PN_LEN];
  104. } gen;
  105. } u;
  106. #ifdef CONFIG_MAC80211_DEBUGFS
  107. struct {
  108. struct dentry *stalink;
  109. struct dentry *dir;
  110. int cnt;
  111. } debugfs;
  112. #endif
  113. unsigned int color;
  114. /*
  115. * key config, must be last because it contains key
  116. * material as variable length member
  117. */
  118. struct ieee80211_key_conf conf;
  119. };
  120. struct ieee80211_key *
  121. ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
  122. const u8 *key_data,
  123. size_t seq_len, const u8 *seq);
  124. /*
  125. * Insert a key into data structures (sdata, sta if necessary)
  126. * to make it used, free old key. On failure, also free the new key.
  127. */
  128. int ieee80211_key_link(struct ieee80211_key *key,
  129. struct ieee80211_link_data *link,
  130. struct sta_info *sta);
  131. int ieee80211_set_tx_key(struct ieee80211_key *key);
  132. void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom);
  133. void ieee80211_key_free_unused(struct ieee80211_key *key);
  134. void ieee80211_set_default_key(struct ieee80211_link_data *link, int idx,
  135. bool uni, bool multi);
  136. void ieee80211_set_default_mgmt_key(struct ieee80211_link_data *link,
  137. int idx);
  138. void ieee80211_set_default_beacon_key(struct ieee80211_link_data *link,
  139. int idx);
  140. void ieee80211_remove_link_keys(struct ieee80211_link_data *link,
  141. struct list_head *keys);
  142. void ieee80211_free_key_list(struct ieee80211_local *local,
  143. struct list_head *keys);
  144. void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
  145. bool force_synchronize);
  146. void ieee80211_free_sta_keys(struct ieee80211_local *local,
  147. struct sta_info *sta);
  148. void ieee80211_reenable_keys(struct ieee80211_sub_if_data *sdata);
  149. int ieee80211_key_switch_links(struct ieee80211_sub_if_data *sdata,
  150. unsigned long del_links_mask,
  151. unsigned long add_links_mask);
  152. void ieee80211_delayed_tailroom_dec(struct wiphy *wiphy,
  153. struct wiphy_work *wk);
  154. #endif /* IEEE80211_KEY_H */