13f3f4cdbSBruce M Simpson.\" 23f3f4cdbSBruce M Simpson.\" Copyright (c) 2004 Bruce M. Simpson <bms@spc.org> 33f3f4cdbSBruce M Simpson.\" Copyright (c) 2004 Darron Broad <darron@kewl.org> 43f3f4cdbSBruce M Simpson.\" All rights reserved. 53f3f4cdbSBruce M Simpson.\" 63f3f4cdbSBruce M Simpson.\" Redistribution and use in source and binary forms, with or without 73f3f4cdbSBruce M Simpson.\" modification, are permitted provided that the following conditions 83f3f4cdbSBruce M Simpson.\" are met: 93f3f4cdbSBruce M Simpson.\" 1. Redistributions of source code must retain the above copyright 103f3f4cdbSBruce M Simpson.\" notice, this list of conditions and the following disclaimer. 113f3f4cdbSBruce M Simpson.\" 2. Redistributions in binary form must reproduce the above copyright 123f3f4cdbSBruce M Simpson.\" notice, this list of conditions and the following disclaimer in the 133f3f4cdbSBruce M Simpson.\" documentation and/or other materials provided with the distribution. 143f3f4cdbSBruce M Simpson.\" 153f3f4cdbSBruce M Simpson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163f3f4cdbSBruce M Simpson.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173f3f4cdbSBruce M Simpson.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183f3f4cdbSBruce M Simpson.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193f3f4cdbSBruce M Simpson.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203f3f4cdbSBruce M Simpson.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213f3f4cdbSBruce M Simpson.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223f3f4cdbSBruce M Simpson.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233f3f4cdbSBruce M Simpson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243f3f4cdbSBruce M Simpson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253f3f4cdbSBruce M Simpson.\" SUCH DAMAGE. 263f3f4cdbSBruce M Simpson.\" $Id: ieee80211_crypto.9,v 1.3 2004/03/04 10:42:56 bruce Exp $ 273f3f4cdbSBruce M Simpson.\" 2811b168b8SEdward Tomasz Napierala.Dd March 29, 2010 292e777780SRuslan Ermilov.Dt IEEE80211_CRYPTO 9 303f3f4cdbSBruce M Simpson.Os 313f3f4cdbSBruce M Simpson.Sh NAME 32692eebe0SSam Leffler.Nm ieee80211_crypto 33692eebe0SSam Leffler.Nd 802.11 cryptographic support 343f3f4cdbSBruce M Simpson.Sh SYNOPSIS 35692eebe0SSam Leffler.In net80211/ieee80211_var.h 36692eebe0SSam Leffler.\" 37692eebe0SSam Leffler.Pp 383f3f4cdbSBruce M Simpson.Ft void 39692eebe0SSam Leffler.Fn ieee80211_crypto_register "const struct ieee80211_cipher *" 40692eebe0SSam Leffler.\" 413f3f4cdbSBruce M Simpson.Ft void 42692eebe0SSam Leffler.Fn ieee80211_crypto_unregister "const struct ieee80211_cipher *" 43692eebe0SSam Leffler.\" 44692eebe0SSam Leffler.Ft int 45692eebe0SSam Leffler.Fn ieee80211_crypto_available "int cipher" 46692eebe0SSam Leffler.\" 47692eebe0SSam Leffler.Pp 48692eebe0SSam Leffler.Ft void 49692eebe0SSam Leffler.Fo ieee80211_notify_replay_failure 50692eebe0SSam Leffler.Fa "struct ieee80211vap *" 51692eebe0SSam Leffler.Fa "const struct ieee80211_frame *" 52692eebe0SSam Leffler.Fa "const struct ieee80211_key *" 53692eebe0SSam Leffler.Fa "uint64_t rsc" 54692eebe0SSam Leffler.Fa "int tid" 55692eebe0SSam Leffler.Fc 56692eebe0SSam Leffler.\" 57692eebe0SSam Leffler.Ft void 58692eebe0SSam Leffler.Fo ieee80211_notify_michael_failure 59692eebe0SSam Leffler.Fa "struct ieee80211vap *" 60692eebe0SSam Leffler.Fa "const struct ieee80211_frame *" 61692eebe0SSam Leffler.Fa "u_int keyix" 62692eebe0SSam Leffler.Fc 63692eebe0SSam Leffler.\" 64692eebe0SSam Leffler.Ft int 65692eebe0SSam Leffler.Fo ieee80211_crypto_newkey 66ace02a6dSChristian Brueffer.Fa "struct ieee80211vap *" 67ace02a6dSChristian Brueffer.Fa "int cipher" 68ace02a6dSChristian Brueffer.Fa "int flags" 69ace02a6dSChristian Brueffer.Fa "struct ieee80211_key *" 70692eebe0SSam Leffler.Fc 71692eebe0SSam Leffler.\" 72692eebe0SSam Leffler.Ft int 73692eebe0SSam Leffler.Fn ieee80211_crypto_setkey "struct ieee80211vap *" "struct ieee80211_key *" 74692eebe0SSam Leffler.\" 75692eebe0SSam Leffler.Ft int 76692eebe0SSam Leffler.Fn ieee80211_crypto_delkey "struct ieee80211vap *" "struct ieee80211_key *" 77692eebe0SSam Leffler.\" 78692eebe0SSam Leffler.Ft void 79692eebe0SSam Leffler.Fn ieee80211_key_update_begin "struct ieee80211vap *" 80692eebe0SSam Leffler.\" 81692eebe0SSam Leffler.Ft void 82692eebe0SSam Leffler.Fn ieee80211_key_update_end "struct ieee80211vap *" 83692eebe0SSam Leffler.\" 84692eebe0SSam Leffler.Ft void 85692eebe0SSam Leffler.Fn ieee80211_crypto_delglobalkeys "struct ieee80211vap *" 86692eebe0SSam Leffler.\" 87692eebe0SSam Leffler.Ft void 88692eebe0SSam Leffler.Fn ieee80211_crypto_reload_keys "struct ieee80211com *" 89692eebe0SSam Leffler.\" 90692eebe0SSam Leffler.Pp 91692eebe0SSam Leffler.Ft struct ieee80211_key * 92692eebe0SSam Leffler.Fn ieee80211_crypto_encap "struct ieee80211_node *" "struct mbuf *" 93692eebe0SSam Leffler.\" 94692eebe0SSam Leffler.Ft struct ieee80211_key * 95692eebe0SSam Leffler.Fn ieee80211_crypto_decap "struct ieee80211_node *" "struct mbuf *" "int flags" 96692eebe0SSam Leffler.\" 97692eebe0SSam Leffler.Ft int 98692eebe0SSam Leffler.Fo ieee80211_crypto_demic 99692eebe0SSam Leffler.Fa "struct ieee80211vap *" 100692eebe0SSam Leffler.Fa "struct ieee80211_key *" 101692eebe0SSam Leffler.Fa "struct mbuf *" 102692eebe0SSam Leffler.Fa "int force" 103692eebe0SSam Leffler.Fc 104692eebe0SSam Leffler.\" 105692eebe0SSam Leffler.Ft int 106692eebe0SSam Leffler.Fo ieee80211_crypto_enmic 107692eebe0SSam Leffler.Fa "struct ieee80211vap *" 108692eebe0SSam Leffler.Fa "struct ieee80211_key *" 109692eebe0SSam Leffler.Fa "struct mbuf *" 110692eebe0SSam Leffler.Fa "int force" 111692eebe0SSam Leffler.Fc 1123f3f4cdbSBruce M Simpson.Sh DESCRIPTION 113692eebe0SSam LefflerThe 114692eebe0SSam Leffler.Nm net80211 115692eebe0SSam Lefflerlayer includes comprehensive cryptographic support for 802.11 protocols. 116692eebe0SSam LefflerSoftware implementations of ciphers required by 117692eebe0SSam LefflerWPA and 802.11i are provided as well as encap/decap processing of 802.11 frames. 118692eebe0SSam LefflerSoftware ciphers are written as kernel modules and 119692eebe0SSam Lefflerregister with the core crypto support. 120692eebe0SSam LefflerThe cryptographic framework supports hardware acceleration of ciphers 121692eebe0SSam Lefflerby drivers with automatic fall-back to software implementations when a 122692eebe0SSam Lefflerdriver is unable to provide necessary hardware services. 123692eebe0SSam Leffler.Sh CRYPTO CIPHER MODULES 124692eebe0SSam Leffler.Nm net80211 125692eebe0SSam Lefflercipher modules register their services using 126692eebe0SSam Leffler.Fn ieee80211_crypto_register 127692eebe0SSam Lefflerand supply a template that describes their operation. 128692eebe0SSam LefflerThis 129692eebe0SSam Leffler.Vt ieee80211_cipher 130692eebe0SSam Lefflerstructure defines protocol-related state such as the number of bytes 131692eebe0SSam Lefflerof space in the 802.11 header to reserve/remove during encap/decap 132692eebe0SSam Lefflerand entry points for setting up keys and doing cryptographic operations. 1333f3f4cdbSBruce M Simpson.Pp 134692eebe0SSam LefflerCipher modules can associate private state to each key through the 135692eebe0SSam Leffler.Vt wk_private 136692eebe0SSam Lefflerstructure member. 137692eebe0SSam LefflerIf state is setup by the module it will be called before a key is destroyed 138692eebe0SSam Lefflerso it can reclaim resources. 1393f3f4cdbSBruce M Simpson.Pp 140692eebe0SSam LefflerCrypto modules can notify the system of two events. 141692eebe0SSam LefflerWhen a packet replay event is recognized 142ace02a6dSChristian Brueffer.Fn ieee80211_notify_replay_failure 143692eebe0SSam Lefflercan be used to signal the event. 144692eebe0SSam LefflerWhen a 145692eebe0SSam Leffler.Dv TKIP 146692eebe0SSam LefflerMichael failure is detected 147692eebe0SSam Leffler.Fn ieee80211_notify_michael_failure 148692eebe0SSam Lefflercan be invoked. 149692eebe0SSam LefflerDrivers may also use these routines to signal events detected by the 150692eebe0SSam Lefflerhardware. 151692eebe0SSam Leffler.Sh CRYPTO KEY MANAGEMENT 1523f3f4cdbSBruce M SimpsonThe 153692eebe0SSam Leffler.Nm net80211 154692eebe0SSam Lefflerlayer implements a per-vap 4-element 155692eebe0SSam Leffler.Dq global key table 156692eebe0SSam Lefflerand a per-station 157692eebe0SSam Leffler.Dq unicast key 158692eebe0SSam Lefflerfor protocols such as WPA, 802.1x, and 802.11i. 159692eebe0SSam LefflerThe global key table is designed to support legacy WEP operation 160692eebe0SSam Lefflerand Multicast/Group keys, 161692eebe0SSam Lefflerthough some applications also use it to implement WPA in station mode. 162692eebe0SSam LefflerKeys in the global table are identified by a key index in the range 0-3. 163692eebe0SSam LefflerPer-station keys are identified by the MAC address of the station and 164692eebe0SSam Lefflerare typically used for unicast PTK bindings. 1653f3f4cdbSBruce M Simpson.Pp 166692eebe0SSam Leffler.Nm net80211 167692eebe0SSam Lefflerprovides 168692eebe0SSam Leffler.Xr ioctl 2 169692eebe0SSam Leffleroperations for managing both global and per-station keys. 170692eebe0SSam LefflerDrivers typically do not participate in software key management; 171692eebe0SSam Lefflerthey are involved only when providing hardware acceleration of 172692eebe0SSam Lefflercryptographic operations. 173692eebe0SSam Leffler.Pp 174692eebe0SSam Leffler.Fn ieee80211_crypto_newkey 175692eebe0SSam Leffleris used to allocate a new 176692eebe0SSam Leffler.Nm net80211 177692eebe0SSam Lefflerkey or reconfigure an existing key. 178692eebe0SSam LefflerThe cipher must be specified along with any fixed key index. 1793f3f4cdbSBruce M SimpsonThe 180692eebe0SSam Leffler.Nm net80211 181692eebe0SSam Lefflerlayer will handle allocating cipher and driver resources to support the key. 182692eebe0SSam Leffler.Pp 183692eebe0SSam LefflerOnce a key is allocated it's contents can be set using 184692eebe0SSam Leffler.Fn ieee80211_crypto_setkey 185692eebe0SSam Lefflerand deleted with 186692eebe0SSam Leffler.Fn ieee80211_crypto_delkey 187692eebe0SSam Leffler(with any cipher and driver resources reclaimed). 188692eebe0SSam Leffler.Pp 189692eebe0SSam Leffler.Fn ieee80211_crypto_delglobalkeys 190692eebe0SSam Leffleris used to reclaim all keys in the global key table for a vap; it 191692eebe0SSam Lefflertypically is used only within the 192692eebe0SSam Leffler.Nm net80211 193692eebe0SSam Lefflerlayer. 194692eebe0SSam Leffler.Pp 195692eebe0SSam Leffler.Fn ieee80211_crypto_reload_keys 196692eebe0SSam Lefflerhandles hardware key state reloading from software key state, such 197692eebe0SSam Leffleras required after a suspend/resume cycle. 198692eebe0SSam Leffler.Sh DRIVER CRYPTO SUPPORT 199692eebe0SSam LefflerDrivers identify ciphers they have hardware support for through the 200692eebe0SSam Leffler.Vt ic_cryptocaps 201692eebe0SSam Lefflerfield of the 202692eebe0SSam Leffler.Vt ieee80211com 203692eebe0SSam Lefflerstructure. 204692eebe0SSam LefflerIf hardware support is available then a driver should also fill in the 205692eebe0SSam Leffler.Dv iv_key_alloc , 206692eebe0SSam Leffler.Dv iv_key_set , 2073f3f4cdbSBruce M Simpsonand 208692eebe0SSam Leffler.Dv iv_key_delete 209692eebe0SSam Lefflermethods of each 210692eebe0SSam Leffler.Vt ieee80211vap 211692eebe0SSam Lefflercreated for use with the device. 212692eebe0SSam LefflerIn addition the methods 213692eebe0SSam Leffler.Dv iv_key_update_begin 214692eebe0SSam Lefflerand 215692eebe0SSam Leffler.Dv iv_key_update_end 216692eebe0SSam Lefflercan be setup to handle synchronization requirements 217692eebe0SSam Lefflerfor updating hardware key state. 218692eebe0SSam Leffler.Pp 219692eebe0SSam LefflerWhen 220692eebe0SSam Leffler.Nm net80211 221692eebe0SSam Lefflerallocates a software key and the driver can accelerate the 222692eebe0SSam Lefflercipher operations the 223692eebe0SSam Leffler.Dv iv_key_alloc 224692eebe0SSam Lefflermethod will be invoked. 225692eebe0SSam LefflerDrivers may return a token that is associated with outbound traffic 226692eebe0SSam Leffler(for use in encrypting frames). 227692eebe0SSam LefflerOtherwise, e.g. if hardware resources are not available, the driver will 228692eebe0SSam Lefflernot return a token and 229692eebe0SSam Leffler.Nm net80211 230692eebe0SSam Lefflerwill arrange to do the work in software and pass frames 231692eebe0SSam Lefflerto the driver that are already prepared for transmission. 232692eebe0SSam Leffler.Pp 233692eebe0SSam LefflerFor receive, drivers mark frames with the 234692eebe0SSam Leffler.Dv M_WEP 235692eebe0SSam Lefflermbuf flag to indicate the hardware has decrypted the payload. 236692eebe0SSam LefflerIf frames have the 2375945b5f5SKevin Lo.Dv IEEE80211_FC1_PROTECTED 238692eebe0SSam Lefflerbit marked in their 802.11 header and are not tagged with 239692eebe0SSam Leffler.Dv M_WEP 240692eebe0SSam Lefflerthen decryption is done in software. 241692eebe0SSam LefflerFor more complicated scenarios the software key state is consulted; e.g. 242692eebe0SSam Lefflerto decide if Michael verification needs to be done in software after 243692eebe0SSam Lefflerthe hardware has handled TKIP decryption. 244692eebe0SSam Leffler.Pp 245692eebe0SSam LefflerDrivers that manage complicated key data structures, e.g. faulting 246692eebe0SSam Lefflersoftware keys into a hardware key cache, can safely manipulate software 247692eebe0SSam Lefflerkey state by bracketing their work with calls to 248692eebe0SSam Leffler.Fn ieee80211_key_update_begin 249692eebe0SSam Lefflerand 250692eebe0SSam Leffler.Fn ieee80211_key_update_end . 251692eebe0SSam LefflerThese calls also synchronize hardware key state update 252692eebe0SSam Lefflerwhen receive traffic is active. 253692eebe0SSam Leffler.Sh SEE ALSO 254692eebe0SSam Leffler.Xr ioctl 2 , 255692eebe0SSam Leffler.Xr wlan_ccmp 4 , 256692eebe0SSam Leffler.Xr wlan_tkip 4 , 257*1e9469d1SChristian Brueffer.Xr wlan_wep 4 , 258*1e9469d1SChristian Brueffer.Xr ieee80211 9 259