VSF Documented
vsf_wifi_crypto.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_WIFI_CRYPTO_H__
19#define __VSF_WIFI_CRYPTO_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "./vsf_wifi_cfg.h"
24
25#if VSF_USE_WIFI == ENABLED && VSF_WIFI_USE_WPA == ENABLED
26
27#include "kernel/vsf_kernel.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*============================ MACROS ========================================*/
34
35/* WPA2-PSK / CCMP key material sizes (octets). */
36#define VSF_WIFI_PMK_LEN 32 /* pairwise master key */
37#define VSF_WIFI_PTK_LEN 48 /* CCMP PTK = KCK(16)+KEK(16)+TK(16) */
38#define VSF_WIFI_KCK_LEN 16 /* EAPOL-Key MIC key */
39#define VSF_WIFI_KEK_LEN 16 /* EAPOL-Key encryption (GTK) key */
40#define VSF_WIFI_TK_LEN 16 /* CCMP temporal key */
41#define VSF_WIFI_NONCE_LEN 32 /* ANonce / SNonce */
42#define VSF_WIFI_MIC_LEN 16 /* EAPOL-Key MIC (HMAC-SHA1 truncated) */
43#define VSF_WIFI_CCMP_NONCE_LEN 13 /* CCM nonce: flag(1)+A2(6)+PN(6) */
44#define VSF_WIFI_CCMP_MIC_LEN 8 /* CCMP MIC */
45
46/*============================ TYPES =========================================*/
47/*============================ GLOBAL VARIABLES ==============================*/
48/*============================ PROTOTYPES ====================================*/
49
54extern vsf_err_t vsf_wifi_pbkdf2_pmk(const char *passphrase,
55 const uint8_t *ssid, uint16_t ssid_len, uint8_t pmk[32]);
56
63extern vsf_err_t vsf_wifi_prf_ptk(const uint8_t pmk[32],
64 const uint8_t aa[6], const uint8_t spa[6],
65 const uint8_t anonce[32], const uint8_t snonce[32],
66 uint8_t ptk[48]);
67
73extern vsf_err_t vsf_wifi_eapol_mic(const uint8_t kck[16],
74 const uint8_t *eapol, uint16_t eapol_len, uint8_t mic[16]);
75
80extern vsf_err_t vsf_wifi_aes_unwrap(const uint8_t *kek, uint16_t kek_len,
81 const uint8_t *in, uint16_t in_len, uint8_t *out);
82
87extern vsf_err_t vsf_wifi_ccmp_encrypt(const uint8_t tk[16],
88 const uint8_t *aad, uint16_t aad_len,
89 const uint8_t nonce[13],
90 const uint8_t *plain, uint16_t plain_len,
91 uint8_t *cipher, uint8_t mic[8]);
92
97extern vsf_err_t vsf_wifi_ccmp_decrypt(const uint8_t tk[16],
98 const uint8_t *aad, uint16_t aad_len,
99 const uint8_t nonce[13],
100 const uint8_t *cipher, uint16_t cipher_len,
101 uint8_t *plain, const uint8_t mic[8]);
102
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif // VSF_USE_WIFI && VSF_WIFI_USE_WPA
114#endif // __VSF_WIFI_CRYPTO_H__
115/* EOF */
vsf_err_t
Definition __type.h:42
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint8_t
Definition stdint.h:5
vsf_err_t vsf_wifi_ccmp_encrypt(const uint8_t tk[16], const uint8_t *aad, uint16_t aad_len, const uint8_t nonce[13], const uint8_t *plain, uint16_t plain_len, uint8_t *cipher, uint8_t mic[8])
CCMP encrypt: AES-CCM with L=2, M=8. Produces cipher (== plain_len) and an 8-byte MIC....
Definition vsf_wifi_crypto.c:225
vsf_err_t vsf_wifi_pbkdf2_pmk(const char *passphrase, const uint8_t *ssid, uint16_t ssid_len, uint8_t pmk[32])
Derive the PMK from a passphrase using PBKDF2-HMAC-SHA1 (4096 rounds). salt = SSID,...
Definition vsf_wifi_crypto.c:52
vsf_err_t vsf_wifi_ccmp_decrypt(const uint8_t tk[16], const uint8_t *aad, uint16_t aad_len, const uint8_t nonce[13], const uint8_t *cipher, uint16_t cipher_len, uint8_t *plain, const uint8_t mic[8])
CCMP decrypt + authenticate. Returns VSF_ERR_FAIL if the MIC check fails (forged / corrupted frame).
Definition vsf_wifi_crypto.c:251
vsf_err_t vsf_wifi_aes_unwrap(const uint8_t *kek, uint16_t kek_len, const uint8_t *in, uint16_t in_len, uint8_t *out)
AES key unwrap (RFC 3394), used to recover the GTK from EAPOL-Key M3. in_len must be a multiple of 8 ...
Definition vsf_wifi_crypto.c:158
vsf_err_t vsf_wifi_prf_ptk(const uint8_t pmk[32], const uint8_t aa[6], const uint8_t spa[6], const uint8_t anonce[32], const uint8_t snonce[32], uint8_t ptk[48])
Derive the 384-bit PTK using PRF-384 (HMAC-SHA1). label = "Pairwise key expansion",...
Definition vsf_wifi_crypto.c:80
vsf_err_t vsf_wifi_crypto_selftest(void)
Run the built-in crypto self-test against IEEE 802.11i / RFC test vectors. Returns VSF_ERR_NONE if al...
Definition vsf_wifi_crypto.c:285
vsf_err_t vsf_wifi_eapol_mic(const uint8_t kck[16], const uint8_t *eapol, uint16_t eapol_len, uint8_t mic[16])
Compute the EAPOL-Key MIC (key descriptor version 2 = HMAC-SHA1 truncated to 16 bytes)....
Definition vsf_wifi_crypto.c:136
Generated from commit: vsfteam/vsf@d3b40b2