From 62cc5052fee8f2600fa786392c41a7151c774bbd Mon Sep 17 00:00:00 2001 From: Chen Wen Date: Tue, 17 Sep 2019 17:42:54 +0800 Subject: [PATCH] feat(wps): optimization wps code --- .../esp8266/include/esp_wifi_crypto_types.h | 3 -- .../src/fast_crypto/fast_aes-cbc.c | 29 ----------- .../src/fast_crypto/fast_aes-unwrap.c | 15 ------ .../src/fast_crypto/fast_aes-wrap.c | 14 ----- .../fast_crypto/fast_crypto_internal-modexp.c | 8 --- .../src/fast_crypto/fast_crypto_internal.c | 2 - .../src/fast_crypto/fast_sha256-internal.c | 16 ------ .../src/fast_crypto/fast_sha256.c | 51 ------------------- .../wpa_supplicant/src/fast_crypto_ops.c | 3 +- 9 files changed, 2 insertions(+), 139 deletions(-) diff --git a/components/esp8266/include/esp_wifi_crypto_types.h b/components/esp8266/include/esp_wifi_crypto_types.h index e6ddf3da..240bf356 100644 --- a/components/esp8266/include/esp_wifi_crypto_types.h +++ b/components/esp8266/include/esp_wifi_crypto_types.h @@ -691,8 +691,6 @@ typedef int (*esp_wps_is_selected_pin_registrar_t)(const void *msg, unsigned cha */ typedef int (*esp_wps_is_selected_pbc_registrar_t)(const void *msg, unsigned char *bssid); - - /** * @brief The crypto callback function structure used when do station security connect. * The structure can be set as software crypto or the crypto optimized by ESP32 @@ -750,7 +748,6 @@ typedef struct{ esp_eap_msg_alloc_t eap_msg_alloc; }wps_crypto_funcs_t; - #ifdef __cplusplus } #endif diff --git a/components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c b/components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c index 18af1a8a..d29fa3b3 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c @@ -78,34 +78,5 @@ fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, s return ret; -} -#else -/** - * fast_aes_128_cbc_encrypt - AES-128 CBC encryption - * @key: Encryption key - * @iv: Encryption IV for CBC mode (16 bytes) - * @data: Data to encrypt in-place - * @data_len: Length of data in bytes (must be divisible by 16) - * Returns: 0 on success, -1 on failure - */ -int -fast_aes_128_cbc_encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len) -{ - return 0; -} - -/** - * fast_aes_128_cbc_decrypt - AES-128 CBC decryption - * @key: Decryption key - * @iv: Decryption IV for CBC mode (16 bytes) - * @data: Data to decrypt in-place - * @data_len: Length of data in bytes (must be divisible by 16) - * Returns: 0 on success, -1 on failure - */ -int -fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len) -{ - return 0; - } #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c b/components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c index bcc785db..e22e025e 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c @@ -84,19 +84,4 @@ fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain return ret; } -#else -/** - * fast_aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394) - * @kek: Key encryption key (KEK) - * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16 - * bytes - * @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits - * @plain: Plaintext key, n * 64 bits - * Returns: 0 on success, -1 on failure (e.g., integrity verification failed) - */ -int -fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain) -{ - return 0; -} #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c b/components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c index f69657ba..f418628a 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c @@ -85,18 +85,4 @@ int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *ciph return ret; } -#else -/** - * fast_aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394) - * @kek: 16-octet Key encryption key (KEK) - * @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16 - * bytes - * @plain: Plaintext key to be wrapped, n * 64 bits - * @cipher: Wrapped key, (n + 1) * 64 bits - * Returns: 0 on success, -1 on failure - */ -int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *cipher) -{ - return 0; -} #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-modexp.c b/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-modexp.c index 383f1c8c..6879082e 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-modexp.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal-modexp.c @@ -61,12 +61,4 @@ int fast_crypto_mod_exp(const uint8_t *base, size_t base_len, return ret; } -#else -int fast_crypto_mod_exp(const uint8_t *base, size_t base_len, - const uint8_t *power, size_t power_len, - const uint8_t *modulus, size_t modulus_len, - uint8_t *result, size_t *result_len) -{ - return 0; -} #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c b/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c index dcb55459..ba593935 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c @@ -282,6 +282,4 @@ int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len) return 0; } -#else - #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_sha256-internal.c b/components/wpa_supplicant/src/fast_crypto/fast_sha256-internal.c index 0e809dc5..e911f449 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_sha256-internal.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_sha256-internal.c @@ -59,20 +59,4 @@ out: return ret; } -#else - -/** - * fast_sha256_vector - SHA256 hash for data vector - * @num_elem: Number of elements in the data vector - * @addr: Pointers to the data areas - * @len: Lengths of the data blocks - * @mac: Buffer for the hash - * Returns: 0 on success, -1 of failure - */ -int -fast_sha256_vector(size_t num_elem, const uint8_t *addr[], const size_t *len, - uint8_t *mac) -{ - return 0; -} #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto/fast_sha256.c b/components/wpa_supplicant/src/fast_crypto/fast_sha256.c index 1c77248c..cdbb6861 100644 --- a/components/wpa_supplicant/src/fast_crypto/fast_sha256.c +++ b/components/wpa_supplicant/src/fast_crypto/fast_sha256.c @@ -22,7 +22,6 @@ #include "crypto/crypto.h" #if CONFIG_SSL_USING_MBEDTLS - /** * fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104) * @key: Key for HMAC operations @@ -165,54 +164,4 @@ fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label, counter++; } } -#else -/** - * fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104) - * @key: Key for HMAC operations - * @key_len: Length of the key in bytes - * @num_elem: Number of elements in the data vector - * @addr: Pointers to the data areas - * @len: Lengths of the data blocks - * @mac: Buffer for the hash (32 bytes) - */ -void -fast_hmac_sha256_vector(const uint8_t *key, size_t key_len, size_t num_elem, - const uint8_t *addr[], const size_t *len, uint8_t *mac) -{ -} - - -/** - * fast_hmac_sha256 - HMAC-SHA256 over data buffer (RFC 2104) - * @key: Key for HMAC operations - * @key_len: Length of the key in bytes - * @data: Pointers to the data area - * @data_len: Length of the data area - * @mac: Buffer for the hash (20 bytes) - */ -void -fast_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data, - size_t data_len, uint8_t *mac) -{ -} - - -/** - * fast_sha256_prf - SHA256-based Pseudo-Random Function (IEEE 802.11r, 8.5.1.5.2) - * @key: Key for PRF - * @key_len: Length of the key in bytes - * @label: A unique label for each purpose of the PRF - * @data: Extra data to bind into the key - * @data_len: Length of the data - * @buf: Buffer for the generated pseudo-random key - * @buf_len: Number of bytes of key to generate - * - * This function is used to derive new, cryptographically separate keys from a - * given key. - */ -void -fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label, - const uint8_t *data, size_t data_len, uint8_t *buf, size_t buf_len) -{ -} #endif \ No newline at end of file diff --git a/components/wpa_supplicant/src/fast_crypto_ops.c b/components/wpa_supplicant/src/fast_crypto_ops.c index 4cbde3eb..0152df89 100644 --- a/components/wpa_supplicant/src/fast_crypto_ops.c +++ b/components/wpa_supplicant/src/fast_crypto_ops.c @@ -85,7 +85,8 @@ const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = { .eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc }; -#else +#else + /* * The parameters is used to set the cyrpto callback function for station connect when in security mode, * every callback function can register as fast_xxx or normal one, i.e, fast_aes_wrap or aes_wrap, the