iPXE
|
Backend for WPA using the CCMP encryption method. More...
#include <string.h>
#include <ipxe/net80211.h>
#include <ipxe/crypto.h>
#include <ipxe/hmac.h>
#include <ipxe/sha1.h>
#include <ipxe/aes.h>
#include <ipxe/wpa.h>
#include <byteswap.h>
#include <errno.h>
Go to the source code of this file.
Data Structures | |
struct | ccmp_ctx |
Context for CCMP encryption and decryption. More... | |
struct | ccmp_head |
Header structure at the beginning of CCMP frame data. More... | |
struct | ccmp_nonce |
CCMP nonce structure. More... | |
struct | ccmp_aad |
CCMP additional authentication data structure. More... | |
Macros | |
#define | CCMP_HEAD_LEN 8 |
CCMP header overhead. More... | |
#define | CCMP_MIC_LEN 8 |
CCMP MIC trailer overhead. More... | |
#define | CCMP_NONCE_LEN 13 |
CCMP nonce length. More... | |
#define | CCMP_AAD_LEN 22 |
CCMP additional authentication data length (for non-QoS, non-WDS frames) More... | |
#define | CCMP_AAD_FC_MASK 0xC38F |
Mask for Frame Control field in AAD. More... | |
#define | CCMP_AAD_SEQ_MASK 0x000F |
Mask for Sequence Control field in AAD. More... | |
#define | PN_MSB 1 |
Value for msb argument of u64_to_pn() for MSB output. More... | |
#define | PN_LSB 0 |
Value for msb argument of u64_to_pn() for LSB output. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER) | |
static u64 | pn_to_u64 (const u8 *pn) |
Convert 6-byte LSB packet number to 64-bit integer. More... | |
static void | u64_to_pn (u64 v, u8 *pn, int msb) |
Convert 64-bit integer to 6-byte packet number. More... | |
static int | ccmp_init (struct net80211_crypto *crypto, const void *key, int keylen, const void *rsc) |
Initialise CCMP state and install key. More... | |
static void | ccmp_ctr_xor (struct ccmp_ctx *ctx, const void *nonce, const void *srcv, void *destv, int len, const void *msrcv, void *mdestv) |
Encrypt or decrypt data stream using AES in Counter mode. More... | |
static void | ccmp_feed_cbc_mac (void *aes_ctx, u8 *B, u8 *X) |
Advance one block in CBC-MAC calculation. More... | |
static void | ccmp_cbc_mac (struct ccmp_ctx *ctx, const void *nonce, const void *data, u16 datalen, const void *aad, void *mic) |
Calculate MIC on plaintext data using CBC-MAC. More... | |
struct io_buffer * | ccmp_encrypt (struct net80211_crypto *crypto, struct io_buffer *iob) |
Encapsulate and encrypt a packet using CCMP. More... | |
static struct io_buffer * | ccmp_decrypt (struct net80211_crypto *crypto, struct io_buffer *eiob) |
Decrypt a packet using CCMP. More... | |
static void | ccmp_kie_mic (const void *kck, const void *msg, size_t len, void *mic) |
Calculate HMAC-SHA1 MIC for EAPOL-Key frame. More... | |
static int | ccmp_kie_decrypt (const void *kek, const void *iv __unused, void *msg, u16 *len) |
Decrypt key data in EAPOL-Key frame. More... | |
Variables | |
struct net80211_crypto ccmp_crypto | __net80211_crypto |
CCMP cryptosystem. More... | |
struct wpa_kie ccmp_kie | __wpa_kie |
CCMP-style key integrity and encryption handler. More... | |
Backend for WPA using the CCMP encryption method.
Definition in file wpa_ccmp.c.
#define CCMP_HEAD_LEN 8 |
CCMP header overhead.
Definition at line 61 of file wpa_ccmp.c.
#define CCMP_MIC_LEN 8 |
CCMP MIC trailer overhead.
Definition at line 64 of file wpa_ccmp.c.
#define CCMP_NONCE_LEN 13 |
CCMP nonce length.
Definition at line 67 of file wpa_ccmp.c.
#define CCMP_AAD_LEN 22 |
CCMP additional authentication data length (for non-QoS, non-WDS frames)
Definition at line 78 of file wpa_ccmp.c.
#define CCMP_AAD_FC_MASK 0xC38F |
Mask for Frame Control field in AAD.
Definition at line 92 of file wpa_ccmp.c.
#define CCMP_AAD_SEQ_MASK 0x000F |
Mask for Sequence Control field in AAD.
Definition at line 95 of file wpa_ccmp.c.
#define PN_MSB 1 |
Value for msb argument of u64_to_pn() for MSB output.
Definition at line 141 of file wpa_ccmp.c.
#define PN_LSB 0 |
Value for msb argument of u64_to_pn() for LSB output.
Definition at line 144 of file wpa_ccmp.c.
FILE_LICENCE | ( | GPL2_OR_LATER | ) |
Convert 6-byte LSB packet number to 64-bit integer.
pn | Pointer to 6-byte packet number |
v | 64-bit integer value of pn |
Definition at line 104 of file wpa_ccmp.c.
Referenced by ccmp_decrypt(), and ccmp_init().
Convert 64-bit integer to 6-byte packet number.
v | 64-bit integer |
msb | If TRUE, reverse the output PN to be in MSB order |
pn | 6-byte packet number |
The PN is stored in LSB order in the packet header and in MSB order in the nonce. WHYYYYY?
Definition at line 127 of file wpa_ccmp.c.
Referenced by ccmp_decrypt(), and ccmp_encrypt().
|
static |
Initialise CCMP state and install key.
crypto | CCMP cryptosystem structure |
key | Pointer to 16-byte temporal key to install |
keylen | Length of key (16 bytes) |
rsc | Initial receive sequence counter |
Definition at line 156 of file wpa_ccmp.c.
References aes_algorithm, cipher_setkey(), ctx, EINVAL, key, pn_to_u64(), net80211_crypto::priv, and rsc.
|
static |
Encrypt or decrypt data stream using AES in Counter mode.
ctx | CCMP cryptosystem context |
nonce | Nonce value, 13 bytes |
srcv | Data to encrypt or decrypt |
len | Number of bytes pointed to by src |
msrcv | MIC value to encrypt or decrypt (may be NULL) |
destv | Encrypted or decrypted data |
mdestv | Encrypted or decrypted MIC value |
This assumes CCMP parameters of L=2 and M=8. The algorithm is defined in RFC 3610.
Definition at line 187 of file wpa_ccmp.c.
References aes_algorithm, CCMP_NONCE_LEN, cipher_encrypt, ctx, dest, len, memcpy(), nonce, S(), and src.
Referenced by ccmp_decrypt(), and ccmp_encrypt().
Advance one block in CBC-MAC calculation.
aes_ctx | AES encryption context with key set |
B | Cleartext block to incorporate (16 bytes) |
X | Previous ciphertext block (16 bytes) |
B | Clobbered |
X | New ciphertext block (16 bytes) |
This function does X := E[key] ( X ^ B ).
Definition at line 238 of file wpa_ccmp.c.
References aes_algorithm, ccmp_ctx::aes_ctx, and cipher_encrypt.
Referenced by ccmp_cbc_mac().
|
static |
Calculate MIC on plaintext data using CBC-MAC.
ctx | CCMP cryptosystem context |
nonce | Nonce value, 13 bytes |
data | Data to calculate MIC over |
datalen | Length of data |
aad | Additional authentication data, for MIC but not encryption |
mic | MIC value (unencrypted), 8 bytes |
aadlen is assumed to be 22 bytes long, as it always is for 802.11 use when transmitting non-QoS, not-between-APs frames (the only type we deal with).
Definition at line 261 of file wpa_ccmp.c.
References aes_algorithm, CCMP_AAD_LEN, ccmp_feed_cbc_mac(), CCMP_NONCE_LEN, cipher_encrypt, ctx, data, datalen, memcpy(), memset(), mic, and nonce.
Referenced by ccmp_decrypt(), and ccmp_encrypt().
struct io_buffer* ccmp_encrypt | ( | struct net80211_crypto * | crypto, |
struct io_buffer * | iob | ||
) |
Encapsulate and encrypt a packet using CCMP.
crypto | CCMP cryptosystem |
iob | I/O buffer containing cleartext packet |
eiob | I/O buffer containing encrypted packet |
Definition at line 320 of file wpa_ccmp.c.
References ccmp_aad::a1, alloc_iob(), CCMP_AAD_FC_MASK, CCMP_AAD_SEQ_MASK, ccmp_cbc_mac(), ccmp_ctr_xor(), CCMP_HEAD_LEN, CCMP_MIC_LEN, ctx, io_buffer::data, datalen, DBGC2, ETH_ALEN, ccmp_aad::fc, hdr, head, IEEE80211_FC_PROTECTED, IEEE80211_TYP_FRAME_HEADER_LEN, iob_len(), iob_put, memcpy(), mic, nonce, NULL, PN_LSB, PN_MSB, net80211_crypto::priv, ccmp_aad::seq, and u64_to_pn().
|
static |
Decrypt a packet using CCMP.
crypto | CCMP cryptosystem |
eiob | I/O buffer containing encrypted packet |
iob | I/O buffer containing cleartext packet |
Definition at line 388 of file wpa_ccmp.c.
References ccmp_aad::a1, alloc_iob(), CCMP_AAD_FC_MASK, CCMP_AAD_SEQ_MASK, ccmp_cbc_mac(), ccmp_ctr_xor(), CCMP_HEAD_LEN, CCMP_MIC_LEN, ctx, io_buffer::data, datalen, DBGC, DBGC2, ETH_ALEN, ccmp_aad::fc, free_iob(), hdr, head, IEEE80211_FC_PROTECTED, IEEE80211_TYP_FRAME_HEADER_LEN, iob_len(), iob_put, memcmp(), memcpy(), nonce, NULL, PN_MSB, pn_to_u64(), net80211_crypto::priv, ccmp_aad::seq, io_buffer::tail, and u64_to_pn().
|
static |
Calculate HMAC-SHA1 MIC for EAPOL-Key frame.
kck | Key Confirmation Key, 16 bytes |
msg | Message to calculate MIC over |
len | Number of bytes to calculate MIC over |
mic | Calculated MIC, 16 bytes long |
Definition at line 478 of file wpa_ccmp.c.
References ctx, hash, hmac_final(), hmac_init(), hmac_update(), kck, len, memcpy(), mic, msg(), sha1_algorithm, SHA1_BLOCK_SIZE, SHA1_CTX_SIZE, and SHA1_DIGEST_SIZE.
|
static |
Decrypt key data in EAPOL-Key frame.
kek | Key Encryption Key, 16 bytes |
iv | Initialisation vector, 16 bytes (unused) |
msg | Message to decrypt |
len | Length of message |
msg | Decrypted message in place of original |
len | Adjusted downward for 8 bytes of overhead |
rc | Return status code |
The returned message may still contain padding of 0xDD followed by zero or more 0x00 octets. It is impossible to remove the padding without parsing the IEs in the packet (another design decision that tends to make one question the 802.11i committee's intelligence...)
Definition at line 510 of file wpa_ccmp.c.
References aes_unwrap(), EINVAL, kek, len, and msg().
struct net80211_crypto ccmp_crypto __net80211_crypto |
CCMP cryptosystem.
Definition at line 459 of file wpa_ccmp.c.
struct wpa_kie ccmp_kie __wpa_kie |
CCMP-style key integrity and encryption handler.
Definition at line 525 of file wpa_ccmp.c.