Skip to content

Commit 8a71c3b

Browse files
Merge pull request #8066 from gojimmypi/pr-espressif-wolfcrypt
Apply various Espressif compatibility updates
2 parents efff8e0 + 187a9b5 commit 8a71c3b

6 files changed

Lines changed: 68 additions & 29 deletions

File tree

wolfcrypt/src/port/Espressif/esp32_aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ int esp_hw_show_aes_metrics(void)
637637
#if defined(WOLFSSL_HW_METRICS)
638638

639639
ESP_LOGI(TAG, "--------------------------------------------------------");
640-
ESP_LOGI(TAG, "------------- wolfSSL ESP HW AES Metrics----------------");
640+
ESP_LOGI(TAG, "------------- wolfSSL ESP HW AES Metrics -------------");
641641
ESP_LOGI(TAG, "--------------------------------------------------------");
642642

643643
ESP_LOGI(TAG, "esp_aes_unsupported_length_usage_ct = %lu",

wolfcrypt/src/port/Espressif/esp32_sha.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ int esp_hw_show_sha_metrics(void)
23842384
int ret = 0;
23852385
#if defined(WOLFSSL_ESP32_CRYPT) && !defined(NO_WOLFSSL_ESP32_CRYPT_HASH)
23862386
ESP_LOGI(TAG, "--------------------------------------------------------");
2387-
ESP_LOGI(TAG, "------------- wolfSSL ESP HW SHA Metrics----------------");
2387+
ESP_LOGI(TAG, "------------- wolfSSL ESP HW SHA Metrics -------------");
23882388
ESP_LOGI(TAG, "--------------------------------------------------------");
23892389

23902390
ESP_LOGI(TAG, "esp_sha_hw_copy_ct = %lu",

wolfcrypt/src/port/Espressif/esp_crt_bundle/esp_crt_bundle.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ esp_err_t esp_crt_bundle_attach(void *conf)
6161
#include <wolfssl/wolfcrypt/asn.h>
6262
#include <wolfssl/wolfcrypt/error-crypt.h>
6363

64-
#include <esp_tls.h> /* needed only for esp_tls_free_global_ca_store() */
64+
#ifdef WOLFSSL_CMAKE_REQUIRED_ESP_TLS
65+
/* We're already here since CONFIG_ESP_TLS_USING_WOLFSSL is enabled, */
66+
/* but do we have a recent version of wolfSSL CMakeLists.txt to support */
67+
/* using wolfSSL in ESP-IDF? If so, include the esp-tls component here: */
68+
#include <esp_tls.h> /* needed only for esp_tls_free_global_ca_store() */
69+
#endif
6570

6671
/* There's a minimum version of wolfSSL needed for Certificate Bundle Support.
6772
*
6873
* See the latest code at:
69-
* https://github.com/wolfSSL/wolfssl or
74+
* https://github.com/wolfSSL/wolfssl or Managed Components at
7075
* https://www.wolfssl.com/wolfssl-now-available-in-espressif-component-registry/
7176
*/
7277
#if defined(WOLFSSL_ESPIDF_COMPONENT_VERSION)
@@ -186,12 +191,10 @@ typedef struct crt_bundle_t {
186191
static WOLFSSL_X509* store_cert = NULL; /* will point to existing param values*/
187192
static WOLFSSL_X509* bundle_cert = NULL; /* the iterating cert being reviewed.*/
188193

189-
static const uint8_t **crts = NULL;
190-
static uint16_t num_certs = 0;
191-
192-
193-
/* Found in <esp_tls.h> */
194-
void esp_tls_free_global_ca_store(void);
194+
#ifdef CONFIG_WOLFSSL_CERTIFICATE_BUNDLE
195+
static const uint8_t **crts = NULL;
196+
static uint16_t num_certs = 0;
197+
#endif
195198

196199
#ifdef CONFIG_WOLFSSL_CERTIFICATE_BUNDLE
197200
static esp_err_t wolfssl_esp_crt_bundle_init(const uint8_t *x509_bundle,
@@ -1514,7 +1517,12 @@ esp_err_t wolfSSL_bundle_cleanup(void)
15141517
s_crt_bundle.crts = NULL;
15151518
}
15161519

1520+
#ifdef WOLFSSL_CMAKE_REQUIRED_ESP_TLS
1521+
/* When the esp-tls is linked as a requirement in CMake and used by the
1522+
* ESP-IDF in the esp-tls component, call at cleanup time: */
15171523
esp_tls_free_global_ca_store();
1524+
#endif
1525+
15181526
/* Be sure to free the bundle_cert first, as it may be part of store. */
15191527
if (bundle_cert != NULL) {
15201528
#ifdef DEBUG_WOLFSSL_MALLOC

wolfcrypt/src/port/Espressif/esp_sdk_mem_lib.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
/* wolfSSL */
2727
/* Always include wolfcrypt/settings.h before any other wolfSSL file. */
28-
/* Reminder: settings.h pulls in user_settings.h; don't include it here. */
29-
#ifdef WOLFSSL_USER_SETTINGS
30-
#include <wolfssl/wolfcrypt/settings.h>
31-
#endif
28+
/* Be sure to define WOLFSSL_USER_SETTINGS, typically in CMakeLists.txt */
29+
/* Reminder: settings.h pulls in user_settings.h */
30+
/* Do not explicitly include user_settings.h here. */
31+
#include <wolfssl/wolfcrypt/settings.h>
3232

3333
#if defined(WOLFSSL_ESPIDF) /* Entire file is only for Espressif EDP-IDF */
3434

@@ -71,8 +71,6 @@ extern wc_ptr_t _rodata_start[];
7171
extern wc_ptr_t _rodata_end[];
7272
extern wc_ptr_t _bss_start[];
7373
extern wc_ptr_t _bss_end[];
74-
extern wc_ptr_t _rtc_data_start[];
75-
extern wc_ptr_t _rtc_data_end[];
7674
extern wc_ptr_t _rtc_bss_start[];
7775
extern wc_ptr_t _rtc_bss_end[];
7876
extern wc_ptr_t _iram_start[];
@@ -83,16 +81,24 @@ extern wc_ptr_t _init_end[];
8381
#endif
8482
extern wc_ptr_t _iram_text_start[];
8583
extern wc_ptr_t _iram_text_end[];
86-
extern wc_ptr_t _iram_bss_start[];
87-
extern wc_ptr_t _iram_bss_end[];
84+
#if defined(CONFIG_IDF_TARGET_ESP32S2)
85+
/* TODO: Find ESP32-S2 equivalent */
86+
#else
87+
extern wc_ptr_t _iram_bss_start[];
88+
extern wc_ptr_t _iram_bss_end[];
89+
#endif
8890
extern wc_ptr_t _noinit_start[];
8991
extern wc_ptr_t _noinit_end[];
9092
extern wc_ptr_t _text_start[];
9193
extern wc_ptr_t _text_end[];
9294
extern wc_ptr_t _heap_start[];
9395
extern wc_ptr_t _heap_end[];
94-
extern wc_ptr_t _rtc_data_start[];
95-
extern wc_ptr_t _rtc_data_end[];
96+
#ifdef CONFIG_IDF_TARGET_ESP32C2
97+
/* no rtc_data on ESP32-C2*/
98+
#else
99+
extern wc_ptr_t _rtc_data_start[];
100+
extern wc_ptr_t _rtc_data_end[];
101+
#endif
96102

97103
#if defined(CONFIG_IDF_TARGET_ARCH_XTENSA) && CONFIG_IDF_TARGET_ARCH_XTENSA == 1
98104
extern void* _thread_local_start;
@@ -194,7 +200,11 @@ int sdk_init_meminfo(void) {
194200
#endif
195201
sdk_log_meminfo(data, _data_start, _data_end);
196202
sdk_log_meminfo(user_data_ram, USER_DATA_START, USER_DATA_END);
203+
#if defined(CONFIG_IDF_TARGET_ESP32S2)
204+
/* TODO: Find ESP32-S2 equivalent of bss */
205+
#else
197206
sdk_log_meminfo(bss, _bss_start, _bss_end);
207+
#endif
198208
sdk_log_meminfo(noinit, _noinit_start, _noinit_end);
199209
sdk_log_meminfo(ets_system, ETS_SYS_START, ETS_SYS_END);
200210
sdk_log_meminfo(rodata, _rodata_start, _rodata_end);
@@ -203,12 +213,20 @@ int sdk_init_meminfo(void) {
203213
sdk_log_meminfo(iramf2, IRAMF2_START, IRAMF2_END);
204214
sdk_log_meminfo(iram, _iram_start, _iram_end);
205215
sdk_log_meminfo(iram_text, _iram_text_start, _iram_text_end);
216+
#if defined(CONFIG_IDF_TARGET_ESP32S2)
217+
/* No iram_bss on ESP32-C2 at this time. TODO: something equivalent? */
218+
#else
206219
sdk_log_meminfo(iram_bss, _iram_bss_start, _iram_bss_end);
220+
#endif
207221
#if defined(CONFIG_IDF_TARGET_ESP8266)
208222
sdk_log_meminfo(init, _init_start, _init_end);
209223
#endif
210224
sdk_log_meminfo(text, _text_start, _text_end);
225+
#if defined(CONFIG_IDF_TARGET_ESP32C2)
226+
/* No rtc_data on ESP32-C2 at this time. TODO: something equivalent? */
227+
#else
211228
sdk_log_meminfo(rtc_data, _rtc_data_start, _rtc_data_end);
229+
#endif
212230
ESP_LOGI(TAG, "-----------------------------------------------------");
213231
sample_heap_var = malloc(1);
214232
if (sample_heap_var == NULL) {

wolfcrypt/src/port/Espressif/esp_sdk_wifi_lib.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
#include <config.h>
2424
#endif
2525

26-
/* Reminder: user_settings.h is needed and included from settings.h
27-
* Be sure to define WOLFSSL_USER_SETTINGS, typically in CMakeLists.txt */
26+
/* wolfSSL */
27+
/* Always include wolfcrypt/settings.h before any other wolfSSL file. */
28+
/* Be sure to define WOLFSSL_USER_SETTINGS, typically in CMakeLists.txt */
29+
/* Reminder: settings.h pulls in user_settings.h */
30+
/* Do not explicitly include user_settings.h here. */
2831
#include <wolfssl/wolfcrypt/settings.h>
2932

3033
#if defined(WOLFSSL_ESPIDF) /* Entire file is only for Espressif EDP-IDF */

wolfssl/wolfcrypt/port/Espressif/esp_crt_bundle.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
#define __ESP_CRT_BUNDLE_wolfssl_LIB_H__
2929

3030
/* This file is typically NOT directly used by applications utilizing the
31-
* wolfSSL libraries. It is used when the wolfssl libary component is configured
32-
* to be utilized by the Espressif ESP-IDF, specifically the esp-tls layer.
31+
* wolfSSL libraries. It is used when the wolfssl library component is
32+
* configured to be utilized by the Espressif ESP-IDF, specifically the
33+
* esp-tls layer.
3334
*
3435
* See: esp-idf api-reference for esp_tls.
3536
* https://github.com/espressif/esp-idf/blob/master/components/esp-tls/esp_tls.h
@@ -53,7 +54,16 @@
5354
* Normally on, this uses the compiler `inline` decorator for bundle functions
5455
* to be optimized, since they are called during a TLS connection.
5556
*
56-
* See Kconfig file (or use idy.py menufconfig) for other bundle settings.
57+
* See Kconfig file (or use idy.py menuconfig) for other bundle settings.
58+
*
59+
*******************************************************************************
60+
** Other Settings:
61+
*******************************************************************************
62+
* WOLFSSL_CMAKE_REQUIRED_ESP_TLS
63+
* This is defined in the wolfssl component cmake file when the esp-tls
64+
* component is required. This is typically when Certificate Bundles are
65+
* enabled, and the esp_tls_free_global_ca_store() in the esp-tls needs
66+
* to be called from the wolfSSL wolfSSL_bundle_cleanup().
5767
*/
5868

5969
/* wolfSSL */
@@ -121,14 +131,14 @@ esp_err_t esp_crt_bundle_attach(void *conf);
121131

122132
#else
123133
/**
124-
* @brief Return ESP_OK for valid bunder, otherwise ESP_FAIL.
134+
* @brief Return ESP_OK for valid bundle, otherwise ESP_FAIL.
125135
*
126136
* Specific to wolfSSL. Not used by ESP-IDF esp-tls layer.
127137
*/
128138
esp_err_t esp_crt_bundle_is_valid(void);
129139

130140
/**
131-
* @brief Return 1 if Cert Bundle loaded, otheriwse 0.
141+
* @brief Return 1 if Cert Bundle loaded, otherwise 0.
132142
*
133143
* Specific to wolfSSL. Not used by ESP-IDF esp-tls layer.
134144
*/
@@ -169,7 +179,7 @@ void esp_crt_bundle_detach(wolfssl_ssl_config *conf);
169179
*
170180
* @return
171181
* - ESP_OK if adding certificates was successful.
172-
* - Other if an error occured or an action must be taken
182+
* - Other if an error occurred or an action must be taken
173183
* by the calling process.
174184
*/
175185
esp_err_t esp_crt_bundle_set(const uint8_t *x509_bundle, size_t bundle_size);
@@ -179,7 +189,7 @@ esp_err_t esp_crt_bundle_set(const uint8_t *x509_bundle, size_t bundle_size);
179189
* @brief Set the issuer and subject values given the current cert.
180190
*
181191
* Used internally by ESP-IDF esp-tls layer. Also helpful for debugging
182-
* and general visibiity to certificate attributes.
192+
* and general visibility to certificate attributes.
183193
*
184194
* The CERT_TAG can be used at the esp-tls or application layer to indicate
185195
* the usage of the respective cert (e.g. the string "peer").

0 commit comments

Comments
 (0)