ieee80211_crypto.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* $OpenBSD: ieee80211_crypto.h,v 1.22 2009/01/26 19:09:41 damien Exp $ */
  2. /*-
  3. * Copyright (c) 2007,2008 Damien Bergamini <damien.bergamini@free.fr>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _NET80211_IEEE80211_CRYPTO_H_
  18. #define _NET80211_IEEE80211_CRYPTO_H_
  19. /*
  20. * 802.11 protocol crypto-related definitions.
  21. */
  22. /*
  23. * 802.11 ciphers.
  24. */
  25. enum ieee80211_cipher {
  26. IEEE80211_CIPHER_NONE = 0x00000000,
  27. IEEE80211_CIPHER_USEGROUP = 0x00000001,
  28. IEEE80211_CIPHER_WEP40 = 0x00000002,
  29. IEEE80211_CIPHER_TKIP = 0x00000004,
  30. IEEE80211_CIPHER_CCMP = 0x00000008,
  31. IEEE80211_CIPHER_WEP104 = 0x00000010,
  32. IEEE80211_CIPHER_BIP = 0x00000020 /* 11w */
  33. };
  34. /*
  35. * 802.11 Authentication and Key Management Protocols.
  36. */
  37. enum ieee80211_akm {
  38. IEEE80211_AKM_NONE = 0x00000000,
  39. IEEE80211_AKM_8021X = 0x00000001,
  40. IEEE80211_AKM_PSK = 0x00000002,
  41. IEEE80211_AKM_SHA256_8021X = 0x00000004, /* 11w */
  42. IEEE80211_AKM_SHA256_PSK = 0x00000008 /* 11w */
  43. };
  44. static __inline int
  45. ieee80211_is_8021x_akm(enum ieee80211_akm akm)
  46. {
  47. return akm == IEEE80211_AKM_8021X ||
  48. akm == IEEE80211_AKM_SHA256_8021X;
  49. }
  50. static __inline int
  51. ieee80211_is_sha256_akm(enum ieee80211_akm akm)
  52. {
  53. return akm == IEEE80211_AKM_SHA256_8021X ||
  54. akm == IEEE80211_AKM_SHA256_PSK;
  55. }
  56. #define IEEE80211_KEYBUF_SIZE 16
  57. #define IEEE80211_TKIP_HDRLEN 8
  58. #define IEEE80211_TKIP_MICLEN 8
  59. #define IEEE80211_TKIP_ICVLEN 4
  60. #define IEEE80211_CCMP_HDRLEN 8
  61. #define IEEE80211_CCMP_MICLEN 8
  62. #define IEEE80211_PMK_LEN 32
  63. struct ieee80211_key {
  64. u_int8_t k_id; /* identifier (0-5) */
  65. enum ieee80211_cipher k_cipher;
  66. u_int k_flags;
  67. #define IEEE80211_KEY_GROUP 0x00000001 /* group data key */
  68. #define IEEE80211_KEY_TX 0x00000002 /* Tx+Rx */
  69. #define IEEE80211_KEY_IGTK 0x00000004 /* integrity group key */
  70. u_int k_len;
  71. u_int64_t k_rsc[IEEE80211_NUM_TID];
  72. u_int64_t k_mgmt_rsc;
  73. u_int64_t k_tsc;
  74. u_int8_t k_key[32];
  75. void *k_priv;
  76. };
  77. /*
  78. * Entry in the PMKSA cache.
  79. */
  80. struct ieee80211_pmk {
  81. enum ieee80211_akm pmk_akm;
  82. u_int32_t pmk_lifetime;
  83. #define IEEE80211_PMK_INFINITE 0
  84. u_int8_t pmk_pmkid[IEEE80211_PMKID_LEN];
  85. u_int8_t pmk_macaddr[IEEE80211_ADDR_LEN];
  86. u_int8_t pmk_key[IEEE80211_PMK_LEN];
  87. TAILQ_ENTRY(ieee80211_pmk) pmk_next;
  88. };
  89. /* forward references */
  90. struct ieee80211com;
  91. struct ieee80211_node;
  92. void ieee80211_crypto_attach(struct ifnet *);
  93. void ieee80211_crypto_detach(struct ifnet *);
  94. struct ieee80211_key *ieee80211_get_txkey(struct ieee80211com *,
  95. const struct ieee80211_frame *, struct ieee80211_node *);
  96. struct ieee80211_key *ieee80211_get_rxkey(struct ieee80211com *,
  97. struct mbuf *, struct ieee80211_node *);
  98. struct mbuf *ieee80211_encrypt(struct ieee80211com *, struct mbuf *,
  99. struct ieee80211_key *);
  100. struct mbuf *ieee80211_decrypt(struct ieee80211com *, struct mbuf *,
  101. struct ieee80211_node *);
  102. int ieee80211_set_key(struct ieee80211com *, struct ieee80211_node *,
  103. struct ieee80211_key *);
  104. void ieee80211_delete_key(struct ieee80211com *, struct ieee80211_node *,
  105. struct ieee80211_key *);
  106. void ieee80211_eapol_key_mic(struct ieee80211_eapol_key *,
  107. const u_int8_t *);
  108. int ieee80211_eapol_key_check_mic(struct ieee80211_eapol_key *,
  109. const u_int8_t *);
  110. #ifndef IEEE80211_STA_ONLY
  111. void ieee80211_eapol_key_encrypt(struct ieee80211com *,
  112. struct ieee80211_eapol_key *, const u_int8_t *);
  113. #endif
  114. int ieee80211_eapol_key_decrypt(struct ieee80211_eapol_key *,
  115. const u_int8_t *);
  116. struct ieee80211_pmk *ieee80211_pmksa_add(struct ieee80211com *,
  117. enum ieee80211_akm, const u_int8_t *, const u_int8_t *, u_int32_t);
  118. struct ieee80211_pmk *ieee80211_pmksa_find(struct ieee80211com *,
  119. struct ieee80211_node *, const u_int8_t *);
  120. void ieee80211_derive_ptk(enum ieee80211_akm, const u_int8_t *,
  121. const u_int8_t *, const u_int8_t *, const u_int8_t *,
  122. const u_int8_t *, struct ieee80211_ptk *);
  123. int ieee80211_cipher_keylen(enum ieee80211_cipher);
  124. int ieee80211_wep_set_key(struct ieee80211com *, struct ieee80211_key *);
  125. void ieee80211_wep_delete_key(struct ieee80211com *,
  126. struct ieee80211_key *);
  127. struct mbuf *ieee80211_wep_encrypt(struct ieee80211com *, struct mbuf *,
  128. struct ieee80211_key *);
  129. struct mbuf *ieee80211_wep_decrypt(struct ieee80211com *, struct mbuf *,
  130. struct ieee80211_key *);
  131. int ieee80211_tkip_set_key(struct ieee80211com *, struct ieee80211_key *);
  132. void ieee80211_tkip_delete_key(struct ieee80211com *,
  133. struct ieee80211_key *);
  134. struct mbuf *ieee80211_tkip_encrypt(struct ieee80211com *,
  135. struct mbuf *, struct ieee80211_key *);
  136. struct mbuf *ieee80211_tkip_decrypt(struct ieee80211com *,
  137. struct mbuf *, struct ieee80211_key *);
  138. void ieee80211_tkip_mic(struct mbuf *, int, const u_int8_t *,
  139. u_int8_t[IEEE80211_TKIP_MICLEN]);
  140. void ieee80211_michael_mic_failure(struct ieee80211com *, u_int64_t);
  141. int ieee80211_ccmp_set_key(struct ieee80211com *, struct ieee80211_key *);
  142. void ieee80211_ccmp_delete_key(struct ieee80211com *,
  143. struct ieee80211_key *);
  144. struct mbuf *ieee80211_ccmp_encrypt(struct ieee80211com *, struct mbuf *,
  145. struct ieee80211_key *);
  146. struct mbuf *ieee80211_ccmp_decrypt(struct ieee80211com *, struct mbuf *,
  147. struct ieee80211_key *);
  148. int ieee80211_bip_set_key(struct ieee80211com *, struct ieee80211_key *);
  149. void ieee80211_bip_delete_key(struct ieee80211com *,
  150. struct ieee80211_key *);
  151. struct mbuf *ieee80211_bip_encap(struct ieee80211com *, struct mbuf *,
  152. struct ieee80211_key *);
  153. struct mbuf *ieee80211_bip_decap(struct ieee80211com *, struct mbuf *,
  154. struct ieee80211_key *);
  155. #endif /* _NET80211_IEEE80211_CRYPTO_H_ */