xref: /freebsd/sys/net80211/ieee80211_crypto.h (revision 6d21920e6d2e03c6ed7360c432b855ca189db305)
11a1e1d21SSam Leffler /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3fe267a55SPedro F. Giffuni  *
47535e66aSSam Leffler  * Copyright (c) 2001 Atsushi Onoe
5b032f27cSSam Leffler  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
61a1e1d21SSam Leffler  * All rights reserved.
71a1e1d21SSam Leffler  *
81a1e1d21SSam Leffler  * Redistribution and use in source and binary forms, with or without
91a1e1d21SSam Leffler  * modification, are permitted provided that the following conditions
101a1e1d21SSam Leffler  * are met:
111a1e1d21SSam Leffler  * 1. Redistributions of source code must retain the above copyright
121a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer.
131a1e1d21SSam Leffler  * 2. Redistributions in binary form must reproduce the above copyright
141a1e1d21SSam Leffler  *    notice, this list of conditions and the following disclaimer in the
151a1e1d21SSam Leffler  *    documentation and/or other materials provided with the distribution.
167535e66aSSam Leffler  *
177535e66aSSam Leffler  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187535e66aSSam Leffler  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
197535e66aSSam Leffler  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
207535e66aSSam Leffler  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
217535e66aSSam Leffler  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
227535e66aSSam Leffler  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237535e66aSSam Leffler  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247535e66aSSam Leffler  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257535e66aSSam Leffler  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
267535e66aSSam Leffler  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271a1e1d21SSam Leffler  */
281a1e1d21SSam Leffler #ifndef _NET80211_IEEE80211_CRYPTO_H_
291a1e1d21SSam Leffler #define _NET80211_IEEE80211_CRYPTO_H_
301a1e1d21SSam Leffler 
311a1e1d21SSam Leffler /*
321a1e1d21SSam Leffler  * 802.11 protocol crypto-related definitions.
331a1e1d21SSam Leffler  */
341a1e1d21SSam Leffler #define	IEEE80211_KEYBUF_SIZE	16
358a1b9b6aSSam Leffler #define	IEEE80211_MICBUF_SIZE	(8+8)	/* space for both tx+rx keys */
361a1e1d21SSam Leffler 
378a1b9b6aSSam Leffler /*
388a1b9b6aSSam Leffler  * Old WEP-style key.  Deprecated.
398a1b9b6aSSam Leffler  */
401a1e1d21SSam Leffler struct ieee80211_wepkey {
418a1b9b6aSSam Leffler 	u_int		wk_len;		/* key length in bytes */
4268e8e04eSSam Leffler 	uint8_t		wk_key[IEEE80211_KEYBUF_SIZE];
431a1e1d21SSam Leffler };
441a1e1d21SSam Leffler 
45b032f27cSSam Leffler struct ieee80211_rsnparms {
46b032f27cSSam Leffler 	uint8_t		rsn_mcastcipher;	/* mcast/group cipher */
47b032f27cSSam Leffler 	uint8_t		rsn_mcastkeylen;	/* mcast key length */
48b032f27cSSam Leffler 	uint8_t		rsn_ucastcipher;	/* selected unicast cipher */
49b032f27cSSam Leffler 	uint8_t		rsn_ucastkeylen;	/* unicast key length */
50b032f27cSSam Leffler 	uint8_t		rsn_keymgmt;		/* selected key mgmt algo */
51b032f27cSSam Leffler 	uint16_t	rsn_caps;		/* capabilities */
52b032f27cSSam Leffler };
53b032f27cSSam Leffler 
548a1b9b6aSSam Leffler struct ieee80211_cipher;
558a1b9b6aSSam Leffler 
568a1b9b6aSSam Leffler /*
578a1b9b6aSSam Leffler  * Crypto key state.  There is sufficient room for all supported
588a1b9b6aSSam Leffler  * ciphers (see below).  The underlying ciphers are handled
598a1b9b6aSSam Leffler  * separately through loadable cipher modules that register with
608a1b9b6aSSam Leffler  * the generic crypto support.  A key has a reference to an instance
618a1b9b6aSSam Leffler  * of the cipher; any per-key state is hung off wk_private by the
628a1b9b6aSSam Leffler  * cipher when it is attached.  Ciphers are automatically called
638a1b9b6aSSam Leffler  * to detach and cleanup any such state when the key is deleted.
648a1b9b6aSSam Leffler  *
658a1b9b6aSSam Leffler  * The generic crypto support handles encap/decap of cipher-related
668a1b9b6aSSam Leffler  * frame contents for both hardware- and software-based implementations.
678a1b9b6aSSam Leffler  * A key requiring software crypto support is automatically flagged and
688a1b9b6aSSam Leffler  * the cipher is expected to honor this and do the necessary work.
698a1b9b6aSSam Leffler  * Ciphers such as TKIP may also support mixed hardware/software
708a1b9b6aSSam Leffler  * encrypt/decrypt and MIC processing.
718a1b9b6aSSam Leffler  */
7268e8e04eSSam Leffler typedef uint16_t ieee80211_keyix;	/* h/w key index */
73c1225b52SSam Leffler 
748a1b9b6aSSam Leffler struct ieee80211_key {
7568e8e04eSSam Leffler 	uint8_t		wk_keylen;	/* key length in bytes */
76ee9d294bSAdrian Chadd 	uint8_t		wk_pad;		/* .. some drivers use this. Fix that. */
77ee9d294bSAdrian Chadd 	uint8_t		wk_pad1[2];
78ee9d294bSAdrian Chadd 	uint32_t	wk_flags;
79ee9d294bSAdrian Chadd #define	IEEE80211_KEY_XMIT	0x00000001	/* key used for xmit */
80ee9d294bSAdrian Chadd #define	IEEE80211_KEY_RECV	0x00000002	/* key used for recv */
81ee9d294bSAdrian Chadd #define	IEEE80211_KEY_GROUP	0x00000004	/* key used for WPA group operation */
82ee9d294bSAdrian Chadd #define	IEEE80211_KEY_NOREPLAY	0x00000008	/* ignore replay failures */
83ee9d294bSAdrian Chadd #define	IEEE80211_KEY_SWENCRYPT	0x00000010	/* host-based encrypt */
84ee9d294bSAdrian Chadd #define	IEEE80211_KEY_SWDECRYPT	0x00000020	/* host-based decrypt */
85ee9d294bSAdrian Chadd #define	IEEE80211_KEY_SWENMIC	0x00000040	/* host-based enmic */
86ee9d294bSAdrian Chadd #define	IEEE80211_KEY_SWDEMIC	0x00000080	/* host-based demic */
87ee9d294bSAdrian Chadd #define	IEEE80211_KEY_DEVKEY	0x00000100	/* device key request completed */
88ee9d294bSAdrian Chadd #define	IEEE80211_KEY_CIPHER0	0x00001000	/* cipher-specific action 0 */
89ee9d294bSAdrian Chadd #define	IEEE80211_KEY_CIPHER1	0x00002000	/* cipher-specific action 1 */
90ee9d294bSAdrian Chadd #define	IEEE80211_KEY_NOIV	0x00004000	/* don't insert IV/MIC for !mgmt */
91ee9d294bSAdrian Chadd #define	IEEE80211_KEY_NOIVMGT	0x00008000	/* don't insert IV/MIC for mgmt */
92ee9d294bSAdrian Chadd #define	IEEE80211_KEY_NOMIC	0x00010000	/* don't insert MIC for !mgmt */
93ee9d294bSAdrian Chadd #define	IEEE80211_KEY_NOMICMGT	0x00020000	/* don't insert MIC for mgmt */
94ee9d294bSAdrian Chadd 
95c1225b52SSam Leffler 	ieee80211_keyix	wk_keyix;	/* h/w key index */
96c1225b52SSam Leffler 	ieee80211_keyix	wk_rxkeyix;	/* optional h/w rx key index */
9768e8e04eSSam Leffler 	uint8_t		wk_key[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
988a1b9b6aSSam Leffler #define	wk_txmic	wk_key+IEEE80211_KEYBUF_SIZE+0	/* XXX can't () right */
998a1b9b6aSSam Leffler #define	wk_rxmic	wk_key+IEEE80211_KEYBUF_SIZE+8	/* XXX can't () right */
100b032f27cSSam Leffler 					/* key receive sequence counter */
101b032f27cSSam Leffler 	uint64_t	wk_keyrsc[IEEE80211_TID_SIZE];
10268e8e04eSSam Leffler 	uint64_t	wk_keytsc;	/* key transmit sequence counter */
1038a1b9b6aSSam Leffler 	const struct ieee80211_cipher *wk_cipher;
1048a1b9b6aSSam Leffler 	void		*wk_private;	/* private cipher state */
10571fe06caSSam Leffler 	uint8_t		wk_macaddr[IEEE80211_ADDR_LEN];
1068a1b9b6aSSam Leffler };
107dd70e17bSSam Leffler #define	IEEE80211_KEY_COMMON 		/* common flags passed in by apps */\
1085d766a09SBernhard Schmidt 	(IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV | IEEE80211_KEY_GROUP | \
1095d766a09SBernhard Schmidt 	 IEEE80211_KEY_NOREPLAY)
1108a1b9b6aSSam Leffler 
1115c1f7f19SSam Leffler #define	IEEE80211_KEY_SWCRYPT \
1125c1f7f19SSam Leffler 	(IEEE80211_KEY_SWENCRYPT | IEEE80211_KEY_SWDECRYPT)
1135c1f7f19SSam Leffler #define	IEEE80211_KEY_SWMIC	(IEEE80211_KEY_SWENMIC | IEEE80211_KEY_SWDEMIC)
1145c1f7f19SSam Leffler 
1155d7c8f20SAndriy Voskoboinyk #define IEEE80211_KEY_DEVICE		/* flags owned by device driver */\
1165d7c8f20SAndriy Voskoboinyk 	(IEEE80211_KEY_DEVKEY|IEEE80211_KEY_CIPHER0|IEEE80211_KEY_CIPHER1| \
117fe75b452SAdrian Chadd 	 IEEE80211_KEY_SWCRYPT|IEEE80211_KEY_SWMIC|IEEE80211_KEY_NOIV | \
118fe75b452SAdrian Chadd 	 IEEE80211_KEY_NOIVMGT|IEEE80211_KEY_NOMIC|IEEE80211_KEY_NOMICMGT)
1195d7c8f20SAndriy Voskoboinyk 
120f2ce0f51SSam Leffler #define	IEEE80211_KEY_BITS \
1210461600dSBjoern A. Zeeb 	"\20\1XMIT\2RECV\3GROUP\4NOREPLAY\5SWENCRYPT\6SWDECRYPT\7SWENMIC\10SWDEMIC" \
1220461600dSBjoern A. Zeeb 	"\11DEVKEY\12CIPHER0\13CIPHER1\14NOIV\15NOIVMGT\16NOMIC\17NOMICMGT"
123f2ce0f51SSam Leffler 
124b032f27cSSam Leffler #define	IEEE80211_KEYIX_NONE	((ieee80211_keyix) -1)
125b032f27cSSam Leffler 
1268a1b9b6aSSam Leffler /*
1278a1b9b6aSSam Leffler  * NB: these values are ordered carefully; there are lots of
128b032f27cSSam Leffler  * of implications in any reordering.  Beware that 4 is used
129b032f27cSSam Leffler  * only to indicate h/w TKIP MIC support in driver capabilities;
130b032f27cSSam Leffler  * there is no separate cipher support (it's rolled into the
131b032f27cSSam Leffler  * TKIP cipher support).
1328a1b9b6aSSam Leffler  */
1338a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_WEP		0
1348a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_TKIP		1
1358a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_AES_OCB	2
1368a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_AES_CCM	3
137b032f27cSSam Leffler #define	IEEE80211_CIPHER_TKIPMIC	4	/* TKIP MIC capability */
1388a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_CKIP		5
1398a1b9b6aSSam Leffler #define	IEEE80211_CIPHER_NONE		6	/* pseudo value */
14005540e62SAdrian Chadd #define	IEEE80211_CIPHER_AES_CCM_256	7
14105540e62SAdrian Chadd #define	IEEE80211_CIPHER_BIP_CMAC_128	8
14205540e62SAdrian Chadd #define	IEEE80211_CIPHER_BIP_CMAC_256	9
14305540e62SAdrian Chadd #define	IEEE80211_CIPHER_BIP_GMAC_128	10
14405540e62SAdrian Chadd #define	IEEE80211_CIPHER_BIP_GMAC_256	11
14505540e62SAdrian Chadd #define	IEEE80211_CIPHER_AES_GCM_128	12
14605540e62SAdrian Chadd #define	IEEE80211_CIPHER_AES_GCM_256	13
1478a1b9b6aSSam Leffler 
14805540e62SAdrian Chadd #define	IEEE80211_CIPHER_LAST		13
14905540e62SAdrian Chadd 
15005540e62SAdrian Chadd #define	IEEE80211_CIPHER_MAX		(IEEE80211_CIPHER_LAST+1)
1518a1b9b6aSSam Leffler 
152b032f27cSSam Leffler /* capability bits in ic_cryptocaps/iv_cryptocaps */
153b032f27cSSam Leffler #define	IEEE80211_CRYPTO_WEP		(1<<IEEE80211_CIPHER_WEP)
154b032f27cSSam Leffler #define	IEEE80211_CRYPTO_TKIP		(1<<IEEE80211_CIPHER_TKIP)
155b032f27cSSam Leffler #define	IEEE80211_CRYPTO_AES_OCB	(1<<IEEE80211_CIPHER_AES_OCB)
156b032f27cSSam Leffler #define	IEEE80211_CRYPTO_AES_CCM	(1<<IEEE80211_CIPHER_AES_CCM)
157b032f27cSSam Leffler #define	IEEE80211_CRYPTO_TKIPMIC	(1<<IEEE80211_CIPHER_TKIPMIC)
158b032f27cSSam Leffler #define	IEEE80211_CRYPTO_CKIP		(1<<IEEE80211_CIPHER_CKIP)
15905540e62SAdrian Chadd #define	IEEE80211_CRYPTO_AES_CCM_256	(1<<IEEE80211_CIPHER_AES_CCM_256)
16005540e62SAdrian Chadd #define	IEEE80211_CRYPTO_BIP_CMAC_128	(1<<IEEE80211_CIPHER_BIP_CMAC_128)
16105540e62SAdrian Chadd #define	IEEE80211_CRYPTO_BIP_CMAC_256	(1<<IEEE80211_CIPHER_BIP_CMAC_256)
16205540e62SAdrian Chadd #define	IEEE80211_CRYPTO_BIP_GMAC_128	(1<<IEEE80211_CIPHER_BIP_GMAC_128)
16305540e62SAdrian Chadd #define	IEEE80211_CRYPTO_BIP_GMAC_256	(1<<IEEE80211_CIPHER_BIP_GMAC_256)
16405540e62SAdrian Chadd #define	IEEE80211_CRYPTO_AES_GCM_128	(1<<IEEE80211_CIPHER_AES_GCM_128)
16505540e62SAdrian Chadd #define	IEEE80211_CRYPTO_AES_GCM_256	(1<<IEEE80211_CIPHER_AES_GCM_256)
1668a1b9b6aSSam Leffler 
1673d13a955SSam Leffler #define	IEEE80211_CRYPTO_BITS \
16805540e62SAdrian Chadd 	"\20\1WEP\2TKIP\3AES\4AES_CCM\5TKIPMIC\6CKIP\10AES_CCM_256" \
16905540e62SAdrian Chadd 	"\11BIP_CMAC_128\12BIP_CMAC_256\13BIP_GMAC_128\14BIP_CMAC_256" \
17005540e62SAdrian Chadd 	"\15AES_GCM_128\16AES_GCM_256"
1713d13a955SSam Leffler 
1728a1b9b6aSSam Leffler #if defined(__KERNEL__) || defined(_KERNEL)
1738a1b9b6aSSam Leffler 
1748a1b9b6aSSam Leffler struct ieee80211com;
175b032f27cSSam Leffler struct ieee80211vap;
1768a1b9b6aSSam Leffler struct ieee80211_node;
1778a1b9b6aSSam Leffler struct mbuf;
1788a1b9b6aSSam Leffler 
179b032f27cSSam Leffler MALLOC_DECLARE(M_80211_CRYPTO);
1808a1b9b6aSSam Leffler 
1810942c81cSSam Leffler void	ieee80211_crypto_attach(struct ieee80211com *);
1820942c81cSSam Leffler void	ieee80211_crypto_detach(struct ieee80211com *);
183e9961ea1SAdrian Chadd void	ieee80211_crypto_set_supported_software_ciphers(struct ieee80211com *,
184e9961ea1SAdrian Chadd 	    uint32_t cipher_set);
185e9961ea1SAdrian Chadd void	ieee80211_crypto_set_supported_hardware_ciphers(struct ieee80211com *,
186e9961ea1SAdrian Chadd 	    uint32_t cipher_set);
187c7f5f140SAdrian Chadd void	ieee80211_crypto_set_supported_driver_keymgmt(struct ieee80211com *,
188c7f5f140SAdrian Chadd 	    uint32_t keymgmt_set);
189b032f27cSSam Leffler void	ieee80211_crypto_vattach(struct ieee80211vap *);
190b032f27cSSam Leffler void	ieee80211_crypto_vdetach(struct ieee80211vap *);
191b032f27cSSam Leffler int	ieee80211_crypto_newkey(struct ieee80211vap *,
192dd70e17bSSam Leffler 		int cipher, int flags, struct ieee80211_key *);
193b032f27cSSam Leffler int	ieee80211_crypto_delkey(struct ieee80211vap *,
1948a1b9b6aSSam Leffler 		struct ieee80211_key *);
19571fe06caSSam Leffler int	ieee80211_crypto_setkey(struct ieee80211vap *, struct ieee80211_key *);
196b032f27cSSam Leffler void	ieee80211_crypto_delglobalkeys(struct ieee80211vap *);
19706b2d888SSam Leffler void	ieee80211_crypto_reload_keys(struct ieee80211com *);
198781487cfSAdrian Chadd void	ieee80211_crypto_set_deftxkey(struct ieee80211vap *,
199781487cfSAdrian Chadd 	    ieee80211_keyix kid);
2008a1b9b6aSSam Leffler 
2018a1b9b6aSSam Leffler /*
2028a1b9b6aSSam Leffler  * Template for a supported cipher.  Ciphers register with the
2038a1b9b6aSSam Leffler  * crypto code and are typically loaded as separate modules
2048a1b9b6aSSam Leffler  * (the null cipher is always present).
2058a1b9b6aSSam Leffler  * XXX may need refcnts
2068a1b9b6aSSam Leffler  */
2078a1b9b6aSSam Leffler struct ieee80211_cipher {
2088a1b9b6aSSam Leffler 	const char *ic_name;		/* printable name */
2098a1b9b6aSSam Leffler 	u_int	ic_cipher;		/* IEEE80211_CIPHER_* */
2108a1b9b6aSSam Leffler 	u_int	ic_header;		/* size of privacy header (bytes) */
2118a1b9b6aSSam Leffler 	u_int	ic_trailer;		/* size of privacy trailer (bytes) */
2128a1b9b6aSSam Leffler 	u_int	ic_miclen;		/* size of mic trailer (bytes) */
213b032f27cSSam Leffler 	void*	(*ic_attach)(struct ieee80211vap *, struct ieee80211_key *);
2148a1b9b6aSSam Leffler 	void	(*ic_detach)(struct ieee80211_key *);
2158a1b9b6aSSam Leffler 	int	(*ic_setkey)(struct ieee80211_key *);
216c0cb9349SAdrian Chadd 	void	(*ic_setiv)(struct ieee80211_key *, uint8_t *);
217ef0d8f63SAdrian Chadd 	int	(*ic_encap)(struct ieee80211_key *, struct mbuf *);
2182cc12adeSSam Leffler 	int	(*ic_decap)(struct ieee80211_key *, struct mbuf *, int);
21908fd0689SAdrian Chadd 	/*
22008fd0689SAdrian Chadd 	 * ic_enmic() and ic_demic() are currently only used by TKIP.
22108fd0689SAdrian Chadd 	 * Please see ieee80211_crypto_enmic() and ieee80211_crypto_demic()
22208fd0689SAdrian Chadd 	 * for more information.
22308fd0689SAdrian Chadd 	 */
22496d88463SSam Leffler 	int	(*ic_enmic)(struct ieee80211_key *, struct mbuf *, int);
22596d88463SSam Leffler 	int	(*ic_demic)(struct ieee80211_key *, struct mbuf *, int);
2268a1b9b6aSSam Leffler };
2278a1b9b6aSSam Leffler extern	const struct ieee80211_cipher ieee80211_cipher_none;
2288a1b9b6aSSam Leffler 
229cda15ce1SSam Leffler #define	IEEE80211_KEY_UNDEFINED(k) \
230cda15ce1SSam Leffler 	((k)->wk_cipher == &ieee80211_cipher_none)
231cda15ce1SSam Leffler 
2320942c81cSSam Leffler void	ieee80211_crypto_register(const struct ieee80211_cipher *);
2330942c81cSSam Leffler void	ieee80211_crypto_unregister(const struct ieee80211_cipher *);
2340942c81cSSam Leffler int	ieee80211_crypto_available(u_int cipher);
2358a1b9b6aSSam Leffler 
23654a95d0dSAdrian Chadd int	ieee80211_crypto_get_key_wepidx(const struct ieee80211vap *,
23754a95d0dSAdrian Chadd 	    const struct ieee80211_key *k);
238ef0d8f63SAdrian Chadd uint8_t	ieee80211_crypto_get_keyid(struct ieee80211vap *vap,
239ef0d8f63SAdrian Chadd 		struct ieee80211_key *k);
24015395998SAdrian Chadd struct ieee80211_key *ieee80211_crypto_get_txkey(struct ieee80211_node *,
24115395998SAdrian Chadd 		struct mbuf *);
242b032f27cSSam Leffler struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211_node *,
243b032f27cSSam Leffler 		struct mbuf *);
244fe75b452SAdrian Chadd int	ieee80211_crypto_decap(struct ieee80211_node *,
245fe75b452SAdrian Chadd 		struct mbuf *, int, struct ieee80211_key **);
246ee9d294bSAdrian Chadd int ieee80211_crypto_demic(struct ieee80211vap *vap, struct ieee80211_key *k,
247ee9d294bSAdrian Chadd 		struct mbuf *, int);
24808fd0689SAdrian Chadd /**
24908fd0689SAdrian Chadd  * @brief Add any pre-fragmentation MIC to an MSDU.
25008fd0689SAdrian Chadd  *
25108fd0689SAdrian Chadd  * This is called before 802.11 fragmentation.  Crypto types that implement
25208fd0689SAdrian Chadd  * a MIC/ICV check per MSDU will not implement this function.
25308fd0689SAdrian Chadd  *
25408fd0689SAdrian Chadd  * As an example, TKIP implements a Michael MIC check over the entire
25508fd0689SAdrian Chadd  * unencrypted MSDU before fragmenting it into MPDUs and passing each
25608fd0689SAdrian Chadd  * MPDU to be separately encrypted with their own MIC/ICV.
25708fd0689SAdrian Chadd  *
25808fd0689SAdrian Chadd  * Please see 802.11-2020 12.5.2.1.2 (TKIP cryptographic encapsulation)
25908fd0689SAdrian Chadd  * for more information.
26008fd0689SAdrian Chadd  *
26108fd0689SAdrian Chadd  * @param vap	the current VAP
26208fd0689SAdrian Chadd  * @param k	the current key
26308fd0689SAdrian Chadd  * @param m	the mbuf representing the MSDU
26408fd0689SAdrian Chadd  * @param f	set to 1 to force a MSDU MIC check, even if HW encrypted
26508fd0689SAdrian Chadd  * @returns	0 if error / MIC encap failed, 1 if OK
2668a1b9b6aSSam Leffler  */
2678a1b9b6aSSam Leffler static __inline int
ieee80211_crypto_enmic(struct ieee80211vap * vap,struct ieee80211_key * k,struct mbuf * m,int force)268b032f27cSSam Leffler ieee80211_crypto_enmic(struct ieee80211vap *vap,
26996d88463SSam Leffler 	struct ieee80211_key *k, struct mbuf *m, int force)
2708a1b9b6aSSam Leffler {
2718a1b9b6aSSam Leffler 	const struct ieee80211_cipher *cip = k->wk_cipher;
27296d88463SSam Leffler 	return (cip->ic_miclen > 0 ? cip->ic_enmic(k, m, force) : 1);
2738a1b9b6aSSam Leffler }
2748a1b9b6aSSam Leffler 
2758a1b9b6aSSam Leffler /*
2768a1b9b6aSSam Leffler  * Reset key state to an unused state.  The crypto
2778a1b9b6aSSam Leffler  * key allocation mechanism insures other state (e.g.
2788a1b9b6aSSam Leffler  * key data) is properly setup before a key is used.
2798a1b9b6aSSam Leffler  */
2808a1b9b6aSSam Leffler static __inline void
ieee80211_crypto_resetkey(struct ieee80211vap * vap,struct ieee80211_key * k,ieee80211_keyix ix)281b032f27cSSam Leffler ieee80211_crypto_resetkey(struct ieee80211vap *vap,
282c1225b52SSam Leffler 	struct ieee80211_key *k, ieee80211_keyix ix)
2838a1b9b6aSSam Leffler {
28479462715SSam Leffler 	k->wk_cipher = &ieee80211_cipher_none;
285b032f27cSSam Leffler 	k->wk_private = k->wk_cipher->ic_attach(vap, k);
286c1225b52SSam Leffler 	k->wk_keyix = k->wk_rxkeyix = ix;
2878a1b9b6aSSam Leffler 	k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
2888a1b9b6aSSam Leffler }
2898a1b9b6aSSam Leffler 
2908a1b9b6aSSam Leffler /*
2918a1b9b6aSSam Leffler  * Crypt-related notification methods.
2928a1b9b6aSSam Leffler  */
293b032f27cSSam Leffler void	ieee80211_notify_replay_failure(struct ieee80211vap *,
2948a1b9b6aSSam Leffler 		const struct ieee80211_frame *, const struct ieee80211_key *,
295ebaf87ebSSam Leffler 		uint64_t rsc, int tid);
296b032f27cSSam Leffler void	ieee80211_notify_michael_failure(struct ieee80211vap *,
297db8ceb8eSBjoern A. Zeeb 		const struct ieee80211_frame *, ieee80211_keyix keyix);
298*6d21920eSAdrian Chadd 
299*6d21920eSAdrian Chadd /* AAD assembly for CCMP/GCMP. */
300*6d21920eSAdrian Chadd uint16_t	ieee80211_crypto_init_aad(const struct ieee80211_frame *,
301*6d21920eSAdrian Chadd 		uint8_t *, int);
302*6d21920eSAdrian Chadd 
3038a1b9b6aSSam Leffler #endif /* defined(__KERNEL__) || defined(_KERNEL) */
3041a1e1d21SSam Leffler #endif /* _NET80211_IEEE80211_CRYPTO_H_ */
305