iPXE
wpa_ccmp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 FILE_SECBOOT ( FORBIDDEN );
22 
23 #include <string.h>
24 #include <ipxe/net80211.h>
25 #include <ipxe/crypto.h>
26 #include <ipxe/hmac.h>
27 #include <ipxe/sha1.h>
28 #include <ipxe/aes.h>
29 #include <ipxe/wpa.h>
30 #include <byteswap.h>
31 #include <errno.h>
32 
33 /** @file
34  *
35  * Backend for WPA using the CCMP encryption method
36  */
37 
38 /** Context for CCMP encryption and decryption */
39 struct ccmp_ctx
40 {
41  /** AES context - only ever used for encryption */
43 
44  /** Most recently sent packet number */
46 
47  /** Most recently received packet number */
49 };
50 
51 /** Header structure at the beginning of CCMP frame data */
52 struct ccmp_head
53 {
54  u8 pn_lo[2]; /**< Bytes 0 and 1 of packet number */
55  u8 _rsvd; /**< Reserved byte */
56  u8 kid; /**< Key ID and ExtIV byte */
57  u8 pn_hi[4]; /**< Bytes 2-5 (2 first) of packet number */
58 } __attribute__ (( packed ));
59 
60 
61 /** CCMP header overhead */
62 #define CCMP_HEAD_LEN 8
63 
64 /** CCMP MIC trailer overhead */
65 #define CCMP_MIC_LEN 8
66 
67 /** CCMP nonce length */
68 #define CCMP_NONCE_LEN 13
69 
70 /** CCMP nonce structure */
71 struct ccmp_nonce
72 {
73  u8 prio; /**< Packet priority, 0 for non-QoS */
74  u8 a2[ETH_ALEN]; /**< Address 2 from packet header (sender) */
75  u8 pn[6]; /**< Packet number */
76 } __attribute__ (( packed ));
77 
78 /** CCMP additional authentication data length (for non-QoS, non-WDS frames) */
79 #define CCMP_AAD_LEN 22
80 
81 /** CCMP additional authentication data structure */
82 struct ccmp_aad
83 {
84  u16 fc; /**< Frame Control field */
85  u8 a1[6]; /**< Address 1 */
86  u8 a2[6]; /**< Address 2 */
87  u8 a3[6]; /**< Address 3 */
88  u16 seq; /**< Sequence Control field */
89  /* Address 4 and QoS Control are included if present */
90 } __attribute__ (( packed ));
91 
92 /** Mask for Frame Control field in AAD */
93 #define CCMP_AAD_FC_MASK 0xC38F
94 
95 /** Mask for Sequence Control field in AAD */
96 #define CCMP_AAD_SEQ_MASK 0x000F
97 
98 
99 /**
100  * Convert 6-byte LSB packet number to 64-bit integer
101  *
102  * @v pn Pointer to 6-byte packet number
103  * @ret v 64-bit integer value of @a pn
104  */
105 static u64 pn_to_u64 ( const u8 *pn )
106 {
107  int i;
108  u64 ret = 0;
109 
110  for ( i = 5; i >= 0; i-- ) {
111  ret <<= 8;
112  ret |= pn[i];
113  }
114 
115  return ret;
116 }
117 
118 /**
119  * Convert 64-bit integer to 6-byte packet number
120  *
121  * @v v 64-bit integer
122  * @v msb If TRUE, reverse the output PN to be in MSB order
123  * @ret pn 6-byte packet number
124  *
125  * The PN is stored in LSB order in the packet header and in MSB order
126  * in the nonce. WHYYYYY?
127  */
128 static void u64_to_pn ( u64 v, u8 *pn, int msb )
129 {
130  int i;
131  u8 *pnp = pn + ( msb ? 5 : 0 );
132  int delta = ( msb ? -1 : +1 );
133 
134  for ( i = 0; i < 6; i++ ) {
135  *pnp = v & 0xFF;
136  pnp += delta;
137  v >>= 8;
138  }
139 }
140 
141 /** Value for @a msb argument of u64_to_pn() for MSB output */
142 #define PN_MSB 1
143 
144 /** Value for @a msb argument of u64_to_pn() for LSB output */
145 #define PN_LSB 0
146 
147 
148 
149 /**
150  * Initialise CCMP state and install key
151  *
152  * @v crypto CCMP cryptosystem structure
153  * @v key Pointer to 16-byte temporal key to install
154  * @v keylen Length of key (16 bytes)
155  * @v rsc Initial receive sequence counter
156  */
157 static int ccmp_init ( struct net80211_crypto *crypto, const void *key,
158  int keylen, const void *rsc )
159 {
160  struct ccmp_ctx *ctx = crypto->priv;
161 
162  if ( keylen != 16 )
163  return -EINVAL;
164 
165  if ( rsc )
166  ctx->rx_seq = pn_to_u64 ( rsc );
167 
168  cipher_setkey ( &aes_algorithm, ctx->aes_ctx, key, keylen );
169 
170  return 0;
171 }
172 
173 
174 /**
175  * Encrypt or decrypt data stream using AES in Counter mode
176  *
177  * @v ctx CCMP cryptosystem context
178  * @v nonce Nonce value, 13 bytes
179  * @v srcv Data to encrypt or decrypt
180  * @v len Number of bytes pointed to by @a src
181  * @v msrcv MIC value to encrypt or decrypt (may be NULL)
182  * @ret destv Encrypted or decrypted data
183  * @ret mdestv Encrypted or decrypted MIC value
184  *
185  * This assumes CCMP parameters of L=2 and M=8. The algorithm is
186  * defined in RFC 3610.
187  */
188 static void ccmp_ctr_xor ( struct ccmp_ctx *ctx, const void *nonce,
189  const void *srcv, void *destv, int len,
190  const void *msrcv, void *mdestv )
191 {
192  u8 A[16], S[16];
193  u16 ctr;
194  int i;
195  const u8 *src = srcv, *msrc = msrcv;
196  u8 *dest = destv, *mdest = mdestv;
197 
198  A[0] = 0x01; /* flags, L' = L - 1 = 1, other bits rsvd */
199  memcpy ( A + 1, nonce, CCMP_NONCE_LEN );
200 
201  if ( msrcv ) {
202  A[14] = A[15] = 0;
203 
204  cipher_encrypt ( &aes_algorithm, ctx->aes_ctx, A, S, 16 );
205 
206  for ( i = 0; i < 8; i++ ) {
207  *mdest++ = *msrc++ ^ S[i];
208  }
209  }
210 
211  for ( ctr = 1 ;; ctr++ ) {
212  A[14] = ctr >> 8;
213  A[15] = ctr & 0xFF;
214 
215  cipher_encrypt ( &aes_algorithm, ctx->aes_ctx, A, S, 16 );
216 
217  for ( i = 0; i < len && i < 16; i++ )
218  *dest++ = *src++ ^ S[i];
219 
220  if ( len <= 16 )
221  break; /* we're done */
222 
223  len -= 16;
224  }
225 }
226 
227 
228 /**
229  * Advance one block in CBC-MAC calculation
230  *
231  * @v aes_ctx AES encryption context with key set
232  * @v B Cleartext block to incorporate (16 bytes)
233  * @v X Previous ciphertext block (16 bytes)
234  * @ret B Clobbered
235  * @ret X New ciphertext block (16 bytes)
236  *
237  * This function does X := E[key] ( X ^ B ).
238  */
239 static void ccmp_feed_cbc_mac ( void *aes_ctx, u8 *B, u8 *X )
240 {
241  int i;
242  for ( i = 0; i < 16; i++ )
243  B[i] ^= X[i];
244  cipher_encrypt ( &aes_algorithm, aes_ctx, B, X, 16 );
245 }
246 
247 
248 /**
249  * Calculate MIC on plaintext data using CBC-MAC
250  *
251  * @v ctx CCMP cryptosystem context
252  * @v nonce Nonce value, 13 bytes
253  * @v data Data to calculate MIC over
254  * @v datalen Length of @a data
255  * @v aad Additional authentication data, for MIC but not encryption
256  * @ret mic MIC value (unencrypted), 8 bytes
257  *
258  * @a aadlen is assumed to be 22 bytes long, as it always is for
259  * 802.11 use when transmitting non-QoS, not-between-APs frames (the
260  * only type we deal with).
261  */
262 static void ccmp_cbc_mac ( struct ccmp_ctx *ctx, const void *nonce,
263  const void *data, u16 datalen,
264  const void *aad, void *mic )
265 {
266  u8 X[16], B[16];
267 
268  /* Zeroth block: flags, nonce, length */
269 
270  /* Rsv AAD - M'- - L'-
271  * 0 1 0 1 1 0 0 1 for an 8-byte MAC and 2-byte message length
272  */
273  B[0] = 0x59;
274  memcpy ( B + 1, nonce, CCMP_NONCE_LEN );
275  B[14] = datalen >> 8;
276  B[15] = datalen & 0xFF;
277 
278  cipher_encrypt ( &aes_algorithm, ctx->aes_ctx, B, X, 16 );
279 
280  /* First block: AAD length field and 14 bytes of AAD */
281  B[0] = 0;
282  B[1] = CCMP_AAD_LEN;
283  memcpy ( B + 2, aad, 14 );
284 
285  ccmp_feed_cbc_mac ( ctx->aes_ctx, B, X );
286 
287  /* Second block: Remaining 8 bytes of AAD, 8 bytes zero pad */
288  memcpy ( B, aad + 14, 8 );
289  memset ( B + 8, 0, 8 );
290 
291  ccmp_feed_cbc_mac ( ctx->aes_ctx, B, X );
292 
293  /* Message blocks */
294  while ( datalen ) {
295  if ( datalen >= 16 ) {
296  memcpy ( B, data, 16 );
297  datalen -= 16;
298  } else {
299  memcpy ( B, data, datalen );
300  memset ( B + datalen, 0, 16 - datalen );
301  datalen = 0;
302  }
303 
304  ccmp_feed_cbc_mac ( ctx->aes_ctx, B, X );
305 
306  data += 16;
307  }
308 
309  /* Get MIC from final value of X */
310  memcpy ( mic, X, 8 );
311 }
312 
313 
314 /**
315  * Encapsulate and encrypt a packet using CCMP
316  *
317  * @v crypto CCMP cryptosystem
318  * @v iob I/O buffer containing cleartext packet
319  * @ret eiob I/O buffer containing encrypted packet
320  */
321 struct io_buffer * ccmp_encrypt ( struct net80211_crypto *crypto,
322  struct io_buffer *iob )
323 {
324  struct ccmp_ctx *ctx = crypto->priv;
325  struct ieee80211_frame *hdr = iob->data;
326  struct io_buffer *eiob;
327  const int hdrlen = IEEE80211_TYP_FRAME_HEADER_LEN;
328  int datalen = iob_len ( iob ) - hdrlen;
329  struct ccmp_head head;
330  struct ccmp_nonce nonce;
331  struct ccmp_aad aad;
332  u8 mic[8], tx_pn[6];
333  void *edata, *emic;
334 
335  ctx->tx_seq++;
336  u64_to_pn ( ctx->tx_seq, tx_pn, PN_LSB );
337 
338  /* Allocate memory */
339  eiob = alloc_iob ( iob_len ( iob ) + CCMP_HEAD_LEN + CCMP_MIC_LEN );
340  if ( ! eiob )
341  return NULL;
342 
343  /* Copy frame header */
344  memcpy ( iob_put ( eiob, hdrlen ), iob->data, hdrlen );
345  hdr = eiob->data;
347 
348  /* Fill in packet number and extended IV */
349  memcpy ( head.pn_lo, tx_pn, 2 );
350  memcpy ( head.pn_hi, tx_pn + 2, 4 );
351  head.kid = 0x20; /* have Extended IV, key ID 0 */
352  head._rsvd = 0;
353  memcpy ( iob_put ( eiob, sizeof ( head ) ), &head, sizeof ( head ) );
354 
355  /* Form nonce */
356  nonce.prio = 0;
357  memcpy ( nonce.a2, hdr->addr2, ETH_ALEN );
358  u64_to_pn ( ctx->tx_seq, nonce.pn, PN_MSB );
359 
360  /* Form additional authentication data */
361  aad.fc = hdr->fc & CCMP_AAD_FC_MASK;
362  memcpy ( aad.a1, hdr->addr1, 3 * ETH_ALEN ); /* all 3 at once */
363  aad.seq = hdr->seq & CCMP_AAD_SEQ_MASK;
364 
365  /* Calculate MIC over the data */
366  ccmp_cbc_mac ( ctx, &nonce, iob->data + hdrlen, datalen, &aad, mic );
367 
368  /* Copy and encrypt data and MIC */
369  edata = iob_put ( eiob, datalen );
370  emic = iob_put ( eiob, CCMP_MIC_LEN );
371  ccmp_ctr_xor ( ctx, &nonce,
372  iob->data + hdrlen, edata, datalen,
373  mic, emic );
374 
375  /* Done! */
376  DBGC2 ( ctx, "WPA-CCMP %p: encrypted packet %p -> %p\n", ctx,
377  iob, eiob );
378 
379  return eiob;
380 }
381 
382 /**
383  * Decrypt a packet using CCMP
384  *
385  * @v crypto CCMP cryptosystem
386  * @v eiob I/O buffer containing encrypted packet
387  * @ret iob I/O buffer containing cleartext packet
388  */
389 static struct io_buffer * ccmp_decrypt ( struct net80211_crypto *crypto,
390  struct io_buffer *eiob )
391 {
392  struct ccmp_ctx *ctx = crypto->priv;
393  struct ieee80211_frame *hdr;
394  struct io_buffer *iob;
395  const int hdrlen = IEEE80211_TYP_FRAME_HEADER_LEN;
396  int datalen = iob_len ( eiob ) - hdrlen - CCMP_HEAD_LEN - CCMP_MIC_LEN;
397  struct ccmp_head *head;
398  struct ccmp_nonce nonce;
399  struct ccmp_aad aad;
400  u8 rx_pn[6], their_mic[8], our_mic[8];
401 
402  iob = alloc_iob ( hdrlen + datalen );
403  if ( ! iob )
404  return NULL;
405 
406  /* Copy frame header */
407  memcpy ( iob_put ( iob, hdrlen ), eiob->data, hdrlen );
408  hdr = iob->data;
409  hdr->fc &= ~IEEE80211_FC_PROTECTED;
410 
411  /* Check and update RX packet number */
412  head = eiob->data + hdrlen;
413  memcpy ( rx_pn, head->pn_lo, 2 );
414  memcpy ( rx_pn + 2, head->pn_hi, 4 );
415 
416  if ( pn_to_u64 ( rx_pn ) <= ctx->rx_seq ) {
417  DBGC ( ctx, "WPA-CCMP %p: packet received out of order "
418  "(%012llx <= %012llx)\n", ctx, pn_to_u64 ( rx_pn ),
419  ctx->rx_seq );
420  free_iob ( iob );
421  return NULL;
422  }
423 
424  ctx->rx_seq = pn_to_u64 ( rx_pn );
425  DBGC2 ( ctx, "WPA-CCMP %p: RX packet number %012llx\n", ctx, ctx->rx_seq );
426 
427  /* Form nonce */
428  nonce.prio = 0;
429  memcpy ( nonce.a2, hdr->addr2, ETH_ALEN );
430  u64_to_pn ( ctx->rx_seq, nonce.pn, PN_MSB );
431 
432  /* Form additional authentication data */
433  aad.fc = ( hdr->fc & CCMP_AAD_FC_MASK ) | IEEE80211_FC_PROTECTED;
434  memcpy ( aad.a1, hdr->addr1, 3 * ETH_ALEN ); /* all 3 at once */
435  aad.seq = hdr->seq & CCMP_AAD_SEQ_MASK;
436 
437  /* Copy-decrypt data and MIC */
438  ccmp_ctr_xor ( ctx, &nonce, eiob->data + hdrlen + sizeof ( *head ),
439  iob_put ( iob, datalen ), datalen,
440  eiob->tail - CCMP_MIC_LEN, their_mic );
441 
442  /* Check MIC */
443  ccmp_cbc_mac ( ctx, &nonce, iob->data + hdrlen, datalen, &aad,
444  our_mic );
445 
446  if ( memcmp ( their_mic, our_mic, CCMP_MIC_LEN ) != 0 ) {
447  DBGC2 ( ctx, "WPA-CCMP %p: MIC failure\n", ctx );
448  free_iob ( iob );
449  return NULL;
450  }
451 
452  DBGC2 ( ctx, "WPA-CCMP %p: decrypted packet %p -> %p\n", ctx,
453  eiob, iob );
454 
455  return iob;
456 }
457 
458 
459 /** CCMP cryptosystem */
460 struct net80211_crypto ccmp_crypto __net80211_crypto = {
462  .init = ccmp_init,
463  .encrypt = ccmp_encrypt,
464  .decrypt = ccmp_decrypt,
465  .priv_len = sizeof ( struct ccmp_ctx ),
466 };
467 
468 
469 
470 
471 /**
472  * Calculate HMAC-SHA1 MIC for EAPOL-Key frame
473  *
474  * @v kck Key Confirmation Key, 16 bytes
475  * @v msg Message to calculate MIC over
476  * @v len Number of bytes to calculate MIC over
477  * @ret mic Calculated MIC, 16 bytes long
478  */
479 static void ccmp_kie_mic ( const void *kck, const void *msg, size_t len,
480  void *mic )
481 {
483  u8 kckb[16];
485 
486  memcpy ( kckb, kck, sizeof ( kckb ) );
487 
488  hmac_init ( &sha1_algorithm, ctx, kckb, sizeof ( kckb ) );
491 
492  memcpy ( mic, hash, 16 );
493 }
494 
495 /**
496  * Decrypt key data in EAPOL-Key frame
497  *
498  * @v kek Key Encryption Key, 16 bytes
499  * @v iv Initialisation vector, 16 bytes (unused)
500  * @v msg Message to decrypt
501  * @v len Length of message
502  * @ret msg Decrypted message in place of original
503  * @ret len Adjusted downward for 8 bytes of overhead
504  * @ret rc Return status code
505  *
506  * The returned message may still contain padding of 0xDD followed by
507  * zero or more 0x00 octets. It is impossible to remove the padding
508  * without parsing the IEs in the packet (another design decision that
509  * tends to make one question the 802.11i committee's intelligence...)
510  */
511 static int ccmp_kie_decrypt ( const void *kek, const void *iv __unused,
512  void *msg, u16 *len )
513 {
514  if ( *len % 8 != 0 )
515  return -EINVAL;
516 
517  if ( aes_unwrap ( kek, msg, msg, *len / 8 - 1 ) != 0 )
518  return -EINVAL;
519 
520  *len -= 8;
521 
522  return 0;
523 }
524 
525 /** CCMP-style key integrity and encryption handler */
526 struct wpa_kie ccmp_kie __wpa_kie = {
528  .mic = ccmp_kie_mic,
529  .decrypt = ccmp_kie_decrypt,
530 };
uint16_t u16
Definition: stdint.h:22
void hmac_init(struct digest_algorithm *digest, void *ctx, const void *key, size_t key_len)
Initialise HMAC.
Definition: hmac.c:58
u16 fc
Frame Control field.
Definition: wpa_ccmp.c:84
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:429
u8 pn[6]
Packet number.
Definition: wpa_ccmp.c:75
pseudo_bit_t hash[0x00010]
Definition: arbel.h:13
Network protected with CCMP (AES-based system)
Definition: net80211.h:174
u8 kid
Key ID and ExtIV byte.
Definition: wpa_ccmp.c:56
#define iob_put(iobuf, len)
Definition: iobuf.h:125
#define SHA1_BLOCK_SIZE
Definition: Tpm20.h:27
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:62
static u64 pn_to_u64(const u8 *pn)
Convert 6-byte LSB packet number to 64-bit integer.
Definition: wpa_ccmp.c:105
FILE_LICENCE(GPL2_OR_LATER)
FILE_SECBOOT(FORBIDDEN)
Error codes.
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
WPA handshake key integrity and encryption handler.
Definition: wpa.h:371
u8 kck[WPA_KCK_LEN]
EAPOL-Key Key Confirmation Key (KCK)
Definition: wpa.h:28
#define DBGC(...)
Definition: compiler.h:505
An 802.11 data or management frame without QoS or WDS header fields.
Definition: ieee80211.h:300
#define AES_CTX_SIZE
AES context size.
Definition: aes.h:46
Cryptographic API.
u8 _rsvd
Reserved byte.
Definition: wpa_ccmp.c:55
uint8_t head
Head number.
Definition: int13.h:34
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
struct cipher_algorithm aes_algorithm
Basic AES algorithm.
Definition: aes.c:784
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
static void u64_to_pn(u64 v, u8 *pn, int msb)
Convert 64-bit integer to 6-byte packet number.
Definition: wpa_ccmp.c:128
static void ccmp_kie_mic(const void *kck, const void *msg, size_t len, void *mic)
Calculate HMAC-SHA1 MIC for EAPOL-Key frame.
Definition: wpa_ccmp.c:479
u8 iv[16]
Initialization vector.
Definition: wpa.h:60
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.
Definition: wpa_ccmp.c:262
struct io_buffer * ccmp_encrypt(struct net80211_crypto *crypto, struct io_buffer *iob)
Encapsulate and encrypt a packet using CCMP.
Definition: wpa_ccmp.c:321
#define PN_MSB
Value for msb argument of u64_to_pn() for MSB output.
Definition: wpa_ccmp.c:142
u8 a1[6]
Address 1.
Definition: wpa_ccmp.c:85
static u16 S(u16 v)
Perform S-box mapping on a 16-bit value.
Definition: wpa_tkip.c:138
#define cipher_encrypt(cipher, ctx, src, dst, len)
Definition: crypto.h:251
void * tail
End of data.
Definition: iobuf.h:55
enum net80211_crypto_alg algorithm
The cryptographic algorithm implemented.
Definition: net80211.h:692
void * memcpy(void *dest, const void *src, size_t len) __nonnull
Common definitions for all types of WPA-protected networks.
Keyed-Hashing for Message Authentication.
static const void * src
Definition: string.h:48
#define IEEE80211_TYP_FRAME_HEADER_LEN
Frame header length for frames we might work with.
Definition: ieee80211.h:60
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
ring len
Length.
Definition: dwmac.h:231
u8 rsc[8]
Receive sequence counter for GTK.
Definition: wpa.h:69
u16 datalen
Length of the data field in bytes, network byte order.
Definition: wpa.h:84
uint64_t u64
Definition: stdint.h:26
static int ccmp_init(struct net80211_crypto *crypto, const void *key, int keylen, const void *rsc)
Initialise CCMP state and install key.
Definition: wpa_ccmp.c:157
int version
Value of version bits in EAPOL-Key info field for which to use.
Definition: wpa.h:376
static void ccmp_feed_cbc_mac(void *aes_ctx, u8 *B, u8 *X)
Advance one block in CBC-MAC calculation.
Definition: wpa_ccmp.c:239
#define CCMP_NONCE_LEN
CCMP nonce length.
Definition: wpa_ccmp.c:68
AES algorithm.
u8 a3[6]
Address 3.
Definition: wpa_ccmp.c:87
#define IEEE80211_FC_PROTECTED
802.11 Frame Control field: Protected flag
Definition: ieee80211.h:264
#define CCMP_AAD_SEQ_MASK
Mask for Sequence Control field in AAD.
Definition: wpa_ccmp.c:96
static void hmac_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Update HMAC.
Definition: hmac.h:43
The iPXE 802.11 MAC layer.
Header structure at the beginning of CCMP frame data.
Definition: wpa_ccmp.c:52
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
u8 kek[WPA_KEK_LEN]
EAPOL-Key Key Encryption Key (KEK)
Definition: wpa.h:31
#define CCMP_AAD_LEN
CCMP additional authentication data length (for non-QoS, non-WDS frames)
Definition: wpa_ccmp.c:79
u64 rx_seq
Most recently received packet number.
Definition: wpa_ccmp.c:48
u64 tx_seq
Most recently sent packet number.
Definition: wpa_ccmp.c:45
#define CCMP_MIC_LEN
CCMP MIC trailer overhead.
Definition: wpa_ccmp.c:65
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.
Definition: wpa_ccmp.c:188
#define ETH_ALEN
Definition: if_ether.h:9
u8 a2[ETH_ALEN]
Address 2 from packet header (sender)
Definition: wpa_ccmp.c:74
u8 nonce[32]
Nonce value.
Definition: wpa.h:52
u8 aes_ctx[AES_CTX_SIZE]
AES context - only ever used for encryption.
Definition: wpa_ccmp.c:42
u8 pn_lo[2]
Bytes 0 and 1 of packet number.
Definition: wpa_ccmp.c:54
#define EAPOL_KEY_VERSION_WPA2
Key descriptor version field value for WPA2 (CCMP)
Definition: wpa.h:81
void * priv
Private data for the algorithm to store key and state info.
Definition: net80211.h:766
CCMP additional authentication data structure.
Definition: wpa_ccmp.c:82
u8 a2[6]
Address 2.
Definition: wpa_ccmp.c:86
#define SHA1_DIGEST_SIZE
Definition: Tpm20.h:26
#define DBGC2(...)
Definition: compiler.h:522
#define CCMP_HEAD_LEN
CCMP header overhead.
Definition: wpa_ccmp.c:62
Context for CCMP encryption and decryption.
Definition: wpa_ccmp.c:39
SHA-1 algorithm.
static struct io_buffer * ccmp_decrypt(struct net80211_crypto *crypto, struct io_buffer *eiob)
Decrypt a packet using CCMP.
Definition: wpa_ccmp.c:389
void * data
Start of data.
Definition: iobuf.h:53
struct wpa_kie ccmp_kie __wpa_kie
CCMP-style key integrity and encryption handler.
Definition: wpa_ccmp.c:526
#define SHA1_CTX_SIZE
SHA-1 context size.
Definition: sha1.h:67
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
u16 seq
Sequence Control field.
Definition: wpa_ccmp.c:88
uint8_t data[48]
Additional event data.
Definition: ena.h:22
CCMP nonce structure.
Definition: wpa_ccmp.c:71
void hmac_final(struct digest_algorithm *digest, void *ctx, void *hmac)
Finalise HMAC.
Definition: hmac.c:88
#define CCMP_AAD_FC_MASK
Mask for Frame Control field in AAD.
Definition: wpa_ccmp.c:93
static int ccmp_kie_decrypt(const void *kek, const void *iv __unused, void *msg, u16 *len)
Decrypt key data in EAPOL-Key frame.
Definition: wpa_ccmp.c:511
u8 prio
Packet priority, 0 for non-QoS.
Definition: wpa_ccmp.c:73
int aes_unwrap(const void *kek, const void *src, void *dest, int nblk)
Unwrap a key or other data using AES Key Wrap (RFC 3394)
Definition: aes_wrap.c:85
Interface to an 802.11 cryptosystem.
Definition: net80211.h:689
struct net80211_crypto ccmp_crypto __net80211_crypto
CCMP cryptosystem.
Definition: wpa_ccmp.c:460
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:115
u8 mic[16]
Message integrity code over the entire EAPOL frame.
Definition: wpa.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
String functions.
uint8_t u8
Definition: stdint.h:20
union @391 key
Sense key.
Definition: scsi.h:18
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
Definition: crypto.h:235
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
Definition: sha1.c:258
#define PN_LSB
Value for msb argument of u64_to_pn() for LSB output.
Definition: wpa_ccmp.c:145
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:38
u8 pn_hi[4]
Bytes 2-5 (2 first) of packet number.
Definition: wpa_ccmp.c:57