Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ed25519_test fails on ESP32 #5948

Closed
PaulMartinsen opened this issue Jan 3, 2023 · 30 comments
Closed

[Bug]: ed25519_test fails on ESP32 #5948

PaulMartinsen opened this issue Jan 3, 2023 · 30 comments
Assignees
Labels

Comments

@PaulMartinsen
Copy link

Contact Details

[email protected]

Version

d686f0a (last commit on 2022/12/23)

Description

Calling wolf_test_task() fails in the ed25519_test() function when running on ESP32, IDF5.0 with error code -229.

Failure point is in ed25519_verify_msg_final_with_sha(...) (ed25519.c) where ret = ConstantCompare(rcheck, sig, ED25519_SIG_SIZE/2);` returns 255 instead of the expected 0.

Note, it takes about 2 minutes between completing the AES-GCM test and reaching this fault, so the log reports several watchdog events warning the idle task is not running (because the tests are using up all the processor time).

A work around is to comment out HAVE_ED25519 in user_settings.h if ED255519 isn't needed.

Reproduction steps

Created new project, based on hello example, in VisualGDB. Using IDFv5, recent commit from WolfSSL master branch and also v5.5.4.
Calling wolf_test_task() from main.

#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include <iostream>

#include <wolfssl/wolfcrypt/settings.h> // make sure this appears before any other wolfSSL headers
#include <wolfcrypt/test/test.h>

using namespace  std;

extern "C" void app_main(void)
{
    printf("Hello world!\n");

  cout << "\n\nWolf tests\n";
  int rc = wolf_test_task();
  cout << "Test result = " << rc << endl;

  
  cout << "Done.";
  
  while (true)
  {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

Wait patiently.

Relevant log output

------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES192   test passed!
AES256   test passed!
AES-GCM  test passed!
�[0;31mE (10500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (10500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (10500) task_wdt: Tasks currently running:�[0m
�[0;31mE (10500) task_wdt: CPU 0: main�[0m
�[0;31mE (10500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (10500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x40082181:0x3FFB6A40 0x400FEEB2:0x3FFB6A60 0x400FF3C9:0x3FFB6A80 0x400FE2A6:0x3FFB6CE0 0x400FE36E:0x3FFB6D00 0x400F63AD:0x3FFB6D20 0x400F6622:0x3FFB6D60 0x400F6764:0x3FFB6DA0 0x400F69BA:0x3FFB6E00 0x400D86B5:0x3FFB6E50 0x400DD968:0x3FFB6EC0 0x400DED03:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (15500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (15500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (15500) task_wdt: Tasks currently running:�[0m
�[0;31mE (15500) task_wdt: CPU 0: main�[0m
�[0;31mE (15500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (15500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FEEA7:0x3FFB69F0 0x400FF3C9:0x3FFB6A10 0x400FE2A6:0x3FFB6C70 0x400FE36E:0x3FFB6C90 0x400F63AD:0x3FFB6CB0 0x400F6622:0x3FFB6CF0 0x400F6686:0x3FFB6D30 0x400F6BE3:0x3FFB6D60 0x400F6D19:0x3FFB6DB0 0x400D909D:0x3FFB6DF0 0x400DD989:0x3FFB6EC0 0x400DED03:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

RSA      test passed!
PWDBASED test passed!
�[0;31mE (20500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (20500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (20500) task_wdt: Tasks currently running:�[0m
�[0;31mE (20500) task_wdt: CPU 0: main�[0m
�[0;31mE (20500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (20500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4000BFED:0x3FFB6BB0 0x400885DF:0x3FFB6BC0 0x400D4BFF:0x3FFB6BE0 0x400FEE40:0x3FFB6C00 0x400FEFDC:0x3FFB6C20 0x400FC8F5:0x3FFB6C50 0x400FC955:0x3FFB6C70 0x400E3FAF:0x3FFB6C90 0x400E4E06:0x3FFB6CD0 0x400E5082:0x3FFB6D00 0x400E52A8:0x3FFB6D60 0x400E61A9:0x3FFB6DC0 0x400E638F:0x3FFB6E50 0x400D9D4D:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF33:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (25500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (25500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (25500) task_wdt: Tasks currently running:�[0m
�[0;31mE (25500) task_wdt: CPU 0: main�[0m
�[0;31mE (25500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (25500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC2B5:0x3FFB6910 0x400FC33E:0x3FFB6940 0x400FE629:0x3FFB6960 0x400E401D:0x3FFB6980 0x400E4E06:0x3FFB69C0 0x400E5082:0x3FFB69F0 0x400E547A:0x3FFB6A50 0x400E592A:0x3FFB6CD0 0x400E5A4F:0x3FFB6D50 0x400E5B28:0x3FFB6DA0 0x400E5D47:0x3FFB6DE0 0x400E5E61:0x3FFB6E50 0x400D9D25:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF3F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (30500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (30500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (30500) task_wdt: Tasks currently running:�[0m
�[0;31mE (30500) task_wdt: CPU 0: main�[0m
�[0;31mE (30500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (30500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4000BFED:0x3FFB6990 0x400885DF:0x3FFB69A0 0x400D511B:0x3FFB69C0 0x400FEF18:0x3FFB69E0 0x400FF051:0x3FFB6A00 0x400FC8F5:0x3FFB6A30 0x400FC955:0x3FFB6A50 0x400E419F:0x3FFB6A70 0x400E4E06:0x3FFB6AB0 0x400E5082:0x3FFB6AE0 0x400E547A:0x3FFB6B40 0x400E55F5:0x3FFB6DC0 0x400E570E:0x3FFB6E40 0x400E57AF:0x3FFB6E60 0x400D9C89:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF4B:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (35500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (35500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (35500) task_wdt: Tasks currently running:�[0m
�[0;31mE (35500) task_wdt: CPU 0: main�[0m
�[0;31mE (35500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (35500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x40139F4D:0x3FFB6C70 0x400FC6B6:0x3FFB6C90 0x400E40D7:0x3FFB6CB0 0x400E4E06:0x3FFB6CF0 0x400E5082:0x3FFB6D20 0x400E52A8:0x3FFB6D80 0x400E5391:0x3FFB6DE0 0x400E69B7:0x3FFB6E20 0x400E6A25:0x3FFB6E80 0x400DA32C:0x3FFB6EA0 0x400DA448:0x3FFB6ED0 0x400DDF4B:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (40500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (40500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (40500) task_wdt: Tasks currently running:�[0m
�[0;31mE (40500) task_wdt: CPU 0: main�[0m
�[0;31mE (40500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (40500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FEEB2:0x3FFB6AB0 0x400FF01D:0x3FFB6AD0 0x400FC8F5:0x3FFB6B00 0x400FC955:0x3FFB6B20 0x400E4104:0x3FFB6B40 0x400E4E06:0x3FFB6B80 0x400E5082:0x3FFB6BB0 0x400E52A8:0x3FFB6C10 0x400E61A9:0x3FFB6C70 0x400E638F:0x3FFB6D00 0x400FBAAB:0x3FFB6D30 0x400FBD8D:0x3FFB6D70 0x400FBDDA:0x3FFB6DB0 0x400D96DA:0x3FFB6DE0 0x400D9A8D:0x3FFB6EC0 0x400DDF5D:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (45500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (45500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (45500) task_wdt: Tasks currently running:�[0m
�[0;31mE (45500) task_wdt: CPU 0: main�[0m
�[0;31mE (45500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (45500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4000BFED:0x3FFB6940 0x400885DF:0x3FFB6950 0x40089773:0x3FFB6970 0x40081FBE:0x3FFB6990 0x4008A941:0x3FFB69B0 0x400FC31D:0x3FFB69D0 0x400FC33E:0x3FFB6A00 0x400FE629:0x3FFB6A20 0x400E3C9F:0x3FFB6A40 0x400E4EEF:0x3FFB6A70 0x400E506B:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400E5AAE:0x3FFB6E80 0x400DA268:0x3FFB6EA0 0x400DA428:0x3FFB6ED0 0x400DDF6A:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (50500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (50500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (50500) task_wdt: Tasks currently running:�[0m
�[0;31mE (50500) task_wdt: CPU 0: main�[0m
�[0;31mE (50500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (50500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC284:0x3FFB69B0 0x400FC33E:0x3FFB69E0 0x400FE629:0x3FFB6A00 0x400E4151:0x3FFB6A20 0x400E4E06:0x3FFB6A60 0x400E5082:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400D9C19:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF77:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (55500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (55500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (55500) task_wdt: Tasks currently running:�[0m
�[0;31mE (55500) task_wdt: CPU 0: main�[0m
�[0;31mE (55500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (55500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4000BFED:0x3FFB6B70 0x400885DF:0x3FFB6B80 0x40086624:0x3FFB6BA0 0x400FF959:0x3FFB6BE0 0x400FEE17:0x3FFB6C00 0x400FEFDC:0x3FFB6C20 0x400FC8F5:0x3FFB6C50 0x400FC955:0x3FFB6C70 0x400E4141:0x3FFB6C90 0x400E4E06:0x3FFB6CD0 0x400E5082:0x3FFB6D00 0x400E52A8:0x3FFB6D60 0x400E618E:0x3FFB6DC0 0x400E638F:0x3FFB6E50 0x400D9D4D:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF77:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (60500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (60500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (60500) task_wdt: Tasks currently running:�[0m
�[0;31mE (60500) task_wdt: CPU 0: main�[0m
�[0;31mE (60500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (60500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x40081D95:0x3FFB6970 0x40081FA6:0x3FFB6990 0x4008A941:0x3FFB69B0 0x400FC31D:0x3FFB69D0 0x400FC33E:0x3FFB6A00 0x400FE629:0x3FFB6A20 0x400E3DD5:0x3FFB6A40 0x400E4EEF:0x3FFB6A70 0x400E506B:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400E5AAE:0x3FFB6E80 0x400DA268:0x3FFB6EA0 0x400DA428:0x3FFB6ED0 0x400DDF77:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (65500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (65500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (65500) task_wdt: Tasks currently running:�[0m
�[0;31mE (65500) task_wdt: CPU 0: main�[0m
�[0;31mE (65500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (65500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC26E:0x3FFB6C40 0x400FC33E:0x3FFB6C70 0x400FE629:0x3FFB6C90 0x400E3D87:0x3FFB6CB0 0x400E4EEF:0x3FFB6CE0 0x400E506B:0x3FFB6D00 0x400E52A8:0x3FFB6D60 0x400E5391:0x3FFB6DC0 0x400E69B7:0x3FFB6E00 0x400E6A25:0x3FFB6E60 0x400D9C0B:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF83:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (70500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (70500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (70500) task_wdt: Tasks currently running:�[0m
�[0;31mE (70500) task_wdt: CPU 0: main�[0m
�[0;31mE (70500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (70500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4000BFED:0x3FFB6920 0x400885DF:0x3FFB6930 0x40089773:0x3FFB6950 0x40081FBE:0x3FFB6970 0x4008A941:0x3FFB6990 0x400FC31D:0x3FFB69B0 0x400FC33E:0x3FFB69E0 0x400FE629:0x3FFB6A00 0x400E3FBF:0x3FFB6A20 0x400E4E06:0x3FFB6A60 0x400E5082:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400E5AAE:0x3FFB6E80 0x400DA322:0x3FFB6EA0 0x400DA448:0x3FFB6ED0 0x400DDF83:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (75500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (75500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (75500) task_wdt: Tasks currently running:�[0m
�[0;31mE (75500) task_wdt: CPU 0: main�[0m
�[0;31mE (75500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (75500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC299:0x3FFB69D0 0x400FC33E:0x3FFB6A00 0x400FE629:0x3FFB6A20 0x400E3D15:0x3FFB6A40 0x400E4EEF:0x3FFB6A70 0x400E506B:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400D9BDD:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (80500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (80500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (80500) task_wdt: Tasks currently running:�[0m
�[0;31mE (80500) task_wdt: CPU 0: main�[0m
�[0;31mE (80500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (80500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC26E:0x3FFB6A00 0x400FC33E:0x3FFB6A30 0x400FE629:0x3FFB6A50 0x400E3F9F:0x3FFB6A70 0x400E4E06:0x3FFB6AB0 0x400E5082:0x3FFB6AE0 0x400E547A:0x3FFB6B40 0x400E55F5:0x3FFB6DC0 0x400E570E:0x3FFB6E40 0x400E57AF:0x3FFB6E60 0x400D9C6D:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (85500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (85500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (85500) task_wdt: Tasks currently running:�[0m
�[0;31mE (85500) task_wdt: CPU 0: main�[0m
�[0;31mE (85500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (85500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x40139F54:0x3FFB6940 0x400FC6B6:0x3FFB6960 0x400E40A1:0x3FFB6980 0x400E4E06:0x3FFB69C0 0x400E5082:0x3FFB69F0 0x400E547A:0x3FFB6A50 0x400E592A:0x3FFB6CD0 0x400E5A4F:0x3FFB6D50 0x400E5B28:0x3FFB6DA0 0x400E5D47:0x3FFB6DE0 0x400E5E61:0x3FFB6E50 0x400D9D25:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (90500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (90500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (90500) task_wdt: Tasks currently running:�[0m
�[0;31mE (90500) task_wdt: CPU 0: main�[0m
�[0;31mE (90500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (90500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FE4BE:0x3FFB6C00 0x400FEF98:0x3FFB6C20 0x400FC8F5:0x3FFB6C50 0x400FC955:0x3FFB6C70 0x400E419F:0x3FFB6C90 0x400E4E06:0x3FFB6CD0 0x400E5179:0x3FFB6D00 0x400E52A8:0x3FFB6D60 0x400E61A9:0x3FFB6DC0 0x400E638F:0x3FFB6E50 0x400D9D4D:0x3FFB6E80 0x400DA3ED:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (95500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (95500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (95500) task_wdt: Tasks currently running:�[0m
�[0;31mE (95500) task_wdt: CPU 0: main�[0m
�[0;31mE (95500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (95500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC295:0x3FFB6BE0 0x400FC33E:0x3FFB6C10 0x400FE629:0x3FFB6C30 0x400E3D87:0x3FFB6C50 0x400E4EEF:0x3FFB6C80 0x400E506B:0x3FFB6CA0 0x400E52A8:0x3FFB6D00 0x400E618E:0x3FFB6D60 0x400E638F:0x3FFB6DF0 0x400D9FBB:0x3FFB6E20 0x400DA201:0x3FFB6E70 0x400DA40D:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (100500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (100500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (100500) task_wdt: Tasks currently running:�[0m
�[0;31mE (100500) task_wdt: CPU 0: main�[0m
�[0;31mE (100500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (100500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400FC281:0x3FFB69B0 0x400FC33E:0x3FFB69E0 0x400FE629:0x3FFB6A00 0x400E3FBF:0x3FFB6A20 0x400E4E06:0x3FFB6A60 0x400E5082:0x3FFB6A90 0x400E547A:0x3FFB6AF0 0x400E592A:0x3FFB6D70 0x400E5A4F:0x3FFB6DF0 0x400E5A85:0x3FFB6E40 0x400E5A99:0x3FFB6E60 0x400E5AAE:0x3FFB6E80 0x400DA322:0x3FFB6EA0 0x400DA448:0x3FFB6ED0 0x400DDF8F:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

�[0;31mE (105500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (105500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (105500) task_wdt: Tasks currently running:�[0m
�[0;31mE (105500) task_wdt: CPU 0: main�[0m
�[0;31mE (105500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (105500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x4013A182:0x3FFB6C10 0x400FE4C1:0x3FFB6C30 0x400FEF98:0x3FFB6C50 0x400FC8F5:0x3FFB6C80 0x400FC955:0x3FFB6CA0 0x400E4104:0x3FFB6CC0 0x400E4E06:0x3FFB6D00 0x400E5082:0x3FFB6D30 0x400E52A8:0x3FFB6D90 0x400E61A9:0x3FFB6DF0 0x400E638F:0x3FFB6E80 0x400DA5C3:0x3FFB6EB0 0x400DDF99:0x3FFB6EF0 0x400DED37:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

ECC      test passed!
ECC buffer test passed!
�[0;31mE (110500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (110500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (110500) task_wdt: Tasks currently running:�[0m
�[0;31mE (110500) task_wdt: CPU 0: main�[0m
�[0;31mE (110500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (110500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x401391E2:0x3FFB6AD0 0x400E8BFB:0x3FFB6AF0 0x400E8DE0:0x3FFB6B90 0x400E2D6D:0x3FFB6C90 0x400E2E21:0x3FFB6CE0 0x400DE28B:0x3FFB6D00 0x400DED6A:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

CURVE25519 test passed!
ed25519.c: 690, 255
ed25519.c: 690, 255
�[0;31mE (115500) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:�[0m
�[0;31mE (115500) task_wdt:  - IDLE (CPU 0)�[0m
�[0;31mE (115500) task_wdt: Tasks currently running:�[0m
�[0;31mE (115500) task_wdt: CPU 0: main�[0m
�[0;31mE (115500) task_wdt: CPU 1: IDLE�[0m
�[0;31mE (115500) task_wdt: Print CPU 0 (current core) backtrace�[0m


Backtrace: 0x40100ABE:0x3FFB0F60 0x40100C74:0x3FFB0F80 0x400828D9:0x3FFB0FA0 0x400EA288:0x3FFB65F0 0x400F173B:0x3FFB6950 0x400E73D5:0x3FFB6B80 0x400E7A33:0x3FFB6C80 0x400E7AD9:0x3FFB6CC0 0x400E7B8B:0x3FFB6CE0 0x400E7BFE:0x3FFB6D00 0x400DE5C6:0x3FFB6D20 0x400DED83:0x3FFB6F20 0x400DEE36:0x3FFB6F40 0x400D7530:0x3FFB6F90 0x4013C807:0x3FFB6FB0 0x400882E9:0x3FFB6FE0

ed25519.c: 690, 255
ed25519.c: 690, 255
ed25519.c: 690, 255
ed25519.c: 690, 255
ed25519.c: 690, 255
ED25519  test failed!
 error = -229
�[0;32mI (117020) wolfcrypt_test: Exiting main with return code: -1
�[0m
Test result = -1
@kareem-wolfssl
Copy link
Contributor

Hi @PaulMartinsen ,

Please try defining CURVED25519_SMALL for your ED25519 issues and let us know if it helps.
If not, please attach your full build settings.

@PaulMartinsen
Copy link
Author

CURVED25519_SMALL is already defined in user_settings.h. As I mentioned, I used commit d686f0a (last commit on 2022/12/23) and am using VisualGBD with IDFv5.

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen I noticed you are getting a bunch of watchdog timeouts during your benchmark tests. Note that in a recent sdkconfig.defaults file, the check idle task settings: CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n, (the same for CPU1).

I've confirmed a fresh install of wolfssl 5.5.4 (specifically commit 9b513fd6 from 12/28) using ESP-IDF v5 completes the benchmark with success on an ESP32.

If you are certain you are already doing this, then perhaps try deleting these directories and building fresh:

.visualgdb
.vs
build

as well as remove your sdkconfig (backup as needed) to ensure the defaults are loaded.

If you've done all these things and still are having problems, check that the wolfssl in your target components directory is actually v5.5.4. I have several different versions of ESP-IDF installed for two different toolchains, Each of course needs to have its own copy of wolfSSL installed. Here's my esp32 which has the gcc 11.2 installed, and the esp32-8.4 is using the gcc 8.4 toolchain.

image

Also: check for a duplicate wolfssl in you local project directory. I do have a new CMakeLists.txt (not yet in a PR) that will check and warn on this.

Here's my benchmark output:

ets Jun  8 2016 00:22:57

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7000
load:0x40078000,len:15452
ho 0 tail 12 room 4
load:0x40080400,len:3840
entry 0x4008064c
I (28) boot: ESP-IDF v5.0-dirty 2nd stage bootloader
I (28) boot: compile time 21:49:43
I (28) boot: chip revision: v1.0
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (43) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (61) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (76) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (83) boot:  2 factory          factory app      00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=11fa8h ( 73640) map
I (137) esp_image: segment 1: paddr=00021fd0 vaddr=3ffb0000 size=02710h ( 10000) load
I (141) esp_image: segment 2: paddr=000246e8 vaddr=40080000 size=0b930h ( 47408) load
I (162) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=34590h (214416) map
I (240) esp_image: segment 4: paddr=000645b8 vaddr=4008b930 size=002f4h (   756) load
I (241) esp_image: segment 5: paddr=000648b4 vaddr=50000000 size=00010h (    16) load
I (252) boot: Loaded app from partition at offset 0x10000
I (252) boot: Disabling RNG early entropy source...
I (269) cpu_start: Pro cpu up.
I (269) cpu_start: Starting app cpu, entry point is 0x40081128
I (256) cpu_start: App cpu up.
I (283) cpu_start: Pro cpu start user code
I (283) cpu_start: cpu freq: 240000000 Hz
I (283) cpu_start: Application information:
I (288) cpu_start: Project name:     wolfssl_benchmark
I (294) cpu_start: App version:      v5.5.4-stable-59-g9b513fd6b-dir
I (301) cpu_start: Compile time:     Jan  3 2023 21:49:22
I (307) cpu_start: ELF file SHA256:  56cca5d4f8165ade...
I (313) cpu_start: ESP-IDF:          v5.0-dirty
I (318) heap_init: Initializing. RAM available for dynamic allocation:
I (326) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (332) heap_init: At 3FFB40F0 len 0002BF10 (175 KiB): DRAM
I (338) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (344) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (351) heap_init: At 4008BC24 len 000143DC (80 KiB): IRAM
I (358) spi_flash: detected chip: generic
I (362) spi_flash: flash io: dio
W (365) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (379) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (394) wolfssl_benchmark: app_main CONFIG_BENCH_ARGV = -lng 0
I (394) wolfssl_benchmark: construct_argv arg:-lng 0

------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
RNG                          1 MiB took 1.005 seconds,    1.312 MiB/s Cycles per byte = 174.38
AES-128-CBC-enc              6 MiB took 1.001 seconds,    5.927 MiB/s Cycles per byte =  38.61
AES-128-CBC-dec              6 MiB took 1.003 seconds,    5.501 MiB/s Cycles per byte =  41.61
AES-192-CBC-enc              6 MiB took 1.001 seconds,    5.927 MiB/s Cycles per byte =  38.64
AES-192-CBC-dec              6 MiB took 1.004 seconds,    5.496 MiB/s Cycles per byte =  41.65
AES-256-CBC-enc              6 MiB took 1.002 seconds,    5.921 MiB/s Cycles per byte =  38.67
AES-256-CBC-dec              5 MiB took 1.000 seconds,    5.493 MiB/s Cycles per byte =  41.68
AES-128-GCM-enc            300 KiB took 1.019 seconds,  294.406 KiB/s Cycles per byte = 796.52
AES-128-GCM-dec            300 KiB took 1.020 seconds,  294.118 KiB/s Cycles per byte = 797.05
AES-192-GCM-enc            300 KiB took 1.023 seconds,  293.255 KiB/s Cycles per byte = 798.95
AES-192-GCM-dec            300 KiB took 1.023 seconds,  293.255 KiB/s Cycles per byte = 799.56
AES-256-GCM-enc            300 KiB took 1.025 seconds,  292.683 KiB/s Cycles per byte = 801.13
AES-256-GCM-dec            300 KiB took 1.026 seconds,  292.398 KiB/s Cycles per byte = 801.56
GMAC Default               392 KiB took 1.000 seconds,  392.000 KiB/s Cycles per byte = 598.04
3DES                       475 KiB took 1.017 seconds,  467.060 KiB/s Cycles per byte = 501.97
MD5                         13 MiB took 1.001 seconds,   13.439 MiB/s Cycles per byte =  17.04
SHA                         15 MiB took 1.001 seconds,   14.926 MiB/s Cycles per byte =  15.34
SHA-256                     15 MiB took 1.001 seconds,   14.658 MiB/s Cycles per byte =  15.61
SHA-512                     17 MiB took 1.001 seconds,   16.878 MiB/s Cycles per byte =  13.55
HMAC-MD5                    13 MiB took 1.001 seconds,   13.292 MiB/s Cycles per byte =  17.22
HMAC-SHA                    14 MiB took 1.000 seconds,   14.429 MiB/s Cycles per byte =  15.87
HMAC-SHA256                 14 MiB took 1.000 seconds,   14.331 MiB/s Cycles per byte =  15.97
HMAC-SHA512                 16 MiB took 1.000 seconds,   16.333 MiB/s Cycles per byte =  14.02
PBKDF2                     640 bytes took 1.001 seconds,  639.361 bytes/s Cycles per byte = 375448.16
RSA     2048   public        52 ops took 1.017 sec, avg 19.558 ms, 51.131 ops/sec
RSA     2048  private         4 ops took 1.048 sec, avg 262.000 ms, 3.817 ops/sec
ECC   [      SECP256R1]   256  key gen         2 ops took 1.139 sec, avg 569.500 ms, 1.756 ops/sec
ECDHE [      SECP256R1]   256    agree         2 ops took 1.138 sec, avg 569.000 ms, 1.757 ops/sec
ECDSA [      SECP256R1]   256     sign         2 ops took 1.144 sec, avg 572.000 ms, 1.748 ops/sec
ECDSA [      SECP256R1]   256   verify         2 ops took 2.224 sec, avg 1112.000 ms, 0.899 ops/sec
CURVE  25519  key gen         3 ops took 1.188 sec, avg 396.000 ms, 2.525 ops/sec
CURVE  25519    agree         4 ops took 1.580 sec, avg 395.000 ms, 2.532 ops/sec
ED     25519  key gen        47 ops took 1.005 sec, avg 21.383 ms, 46.766 ops/sec
ED     25519     sign        42 ops took 1.042 sec, avg 24.810 ms, 40.307 ops/sec
ED     25519   verify        26 ops took 1.026 sec, avg 39.462 ms, 25.341 ops/sec
Benchmark complete

oddly, I was unable to find d686f0a or 14d23e4 in my history, or I would have tested that specific commit you mentioned above:

image

for completeness, here's my user_settings.h in C:\SysGCC\esp32\esp-idf\v5.0\components\wolfssl\include:

/* user_settings.h
 *
 * Copyright (C) 2006-2022 wolfSSL Inc.
 *
 * This file is part of wolfSSL.
 *
 * wolfSSL is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * wolfSSL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
 */
#undef WOLFSSL_ESPIDF
#undef WOLFSSL_ESPWROOM32
#undef WOLFSSL_ESPWROOM32SE
#undef WOLFSSL_ESPWROOM32
#undef WOLFSSL_ESP8266

#define WOLFSSL_ESPIDF

/*
 * choose ONE of these Espressif chips to define:
 *
 * WOLFSSL_ESPWROOM32
 * WOLFSSL_ESPWROOM32SE
 * WOLFSSL_ESP8266
 */

#define WOLFSSL_ESPWROOM32

/* #define DEBUG_WOLFSSL_VERBOSE */

#define BENCH_EMBEDDED
#define USE_CERT_BUFFERS_2048

/* TLS 1.3                                 */
#define WOLFSSL_TLS13
#define HAVE_TLS_EXTENSIONS
#define WC_RSA_PSS
#define HAVE_HKDF
#define HAVE_AEAD
#define HAVE_SUPPORTED_CURVES

/* when you want to use SINGLE THREAD */
/* #define SINGLE_THREADED */
#define NO_FILESYSTEM

#define HAVE_AESGCM
/* when you want to use SHA384 */
/* #define WOLFSSL_SHA384 */
#define WOLFSSL_SHA512
#define HAVE_ECC
#define HAVE_CURVE25519
#define CURVE25519_SMALL
#define HAVE_ED25519

/* when you want to use pkcs7 */
/* #define HAVE_PKCS7 */

#if defined(HAVE_PKCS7)
    #define HAVE_AES_KEYWRAP
    #define HAVE_X963_KDF
    #define WOLFSSL_AES_DIRECT
#endif

/* when you want to use aes counter mode */
/* #define WOLFSSL_AES_DIRECT */
/* #define WOLFSSL_AES_COUNTER */

/* esp32-wroom-32se specific definition */
#if defined(WOLFSSL_ESPWROOM32SE)
    #define WOLFSSL_ATECC508A
    #define HAVE_PK_CALLBACKS
    /* when you want to use a custom slot allocation for ATECC608A */
    /* unless your configuration is unusual, you can use default   */
    /* implementation.                                             */
    /* #define CUSTOM_SLOT_ALLOCATION                              */
#endif

/* rsa primitive specific definition */
#if defined(WOLFSSL_ESPWROOM32) || defined(WOLFSSL_ESPWROOM32SE)
    /* Define USE_FAST_MATH and SMALL_STACK                        */
    #define ESP32_USE_RSA_PRIMITIVE
    /* threshold for performance adjustment for hw primitive use   */
    /* X bits of G^X mod P greater than                            */
    #define EPS_RSA_EXPT_XBTIS           36
    /* X and Y of X * Y mod P greater than                         */
    #define ESP_RSA_MULM_BITS            2000
#endif

/* debug options */
/* #define DEBUG_WOLFSSL */
/* #define WOLFSSL_ESP32WROOM32_CRYPT_DEBUG */
/* #define WOLFSSL_ATECC508A_DEBUG          */

/* date/time                               */
/* if it cannot adjust time in the device, */
/* enable macro below                      */
/* #define NO_ASN_TIME */
/* #define XTIME time */

/* when you want not to use HW acceleration */
/* #define NO_ESP32WROOM32_CRYPT */
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH*/
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES */
/* #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI */

/* adjust wait-timeout count if you see timeout in rsa hw acceleration */
#define ESP_RSA_TIMEOUT_CNT    0x249F00

#if defined(CONFIG_IDF_TARGET_ESP32C3)
    #define NO_ESP32WROOM32_CRYPT
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI
#elif defined(CONFIG_IDF_TARGET_ESP_OTHER)
   /* other */
#else
  /* default is ESP32-WROOM */
#endif

Are you using an ESP32-S2, -S3, C3? Try to turn off hardware acceleration to see if that makes a difference.

@PaulMartinsen
Copy link
Author

HI @gojimmypi , I discovered this while working on an ESP32-S3 port. When I found the test failed for both the ESP32-S3 and the ESP32 I raised the issue. I'm not sure if I need ED25519, but others might.

For this issue, we could consider only the ESP32 target as WolfSSL doesn't support hardware acceleration on the ESP32-s3 yet. Also when I tried to run without hardware acceleration I got unhandled exceptions. I didn't look too closely as it wasn't important to me at this point.

I'm not using the benchmark example. I'm calling wolf_test_task() from a program based on the hello world example in VisualGDB. Specifically:

#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include <iostream>

#include <wolfssl/wolfcrypt/settings.h> // make sure this appears before any other wolfSSL headers
#include <wolfcrypt/test/test.h>

using namespace  std;

extern "C" void app_main(void)
{
    printf("Hello world!\n");

  cout << "\n\nWolf tests\n";
  int rc = wolf_test_task();
  cout << "Test result = " << rc << endl;

  
  cout << "Done.";
  
  while (true)
  {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

I compared the user_settings.h you supplied with mine and they are the same.

I loaded the bench mark program into VisualGDB, built against IDF-v5 and programmed it onto an ESP32. The output I got was:

------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each)
RNG                          1 MiB took 1.002 seconds,    1.316 MiB/s Cycles per byte = 173.99
AES-128-CBC-enc              6 MiB took 1.000 seconds,    5.859 MiB/s Cycles per byte =  39.07
AES-128-CBC-dec              4 MiB took 1.002 seconds,    4.459 MiB/s Cycles per byte =  51.32
AES-192-CBC-enc              6 MiB took 1.004 seconds,    5.860 MiB/s Cycles per byte =  39.06
AES-192-CBC-dec              4 MiB took 1.002 seconds,    4.459 MiB/s Cycles per byte =  51.35
AES-256-CBC-enc              6 MiB took 1.001 seconds,    5.854 MiB/s Cycles per byte =  39.06
AES-256-CBC-dec              4 MiB took 1.003 seconds,    4.454 MiB/s Cycles per byte =  51.39
AES-128-GCM-enc            300 KiB took 1.019 seconds,  294.406 KiB/s Cycles per byte = 796.53
AES-128-GCM-dec            300 KiB took 1.021 seconds,  293.830 KiB/s Cycles per byte = 797.50
AES-192-GCM-enc            300 KiB took 1.023 seconds,  293.255 KiB/s Cycles per byte = 799.06
AES-192-GCM-dec            300 KiB took 1.024 seconds,  292.969 KiB/s Cycles per byte = 799.89
AES-256-GCM-enc            300 KiB took 1.025 seconds,  292.683 KiB/s Cycles per byte = 801.12
AES-256-GCM-dec            300 KiB took 1.026 seconds,  292.398 KiB/s Cycles per byte = 801.66
GMAC Default               392 KiB took 1.000 seconds,  392.000 KiB/s Cycles per byte = 598.06
3DES                       475 KiB took 1.018 seconds,  466.601 KiB/s Cycles per byte = 501.98
MD5                         13 MiB took 1.000 seconds,   13.428 MiB/s Cycles per byte =  17.04
SHA                         15 MiB took 1.000 seconds,   14.917 MiB/s Cycles per byte =  15.34
SHA-256                     15 MiB took 1.001 seconds,   14.658 MiB/s Cycles per byte =  15.61
SHA-512                     17 MiB took 1.000 seconds,   16.748 MiB/s Cycles per byte =  13.66
HMAC-MD5                    13 MiB took 1.001 seconds,   13.292 MiB/s Cycles per byte =  17.22
HMAC-SHA                    15 MiB took 1.001 seconds,   14.634 MiB/s Cycles per byte =  15.64
HMAC-SHA256                 14 MiB took 1.000 seconds,   14.331 MiB/s Cycles per byte =  15.97
HMAC-SHA512                 16 MiB took 1.000 seconds,   16.309 MiB/s Cycles per byte =  14.03
PBKDF2                     640 bytes took 1.001 seconds,  639.361 bytes/s Cycles per byte = 375653.78
RSA     1024  key gen         1 ops took 6.719 sec, avg 6719.000 ms, 0.149 ops/sec
RSA     2048  key gen         1 ops took 16.123 sec, avg 16123.000 ms, 0.062 ops/sec
RSA     2048   public        52 ops took 1.014 sec, avg 19.500 ms, 51.282 ops/sec
RSA     2048  private         4 ops took 1.041 sec, avg 260.250 ms, 3.842 ops/sec
ECC   [      SECP256R1]   256  key gen         4 ops took 1.325 sec, avg 331.250 ms, 3.019 ops/sec
ECDHE [      SECP256R1]   256    agree         4 ops took 1.323 sec, avg 330.750 ms, 3.023 ops/sec
ECDSA [      SECP256R1]   256     sign         4 ops took 1.336 sec, avg 334.000 ms, 2.994 ops/sec
ECDSA [      SECP256R1]   256   verify         2 ops took 1.277 sec, avg 638.500 ms, 1.566 ops/sec
CURVE  25519  key gen         3 ops took 1.187 sec, avg 395.667 ms, 2.527 ops/sec
CURVE  25519    agree         4 ops took 1.580 sec, avg 395.000 ms, 2.532 ops/sec
ED     25519  key gen        46 ops took 1.005 sec, avg 21.848 ms, 45.771 ops/sec
ED     25519     sign        40 ops took 1.027 sec, avg 25.675 ms, 38.948 ops/sec
ED     25519   verify        26 ops took 1.023 sec, avg 39.346 ms, 25.415 ops/sec
Benchmark complete

This didn't report any errors for the ED25519 benchmark. However, as I mentioned, I am calling wolf_test_task().

@gojimmypi
Copy link
Contributor

@PaulMartinsen ah yes, my mistake: test not benchmark. Also, I believe I had previously stated that all that is needed is some user_settings.h changes. This is incorrect with regards to the current wolfSSL branch. I do however have the needed changes on my Espressif_Multichip branch. Additionally I've also created PR#5956 for you; a minor change to the random.c for the ESP32-S3 and a VisualGDB file for the IDF v5.

If using instead WSL to build & flash:

idf.py set-target esp32s3
idf.py fullclean
idf.py  -b 921600  -p /dev/ttyS8  build flash monitor -b 112000

Here's my most recent change to the end of user_settings.h for the CONFIG_IDF_TARGET_ESP32S3:

#if defined(CONFIG_IDF_TARGET_ESP32C3)
    #define NO_ESP32WROOM32_CRYPT
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
    #define NO_ESP32WROOM32_CRYPT
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_HASH
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_AES
    #define NO_WOLFSSL_ESP32WROOM32_CRYPT_RSA_PRI
#elif defined(CONFIG_IDF_TARGET_ESP_OTHER)
   /* other */
#else
  /* default is ESP32-WROOM */
#endif

As you noted, I'm also calling wolf_test_task() in main.c.

It is not super fast at this time without hardware acceleration, but the wolfssl_test is fully functional on my Espressif_Multichip branch. The output includes the changes in #5955 that add git version information to the wolfssl version.h file:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x1684
load:0x403c9700,len:0xb94
load:0x403cc700,len:0x2e1c
entry 0x403c98e8
I (25) boot: ESP-IDF v5.0-dirty 2nd stage bootloader
I (25) boot: compile time 15:12:45
I (25) boot: chip revision: v0.1
I (27) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (34) boot.esp32s3: Boot SPI Speed : 80MHz
I (39) boot.esp32s3: SPI Mode       : DIO
I (43) boot.esp32s3: SPI Flash Size : 2MB
I (48) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (72) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (79) boot:  2 factory          factory app      00 00 00010000 00100000
I (87) boot: End of partition table
I (91) boot_comm: chip revision: 1, min. application chip revision: 0
I (98) esp_image: segment 0: paddr=00010020 vaddr=3c050020 size=180ach ( 98476) map
I (124) esp_image: segment 1: paddr=000280d4 vaddr=3fc90400 size=021a0h (  8608) load
I (126) esp_image: segment 2: paddr=0002a27c vaddr=40374000 size=05d9ch ( 23964) load
I (135) esp_image: segment 3: paddr=00030020 vaddr=42000020 size=44760h (280416) map
I (189) esp_image: segment 4: paddr=00074788 vaddr=40379d9c size=06628h ( 26152) load
I (195) esp_image: segment 5: paddr=0007adb8 vaddr=50000000 size=00010h (    16) load
I (200) boot: Loaded app from partition at offset 0x10000
I (201) boot: Disabling RNG early entropy source...
I (217) cpu_start: Pro cpu up.
I (218) cpu_start: Single core mode
I (227) cpu_start: Pro cpu start user code
I (227) cpu_start: cpu freq: 160000000 Hz
I (227) cpu_start: Application information:
I (230) cpu_start: Project name:     wolfssl_test
I (235) cpu_start: App version:      v5.5.4-stable-127-gaba48e45e-di
I (242) cpu_start: Compile time:     Jan  4 2023 15:25:01
I (248) cpu_start: ELF file SHA256:  54d5b0a1b5444a02...
I (254) cpu_start: ESP-IDF:          v5.0-dirty
I (259) heap_init: Initializing. RAM available for dynamic allocation:
I (267) heap_init: At 3FC92ED8 len 00056838 (346 KiB): D/IRAM
I (273) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (280) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (286) heap_init: At 600FE010 len 00001FF0 (7 KiB): RTCRAM
I (293) spi_flash: detected chip: generic
I (297) spi_flash: flash io: dio
W (301) spi_flash: Detected size(8192k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (314) cpu_start: Starting scheduler on PRO CPU.
I (320) wolfssl_test: --------------------------------------------------------
I (320) wolfssl_test: --------------------------------------------------------
I (330) wolfssl_test: ---------------------- BEGIN MAIN ----------------------
I (340) wolfssl_test: --------------------------------------------------------
I (350) wolfssl_test: --------------------------------------------------------
I (350) wolfssl_test: LIBWOLFSSL_VERSION_STRING = 5.5.4
I (360) wolfssl_test: CONFIG_IDF_TARGET = esp32s3
I (370) wolfssl_test: LIBWOLFSSL_VERSION_GIT_HASH = adb406e1eebf05e452afca98fa9bf3ccd7abcfca
I (370) wolfssl_test: LIBWOLFSSL_VERSION_GIT_SHORT_HASH = adb406e1e
I (380) wolfssl_test: LIBWOLFSSL_VERSION_GIT_HASH_DATE = Wed Jan 4 08:48:24 2023 -0800
I (390) wolfssl_test: Stack HWM: 53580

I (390) wolfssl_test: NO_ESP32WROOM32_CRYPT defined! HW acceleration DISABLED.
I (400) wolfssl_test: CONFIG_IDF_TARGET=esp32s3
------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES192   test passed!
AES256   test passed!
AES-GCM  test passed!
RSA      test passed!
PWDBASED test passed!
ECC      test passed!
ECC buffer test passed!
CURVE25519 test passed!
ED25519  test passed!
logging  test passed!
time test passed!
mutex    test passed!
Test complete
I (114410) wolfcrypt_test: Exiting main with return code:  0

I (114420) wolfssl_test: wolf_test_task complete success result code = 0

Please confirm once you have the benchmark and tests working on the ESP32 (without any changes). Then let's update the GitHub subject, as it's not really a bug regarding the -S3 capabilities at this time.

I'm looking forward to helping you get full ESP32-S3 support!

Cheers

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen if you are interested in TLS 1.3 examples for the ESP32 IDF v5, my wolfSSL/wolfssl-examples#360 was merged yesterday.

Those examples should, in theory also work with my Espressif_Multichip branch, but I've not actually test them on the ESP32-S3 yet.

@PaulMartinsen
Copy link
Author

Hi @gojimmypi , I tested on a new computer, with a fresh install tonight and an ESP32 (not ESP32s3) and found

  1. If I create a new program in VisualGDB based on the hello world example and call wolf_test_task using the code above then the ed25519 test fails as described above.
  2. If I build the wolfssl_test example in WolfSSL/IDE/Espressif/ESP-IDF/examples/wolfssl_test and upload that then the ed25519 test passes.

I started going through differences in the sdconfig file between the two projects. So far I found neither increasing the main task stack to 11,000 nor disabling the idle task timers for the VisualGDB program makes a difference to the ed25519 test result (it still fails on the ESP32 when the program is built from the hello world example). I'll keep working through the differences as time permits.

@gojimmypi
Copy link
Contributor

gojimmypi commented Jan 11, 2023

Hi @PaulMartinsen that's certainly curious.

The first thing that came to mind was the version of VisualGDB and more importantly the version of the ESP-IDF used between a new project and the existing one. Is the #2 example also a VisualGDB project?

Exactly which version of VisualGDB are you using? I had some difficulty getting my ESP-IDF v5 going, but at the end of the year there was another sysprogs release and everything seemed to come together after that:

https://twitter.com/gojimmypi/status/1608950750486597638

Is there any chance that the config used for a new project points to either a different toolchain and/or a different ESP-IDF version or directory with a different version of wolfSSL? Could there be a stray user_settings.h file?

If it is failing as noted above (watchdog timeout) then perhaps all the sdkconfig.defaults are not applied in the new project?

I'm wondering what else might be different in your new program based on the example. Is it a project that you can share?

@gojimmypi
Copy link
Contributor

@PaulMartinsen one more idea: you mentioned the failure in your new program based on the example. I'm wondering if you are calling wolf_test_task from a different FreeRTOS thread that perhaps has too small of stack setting? The sdkconfig.defaults are for the main() task only.

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen I'm revisiting your example code, above. Is that the exact code you are using in VisualGDB in your main.c? The issue header says ESP32, but were you running the tests in a non-ESP32 environment?

I've been recently spending so much time with the Linux tools that when I first read this issue, I didn't even notice the stdio.h, <iostream> and printf. Those are all massive drains on embedded resources. I'm not even sure this is possible on the ESP32:

cout << "\n\nWolf tests\n";

I can't even get that code to compile, even when removing the printf and cout statements.

../../../main/main.c:29:10: fatal error: iostream: No such file or directory
   29 | #include <iostream>
      |          ^~~~~~~~~~

I was however, able to get this to work:

/* ESP-IDF */
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"

#include <wolfssl/wolfcrypt/settings.h> // make sure this appears before any other wolfSSL headers
#ifndef WOLFSSL_ESPIDF
#warning "problem with wolfSSL user settings. Check components/wolfssl/include"
#endif

#include <wolfcrypt/test/test.h>
/* see wolfssl/wolfcrypt/test/test.h */
extern int wolf_test_task();

/* entry point */

void app_main(void)
{
  printf("Hello world!\n");

  int rc = wolf_test_task();

  while (true)
  {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

This is essentially the same as your code, including the printf, but without the cout.

I'd really like to be able to see your entire test project, if possible. Thank you.

@PaulMartinsen
Copy link
Author

Hi @gojimmypi ,

I attached a copy of the project I was building with VisualGDB (#1 above) ED25519Test.zip.

I used version 5.6.109.4769 of VisualGDB and IDF-v5 when building this. The #2 project was build directly in the example folder using idf.py (no VisualGDB). This machine has only a single version of VisualGDB, IDFv5 and WolfSSL to avoid any confusion.

I don't get the watchdog timeouts if I disable them. Sorry I wasn't clear on that; was getting late! They should be a red-herring though.

My understanding is wolf_test_task is being called from the main task so the 11,000 byte stack should apply.

I think your native c code in the previous post should be functionally identical. I'd renamed main.c to main.cpp to build main with the c++ compiler (previously it was part of a larger piece of code).

Does the attached test project work for you?

Thanks for your help with this,
Paul.

@gojimmypi
Copy link
Contributor

gojimmypi commented Jan 12, 2023

Hi @PaulMartinsen ,

The attached zip file was tremendously helpful! Thank you for providing that. I learned several things from your project.

But more importantly, I found a way to fix the ed25519 test error, although not the root cause.

Oddly, making a single change to Stack Smashing Protection Mode in VisualGDB and the problem goes away:

image

Using winmerge to compare the effects of that setting:

image

and

image

Now, I realize that is not really very intuitive and there may be some underlying issue that needs to be addressed in either wolfSSL or the Espressif toolchain.... but at least it is a start.

Here's the full output from your app with no other change other than the stack setting, setting my serial port to COM20, and using the Tigard JTAG to debug:

ets Jun  8 2016 00:22:57

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:7000
load:0x40078000,len:15452
ho 0 tail 12 room 4
load:0x40080400,len:3840
entry 0x4008064c
I (28) boot: ESP-IDF v5.0-dirty 2nd stage bootloader
I (28) boot: compile time 12:53:11
I (28) boot: chip revision: v1.0
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed      : 40MHz
I (43) boot.esp32: SPI Mode       : DIO
I (47) boot.esp32: SPI Flash Size : 2MB
I (52) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (61) boot: ## Label            Usage          Type ST Offset   Length
I (68) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (76) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (83) boot:  2 factory          factory app      00 00 00010000 00100000
I (91) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=2984ch (170060) map
I (172) esp_image: segment 1: paddr=00039874 vaddr=3ffb0000 size=028e0h ( 10464) load
I (176) esp_image: segment 2: paddr=0003c15c vaddr=40080000 size=03ebch ( 16060) load
I (184) esp_image: segment 3: paddr=00040020 vaddr=400d0020 size=6db3ch (449340) map
I (349) esp_image: segment 4: paddr=000adb64 vaddr=40083ebc size=07ed0h ( 32464) load
I (362) esp_image: segment 5: paddr=000b5a3c vaddr=50000000 size=00010h (    16) load
I (369) boot: Loaded app from partition at offset 0x10000
I (369) boot: Disabling RNG early entropy source...
I (382) cpu_start: Pro cpu up.
I (382) cpu_start: Starting app cpu, entry point is 0x40081224
I (369) cpu_start: App cpu up.
I (397) cpu_start: Pro cpu start user code
I (397) cpu_start: cpu freq: 160000000 Hz
I (397) cpu_start: Application information:
I (402) cpu_start: Project name:     hello_world
I (407) cpu_start: App version:      1
I (411) cpu_start: Compile time:     Jan 12 2023 12:52:52
I (417) cpu_start: ELF file SHA256:  99669e94d6b26901...
I (423) cpu_start: ESP-IDF:          v5.0-dirty
I (429) heap_init: Initializing. RAM available for dynamic allocation:
I (436) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (442) heap_init: At 3FFB4880 len 0002B780 (173 KiB): DRAM
I (448) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (454) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (461) heap_init: At 4008BD8C len 00014274 (80 KiB): IRAM
I (469) spi_flash: detected chip: generic
I (472) spi_flash: flash io: dio
W (476) spi_flash: Detected size(4096k) larger than the size in the binary image header(
2048k). Using the size in the binary image header.
I (493) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!


Wolf tests
------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES192   test passed!
AES256   test passed!
AES-GCM  test passed!
RSA      test passed!
PWDBASED test passed!
ECC      test passed!
ECC buffer test passed!
CURVE25519 test passed!
ED25519  test passed!
logging  test passed!
time test passed!
mutex    test passed!
Test complete
I (116843) wolfcrypt_test: Exiting main with return code:  0

Test result = 0

I realize this is already Friday for you... but if you could kindly test and confirm this, I'll take a closer look over the weekend.

@PaulMartinsen
Copy link
Author

Great work @gojimmypi!. When I made that change to the stack smashing protection mode in the solution where I was working on the ESP32s3 hardware support I found the ED25519 test passes now. On both the ESP32 & the ESP32s3.

Those flags seem to be putting guard bytes around the stack. Normally such things show up faults, not make the program work! A weird one for sure. Hopefully you can track down the root-cause.

Wolf tests
------------------------------------------------------------------------------
 wolfSSL version 5.5.4
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES256   test passed!
AES-GCM  test passed!
RSA      test passed!
PWDBASED test passed!
ECC      test passed!
ECC buffer test passed!
CURVE25519 test passed!
ED25519  test passed!
logging  test passed!
time test passed!
mutex    test passed!
Test complete
Test result = 0

Done.

@gojimmypi
Copy link
Contributor

gojimmypi commented Jan 21, 2023

The problem here appears to be byte alignment of the WC_ESP32SHA typedef struct in wolfcrypt/port/Espressif/esp32-crypt.h used exclusively by the Espressif port and only when Stack Smashing is set to None and hardware acceleration enabled.

This is counter-intuitive as noted above: as one would expect the problem to be visible when turning on the stack monitoring feature. The problem is not observed when setting Stack Smashing to Normal.

To illustrate the byte-alignment cause, here's a code compare of passing and non-passing test results:

image

Simply moving the position of the lockDepth variable in the struct affects the result of a passing or non-passing ED25519 test.

Note that some individually movable and unused guard bytes are included in this example and have been used to detect struct memory corruption to the WC_ESP32SHA instance in the ctx. None were observed.

Moving all of the largest types to the beginning of the typedef struct also results in a successful ED25519 test:

image

Stackoverflow has a variety of results regarding typedef struct byte alignment memory allocation which are interesting, but none definitive on this particular issue.

Here's an example of the WC_ESP32SHA instance taking up 7 bytes in the middle of the test guard bytes that were set to 0x72

image

Here's the typedef struct for the above example:

image

The error occurs in ed25519_verify_msg_final_with_sha():

image

This is in the call to wc_ed25519ph_verify_msg() in the test.c, on or about line 28,082:

image

The actual error is triggered in the ed25519 ConstantCompare() but of course by the time we get there, the data is already bad.

image

The compare fails on the 3rd call; two previous compares were successful.

I'll be soon creating a PR that at least fixes the problem. However, I plan to leave this ticket open to continue investigating this odd situation as it is not at all intuitive and may be indicative of some other underlying problems.

On the topic of other problems, one thing considered was the enum ESP32_SHA_FAIL_NEED_UNROLL = -1 , similar to what Espressif does in sha.h. Due to the type ambiguity of the -1 and this byte alignment problem seen, I plan to also change the wolfssl enum value to a non-negative value.

@PaulMartinsen
Copy link
Author

Hi Jim, Great work tracking that one down. A tricky one for sure! It sounds like setting the stack smashing mode shifted the memory around so it was better aligned (coincidentally?). Is that right?

I wonder if it is affected by optimization level too? I was using Debug (-Og). It would be interesting to see what assembly is being generated. I'm wondering if it is working with the reordered fields only because it is still overwriting a byte but in a situation that doesn't matter. I don't see any alignment modification on your typedef. I thought these structures are usually padded to a multiple of 2 or 4, etc. Seems like it might be incorrect translation of the source code. All in all, it quite alarming!

@gojimmypi
Copy link
Contributor

Thanks, @PaulMartinsen! Indeed this has been an interesting problem. I agree and believe there are likely peripheral effects when turning on Espressif Stack Smashing, and object alignment appears to be one of them.

I've tried a variety of typedef struct { } WC_ESP32SHA __attribute__ ((aligned (N))); values, attempting to align on N=2, 4, and 8-byte boundaries. All fail with a byte type listed first. Even with the largest ESP32_MODE mode listed first, the test fails on N=8, but is successful for N=2 and also successful for N=4. In any case, like ordering the elements, this directive could end up hiding a different issue.

Note PR #5997 is not my final solution. I've already had a wolfSSL staff engineer contact me stating "that PR looks fishy". I agree. That change does however significantly improve things to at least pass the test when Espressif Stack Smashing is turned off. More work is needed.

I still believe there's some other underlying potential problem. I've been looking at a variety of memcpy operations, given the thought that perhaps the target and destination are on a different byte boundary and padded differently internally. I've not yet found any likely candidates. While doing some testing though, I did bump into a problem with the SHA buffer size, thus PR 5998. Perhaps unlikely to occur under normal circumstances, it seems to be a good check to have anyhow.

Regarding unexpected overwriting of memory: in my dev branch I have a variety of guard bytes that I've experimented with at the beginning and/or the end of the struct. I've not yet seen one with unexpected contents.

In any case, the good thing here is that there are some fairly aggressive and comprehensive tests, both in the test application as well as the Jenkins build.

@gojimmypi
Copy link
Contributor

I'm close to getting a PR together to fully resolve this issue. This was never a byte alignment problem, despite the compelling evidence to the contrary. The root cause was the use of copied SHA ctx that appeared to be initialized, but contained HW state data from the source. In general, copied HW state data cannot be used in a copy destination ctx.

I've updated #5989 with the details of the root cause of this ED25519 failure. Working code is on my ED25519_SHA2_fix branch. In particular the new esp_sha_init() that attempts to detect if an instance is a copy. HW is demoted to SW if a copy is detected. More details are on my Twitter microblog and will be included in PR.

@gojimmypi
Copy link
Contributor

gojimmypi commented May 3, 2023

Hi @PaulMartinsen this issue of the ED25519 test failure on the ESP32 should now be fixed in the master branch with the merge of #6287.

Although there were a variety of theories noted in above referenced issues and pull requests for things such as byte-alignment, stack issues, and initialization, note that the actual root cause was related to the copy of a ctx object with a SHA calculation in progress. There's now a new initializer attribute that keeps track of which ctx (address) actually performed the initialization. If the respective ctx->initializer does not match the self address of the ctx, we know that it is a copy and revert to SW.

See the Espressif wolfssl_test and the various VisualGDB Project Files.

Note that for the ESP32-S3, the AES192 HW is not supported. These lines will need to be added to the default user_settings.h:

#include <sdkconfig.h>
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_AES)
    /* AES192 is not supported on the ESP32-S3 HW at this time */
    #define NO_AES_192
#endif

For the problematic AES192 on the ESP32-S3, I have an updated CMakeFiles.txt in the works that will allow for project-specific user settings in a future PR. I also plan to make this fall back to SW more gracefully.

Can you please check the ED25519 on your device and close this issue upon confirmation that it is working as desired?

Thank you.

@PaulMartinsen
Copy link
Author

Hi @gojimmypi , sorry for the delay on this. Super busy atm.

I ran into a few problems testing this on my system (Windows 11).

  1. Opening Wolf\wolfssl\IDE\Espressif\ESP-IDF\examples\wolfssl_test\VisualGDB\wolfssl_test_IDF_v5_ESP32S3.sln produces errors.
    On opening the solution file, VisualGDB reports "Missing toolchain", com.visualgdb.xtensa-esp-efl 8.4.0/8.1.0/r9 is not installed. I resolved with the option "Use toolchain with version 11.2.0/9.2.90/r2". Then it reports "The selected toolchain does not contain the ESP-IDF v4.4.2 checkout", and offers to install it.

  2. Command line tools don't work.
    After running export.bat in ESP32\v5\esp-idf\v5.0 (the version of the Espressif IDFv5.0 I got from SysProg that VisualGDB uses), I use idf.py -p COM5 flash to build. Noticed it was building for ESP32, try to use idf.py menuconfig to resolve; doesn't work.

THe error I get is

CMake Error at C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/tools/cmake/component.cmake:280 (message):     
  SRC_DIRS entry 'C:/Users/Paul/Projects/BLS/XXX' does not exist.                                                       
Call Stack (most recent call first):                                                                                    
  C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/tools/cmake/component.cmake:442 (__component_add_sources)   
  C:/Programming/Toolchains/VisualGDB/ESP32/v5/esp-idf/v5.0/tools/cmake/component.cmake:628 (idf_component_register)    
  components/wolfssl/CMakeLists.txt:203 (register_component)                                                            

The problem is we have spaces on Windows, so that the SRC_DIRS entry should have been C:/Users/Paul/Projects/BLS/XXX Projects/Software/Vendor/WolfSSL/....

The VisualGDB debugger has a problem with spaces too, which I resolve with subst s: "C:/Users/Paul/Projects/BLS/XXX Projects/Software/", which maps the path with spaces into a drive. Unfortunately cmake is too clever for subst and uses the original path with the same error.

I modified the cmakelists.txt file to match the one I use, which resolved the space problem. Then it didn't like paths with more than 250 characters. Another problem that should be easily solved with subst, but nope. set(CMAKE_OBJECT_PATH_MAX, 350) doesn't work either.

After copying to a temp folder, it builds, uploads and.... all tests pass :).

I'd say its worth fixing the space problem and path length shouldn't be a problem in modern file systems either. spaces would be a showstopper for me; the long paths are more of a side effect of the deep nesting you folks have that (probably ) doesn't affect projects. I didn't try very hard with set(CMAKE_OBJECT_PATH_MAX, 350), only putting in the test project's cmakelists file. Maybe there's a solution but i ran out of time now.

�[0;32mI (379) wolfssl_test: --------------------------------------------------------�[0m
�[0;32mI (379) wolfssl_test: --------------------------------------------------------�[0m
�[0;32mI (389) wolfssl_test: ---------------------- BEGIN MAIN ----------------------�[0m
�[0;32mI (399) wolfssl_test: --------------------------------------------------------�[0m
�[0;32mI (409) wolfssl_test: --------------------------------------------------------�[0m
�[0;32mI (409) wolfssl_test: CONFIG_IDF_TARGET = esp32s3�[0m
�[0;32mI (419) wolfssl_test: LIBWOLFSSL_VERSION_STRING = 5.6.0�[0m
�[0;32mI (429) wolfssl_test: CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ = 160 MHz�[0m
�[0;32mI (429) wolfssl_test: Xthal_have_ccount = 1�[0m
�[0;32mI (439) wolfssl_test: Stack HWM: 53456
�[0m
�[0;32mI (439) wolfssl_test: NO_ESP32WROOM32_CRYPT defined! HW acceleration DISABLED.�[0m
------------------------------------------------------------------------------
 wolfSSL version 5.6.0
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
base16   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-384  test passed!
SHA-512  test passed!
SHA-512/224  test passed!
SHA-512/256  test passed!
SHA-3    test passed!
SHAKE128 test passed!
SHAKE256 test passed!
Hash     test passed!
RIPEMD   test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA384 test passed!
HMAC-SHA512 test passed!
HMAC-SHA3   test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
X963-KDF    test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES192   test passed!
AES256   test passed!
AES-GCM  test passed!
AES Key Wrap test passed!
RSA      test passed!
PWDBASED test passed!
openSSL extra test
OPENSSL  test passed!
OPENSSL (EVP MD) passed!
OPENSSL (PKEY0) passed!
OPENSSL (PKEY1) passed!
OPENSSL (EVP Sign/Verify) passed!
ECC      test passed!
ECC buffer test passed!
CURVE25519 test passed!
ED25519  test passed!
PKCS7encrypted  test passed!
PKCS7signed     test passed!
PKCS7enveloped  test passed!
PKCS7authenveloped  test passed!
logging  test passed!
time test passed!
mutex    test passed!
Test complete
�[0;32mI (283419) wolfcrypt_test: Exiting main with return code:  0
�[0m
�[0;32mI (283429) wolfssl_test: wolf_test_task complete success result code = 0�[0m

@bandi13
Copy link
Contributor

bandi13 commented May 22, 2023

For the long paths, it may actually be a Windows defaults issue. I've had to set a registry value to allow long paths on Windows. Put the following in a file called something.reg:

Windows Registry Editor Version 5.00

; Allow long file paths (>256 chars) to fix some compile issues
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001

Hopefully that fixes it.

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen ! Thank you for the feedback.

On opening the solution file, VisualGDB reports "Missing toolchain", com.visualgdb.xtensa-esp-efl 8.4.0/8.1.0/r9 is not installed.

Indeed there was a time when I had 8.4.0/8.1.0/r9 configured with ESP-IDF v5. I thought I had cleaned them all up to use 11.2.0/9.2.90/r2, instead. The wolfssl_test_IDF_v5_ESP32S3 appears to have the GCC 11.2.0 setting.

Can you please confirm which wolfSSL version you are using? I think this is all cleaned up on the current master branch.

I definitely want robust project files ready to go. I have a Sysprogs support request: Difficulties switching Espressif ESP-IDF version or Chipset. The response indicates that there's not a graceful solution to changing chipsets coming anytime soon. So it's even more important that project files are properly configured.

The VisualGDB debugger has a problem with spaces ... paths with more than 250 characters

I have a considerably more robust wolfSSL component CMakeFiles.txt that I think is using your suggestion on quoted paths, although modified a bit. This version also allows for a local project ./components/wolfssl/include/user_settings.h, and not in the shared wolfssl ./include directory.

Regardless of we might do here, please note the official Espressif Standard Setup of Toolchain for Windows indicates that the installation path must not be longer than 90 chars and contain no spaces:

image

I didn't try very hard with set(CMAKE_OBJECT_PATH_MAX, 350)

@bandi13 has a good suggestion of using a registry setting. I think the error is specific to Windows and unlikely that a CMake setting will fix that. (although I do not know for certain).

I probably will not apply that registry setting to my machine, as I prefer to not have any unusual settings that a customer typically will not have. But then, I do all my work in a \workspace\ directory, and not .\users\etc...\

I'll do my best to help you with the path issue, but I think the official wolfSSL support response will be to follow the Espressif guidance. I'm certain you are not the only one with spaces in the path. I definitely would like things to work for the maximum number of users without needing to fuss.

btw - I know I've been referring you to my ED25519_SHA2_fix branch... now is probably not a good time to be using code from there. I'm still working on the excellent find of yours in #6205 which has turned out to be really quite an interesting problem. At the moment, that branch is very much in flux, sometimes inoperable.

You may be interested in my new wolfSSL example coming soon, based exactly on your signing example: currently called wolfssl_server_6205 for the key_test app. Until #6205 is fully resolved, I will continue to use your cert. Once published as a general example I will change to one of the wolfSSL certs.

Thanks again for your patience and for taking the time to write up feedback. It's super helpful. I hope you are making good progress on your project. Please let me know if there's anything else I can do to help.

Cheers

@PaulMartinsen
Copy link
Author

Hi @gojimmypi ,

I took another look after merging all the changes in from the wolfssl master branch. Version problem was in wolfssl_test.vgdbproj. This file was still present in my local copy and my wolfssl_test_IDF_v5_ESP32s3.sln had a reference to it from a bad merge.

I pulled a fresh copy of the wolfssl repository. And now the wolfssl_test_IDF_v5_ESP32s3.sln opens, and builds and ... oh. It failed with an unsupported mode. I didn't expect that. Double checked I got the s3 solution. The only change I made in the project was opening the VisualGDB Project Properties to change the COM port. OUtput is:

�[0;32mI (436) wolfssl_test: ESP32WROOM32_CRYPT is enabled for  ESP32-S3.�[0m
------------------------------------------------------------------------------
 wolfSSL version 5.6.0
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
SHA-512/224  test passed!
SHA-512/256  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
�[0;31mE (786) wolf_hw_aes: esp_aes_hw_Set_KeyMode unsupported mode: 1�[0m
�[0;31mE (796) wolf_hw_aes: wc_esp32AesCbcEncrypt failed HW Set KeyMode�[0m
�[0;31mE (796) wolf_hw_aes: esp_aes_hw_Set_KeyMode unsupported mode: 5�[0m
�[0;31mE (806) wolf_hw_aes: wc_esp32AesCbcDecrypt failed HW Set KeyMode�[0m
AES192   test failed!
 error L=10976
 [fiducial line numbers: 7581 23065 33441 45608]
�[0;32mI (816) wolfcrypt_test: Exiting main with return code: -1
�[0m
�[0;31mE (826) wolfssl_test: wolf_test_task FAIL result code = -1�[0m

Bit short of time this morning to figure out what went wrong. As it has been a problem in the past, I randomly tried adding #define NO_AES_192 to the bottom of wolfssl/include/user_settings.h. Rebuild and upload, but I still end up with the same error, unfortunately.

On the topic of spacy paths, I would think of WolfSSL as a library and not part of the tool-chain. Espressif's problem comes from relying on a 3rd party debugger, which I imagine they have little control over. I imagine some annoying person must have complained too much so the gcc compilers and linkers are happy with spaces now. And now you've got that nice build-in-place make file going I think WolfSSL can expect users to want to reference the WolfSSL library as a submodule within their projects (well, that's what I do anyway :) ).

I didn't get a chance this morning to check the new make file you linked to, but will report back when I get a chance.

@gojimmypi
Copy link
Contributor

gojimmypi commented May 29, 2023

Hi there @PaulMartinsen !

took another look .... Version problem was in wolfssl_test.vgdbproj. This file was still present

Ah, yes. I'm glad you were able to find that. As you saw I renamed the project files to be chip and IDF-version specific. That's odd git did not indicate the file deletion. In any case, thanks for confirming it was not a toolchain version mismatch.

oh. It failed with an unsupported mode.

Thanks for the reminder on that. Indeed the S3 does not support AES-192 HW acceleration. See #6375 and page 834 of the ESP32-S3 Technical Reference Manual:

image

I randomly tried adding #define NO_AES_192 to the bottom of wolfssl/include/user_settings.h

Please note the interim fix, and for all future versions, the #include <sdkconfig.h> will need to be present in the wolfSSL user_settings.h file to properly handle chip-specific features. (e.g. the CONFIG_IDF_TARGET_ESP32S3 setting for the AES Hardware). Try something like this:

#include <sdkconfig.h>
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_AES)
    /* AES192 is not supported on the ESP32-S3 HW at this time */
    #define NO_AES_192
#endif

See if that works for you. If not, I'll dig a little deeper and create an interim PR to fix that.

On the topic of spacy paths, I would think of WolfSSL as a library and not part of the tool-chain.

I see your point there and agree that the scope of "what is the toolchain" could be somewhat ambiguous. As it is not entirely clear, I'd say that the official response is to honor the ESP-IDF guidelines with no spaces, and not use long paths. That said, I also would like to it still work with spaces, if possible.

In the case of paths in the project, I took my WIP wolfssl_test and copied it to a directory with paces in the path. The respective wolfSSL component CMakeFiles.txt seemed to work. If you take that CMake file for a test drive and confirm it works in your environment, I'll create a PR and apply this to existing samples.

I appreciate your patience as we work though these issues. Looking forward to your response. Cheers

@PaulMartinsen
Copy link
Author

Hi @gojimmypi ,

Quick update....after adding to wolfssl/include/user_settings.h the following:

#include <sdkconfig.h>
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_AES)
    /* AES192 is not supported on the ESP32-S3 HW at this time */
    #define NO_AES_192
#endif

The (enabled) tests all passed. I'm a little unclear why adding only #define NO_AES_192 didn't achieve the same thing. Is your point that #include <sdkconfig.h> must be present in user_settings.h for additional reasons now?

Also, the file I changed (wolfssl/include/user_settings.h) isn't in the repository I checked out. I'm not exactly clear where it came from, but that source file may need these extra lines too. There were several other user_settings.h files in the repository, but the one in include was the one I changed.

Justthespacestocheckoutnow. ;-)

�[0;32mI (436) wolfssl_test: ESP32WROOM32_CRYPT is enabled for  ESP32-S3.�[0m
------------------------------------------------------------------------------
 wolfSSL version 5.6.0
------------------------------------------------------------------------------
error    test passed!
MEMORY   test passed!
base64   test passed!
asn      test passed!
RANDOM   test passed!
MD5      test passed!
MD4      test passed!
SHA      test passed!
SHA-256  test passed!
SHA-512  test passed!
SHA-512/224  test passed!
SHA-512/256  test passed!
Hash     test passed!
HMAC-MD5 test passed!
HMAC-SHA test passed!
HMAC-SHA256 test passed!
HMAC-SHA512 test passed!
HMAC-KDF    test passed!
TLSv1.3 KDF test passed!
GMAC     test passed!
DES      test passed!
DES3     test passed!
AES      test passed!
AES256   test passed!
AES-GCM  test passed!
RSA      test passed!
PWDBASED test passed!
ECC      test passed!
ECC buffer test passed!
CURVE25519 test passed!
ED25519  test passed!
logging  test passed!
time test passed!
mutex    test passed!
Test complete
�[0;32mI (125606) wolfcrypt_test: Exiting main with return code:  0
�[0m
�[0;32mI (125616) wolfssl_test: wolf_test_task complete success result code = 0�[0m

@PaulMartinsen
Copy link
Author

Hi @gojimmypi , this morning I noticed #define NO_AES_192 in a user_settings.h file I didn't expect to be in. This leads me to believe when I thought I was adding that to fix the test issue mentioned above I might have been modifying the wrong file and reached an incorrect conclusion that adding #define NO_AES_192 wasn't having an impact on the test program. Sorry about that.

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen -

a user_settings.h file I didn't expect to be in

I understand. Between the current master wolfSSL, and the code on my WIP ED25519_SHA2_fix branch that I've referred to, there's been a change from using a shared user_settings.h in the wolfSSL source directory for all projects, to being specific to each project as seen in my wolfssl_test/components/wolfssl/include. I apologize for any confusion this has caused.

There should be some detection logic if a user_settings.h file is found in more than one location.

My goal is to completely remove the functionality where a single user_settings.h was common to all projects using wolfSSL, and instead move to the project-specific settings, as noted in #6118.

Note that I am also working on an alternative solution that will introduce a new mechanism for including wolfSSL into a project. This week I've successfully configured wolfSSL at components.espressif.com. I will be creating a PR for a demo example in the near future.

I do not expect to combine these two options. The above-mentioned project-specific CMakeFiles.txt with a local user_settings.h lends itself to being able to easily edit the wolfSSL source code. This is ideal for wolfSSL developers.

In contrast, the components at the ESP Registry are extremely easy for the new user to integrate into a project. The drawback (or benefit, depending on your perspective) is that the component source files are not easily edited. In fact, there's a hash file that even detects changes and complains at build time! Given the install mechanism, there's certainly no easy way to push any local wolfSSL changes back to GitHub.

I'm a little unclear why adding only #define NO_AES_192 didn't achieve the same thing

As for the AES192 - I should have clarified the interim workaround to turn off AES192 for only the ESP32-S3 requires the #include <sdkconfig.h> as the CONFIG_IDF_TARGET_ESP32S3 is defined there from the local sdkconfig file.

#include <sdkconfig.h>
#if defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(NO_WOLFSSL_ESP32WROOM32_CRYPT_AES)
    /* AES192 is not supported on the ESP32-S3 HW at this time */
    #define NO_AES_192
#endif

Without the sdkconfig.h the NO_AES_192 would not be defined as CONFIG_IDF_TARGET_ESP32S3 would not be defined. I have #6375 as a reminder that I need to create something a bit more graceful.

Justthespacestocheckoutnow. ;-)

I look forward to your report on my latest CMake file and if it works in your environment with spaces in the path.

Note that I plan to have a single, universal CMake file that will be used in all projects, both from the ESP Registry and from the GitHub repo. There are relatively small changes needed to detect if the CMake file is part of an Espressif component or a local project.

See #6234 for a roadmap of Espressif updates.

Thanks again for all your patience and cooperation. Cheers

@PaulMartinsen
Copy link
Author

Hi @gojimmypi ,

I had another look building. This time with the new CMake file, which I downloaded and placed into C:\Users\Paul\Projects\OpenSource\wolf ssl\IDE\Espressif\ESP-IDF\examples\wolfssl_test\components\wolfssl.

Running idf.py build produced the expected errors asking me to first move user_settings.h then config.h from ...\wolf ssl\include into '...wolfssl_test\components\wolfssl\include`.

A question: does this new approach to user_settings.h apply to all WolfSSL platforms? For example, will the user_settings.h file for a Windows build also go into a new location? Or will I get build errors on Espressif if I have a user_settings.h for windows in wolfssl\include?

Now idf.py build fails in several places, unable to find lwip/sockets.h. This file is in C:\Programming\Toolchains\VisualGDB\ESP32\v5\esp-idf\v5.0\components\lwip\lwip\src\include\lwip, so I'm a bit unclear why it can't be found. This happens in ccache. I'm not sure what that is, but it has similar command line parameters as the compiler but I don't see with -I to a path that includes lwip in the build output.

I noticed line 30 of the new make file has

#set(COMPONENT_REQUIRES lwip) # we typically don't need lwip directly in wolfssl component

If I un-comment that and rebuild, the build is successful when the path to the WolfSSL library includes a space. :)

The universal make file sounds very helpful. Generally I would put a library, such as WolfSSL, into a vendor folder, as a submodule in my project repository. This makes it easier to share the project with others. In theory they just check out the main project and get everything they need. Assuming they have the toolchain. Ideally, I would link the submodule to the vendors library but this only works if there is no need to edit any configuration file in the repository (because I wouldn't be able to push those changes to the vendor so a person checking out the project won't get them). So this means it would be much better if the user_settings.h file can be in my project and repository. Of course, it would be clearer if that file was called wolfssl_settings.h or similar to maintain the connection to its purpose and avoid conflicts with other libraries. Currently user_settings.h is a mix of device settings (e.g., disable AES192 on ESP32s3) and feature selection (e.g., disable TLSv1.2 support). Perhaps __has_include could be used for such a feature for users building on C++17 or later? Do you envisage supporting that kind of workflow with the universal make file?

@gojimmypi
Copy link
Contributor

Hi @PaulMartinsen

Apologies for the delayed response. I got a bit nerd-sniped and chased this bunny down the rabbit hole to get a native Xtensa cross-compiled Linux kernel to run on the ESP32-S3 over the weekend.

Oh, that's in addition to now having wolfSSL as a managed component that I also published just last week. Beware though, as a fellow VisualGDB user, I encountered an unexpected issue where the managed components are ignored in Visual Studio. I need to follow-up with the sysprogs response and see if I can get that working. Compiles just fine from commandline.

Running idf.py build produced the expected errors asking me to first move user_settings.h then config.h

ah, that's excellent! I'm glad it worked as desired. Having the project-specific config and settings files is really the best approach. I'm glad my latest CMakeFiles.txt is working well for you. I'll put together a PR soon for that. I've delayed that a bit as there was a recent release update to wolfSSL v5.6.2. Thanks very much for taking it for a test drive.

A question: does this new approach to user_settings.h apply to all WolfSSL platforms?

That's an excellent question! No. At this time, the CMakeFiles.txt for local project settings is very specific to the Espressif environment.

However, check out this blog Using user_settings.h with wolfSSL.

will I get build errors on Espressif if I have a user_settings.h for windows in wolfssl\include?

Probably, if that wolfssl\include is the same codebase that the Espressif CMakeLists.txt is pointing to. I see where you are going with this. Do you have some suggestions as to how we might allow both?

Note that when using managed components, the wolfSSL code is downloaded automatically at build time from the ESP Component Registry. This of course has pros and cons. The code is specific to the project, but contributing to the upstream GitHub repo would be rather awkward.

Heads up I have an untested feature to specify wolfSSL source code location in an environment variable. (for Espressif)

unable to find lwip/sockets.h ... set(COMPONENT_REQUIRES lwip)

Ah yes, I pointed you at the benchmark version of my newest CMakeLists.txt. Indeed lwip is not required there, but is required when using the Espressif network features. Thanks for the reminder. I'm glad you were able to resolve that.

submodule ... easier to share the project with others.

All excellent comments and observations. I'm interested in your feedback with regards to the new information on ESP Registry capabilities.

Do you envisage supporting that kind of workflow with the universal make file?

Yes, I'd like to see a universal makefile that detects, or can be configured, where it is and how to act accordingly.

Plus: Customers can request just about any feature. :)

@PaulMartinsen
Copy link
Author

Hi @gojimmypi ,

Sorry for the tardy reply. I've been busing getting ws-eventing going and building support to maintain multiple simultaneous sockets so we only need to the TLS handshake once, or at least not for every message to every peer. Keeping me busy, but nothing like running linux on an ESP32s3! I'm impressed!

On the ESP registry capabilities: I think this is a nice, low effort way to explore/test libraries. Similar concept to nuget and the Arduino library manager, which works well. And I used this approach initially with an Espressif neo-pixel library. In the long run, I would include the library as a git submodule, either referencing the vendor library or a fork of it. That's the approach I used with WolfSSL. I suppose vendor registries might be less stable over than major sources like github.

On build settings: for me, targeting windows and esp32s3 has turned out to be a good decision, partly because the Espressif support is still evolving in the WolfSSL library and partly because development is just easier in a desktop environment. Portable code is always a bonus. For that reason, I think flagging inclue/user_settings.h from cmakelists.txt is both a good idea and a bad idea. Good because you're moving to a better approach on the Espressif side and flagging the error will help the transition. Bad because it breaks the current windows build process. I wonder if it could be a warning on the Espressif side? The WolfSSL library doesn't generate many warnings so it would still stand out.

A better solution overall, for me at least, would be to setup the Windows build to use a shared items project. The WolfSSL repository's example lib project would reference that to create .lib or .dll though it would contain little more than pre-processor macro definitions and the user_settings.h file. And configuring the library could be as simple as copying the lib file from the submodule into the the solution. It can still reference the shared items project in the submodule without change and customization is committed to the project repository. Similarly, contributions in the WolfSSL source could be made in a forked submodule without mucking about with the standard Wolf example projects.

Shared item projects is the approach I'm currently using to target Windows and Espressif (with cmakelists.txt) in one solution & have used on several other embedded projects. I think it is the analog for Visual Studio of your build-in-place approach with cmakelists.txt. The recommended WolfSSL approach still modifies the Visual Studio project in the WolfSSl repository (with the include path). With this approach, I like the idea of generating errors in the Espressif build when it finds extraneous user_settings.h files.

@gojimmypi
Copy link
Contributor

targeting windows and esp32s3 has turned out to be a good decision

I'm so glad things are going well for your project!

ESP registry capabilities: I think this is a nice, low effort way to explore/test libraries.

Thanks! Yes, that's absolutely the objective of wolfSSL in the ESP Registry: something super easy to get started.

nothing like running linux on an ESP32s3! I'm impressed

I'm standing on the shoulders of giants, but yes!! Linux on the ESP32-S3 is really cool.

Did you see my initial performance benchmark comparison?

flagging include/user_settings.h ... Bad because it breaks the current windows build process

Interesting; can you provide more details, perhaps provide an example solution / project set? Is this regarding the my cmake warning when more than one user_settings.h file is found? Perhaps this is problematic when the user_settings.h is in the wolfSSL source?

I do have an update - recall the local user_settings.h in the project components directory. I need to get a PR together for that.

I've reached out to the internal support to see if there are other ideas on sharing wolfSSL between projects on different platforms, such as your Windows & ESP32.

better solution overall, for me at least, would be to setup the Windows build to use a shared items project

I'll take a look at that. Thanks for the suggestion. :)

As for this issue, I'm fairly certain that the ED25519 test on the ESP32 for both hardware and software was fixed some time ago. I think it is a bit misleading to leave this issue open. If you don't mind, I'm going to go ahead and close it. Please feel free to open any additional issues as appropriate.

I do appreciate all your feedback and ideas. We can certainly continue the discussion here, or perhaps over on my Espressif Improvements Roadmap Issue #6234.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants