Skip to content

Commit 0a7d44c

Browse files
committed
feat(wps): sync wps_internal code to esp8266
feat(wps): modify CMakeLists.txt
1 parent 6ac71ff commit 0a7d44c

14 files changed

+155
-90
lines changed

components/esp8266/include/esp_wifi_crypto_types.h

-42
Original file line numberDiff line numberDiff line change
@@ -750,48 +750,6 @@ typedef struct{
750750
esp_eap_msg_alloc_t eap_msg_alloc;
751751
}wps_crypto_funcs_t;
752752

753-
/**
754-
* @brief The crypto callback function structure used when do WPA enterprise connect.
755-
* The structure can be set as software crypto or the crypto optimized by ESP32
756-
* hardware.
757-
*/
758-
typedef struct {
759-
uint32_t size;
760-
uint32_t version;
761-
esp_crypto_hash_init_t crypto_hash_init; /**< function used to initialize a crypto_hash structure when use TLSV1 */
762-
esp_crypto_hash_update_t crypto_hash_update; /**< function used to calculate hash data when use TLSV1 */
763-
esp_crypto_hash_finish_t crypto_hash_finish; /**< function used to finish the hash calculate when use TLSV1 */
764-
esp_crypto_cipher_init_t crypto_cipher_init; /**< function used to initialize a crypt_cipher structure when use TLSV1 */
765-
esp_crypto_cipher_encrypt_t crypto_cipher_encrypt; /**< function used to encrypt cipher when use TLSV1 */
766-
esp_crypto_cipher_decrypt_t crypto_cipher_decrypt; /**< function used to decrypt cipher when use TLSV1 */
767-
esp_crypto_cipher_deinit_t crypto_cipher_deinit; /**< function used to free context when use TLSV1 */
768-
esp_crypto_mod_exp_t crypto_mod_exp; /**< function used to do key exchange when use TLSV1 */
769-
esp_sha256_vector_t sha256_vector; /**< function used to do X.509v3 certificate parsing and processing */
770-
esp_tls_init_t tls_init;
771-
esp_tls_deinit_t tls_deinit;
772-
esp_eap_peer_blob_init_t eap_peer_blob_init;
773-
esp_eap_peer_blob_deinit_t eap_peer_blob_deinit;
774-
esp_eap_peer_config_init_t eap_peer_config_init;
775-
esp_eap_peer_config_deinit_t eap_peer_config_deinit;
776-
esp_eap_peer_register_methods_t eap_peer_register_methods;
777-
esp_eap_peer_unregister_methods_t eap_peer_unregister_methods;
778-
esp_eap_deinit_prev_method_t eap_deinit_prev_method;
779-
esp_eap_peer_get_eap_method_t eap_peer_get_eap_method;
780-
esp_eap_sm_abort_t eap_sm_abort;
781-
esp_eap_sm_build_nak_t eap_sm_build_nak;
782-
esp_eap_sm_build_identity_resp_t eap_sm_build_identity_resp;
783-
esp_eap_msg_alloc_t eap_msg_alloc;
784-
} wpa2_crypto_funcs_t;
785-
786-
/**
787-
* @brief The crypto callback function structure used in mesh vendor IE encryption. The
788-
* structure can be set as software crypto or the crypto optimized by ESP32
789-
* hardware.
790-
*/
791-
typedef struct{
792-
esp_aes_128_encrypt_t aes_128_encrypt; /**< function used in mesh vendor IE encryption */
793-
esp_aes_128_decrypt_t aes_128_decrypt; /**< function used in mesh vendor IE decryption */
794-
} mesh_crypto_funcs_t;
795753

796754
#ifdef __cplusplus
797755
}

components/wpa_supplicant/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
set(COMPONENT_SRCDIRS "src/crypto" "src/wps" "port")
1+
2+
set(COMPONENT_SRCDIRS "src/crypto" "src/fast_crypto" "src/wps" "port" "src")
23
set(COMPONENT_ADD_INCLUDEDIRS "include" "port/include")
4+
set(COMPONENT_PRIV_REQUIRES "ssl" "freertos" "heap" "newlib" "util")
35

4-
set(COMPONENT_PRIV_REQUIRES "freertos" "heap" "newlib" "util")
56

67
register_component()
78

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
COMPONENT_ADD_INCLUDEDIRS := include include/wps port/include
2-
COMPONENT_SRCDIRS := src/crypto src/wps src/fast_crypto port
2+
COMPONENT_SRCDIRS := src/crypto src/wps src/fast_crypto src port
33

44
CFLAGS += -DEMBEDDED_SUPP -D__ets__ -DESPRESSIF_USE -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESP8266_WORKAROUND -Wno-strict-aliasing

components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44

5+
#include "sdkconfig.h"
56

67
#include "crypto/includes.h"
78
#include "crypto/common.h"
@@ -77,5 +78,34 @@ fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, s
7778

7879
return ret;
7980

81+
}
82+
#else
83+
/**
84+
* fast_aes_128_cbc_encrypt - AES-128 CBC encryption
85+
* @key: Encryption key
86+
* @iv: Encryption IV for CBC mode (16 bytes)
87+
* @data: Data to encrypt in-place
88+
* @data_len: Length of data in bytes (must be divisible by 16)
89+
* Returns: 0 on success, -1 on failure
90+
*/
91+
int
92+
fast_aes_128_cbc_encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len)
93+
{
94+
return 0;
95+
}
96+
97+
/**
98+
* fast_aes_128_cbc_decrypt - AES-128 CBC decryption
99+
* @key: Decryption key
100+
* @iv: Decryption IV for CBC mode (16 bytes)
101+
* @data: Data to decrypt in-place
102+
* @data_len: Length of data in bytes (must be divisible by 16)
103+
* Returns: 0 on success, -1 on failure
104+
*/
105+
int
106+
fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len)
107+
{
108+
return 0;
109+
80110
}
81111
#endif

components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
#include "sdkconfig.h"
1415

1516
#include "crypto/includes.h"
1617
#include "crypto/common.h"
1718

1819
#if CONFIG_SSL_USING_MBEDTLS
1920
#include "mbedtls/aes.h"
20-
2121
/**
2222
* fast_aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
2323
* @kek: Key encryption key (KEK)
@@ -84,4 +84,19 @@ fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain
8484

8585
return ret;
8686
}
87+
#else
88+
/**
89+
* fast_aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
90+
* @kek: Key encryption key (KEK)
91+
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
92+
* bytes
93+
* @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits
94+
* @plain: Plaintext key, n * 64 bits
95+
* Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
96+
*/
97+
int
98+
fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain)
99+
{
100+
return 0;
101+
}
87102
#endif

components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "sdkconfig.h"
16+
1517
#include "crypto/includes.h"
1618

1719
#include "crypto/common.h"
@@ -83,4 +85,18 @@ int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *ciph
8385

8486
return ret;
8587
}
88+
#else
89+
/**
90+
* fast_aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
91+
* @kek: 16-octet Key encryption key (KEK)
92+
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
93+
* bytes
94+
* @plain: Plaintext key to be wrapped, n * 64 bits
95+
* @cipher: Wrapped key, (n + 1) * 64 bits
96+
* Returns: 0 on success, -1 on failure
97+
*/
98+
int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *cipher)
99+
{
100+
return 0;
101+
}
86102
#endif

components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-cipher.c

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
//#include "wpa/includes.h"
16+
#include "sdkconfig.h"
1617

1718
//#include "wpa/common.h"
1819
#include "crypto/common.h"

components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-modexp.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "sdkconfig.h"
16+
1517
#include "crypto/includes.h"
1618

1719
#include "crypto/common.h"
@@ -20,8 +22,7 @@
2022
#if CONFIG_SSL_USING_MBEDTLS
2123
#include "mbedtls/bignum.h"
2224

23-
int
24-
fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
25+
int fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
2526
const uint8_t *power, size_t power_len,
2627
const uint8_t *modulus, size_t modulus_len,
2728
uint8_t *result, size_t *result_len)
@@ -60,4 +61,12 @@ fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
6061

6162
return ret;
6263
}
64+
#else
65+
int fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
66+
const uint8_t *power, size_t power_len,
67+
const uint8_t *modulus, size_t modulus_len,
68+
uint8_t *result, size_t *result_len)
69+
{
70+
return 0;
71+
}
6372
#endif

components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* This software may be distributed under the terms of the BSD license.
88
* See README for more details.
99
*/
10+
#include "sdkconfig.h"
1011

1112
#include "crypto/includes.h"
1213
#include "crypto/common.h"
@@ -281,4 +282,6 @@ int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
281282

282283
return 0;
283284
}
285+
#else
286+
284287
#endif

components/wpa_supplicant/src/fast_crypto/fast_sha256-internal.c

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "sdkconfig.h"
16+
1517
#include "crypto/includes.h"
1618
#include "crypto/common.h"
1719

@@ -57,4 +59,20 @@ fast_sha256_vector(size_t num_elem, const uint8_t *addr[], const size_t *len,
5759

5860
return ret;
5961
}
62+
#else
63+
64+
/**
65+
* fast_sha256_vector - SHA256 hash for data vector
66+
* @num_elem: Number of elements in the data vector
67+
* @addr: Pointers to the data areas
68+
* @len: Lengths of the data blocks
69+
* @mac: Buffer for the hash
70+
* Returns: 0 on success, -1 of failure
71+
*/
72+
int
73+
fast_sha256_vector(size_t num_elem, const uint8_t *addr[], const size_t *len,
74+
uint8_t *mac)
75+
{
76+
return 0;
77+
}
6078
#endif

components/wpa_supplicant/src/fast_crypto/fast_sha256.c

+51
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
* See README and COPYING for more details.
1515
*/
16+
#include "sdkconfig.h"
1617

1718
#include "crypto/includes.h"
1819

@@ -164,4 +165,54 @@ fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label,
164165
counter++;
165166
}
166167
}
168+
#else
169+
/**
170+
* fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104)
171+
* @key: Key for HMAC operations
172+
* @key_len: Length of the key in bytes
173+
* @num_elem: Number of elements in the data vector
174+
* @addr: Pointers to the data areas
175+
* @len: Lengths of the data blocks
176+
* @mac: Buffer for the hash (32 bytes)
177+
*/
178+
void
179+
fast_hmac_sha256_vector(const uint8_t *key, size_t key_len, size_t num_elem,
180+
const uint8_t *addr[], const size_t *len, uint8_t *mac)
181+
{
182+
}
183+
184+
185+
/**
186+
* fast_hmac_sha256 - HMAC-SHA256 over data buffer (RFC 2104)
187+
* @key: Key for HMAC operations
188+
* @key_len: Length of the key in bytes
189+
* @data: Pointers to the data area
190+
* @data_len: Length of the data area
191+
* @mac: Buffer for the hash (20 bytes)
192+
*/
193+
void
194+
fast_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data,
195+
size_t data_len, uint8_t *mac)
196+
{
197+
}
198+
199+
200+
/**
201+
* fast_sha256_prf - SHA256-based Pseudo-Random Function (IEEE 802.11r, 8.5.1.5.2)
202+
* @key: Key for PRF
203+
* @key_len: Length of the key in bytes
204+
* @label: A unique label for each purpose of the PRF
205+
* @data: Extra data to bind into the key
206+
* @data_len: Length of the data
207+
* @buf: Buffer for the generated pseudo-random key
208+
* @buf_len: Number of bytes of key to generate
209+
*
210+
* This function is used to derive new, cryptographically separate keys from a
211+
* given key.
212+
*/
213+
void
214+
fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label,
215+
const uint8_t *data, size_t data_len, uint8_t *buf, size_t buf_len)
216+
{
217+
}
167218
#endif

components/esp8266/source/fast_crypto_ops.c renamed to components/wpa_supplicant/src/fast_crypto_ops.c

+2-40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "sdkconfig.h"
16+
1517
#include "crypto/common.h"
1618
#include "crypto/aes_wrap.h"
1719
#include "crypto/sha256.h"
@@ -137,44 +139,4 @@ const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
137139
.wps_is_selected_pbc_registrar = (esp_wps_is_selected_pbc_registrar_t)wps_is_selected_pbc_registrar,
138140
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
139141
};
140-
#endif
141-
/*
142-
* What should notice is that the cyrpto hash type function and crypto cipher type function can not register
143-
* as different, i.e, if you use fast_crypto_hash_init, you should use fast_crypto_hash_update and
144-
* fast_crypto_hash_finish for finish hash calculate, rather than call crypto_hash_update and
145-
* crypto_hash_finish, so do crypto_cipher.
146-
*/
147-
#if 0
148-
const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = {
149-
.size = sizeof(wpa2_crypto_funcs_t),
150-
.version = ESP_WIFI_CRYPTO_VERSION,
151-
.crypto_hash_init = (esp_crypto_hash_init_t)fast_crypto_hash_init,
152-
.crypto_hash_update = (esp_crypto_hash_update_t)fast_crypto_hash_update,
153-
.crypto_hash_finish = (esp_crypto_hash_finish_t)fast_crypto_hash_finish,
154-
.crypto_cipher_init = (esp_crypto_cipher_init_t)fast_crypto_cipher_init,
155-
.crypto_cipher_encrypt = (esp_crypto_cipher_encrypt_t)fast_crypto_cipher_encrypt,
156-
.crypto_cipher_decrypt = (esp_crypto_cipher_decrypt_t)fast_crypto_cipher_decrypt,
157-
.crypto_cipher_deinit = (esp_crypto_cipher_deinit_t)fast_crypto_cipher_deinit,
158-
.crypto_mod_exp = (esp_crypto_mod_exp_t)crypto_mod_exp,
159-
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector,
160-
.tls_init = (esp_tls_init_t)tls_init,
161-
.tls_deinit = (esp_tls_deinit_t)tls_deinit,
162-
.eap_peer_blob_init = (esp_eap_peer_blob_init_t)eap_peer_blob_init,
163-
.eap_peer_blob_deinit = (esp_eap_peer_blob_deinit_t)eap_peer_blob_deinit,
164-
.eap_peer_config_init = (esp_eap_peer_config_init_t)eap_peer_config_init,
165-
.eap_peer_config_deinit = (esp_eap_peer_config_deinit_t)eap_peer_config_deinit,
166-
.eap_peer_register_methods = (esp_eap_peer_register_methods_t)eap_peer_register_methods,
167-
.eap_peer_unregister_methods = (esp_eap_peer_unregister_methods_t)eap_peer_unregister_methods,
168-
.eap_deinit_prev_method = (esp_eap_deinit_prev_method_t)eap_deinit_prev_method,
169-
.eap_peer_get_eap_method = (esp_eap_peer_get_eap_method_t)eap_peer_get_eap_method,
170-
.eap_sm_abort = (esp_eap_sm_abort_t)eap_sm_abort,
171-
.eap_sm_build_nak = (esp_eap_sm_build_nak_t)eap_sm_build_nak,
172-
.eap_sm_build_identity_resp = (esp_eap_sm_build_identity_resp_t)eap_sm_build_identity_resp,
173-
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
174-
};
175-
176-
const mesh_crypto_funcs_t g_wifi_default_mesh_crypto_funcs = {
177-
.aes_128_encrypt = (esp_aes_128_encrypt_t)fast_aes_128_cbc_encrypt,
178-
.aes_128_decrypt = (esp_aes_128_decrypt_t)fast_aes_128_cbc_decrypt,
179-
};
180142
#endif

examples/wifi/wps/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# The following four lines of boilerplate have to be in your project's CMakeLists
1+
# The following lines of boilerplate have to be in your project's CMakeLists
22
# in this exact order for cmake to work correctly
33
cmake_minimum_required(VERSION 3.5)
44

55
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6-
project(wps)
6+
project(wps_example)

examples/wifi/wps/main/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
set(COMPONENT_SRCS "wps.c")
2+
set(COMPONENT_ADD_INCLUDEDIRS ".")
23

34
register_component()

0 commit comments

Comments
 (0)