Topic: Program can't find WolfSSL headers in ESP-IDF

Hello. I've been using wolfssl in Arduino IDE with my ESP32, but then I found out that I couldn't enable hardware acceleration using Arduino IDE (I tried, but there was a mising freertos.h error when compiling). Then I decided to switch to ESP-IDF, and so I ported my code to this environment.

I've added wolfssl as a component to my project, in the following folder structure:

my_project
|_components
   |_wolfssl
      |_include
      |  |_user_settings.h
      |_CMakeLists.txt

The wolfssl source code is located in C:/, and I added it as an enviroment variable so I could reference in the CMakeLists file, as https://github.com/wolfSSL/wolfssl/tree … -component tells us to. I've also defined the macros I need in user_settings.h, which are:

#define WOLFSSL_SHAKE256
#define WOLFSSL_CUSTOM_CURVES
#define WOLFSSL_KEY_GEN
#define ECC256
#define HAVE_ECC_BRAINPOOL
#define HAVE_ED448

However, when I build my project, I get many errors of undefined identifiers, such as "identifier 'wc_ed25519_init' is undefined", even though I've included all necessary headers, and even though CTRL + Clicking in those functions/variables successfully navigates to the respective file. Also, some functions are found, such as "wc_InitRsaKey".

Is there something I'm missing here? I've been stuck on this for the last 3 days and any help would be hugely appreciated.

Share

Re: Program can't find WolfSSL headers in ESP-IDF

Hello gabriel and thank you for your interest in wolfSSL.

It does appear that your local project component directory is correctly structured.

Without seeing your source code, it is difficult to say exactly what the root cause of the problem may be, but I do have some suggestions for you.

I started with the bare-bones Espressif template example here:

https://github.com/wolfSSL/wolfssl/tree … s/template

Using your example of  needing`wc_InitRsaKey()`, the `ed25519.h` file needs to be included.

The two most important things to remember:

1) `WOLFSSL_USER_SETTINGS` needs to be defined. See the first line in the `template/main/CMakeLists.txt`:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")

2) It is important to include the wolfssl/wolfcrypt/settings.h files before any other wolfSSL includes.


#ifdef WOLFSSL_USER_SETTINGS
    #include <wolfssl/wolfcrypt/settings.h>
    #ifndef WOLFSSL_ESPIDF
        #warning "Problem with wolfSSL user_settings."
        #warning "Check components/wolfssl/include"
    #endif
    #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
#else
    /* Define WOLFSSL_USER_SETTINGS project wide for settings.h to include   */
    /* wolfSSL user settings in ./components/wolfssl/include/user_settings.h */
    #error "Missing WOLFSSL_USER_SETTINGS in CMakeLists or Makefile:\
    CFLAGS +=-DWOLFSSL_USER_SETTINGS"
#endif

#include <wolfssl/wolfcrypt/ed25519.h>

Then I added these two lines to `void app_main(void)` int `main.c`:


    ed25519_key key;
    wc_ed25519_init(&key);

I was able to confirm the template example would compile.

If you try these steps and the file still cannot be found, please reply with the CMake output, in particular the sections that include the `WOLFSSL_ROOT` keyword. Ensure you are using a recent CMakeLists.txt, such as the one on the example template `components/wolfssl` directory. There should be something like this in the log:

-- Starting FIND_WOLFSSL_DIRECTORY: 
-- The WOLFSSL_ROOT environment variable is not set. Searching...
-- WOLFSSL_ROOT found in sdkconfig/KConfig: ~/workspace/wolfssl
-- CONFIG_CUSTOM_SETTING_WOLFSSL_ROOT sdkconfig setting = ~/workspace/wolfssl
-- WOLFSSL_ROOT Variable defined, but source code not found: C:/Users/<user>/workspace/wolfssl
-- CMAKE_CURRENT_SOURCE_DIR = .

After the lines of search, there should be an indication of the wolfSSL directory found:

-- Found wolfssl in CURRENT_SEARCH_DIR = C:/workspace/wolfssl-<user>
-- Found WOLFSSL_ROOT via CMake specification.

You may consider setting an environment variable `WOLFSSL_ROOT` that points your wolfSSL source code directory if your directory structure is such that wolfSSL is not in a parent directory from your project. Moving your project into the wolfSSL directory structure is also an option.

There's additional information and a link to a YouTube video on Getting Started with wolfSSL on the ESP32 here:

https://github.com/wolfSSL/wolfssl/tree … /Espressif

If these tips don't help, it would be great if you could supply a small reproducer app sample so I can further assist you.

Please let me know how it goes. Thank you.

Jim

Share

Re: Program can't find WolfSSL headers in ESP-IDF

gojimmypi wrote:

Please let me know how it goes. Thank you.

Hello Jim, and thank you very much for your quick answer!

This is the source code of my project: https://github.com/siegjor/esp32-crypto-api/tree/main

Something that I forgot to say earlier, but that it might be relevant, is that I'm trying to develop a component, called CryptoAPI, and it's in this component that I'll use wolfssl (and as you notice from the source code, other libraries too). My main.cpp file will only contain a include for my CryptoAPI.h file, which includes the WolfsslModule.h file, which includes all of the wolfssl headers I need to use.

Now for the fixes you suggested me:

gojimmypi wrote:

`WOLFSSL_USER_SETTINGS` needs to be defined. See the first line in the `template/main/CMakeLists.txt

I've noticed that it WOLFSSL_USER_SETTINGS was already being defined in "esp32-crypto-api/components
/wolfssl/CMakeLists.txt", so I imagined it was ok. I've done as you said and defined it in esp32-crypto-api/main/CMakeLists.txt, but it still didn't work.

gojimmypi wrote:

2) It is important to include the wolfssl/wolfcrypt/settings.h files before any other wolfSSL includes.

As you can see in "esp32-crypto-api/components/CryptoAPI/include/WolfsslModule.h", I'm already doing that.

gojimmypi wrote:

If you try these steps and the file still cannot be found, please reply with the CMake output

I've found some of the lines you mentioned:

-- ************************************************************************************************
-- wolfssl component config:
-- ************************************************************************************************
-- Starting FIND_WOLFSSL_DIRECTORY: C:/wolfssl
-- Parameter found for FIND_WOLFSSL_DIRECTORY
-- Setting wolfSSL search directory to: C:/wolfssl
-- Found wolfSSL source code via setting: C:/wolfssl
-- Found WOLFSSL_ROOT via CMake specification.
-- Confirmed wolfssl directory at: C:/wolfssl
-- WOLFSSL_EXTRA_PROJECT_DIR = C:/wolfssl/src/
-- This COMPONENT_SRCDIRS = "C:/wolfssl/src/";"C:/wolfssl/wolfcrypt/src";"C:/wolfssl/wolfcrypt/src/port/Espressif";"C:/wolfssl/wolfcrypt/src/port/Espressif/esp_crt_bundle";"C:/wolfssl/wolfcrypt/src/port/atmel";"C:/wolfssl/src/"
-- Added definition for user_settings.h: -DWOLFSSL_USER_SETTINGS_DIR="C://Users//myuser//Documents//CryptoAPI//components//wolfssl//include//user_settings.h"
-- IDF_PATH = C:\Espressif\frameworks\esp-idf-v5.3.1
-- PROJECT_SOURCE_DIR = C:/Espressif/frameworks/esp-idf-v5.3.1
-- EXCLUDE_ASM = C:/Users/myuser/Documents/CryptoAPI;C:/wolfssl/wolfcrypt/src/aes_asm.S;C:/wolfssl/wolfcrypt/src/aes_gcm_asm.S;C:/wolfssl/wolfcrypt/src/aes_gcm_x86_asm.S;C:/wolfssl/wolfcrypt/src/aes_xts_asm.S;C:/wolfssl/wolfcrypt/src/chacha_asm.S;C:/wolfssl/wolfcrypt/src/fe_x25519_asm.S;C:/wolfssl/wolfcrypt/src/poly1305_asm.S;C:/wolfssl/wolfcrypt/src/sha256_asm.S;C:/wolfssl/wolfcrypt/src/sha3_asm.S;C:/wolfssl/wolfcrypt/src/sha512_asm.S;C:/wolfssl/wolfcrypt/src/sm3_asm.S;C:/wolfssl/wolfcrypt/src/sp_sm2_x86_64_asm.S;C:/wolfssl/wolfcrypt/src/sp_x86_64_asm.S;C:/wolfssl/wolfcrypt/src/wc_kyber_asm.S
--
-- Using developer repo ./components/wolfssl in CMAKE_HOME_DIRECTORY = C:/Users/Brist/Documents/TCC/codigo/esp-idf-code/CryptoAPI
--
-- ************************************************************************************************
-- Using existing wolfSSL user_settings.h in C:/Users/myuser/Documents/CryptoAPI/components/wolfssl/include/user_settings.h
-- Using existing wolfSSL config.h           C:/Users/myuser/Documents/CryptoAPI/components/wolfssl/include/config.h

There's however a line before these ones that maybe can have something to do with this problem?

-- Begin wolfssl
-- C:/Users/myuser/Documents/CryptoAPI/components/wolfssl is not within IDF_PATH. (<-- this line)

I've also already set a WOLFSSL_ROOT env variable pointing to "C:/wolfssl". And while I have yet to try your approach of putting my project within the wolfssl directory structure, I did try adding wolfssl as a managed component and also installing it via the setup_win.bat, but none of it worked, as both of these options resulted in the same problem I'm facing now.

Some other information that might be relevant:
- I'm using vscode, and I setup this project through the espressif extension UI ("create new project", etc.);
- Before running idf.py set-target esp32 (or after deleting the build folder), the wolfssl header files in WolfsslModule.h aren't found ("cannot open source file wolfssl/wolfcrypt/settings.h");
- After running the command above and generating the build folder, the IDE apparently finds those headers, but the problem of undefined identifiers arises.

If there's any other useful info that I could provide, please let me know.

Thank you very much for your help, I'll keep trying to make it work somehow while I wait for your reply.

Gabriel

Share

Re: Program can't find WolfSSL headers in ESP-IDF

Hello Gabriel,

Thank you for providing the source code and additional details.

Now that I see what you are doing, perhaps this will help.

I placed your code in my `wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples`directory so that wolfSSL source code would be found in a parent directory. Alternatively, the `WOLFSSL_ROOT` environment variable can be set, as described above. From your log, you probably don't need to move your code.

Please try adding these two lines to the `CryptoAPI` component `CmakeLists.txt` in `esp32-crypto-api\components\CryptoAPI`:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWOLFSSL_USER_SETTINGS")

There are still a few compile errors, indirectly related to wolfSSL that can be readily addressed, but otherwise successful:


Error    enumeration value 'RSA' not handled in switch wolfssl_IDF_v5.2_ESP32 C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\esp32-crypto-api\components\CryptoAPI\src\WolfsslModule.cpp 98  
Error    'ret' may be used uninitialized               wolfssl_IDF_v5.2_ESP32 C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\esp32-crypto-api\components\CryptoAPI\src\WolfsslModule.cpp 399 
Error    'cert_type' may be used uninitialized         wolfssl_IDF_v5.2_ESP32 C:\workspace\wolfssl-gojimmypi\IDE\Espressif\ESP-IDF\examples\esp32-crypto-api\components\CryptoAPI\src\WolfsslModule.cpp 488 

The message you asked about is informative and otherwise ok:

C:/Users/myuser/Documents/CryptoAPI/components/wolfssl is not within IDF_PATH.

It only indicates that the wolfSSL is not an ESP-IDF component.

Please let me know how that goes.

Best Regards,

Jim

Share

Re: Program can't find WolfSSL headers in ESP-IDF

gojimmypi wrote:

Please let me know how that goes.
Jim

Hello Jim,

It worked!!! I've addressed those errors and now my project builds fine.

Thank you very very much for your help!

Gabriel

Share

Re: Program can't find WolfSSL headers in ESP-IDF

Hello Gabriel,

That's excellent! Glad you have it working.

Note that wolfSSL has many different configuration options to tune for performance, size, etc. See the docs:

https://www.wolfssl.com/documentation/m … ter02.html

If you decide to include OpenSSL in your analysis, there's a wolfSSL compatibility layer:

https://www.wolfssl.com/documentation/m … ter13.html

Best of luck with your project! Please let me know if I can help in any way.

Jim

Share