Home | History | Annotate | Line # | Download | only in net80211
ieee80211_crypto.h revision 1.1.1.2
      1      1.1  dyoung /*-
      2      1.1  dyoung  * Copyright (c) 2001 Atsushi Onoe
      3  1.1.1.2  dyoung  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
      4      1.1  dyoung  * All rights reserved.
      5      1.1  dyoung  *
      6      1.1  dyoung  * Redistribution and use in source and binary forms, with or without
      7      1.1  dyoung  * modification, are permitted provided that the following conditions
      8      1.1  dyoung  * are met:
      9      1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     10      1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     11      1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     14      1.1  dyoung  * 3. The name of the author may not be used to endorse or promote products
     15      1.1  dyoung  *    derived from this software without specific prior written permission.
     16      1.1  dyoung  *
     17      1.1  dyoung  * Alternatively, this software may be distributed under the terms of the
     18      1.1  dyoung  * GNU General Public License ("GPL") version 2 as published by the Free
     19      1.1  dyoung  * Software Foundation.
     20      1.1  dyoung  *
     21      1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22      1.1  dyoung  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23      1.1  dyoung  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24      1.1  dyoung  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25      1.1  dyoung  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26      1.1  dyoung  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27      1.1  dyoung  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28      1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29      1.1  dyoung  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30      1.1  dyoung  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31      1.1  dyoung  *
     32  1.1.1.2  dyoung  * $FreeBSD: src/sys/net80211/ieee80211_crypto.h,v 1.7 2005/04/12 17:55:13 sam Exp $
     33      1.1  dyoung  */
     34      1.1  dyoung #ifndef _NET80211_IEEE80211_CRYPTO_H_
     35      1.1  dyoung #define _NET80211_IEEE80211_CRYPTO_H_
     36      1.1  dyoung 
     37      1.1  dyoung /*
     38      1.1  dyoung  * 802.11 protocol crypto-related definitions.
     39      1.1  dyoung  */
     40      1.1  dyoung #define	IEEE80211_KEYBUF_SIZE	16
     41  1.1.1.2  dyoung #define	IEEE80211_MICBUF_SIZE	(8+8)	/* space for both tx+rx keys */
     42      1.1  dyoung 
     43  1.1.1.2  dyoung /*
     44  1.1.1.2  dyoung  * Old WEP-style key.  Deprecated.
     45  1.1.1.2  dyoung  */
     46      1.1  dyoung struct ieee80211_wepkey {
     47  1.1.1.2  dyoung 	u_int		wk_len;		/* key length in bytes */
     48  1.1.1.2  dyoung 	u_int8_t	wk_key[IEEE80211_KEYBUF_SIZE];
     49  1.1.1.2  dyoung };
     50  1.1.1.2  dyoung 
     51  1.1.1.2  dyoung struct ieee80211_cipher;
     52  1.1.1.2  dyoung 
     53  1.1.1.2  dyoung /*
     54  1.1.1.2  dyoung  * Crypto key state.  There is sufficient room for all supported
     55  1.1.1.2  dyoung  * ciphers (see below).  The underlying ciphers are handled
     56  1.1.1.2  dyoung  * separately through loadable cipher modules that register with
     57  1.1.1.2  dyoung  * the generic crypto support.  A key has a reference to an instance
     58  1.1.1.2  dyoung  * of the cipher; any per-key state is hung off wk_private by the
     59  1.1.1.2  dyoung  * cipher when it is attached.  Ciphers are automatically called
     60  1.1.1.2  dyoung  * to detach and cleanup any such state when the key is deleted.
     61  1.1.1.2  dyoung  *
     62  1.1.1.2  dyoung  * The generic crypto support handles encap/decap of cipher-related
     63  1.1.1.2  dyoung  * frame contents for both hardware- and software-based implementations.
     64  1.1.1.2  dyoung  * A key requiring software crypto support is automatically flagged and
     65  1.1.1.2  dyoung  * the cipher is expected to honor this and do the necessary work.
     66  1.1.1.2  dyoung  * Ciphers such as TKIP may also support mixed hardware/software
     67  1.1.1.2  dyoung  * encrypt/decrypt and MIC processing.
     68  1.1.1.2  dyoung  */
     69  1.1.1.2  dyoung /* XXX need key index typedef */
     70  1.1.1.2  dyoung /* XXX pack better? */
     71  1.1.1.2  dyoung /* XXX 48-bit rsc/tsc */
     72  1.1.1.2  dyoung struct ieee80211_key {
     73  1.1.1.2  dyoung 	u_int8_t	wk_keylen;	/* key length in bytes */
     74  1.1.1.2  dyoung 	u_int8_t	wk_flags;
     75  1.1.1.2  dyoung #define	IEEE80211_KEY_XMIT	0x01	/* key used for xmit */
     76  1.1.1.2  dyoung #define	IEEE80211_KEY_RECV	0x02	/* key used for recv */
     77  1.1.1.2  dyoung #define	IEEE80211_KEY_GROUP	0x04	/* key used for WPA group operation */
     78  1.1.1.2  dyoung #define	IEEE80211_KEY_SWCRYPT	0x10	/* host-based encrypt/decrypt */
     79  1.1.1.2  dyoung #define	IEEE80211_KEY_SWMIC	0x20	/* host-based enmic/demic */
     80  1.1.1.2  dyoung 	u_int16_t	wk_keyix;	/* key index */
     81  1.1.1.2  dyoung 	u_int8_t	wk_key[IEEE80211_KEYBUF_SIZE+IEEE80211_MICBUF_SIZE];
     82  1.1.1.2  dyoung #define	wk_txmic	wk_key+IEEE80211_KEYBUF_SIZE+0	/* XXX can't () right */
     83  1.1.1.2  dyoung #define	wk_rxmic	wk_key+IEEE80211_KEYBUF_SIZE+8	/* XXX can't () right */
     84  1.1.1.2  dyoung 	u_int64_t	wk_keyrsc;	/* key receive sequence counter */
     85  1.1.1.2  dyoung 	u_int64_t	wk_keytsc;	/* key transmit sequence counter */
     86  1.1.1.2  dyoung 	const struct ieee80211_cipher *wk_cipher;
     87  1.1.1.2  dyoung 	void		*wk_private;	/* private cipher state */
     88  1.1.1.2  dyoung };
     89  1.1.1.2  dyoung #define	IEEE80211_KEY_COMMON 		/* common flags passed in by apps */\
     90  1.1.1.2  dyoung 	(IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV | IEEE80211_KEY_GROUP)
     91  1.1.1.2  dyoung 
     92  1.1.1.2  dyoung /*
     93  1.1.1.2  dyoung  * NB: these values are ordered carefully; there are lots of
     94  1.1.1.2  dyoung  * of implications in any reordering.  In particular beware
     95  1.1.1.2  dyoung  * that 4 is not used to avoid conflicting with IEEE80211_F_PRIVACY.
     96  1.1.1.2  dyoung  */
     97  1.1.1.2  dyoung #define	IEEE80211_CIPHER_WEP		0
     98  1.1.1.2  dyoung #define	IEEE80211_CIPHER_TKIP		1
     99  1.1.1.2  dyoung #define	IEEE80211_CIPHER_AES_OCB	2
    100  1.1.1.2  dyoung #define	IEEE80211_CIPHER_AES_CCM	3
    101  1.1.1.2  dyoung #define	IEEE80211_CIPHER_CKIP		5
    102  1.1.1.2  dyoung #define	IEEE80211_CIPHER_NONE		6	/* pseudo value */
    103  1.1.1.2  dyoung 
    104  1.1.1.2  dyoung #define	IEEE80211_CIPHER_MAX		(IEEE80211_CIPHER_NONE+1)
    105  1.1.1.2  dyoung 
    106  1.1.1.2  dyoung #define	IEEE80211_KEYIX_NONE	((u_int16_t) -1)
    107  1.1.1.2  dyoung 
    108  1.1.1.2  dyoung #if defined(__KERNEL__) || defined(_KERNEL)
    109  1.1.1.2  dyoung 
    110  1.1.1.2  dyoung struct ieee80211com;
    111  1.1.1.2  dyoung struct ieee80211_node;
    112  1.1.1.2  dyoung struct mbuf;
    113  1.1.1.2  dyoung 
    114  1.1.1.2  dyoung /*
    115  1.1.1.2  dyoung  * Crypto state kept in each ieee80211com.  Some of this
    116  1.1.1.2  dyoung  * can/should be shared when virtual AP's are supported.
    117  1.1.1.2  dyoung  *
    118  1.1.1.2  dyoung  * XXX save reference to ieee80211com to properly encapsulate state.
    119  1.1.1.2  dyoung  * XXX split out crypto capabilities from ic_caps
    120  1.1.1.2  dyoung  */
    121  1.1.1.2  dyoung struct ieee80211_crypto_state {
    122  1.1.1.2  dyoung 	struct ieee80211_key	cs_nw_keys[IEEE80211_WEP_NKID];
    123  1.1.1.2  dyoung 	u_int16_t		cs_def_txkey;	/* default/group tx key index */
    124  1.1.1.2  dyoung 
    125  1.1.1.2  dyoung 	int			(*cs_key_alloc)(struct ieee80211com *,
    126  1.1.1.2  dyoung 					const struct ieee80211_key *);
    127  1.1.1.2  dyoung 	int			(*cs_key_delete)(struct ieee80211com *,
    128  1.1.1.2  dyoung 					const struct ieee80211_key *);
    129  1.1.1.2  dyoung 	int			(*cs_key_set)(struct ieee80211com *,
    130  1.1.1.2  dyoung 					const struct ieee80211_key *,
    131  1.1.1.2  dyoung 					const u_int8_t mac[IEEE80211_ADDR_LEN]);
    132  1.1.1.2  dyoung 	void			(*cs_key_update_begin)(struct ieee80211com *);
    133  1.1.1.2  dyoung 	void			(*cs_key_update_end)(struct ieee80211com *);
    134  1.1.1.2  dyoung };
    135  1.1.1.2  dyoung 
    136  1.1.1.2  dyoung void	ieee80211_crypto_attach(struct ieee80211com *);
    137  1.1.1.2  dyoung void	ieee80211_crypto_detach(struct ieee80211com *);
    138  1.1.1.2  dyoung int	ieee80211_crypto_newkey(struct ieee80211com *,
    139  1.1.1.2  dyoung 		int cipher, int flags, struct ieee80211_key *);
    140  1.1.1.2  dyoung int	ieee80211_crypto_delkey(struct ieee80211com *,
    141  1.1.1.2  dyoung 		struct ieee80211_key *);
    142  1.1.1.2  dyoung int	ieee80211_crypto_setkey(struct ieee80211com *,
    143  1.1.1.2  dyoung 		struct ieee80211_key *, const u_int8_t macaddr[IEEE80211_ADDR_LEN]);
    144  1.1.1.2  dyoung void	ieee80211_crypto_delglobalkeys(struct ieee80211com *);
    145  1.1.1.2  dyoung 
    146  1.1.1.2  dyoung /*
    147  1.1.1.2  dyoung  * Template for a supported cipher.  Ciphers register with the
    148  1.1.1.2  dyoung  * crypto code and are typically loaded as separate modules
    149  1.1.1.2  dyoung  * (the null cipher is always present).
    150  1.1.1.2  dyoung  * XXX may need refcnts
    151  1.1.1.2  dyoung  */
    152  1.1.1.2  dyoung struct ieee80211_cipher {
    153  1.1.1.2  dyoung 	const char *ic_name;		/* printable name */
    154  1.1.1.2  dyoung 	u_int	ic_cipher;		/* IEEE80211_CIPHER_* */
    155  1.1.1.2  dyoung 	u_int	ic_header;		/* size of privacy header (bytes) */
    156  1.1.1.2  dyoung 	u_int	ic_trailer;		/* size of privacy trailer (bytes) */
    157  1.1.1.2  dyoung 	u_int	ic_miclen;		/* size of mic trailer (bytes) */
    158  1.1.1.2  dyoung 	void*	(*ic_attach)(struct ieee80211com *, struct ieee80211_key *);
    159  1.1.1.2  dyoung 	void	(*ic_detach)(struct ieee80211_key *);
    160  1.1.1.2  dyoung 	int	(*ic_setkey)(struct ieee80211_key *);
    161  1.1.1.2  dyoung 	int	(*ic_encap)(struct ieee80211_key *, struct mbuf *,
    162  1.1.1.2  dyoung 			u_int8_t keyid);
    163  1.1.1.2  dyoung 	int	(*ic_decap)(struct ieee80211_key *, struct mbuf *);
    164  1.1.1.2  dyoung 	int	(*ic_enmic)(struct ieee80211_key *, struct mbuf *);
    165  1.1.1.2  dyoung 	int	(*ic_demic)(struct ieee80211_key *, struct mbuf *);
    166      1.1  dyoung };
    167  1.1.1.2  dyoung extern	const struct ieee80211_cipher ieee80211_cipher_none;
    168  1.1.1.2  dyoung 
    169  1.1.1.2  dyoung void	ieee80211_crypto_register(const struct ieee80211_cipher *);
    170  1.1.1.2  dyoung void	ieee80211_crypto_unregister(const struct ieee80211_cipher *);
    171  1.1.1.2  dyoung int	ieee80211_crypto_available(u_int cipher);
    172      1.1  dyoung 
    173  1.1.1.2  dyoung struct ieee80211_key *ieee80211_crypto_encap(struct ieee80211com *,
    174  1.1.1.2  dyoung 		struct ieee80211_node *, struct mbuf *);
    175  1.1.1.2  dyoung struct ieee80211_key *ieee80211_crypto_decap(struct ieee80211com *,
    176  1.1.1.2  dyoung 		struct ieee80211_node *, struct mbuf *);
    177  1.1.1.2  dyoung 
    178  1.1.1.2  dyoung /*
    179  1.1.1.2  dyoung  * Check and remove any MIC.
    180  1.1.1.2  dyoung  */
    181  1.1.1.2  dyoung static __inline int
    182  1.1.1.2  dyoung ieee80211_crypto_demic(struct ieee80211com *ic, struct ieee80211_key *k,
    183  1.1.1.2  dyoung 	struct mbuf *m)
    184  1.1.1.2  dyoung {
    185  1.1.1.2  dyoung 	const struct ieee80211_cipher *cip = k->wk_cipher;
    186  1.1.1.2  dyoung 	return (cip->ic_miclen > 0 ? cip->ic_demic(k, m) : 1);
    187  1.1.1.2  dyoung }
    188  1.1.1.2  dyoung 
    189  1.1.1.2  dyoung /*
    190  1.1.1.2  dyoung  * Add any MIC.
    191  1.1.1.2  dyoung  */
    192  1.1.1.2  dyoung static __inline int
    193  1.1.1.2  dyoung ieee80211_crypto_enmic(struct ieee80211com *ic,
    194  1.1.1.2  dyoung 	struct ieee80211_key *k, struct mbuf *m)
    195  1.1.1.2  dyoung {
    196  1.1.1.2  dyoung 	const struct ieee80211_cipher *cip = k->wk_cipher;
    197  1.1.1.2  dyoung 	return (cip->ic_miclen > 0 ? cip->ic_enmic(k, m) : 1);
    198  1.1.1.2  dyoung }
    199  1.1.1.2  dyoung 
    200  1.1.1.2  dyoung /*
    201  1.1.1.2  dyoung  * Reset key state to an unused state.  The crypto
    202  1.1.1.2  dyoung  * key allocation mechanism insures other state (e.g.
    203  1.1.1.2  dyoung  * key data) is properly setup before a key is used.
    204  1.1.1.2  dyoung  */
    205  1.1.1.2  dyoung static __inline void
    206  1.1.1.2  dyoung ieee80211_crypto_resetkey(struct ieee80211com *ic,
    207  1.1.1.2  dyoung 	struct ieee80211_key *k, u_int16_t ix)
    208  1.1.1.2  dyoung {
    209  1.1.1.2  dyoung 	k->wk_cipher = &ieee80211_cipher_none;;
    210  1.1.1.2  dyoung 	k->wk_private = k->wk_cipher->ic_attach(ic, k);
    211  1.1.1.2  dyoung 	k->wk_keyix = ix;
    212  1.1.1.2  dyoung 	k->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
    213  1.1.1.2  dyoung }
    214  1.1.1.2  dyoung 
    215  1.1.1.2  dyoung /*
    216  1.1.1.2  dyoung  * Crypt-related notification methods.
    217  1.1.1.2  dyoung  */
    218  1.1.1.2  dyoung void	ieee80211_notify_replay_failure(struct ieee80211com *,
    219  1.1.1.2  dyoung 		const struct ieee80211_frame *, const struct ieee80211_key *,
    220  1.1.1.2  dyoung 		u_int64_t rsc);
    221  1.1.1.2  dyoung void	ieee80211_notify_michael_failure(struct ieee80211com *,
    222  1.1.1.2  dyoung 		const struct ieee80211_frame *, u_int keyix);
    223  1.1.1.2  dyoung #endif /* defined(__KERNEL__) || defined(_KERNEL) */
    224      1.1  dyoung #endif /* _NET80211_IEEE80211_CRYPTO_H_ */
    225