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