wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
wpa_common.c File Reference

WPA/RSN - Shared functions for supplicant and authenticator. More...

#include "includes.h"
#include "common.h"
#include "crypto/md5.h"
#include "crypto/sha1.h"
#include "crypto/sha256.h"
#include "crypto/sha384.h"
#include "crypto/aes_wrap.h"
#include "crypto/crypto.h"
#include "ieee802_11_defs.h"
#include "defs.h"
#include "wpa_common.h"

Functions

unsigned int wpa_mic_len (int akmp)
 
int wpa_eapol_key_mic (const u8 *key, size_t key_len, int akmp, int ver, const u8 *buf, size_t len, u8 *mic)
 Calculate EAPOL-Key MIC. More...
 
int wpa_pmk_to_ptk (const u8 *pmk, size_t pmk_len, const char *label, const u8 *addr1, const u8 *addr2, const u8 *nonce1, const u8 *nonce2, struct wpa_ptk *ptk, int akmp, int cipher)
 Calculate PTK from PMK, addresses, and nonces. More...
 
int wpa_cipher_valid_group (int cipher)
 
int wpa_parse_wpa_ie_rsn (const u8 *rsn_ie, size_t rsn_ie_len, struct wpa_ie_data *data)
 Parse RSN IE. More...
 
int wpa_parse_wpa_ie_wpa (const u8 *wpa_ie, size_t wpa_ie_len, struct wpa_ie_data *data)
 
void rsn_pmkid (const u8 *pmk, size_t pmk_len, const u8 *aa, const u8 *spa, u8 *pmkid, int use_sha256)
 Calculate PMK identifier. More...
 
const char * wpa_cipher_txt (int cipher)
 Convert cipher suite to a text string. More...
 
const char * wpa_key_mgmt_txt (int key_mgmt, int proto)
 Convert key management suite to a text string. More...
 
u32 wpa_akm_to_suite (int akm)
 
int wpa_compare_rsn_ie (int ft_initial_assoc, const u8 *ie1, size_t ie1len, const u8 *ie2, size_t ie2len)
 
int wpa_cipher_key_len (int cipher)
 
int wpa_cipher_rsc_len (int cipher)
 
int wpa_cipher_to_alg (int cipher)
 
int wpa_cipher_valid_pairwise (int cipher)
 
u32 wpa_cipher_to_suite (int proto, int cipher)
 
int rsn_cipher_put_suites (u8 *start, int ciphers)
 
int wpa_cipher_put_suites (u8 *start, int ciphers)
 
int wpa_pick_pairwise_cipher (int ciphers, int none_allowed)
 
int wpa_pick_group_cipher (int ciphers)
 
int wpa_parse_cipher (const char *value)
 
int wpa_write_ciphers (char *start, char *end, int ciphers, const char *delim)
 
int wpa_select_ap_group_cipher (int wpa, int wpa_pairwise, int rsn_pairwise)
 

Detailed Description

WPA/RSN - Shared functions for supplicant and authenticator.

Function Documentation

void rsn_pmkid ( const u8 *  pmk,
size_t  pmk_len,
const u8 *  aa,
const u8 *  spa,
u8 *  pmkid,
int  use_sha256 
)

Calculate PMK identifier.

Parameters
pmkPairwise master key
pmk_lenLength of pmk in bytes
aaAuthenticator address
spaSupplicant address
pmkidBuffer for PMKID
use_sha256Whether to use SHA256-based KDF

IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy PMKID = HMAC-SHA1-128(PMK, "PMK Name" || AA || SPA)

const char* wpa_cipher_txt ( int  cipher)

Convert cipher suite to a text string.

Parameters
cipherCipher suite (WPA_CIPHER_* enum)
Returns
Pointer to a text string of the cipher suite name
int wpa_eapol_key_mic ( const u8 *  key,
size_t  key_len,
int  akmp,
int  ver,
const u8 *  buf,
size_t  len,
u8 *  mic 
)

Calculate EAPOL-Key MIC.

Parameters
keyEAPOL-Key Key Confirmation Key (KCK)
key_lenKCK length in octets
akmpWPA_KEY_MGMT_* used in key derivation
verKey descriptor version (WPA_KEY_INFO_TYPE_*)
bufPointer to the beginning of the EAPOL header (version field)
lenLength of the EAPOL frame (from EAPOL header to the end of the frame)
micPointer to the buffer to which the EAPOL-Key MIC is written
Returns
0 on success, -1 on failure

Calculate EAPOL-Key MIC for an EAPOL-Key packet. The EAPOL-Key MIC field has to be cleared (all zeroes) when calling this function.

Note: 'IEEE Std 802.11i-2004 - 8.5.2 EAPOL-Key frames' has an error in the description of the Key MIC calculation. It includes packet data from the beginning of the EAPOL-Key header, not EAPOL header. This incorrect change happened during final editing of the standard and the correct behavior is defined in the last draft (IEEE 802.11i/D10).

const char* wpa_key_mgmt_txt ( int  key_mgmt,
int  proto 
)

Convert key management suite to a text string.

Parameters
key_mgmtKey management suite (WPA_KEY_MGMT_* enum)
protoWPA/WPA2 version (WPA_PROTO_*)
Returns
Pointer to a text string of the key management suite name
int wpa_parse_wpa_ie_rsn ( const u8 *  rsn_ie,
size_t  rsn_ie_len,
struct wpa_ie_data data 
)

Parse RSN IE.

Parameters
rsn_ieBuffer containing RSN IE
rsn_ie_lenRSN IE buffer length (including IE number and length octets)
dataPointer to structure that will be filled in with parsed data
Returns
0 on success, <0 on failure
int wpa_pmk_to_ptk ( const u8 *  pmk,
size_t  pmk_len,
const char *  label,
const u8 *  addr1,
const u8 *  addr2,
const u8 *  nonce1,
const u8 *  nonce2,
struct wpa_ptk ptk,
int  akmp,
int  cipher 
)

Calculate PTK from PMK, addresses, and nonces.

Parameters
pmkPairwise master key
pmk_lenLength of PMK
labelLabel to use in derivation
addr1AA or SA
addr2SA or AA
nonce1ANonce or SNonce
nonce2SNonce or ANonce
ptkBuffer for pairwise transient key
akmpNegotiated AKM
cipherNegotiated pairwise cipher
Returns
0 on success, -1 on failure

IEEE Std 802.11i-2004 - 8.5.1.2 Pairwise key hierarchy PTK = PRF-X(PMK, "Pairwise key expansion", Min(AA, SA) || Max(AA, SA) || Min(ANonce, SNonce) || Max(ANonce, SNonce))

STK = PRF-X(SMK, "Peer key expansion", Min(MAC_I, MAC_P) || Max(MAC_I, MAC_P) || Min(INonce, PNonce) || Max(INonce, PNonce))