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