mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-09-21 22:06:46 +08:00
feat(wps): support encryption mode configurable
This commit is contained in:
@ -25,14 +25,10 @@
|
|||||||
|
|
||||||
#include "eap/eap_defs.h"
|
#include "eap/eap_defs.h"
|
||||||
#include "eap/eap_common.h"
|
#include "eap/eap_common.h"
|
||||||
#if 0
|
|
||||||
#include "wpa2/eap_peer/eap.h"
|
|
||||||
#include "wpa2/tls/tls.h"
|
|
||||||
#include "wpa2/eap_peer/eap_methods.h"
|
|
||||||
#include "wpa2/eap_peer/eap_i.h"
|
|
||||||
#include "wpa2/eap_peer/eap_common.h"
|
|
||||||
#endif
|
|
||||||
#include "esp_wifi_crypto_types.h"
|
#include "esp_wifi_crypto_types.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
/*
|
/*
|
||||||
* The parameters is used to set the cyrpto callback function for station connect when in security mode,
|
* 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
|
* every callback function can register as fast_xxx or normal one, i.e, fast_aes_wrap or aes_wrap, the
|
||||||
@ -87,6 +83,61 @@ const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
|
|||||||
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
|
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#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
|
||||||
|
* difference between them is the normal API is calculate by software, the fast one use the hardware
|
||||||
|
* crypto in it, can be faster than the normal one, so the callback function register in default is which
|
||||||
|
* we recommend, so as the API in WPS default and WPA2 default.
|
||||||
|
*/
|
||||||
|
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
|
||||||
|
.size = sizeof(wpa_crypto_funcs_t),
|
||||||
|
.version = ESP_WIFI_CRYPTO_VERSION,
|
||||||
|
.aes_wrap = (esp_aes_wrap_t)aes_wrap,
|
||||||
|
.aes_unwrap = (esp_aes_unwrap_t)aes_unwrap,
|
||||||
|
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)hmac_sha256_vector,
|
||||||
|
.sha256_prf = (esp_sha256_prf_t)fast_sha256_prf,
|
||||||
|
.hmac_md5 = (esp_hmac_md5_t)hmac_md5,
|
||||||
|
.hamc_md5_vector = (esp_hmac_md5_vector_t)hmac_md5_vector,
|
||||||
|
.hmac_sha1 = (esp_hmac_sha1_t)hmac_sha1,
|
||||||
|
.hmac_sha1_vector = (esp_hmac_sha1_vector_t)hmac_sha1_vector,
|
||||||
|
.sha1_prf = (esp_sha1_prf_t)sha1_prf,
|
||||||
|
.sha1_vector = (esp_sha1_vector_t)sha1_vector,
|
||||||
|
.pbkdf2_sha1 = (esp_pbkdf2_sha1_t)pbkdf2_sha1,
|
||||||
|
.rc4_skip = (esp_rc4_skip_t)rc4_skip,
|
||||||
|
.md5_vector = (esp_md5_vector_t)md5_vector,
|
||||||
|
.aes_encrypt = (esp_aes_encrypt_t)aes_encrypt,
|
||||||
|
.aes_encrypt_init = (esp_aes_encrypt_init_t)aes_encrypt_init,
|
||||||
|
.aes_encrypt_deinit = (esp_aes_encrypt_deinit_t)aes_encrypt_deinit,
|
||||||
|
.aes_decrypt = (esp_aes_decrypt_t)aes_decrypt,
|
||||||
|
.aes_decrypt_init = (esp_aes_decrypt_init_t)aes_decrypt_init,
|
||||||
|
.aes_decrypt_deinit = (esp_aes_decrypt_deinit_t)aes_decrypt_deinit
|
||||||
|
};
|
||||||
|
|
||||||
|
const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
|
||||||
|
.size = sizeof(wps_crypto_funcs_t),
|
||||||
|
.version = ESP_WIFI_CRYPTO_VERSION,
|
||||||
|
.aes_128_encrypt = (esp_aes_128_encrypt_t)aes_128_cbc_encrypt,
|
||||||
|
.aes_128_decrypt = (esp_aes_128_decrypt_t)aes_128_cbc_decrypt,
|
||||||
|
.crypto_mod_exp = (esp_crypto_mod_exp_t)crypto_mod_exp,
|
||||||
|
.hmac_sha256 = (esp_hmac_sha256_t)hmac_sha256,
|
||||||
|
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)hmac_sha256_vector,
|
||||||
|
.sha256_vector = (esp_sha256_vector_t)sha256_vector,
|
||||||
|
.uuid_gen_mac_addr = (esp_uuid_gen_mac_addr_t)uuid_gen_mac_addr,
|
||||||
|
.dh5_free = (esp_dh5_free_t)dh5_free,
|
||||||
|
.wps_build_assoc_req_ie = (esp_wps_build_assoc_req_ie_t)wps_build_assoc_req_ie,
|
||||||
|
.wps_build_assoc_resp_ie = (esp_wps_build_assoc_resp_ie_t)wps_build_assoc_resp_ie,
|
||||||
|
.wps_build_probe_req_ie = (esp_wps_build_probe_req_ie_t)wps_build_probe_req_ie,
|
||||||
|
.wps_build_public_key = (esp_wps_build_public_key_t)wps_build_public_key,
|
||||||
|
.wps_enrollee_get_msg = (esp_wps_enrollee_get_msg_t)wps_enrollee_get_msg,
|
||||||
|
.wps_enrollee_process_msg = (esp_wps_enrollee_process_msg_t)wps_enrollee_process_msg,
|
||||||
|
.wps_generate_pin = (esp_wps_generate_pin_t)wps_generate_pin,
|
||||||
|
.wps_is_selected_pin_registrar = (esp_wps_is_selected_pin_registrar_t)wps_is_selected_pin_registrar,
|
||||||
|
.wps_is_selected_pbc_registrar = (esp_wps_is_selected_pbc_registrar_t)wps_is_selected_pbc_registrar,
|
||||||
|
.eap_msg_alloc = (esp_eap_msg_alloc_t)eap_msg_alloc
|
||||||
|
};
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* What should notice is that the cyrpto hash type function and crypto cipher type function can not register
|
* What should notice is that the cyrpto hash type function and crypto cipher type function can not register
|
||||||
* as different, i.e, if you use fast_crypto_hash_init, you should use fast_crypto_hash_update and
|
* as different, i.e, if you use fast_crypto_hash_init, you should use fast_crypto_hash_update and
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include "crypto/common.h"
|
#include "crypto/common.h"
|
||||||
#include "crypto/aes.h"
|
#include "crypto/aes.h"
|
||||||
#include "crypto/aes_wrap.h"
|
#include "crypto/aes_wrap.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,3 +78,4 @@ fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, s
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "crypto/includes.h"
|
#include "crypto/includes.h"
|
||||||
#include "crypto/common.h"
|
#include "crypto/common.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,3 +84,4 @@ fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -17,6 +17,8 @@
|
|||||||
#include "crypto/common.h"
|
#include "crypto/common.h"
|
||||||
#include "crypto/aes.h"
|
#include "crypto/aes.h"
|
||||||
#include "crypto/aes_wrap.h"
|
#include "crypto/aes_wrap.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,3 +83,4 @@ int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *ciph
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -21,6 +21,8 @@
|
|||||||
#if defined(CONFIG_DES) || defined(CONFIG_DES3)
|
#if defined(CONFIG_DES) || defined(CONFIG_DES3)
|
||||||
#include "crypto/des_i.h"
|
#include "crypto/des_i.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/aes.h"
|
#include "mbedtls/aes.h"
|
||||||
|
|
||||||
struct fast_crypto_cipher {
|
struct fast_crypto_cipher {
|
||||||
@ -285,3 +287,4 @@ void fast_crypto_cipher_deinit(struct crypto_cipher *ctx)
|
|||||||
}
|
}
|
||||||
os_free(ctx);
|
os_free(ctx);
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -16,10 +16,9 @@
|
|||||||
|
|
||||||
#include "crypto/common.h"
|
#include "crypto/common.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "mbedtls/bignum.h"
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "freertos/task.h"
|
#include "mbedtls/bignum.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
||||||
@ -38,10 +37,8 @@ fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
|||||||
mbedtls_mpi_read_binary(&bn_base, base, base_len);
|
mbedtls_mpi_read_binary(&bn_base, base, base_len);
|
||||||
mbedtls_mpi_read_binary(&bn_exp, power, power_len);
|
mbedtls_mpi_read_binary(&bn_exp, power, power_len);
|
||||||
mbedtls_mpi_read_binary(&bn_modulus, modulus, modulus_len);
|
mbedtls_mpi_read_binary(&bn_modulus, modulus, modulus_len);
|
||||||
//printf("[%s]line:[%d]%d\r\n", __func__, __LINE__, xTaskGetTickCount());
|
|
||||||
|
|
||||||
ret = mbedtls_mpi_exp_mod(&bn_result, &bn_base, &bn_exp, &bn_modulus, &bn_rinv);
|
ret = mbedtls_mpi_exp_mod(&bn_result, &bn_base, &bn_exp, &bn_modulus, &bn_rinv);
|
||||||
//printf("[%s]line:[%d]%d\r\n", __func__, __LINE__, xTaskGetTickCount());
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mbedtls_mpi_free(&bn_base);
|
mbedtls_mpi_free(&bn_base);
|
||||||
@ -63,3 +60,4 @@ fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -13,6 +13,8 @@
|
|||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "crypto/sha1_i.h"
|
#include "crypto/sha1_i.h"
|
||||||
#include "crypto/md5_i.h"
|
#include "crypto/md5_i.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/sha256.h"
|
#include "mbedtls/sha256.h"
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +162,6 @@ void fast_crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t le
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
|
int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
|
||||||
{
|
{
|
||||||
u8 k_pad[64];
|
u8 k_pad[64];
|
||||||
@ -280,3 +281,4 @@ int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "crypto/includes.h"
|
#include "crypto/includes.h"
|
||||||
#include "crypto/common.h"
|
#include "crypto/common.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
#include "mbedtls/sha256.h"
|
#include "mbedtls/sha256.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,4 +57,4 @@ out:
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -20,6 +20,7 @@
|
|||||||
#include "crypto/sha256.h"
|
#include "crypto/sha256.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
|
|
||||||
|
#if CONFIG_SSL_USING_MBEDTLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104)
|
* fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104)
|
||||||
@ -163,3 +164,4 @@ fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label,
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
Reference in New Issue
Block a user