From b823da9bb9d8fab9b5ab16a0a21b87b790d02f26 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Thu, 15 Dec 2022 16:11:39 -0500 Subject: [PATCH 1/5] Fix build issues with the latest ESP-IDF --- wolfcrypt/benchmark/benchmark.c | 2 +- wolfcrypt/src/port/Espressif/esp32_aes.c | 2 +- wolfcrypt/src/port/Espressif/esp32_sha.c | 2 +- wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h | 1 + wolfssl/wolfcrypt/wc_port.h | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 061a42763e..f8fa1cc29a 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -8201,7 +8201,7 @@ void bench_sphincsKeySign(byte level, byte optim) #endif double current_time(int reset) { - portTickType tickCount; + TickType_t tickCount; (void) reset; diff --git a/wolfcrypt/src/port/Espressif/esp32_aes.c b/wolfcrypt/src/port/Espressif/esp32_aes.c index 0256685cb3..abcfc83114 100644 --- a/wolfcrypt/src/port/Espressif/esp32_aes.c +++ b/wolfcrypt/src/port/Espressif/esp32_aes.c @@ -157,7 +157,7 @@ static void esp_aes_hw_Set_KeyMode(Aes *ctx, ESP32_AESPROCESS mode) static void esp_aes_bk(const byte* in, byte* out) { const word32 *inwords = (const word32 *)in; - word32 *outwords = (word32 *)out; + uint32_t *outwords = (uint32_t *)out; ESP_LOGV(TAG, "enter esp_aes_bk"); diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index 557bde8a94..3f62765002 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -551,7 +551,7 @@ int wc_esp_digest_state(WC_ESP32SHA* ctx, byte* hash) * DPORT_SEQUENCE_REG_READ(address + i * 4); */ esp_dport_access_read_buffer( - (word32*)(hash), /* the result will be found in hash upon exit */ + (uint32_t*)(hash), /* the result will be found in hash upon exit */ SHA_TEXT_BASE, /* there's a fixed reg addy for all SHA */ wc_esp_sha_digest_size(ctx->sha_type) / sizeof(word32) /* # 4-byte */ ); diff --git a/wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h b/wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h index d5ca086254..32d4107dee 100644 --- a/wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h +++ b/wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h @@ -27,6 +27,7 @@ #include "esp_idf_version.h" #include "esp_types.h" #include "esp_log.h" +#include "esp_random.h" #ifdef WOLFSSL_ESP32WROOM32_CRYPT_DEBUG #undef LOG_LOCAL_LEVEL diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 79cac76e94..306692b649 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -202,7 +202,7 @@ #else /* MULTI_THREADED */ /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ #if defined(FREERTOS) - typedef xSemaphoreHandle wolfSSL_Mutex; + typedef SemaphoreHandle_t wolfSSL_Mutex; #elif defined(FREERTOS_TCP) #include "FreeRTOS.h" #include "semphr.h" From b9e69f179502a2c0a5bbb6aa86bcbb0df59d2216 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 16 Dec 2022 10:23:09 -0500 Subject: [PATCH 2/5] Fixes for wolfssl_client example --- .../examples/wolfssl_client/main/wifi_connect.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c index 00475d460b..262106b310 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c @@ -29,19 +29,17 @@ #include "nvs_flash.h" #if ESP_IDF_VERSION_MAJOR >= 4 #include "protocol_examples_common.h" -#endif - +#else const static int CONNECTED_BIT = BIT0; static EventGroupHandle_t wifi_event_group; +#endif + /* proto-type */ extern void tls_smp_client_task(); static void tls_smp_client_init(); const static char *TAG = "tls_client"; -static EventGroupHandle_t wifi_event_group; -extern void tls_smp_client_task(); - static void set_time() { /* set dummy wallclock time. */ @@ -80,7 +78,7 @@ static void set_time() static void tls_smp_client_init(void) { int ret; - xTaskHandle _handle; + TaskHandle_t _handle; /* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */ ret = xTaskCreate(tls_smp_client_task, TLS_SMP_CLIENT_TASK_NAME, @@ -93,6 +91,7 @@ static void tls_smp_client_init(void) ESP_LOGI(TAG, "create thread %s failed", TLS_SMP_CLIENT_TASK_NAME); } } +#if ESP_IDF_VERSION_MAJOR < 4 /* event handler for wifi events */ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { @@ -121,6 +120,7 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) } return ESP_OK; } +#endif /* entry point */ void app_main(void) { @@ -137,7 +137,6 @@ void app_main(void) /* */ #if ESP_IDF_VERSION_MAJOR >= 4 - (void) wifi_event_handler; ESP_ERROR_CHECK(esp_event_loop_create_default()); /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. * Read "Establishing Wi-Fi or Ethernet Connection" section in From 814ad9fc38a677e434c484bae212c1f4e72784d9 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 16 Dec 2022 11:55:28 -0500 Subject: [PATCH 3/5] Better fixes --- .../ESP-IDF/examples/wolfssl_client/main/wifi_connect.c | 6 +++++- wolfcrypt/benchmark/benchmark.c | 4 ++++ wolfcrypt/src/port/Espressif/esp32_aes.c | 4 ++++ wolfcrypt/src/port/Espressif/esp32_sha.c | 4 ++++ wolfssl/wolfcrypt/wc_port.h | 4 ++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c index 262106b310..c9c87e368f 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c @@ -78,7 +78,11 @@ static void set_time() static void tls_smp_client_init(void) { int ret; - TaskHandle_t _handle; + #if ESP_IDF_VERSION_MAJOR >= 4 + TaskHandle_t _handle; + #else + xTaskHandle _handle; + #endif /* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */ ret = xTaskCreate(tls_smp_client_task, TLS_SMP_CLIENT_TASK_NAME, diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index f8fa1cc29a..eda6ed287d 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -8201,7 +8201,11 @@ void bench_sphincsKeySign(byte level, byte optim) #endif double current_time(int reset) { + #if ESP_IDF_VERSION_MAJOR >= 4 TickType_t tickCount; + #else + portTickType tickCount; + #endif (void) reset; diff --git a/wolfcrypt/src/port/Espressif/esp32_aes.c b/wolfcrypt/src/port/Espressif/esp32_aes.c index abcfc83114..8aefd491f0 100644 --- a/wolfcrypt/src/port/Espressif/esp32_aes.c +++ b/wolfcrypt/src/port/Espressif/esp32_aes.c @@ -157,7 +157,11 @@ static void esp_aes_hw_Set_KeyMode(Aes *ctx, ESP32_AESPROCESS mode) static void esp_aes_bk(const byte* in, byte* out) { const word32 *inwords = (const word32 *)in; + #if ESP_IDF_VERSION_MAJOR >= 4 uint32_t *outwords = (uint32_t *)out; + #else + word32 *outwords = (word32 *)out; + #endif ESP_LOGV(TAG, "enter esp_aes_bk"); diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index 3f62765002..f63ce5a70f 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -551,7 +551,11 @@ int wc_esp_digest_state(WC_ESP32SHA* ctx, byte* hash) * DPORT_SEQUENCE_REG_READ(address + i * 4); */ esp_dport_access_read_buffer( + #if ESP_IDF_VERSION_MAJOR >= 4 (uint32_t*)(hash), /* the result will be found in hash upon exit */ + #else + (word32*)(hash), /* the result will be found in hash upon exit */ + #endif SHA_TEXT_BASE, /* there's a fixed reg addy for all SHA */ wc_esp_sha_digest_size(ctx->sha_type) / sizeof(word32) /* # 4-byte */ ); diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 306692b649..256712230c 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -202,7 +202,11 @@ #else /* MULTI_THREADED */ /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ #if defined(FREERTOS) + #if ESP_IDF_VERSION_MAJOR >= 4 typedef SemaphoreHandle_t wolfSSL_Mutex; + #else + typedef xSemaphoreHandle wolfSSL_Mutex; + #endif #elif defined(FREERTOS_TCP) #include "FreeRTOS.h" #include "semphr.h" From d0f0d66b803f19ab40ef772dc7f88b858c78a77f Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 16 Dec 2022 11:55:53 -0500 Subject: [PATCH 4/5] Add in changes to wolfssl_server --- .../examples/wolfssl_server/main/wifi_connect.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c index d2125000c3..672c85fe2d 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c @@ -29,10 +29,11 @@ #include "nvs_flash.h" #if ESP_IDF_VERSION_MAJOR >= 4 #include "protocol_examples_common.h" -#endif - +#else const static int CONNECTED_BIT = BIT0; static EventGroupHandle_t wifi_event_group; +#endif + /* prefix for logging */ const static char *TAG = "tls_server"; /* proto-type definition */ @@ -77,7 +78,11 @@ static void set_time() static void tls_smp_server_init(void) { int ret; - xTaskHandle _handle; + #if ESP_IDF_VERSION_MAJOR >= 4 + TaskHandle_t _handle; + #else + xTaskHandle _handle; + #endif /* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */ ret = xTaskCreate(tls_smp_server_task, TLS_SMP_SERVER_TASK_NAME, @@ -90,6 +95,7 @@ static void tls_smp_server_init(void) ESP_LOGI(TAG, "create thread %s failed", TLS_SMP_SERVER_TASK_NAME); } } +#if ESP_IDF_VERSION_MAJOR < 4 /* event handler for wifi events */ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { @@ -118,6 +124,7 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) } return ESP_OK; } +#endif /* entry point */ void app_main(void) { @@ -134,7 +141,6 @@ void app_main(void) #endif /* */ #if ESP_IDF_VERSION_MAJOR >= 4 - (void) wifi_event_handler; ESP_ERROR_CHECK(esp_event_loop_create_default()); /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. * Read "Establishing Wi-Fi or Ethernet Connection" section in From bc15f67d8da81e2322d24717b3344df2184f52eb Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Mon, 19 Dec 2022 11:13:58 -0500 Subject: [PATCH 5/5] Fixing indentation on preprocessor commands --- .../ESP-IDF/examples/wolfssl_client/main/wifi_connect.c | 6 +++--- .../ESP-IDF/examples/wolfssl_server/main/wifi_connect.c | 6 +++--- wolfcrypt/benchmark/benchmark.c | 6 +++--- wolfcrypt/src/port/Espressif/esp32_aes.c | 6 +++--- wolfcrypt/src/port/Espressif/esp32_sha.c | 6 +++--- wolfssl/wolfcrypt/wc_port.h | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c index c9c87e368f..7379c7aa5b 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/main/wifi_connect.c @@ -78,11 +78,11 @@ static void set_time() static void tls_smp_client_init(void) { int ret; - #if ESP_IDF_VERSION_MAJOR >= 4 +#if ESP_IDF_VERSION_MAJOR >= 4 TaskHandle_t _handle; - #else +#else xTaskHandle _handle; - #endif +#endif /* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */ ret = xTaskCreate(tls_smp_client_task, TLS_SMP_CLIENT_TASK_NAME, diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c index 672c85fe2d..d05983905c 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/main/wifi_connect.c @@ -78,11 +78,11 @@ static void set_time() static void tls_smp_server_init(void) { int ret; - #if ESP_IDF_VERSION_MAJOR >= 4 +#if ESP_IDF_VERSION_MAJOR >= 4 TaskHandle_t _handle; - #else +#else xTaskHandle _handle; - #endif +#endif /* http://esp32.info/docs/esp_idf/html/dd/d3c/group__xTaskCreate.html */ ret = xTaskCreate(tls_smp_server_task, TLS_SMP_SERVER_TASK_NAME, diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 1b5e9be76e..87aa743f5f 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -8216,11 +8216,11 @@ void bench_sphincsKeySign(byte level, byte optim) #endif double current_time(int reset) { - #if ESP_IDF_VERSION_MAJOR >= 4 + #if ESP_IDF_VERSION_MAJOR >= 4 TickType_t tickCount; - #else + #else portTickType tickCount; - #endif + #endif (void) reset; diff --git a/wolfcrypt/src/port/Espressif/esp32_aes.c b/wolfcrypt/src/port/Espressif/esp32_aes.c index 8aefd491f0..062cd8bad2 100644 --- a/wolfcrypt/src/port/Espressif/esp32_aes.c +++ b/wolfcrypt/src/port/Espressif/esp32_aes.c @@ -157,11 +157,11 @@ static void esp_aes_hw_Set_KeyMode(Aes *ctx, ESP32_AESPROCESS mode) static void esp_aes_bk(const byte* in, byte* out) { const word32 *inwords = (const word32 *)in; - #if ESP_IDF_VERSION_MAJOR >= 4 +#if ESP_IDF_VERSION_MAJOR >= 4 uint32_t *outwords = (uint32_t *)out; - #else +#else word32 *outwords = (word32 *)out; - #endif +#endif ESP_LOGV(TAG, "enter esp_aes_bk"); diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index f63ce5a70f..2910291b18 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -551,11 +551,11 @@ int wc_esp_digest_state(WC_ESP32SHA* ctx, byte* hash) * DPORT_SEQUENCE_REG_READ(address + i * 4); */ esp_dport_access_read_buffer( - #if ESP_IDF_VERSION_MAJOR >= 4 +#if ESP_IDF_VERSION_MAJOR >= 4 (uint32_t*)(hash), /* the result will be found in hash upon exit */ - #else +#else (word32*)(hash), /* the result will be found in hash upon exit */ - #endif +#endif SHA_TEXT_BASE, /* there's a fixed reg addy for all SHA */ wc_esp_sha_digest_size(ctx->sha_type) / sizeof(word32) /* # 4-byte */ ); diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 6ff1c27616..b5bdbba4c9 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -203,9 +203,9 @@ /* FREERTOS comes first to enable use of FreeRTOS Windows simulator only */ #if defined(FREERTOS) #if ESP_IDF_VERSION_MAJOR >= 4 - typedef SemaphoreHandle_t wolfSSL_Mutex; + typedef SemaphoreHandle_t wolfSSL_Mutex; #else - typedef xSemaphoreHandle wolfSSL_Mutex; + typedef xSemaphoreHandle wolfSSL_Mutex; #endif #elif defined(FREERTOS_TCP) #include "FreeRTOS.h"