From fec7469c19b1ae2284defa3b6314297181db16fd Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Wed, 30 Nov 2022 10:01:46 -0800 Subject: [PATCH] Tidy up Espressif ESP32 test and benchmark examples (#5800) Tidy up Espressif ESP32 test and benchmark examples: * add VisualGDB project and solution files for server and client * "hardware in use revert to software" is now verbose level message * Remove (void) TAG; - not needed to appease compiler * include esp_log.h lib with defined(WOLFSSL_ESPIDF) * large ESP32 default stack size * check for max number of arguments assembled into array * cleanup & comments per code review * wolfssl_test VisualGDB updates * Espressif wolfssl_test default stack 55,000 bytes --- IDE/Espressif/ESP-IDF/UPDATE.md | 23 ++ .../examples/wolfssl_benchmark/CMakeLists.txt | 6 + .../examples/wolfssl_benchmark/README.md | 174 +++++++++++ .../VisualGDB_wolfssl_benchmark.sln | 39 +++ .../VisualGDB_wolfssl_benchmark.vgdbproj | 268 +++++++++++++++++ .../wolfssl_benchmark/main/CMakeLists.txt | 2 +- .../main/{helper.c => main.c} | 94 ++++-- .../examples/wolfssl_benchmark/main/main.h | 29 ++ .../wolfssl_benchmark/sdkconfig.defaults | 31 +- .../VisualGDB_wolfssl_client.sln | 31 ++ .../VisualGDB_wolfssl_client.vgdbproj | 265 +++++++++++++++++ .../VisualGDB_wolfssl_server.sln | 31 ++ .../VisualGDB_wolfssl_server.vgdbproj | 269 ++++++++++++++++++ .../examples/wolfssl_test/CMakeLists.txt | 8 +- .../ESP-IDF/examples/wolfssl_test/README.md | 140 ++++++++- .../wolfssl_test/VisualGDB_wolfssl_test.sln | 42 +++ .../VisualGDB_wolfssl_test.vgdbproj | 269 ++++++++++++++++++ .../examples/wolfssl_test/main/CMakeLists.txt | 6 +- .../wolfssl_test/main/Kconfig.projbuild | 29 ++ .../ESP-IDF/examples/wolfssl_test/main/main.c | 172 +++++++++++ .../examples/wolfssl_test/main/time_helper.c | 119 ++++++++ .../examples/wolfssl_test/main/time_helper.h | 32 +++ .../examples/wolfssl_test/sdkconfig.defaults | 27 +- IDE/Espressif/ESP-IDF/libs/CMakeLists.txt | 3 + IDE/Espressif/ESP-IDF/libs/README.md | 7 + IDE/Espressif/ESP-IDF/libs/component.mk | 2 + IDE/Espressif/ESP-IDF/libs/tigard.cfg | 8 + IDE/Espressif/ESP-IDF/setup.sh | 11 +- IDE/Espressif/ESP-IDF/setup_win.bat | 5 - wolfcrypt/src/port/Espressif/esp32_sha.c | 4 +- wolfcrypt/src/sha256.c | 4 +- wolfcrypt/test/test.c | 18 +- wolfcrypt/test/test.h | 5 + 33 files changed, 2116 insertions(+), 57 deletions(-) create mode 100644 IDE/Espressif/ESP-IDF/UPDATE.md create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.sln create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.vgdbproj rename IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/{helper.c => main.c} (65%) create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.h create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.sln create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.vgdbproj create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.sln create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.vgdbproj create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.sln create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.vgdbproj create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/Kconfig.projbuild create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/main.c create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.c create mode 100644 IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.h create mode 100644 IDE/Espressif/ESP-IDF/libs/README.md create mode 100644 IDE/Espressif/ESP-IDF/libs/tigard.cfg diff --git a/IDE/Espressif/ESP-IDF/UPDATE.md b/IDE/Espressif/ESP-IDF/UPDATE.md new file mode 100644 index 000000000..63d3bce7d --- /dev/null +++ b/IDE/Espressif/ESP-IDF/UPDATE.md @@ -0,0 +1,23 @@ +# Espressif Updates + +See [#5795]() + +## Changes in November 2022 + +Updates to Espressif ESP-IDF wolfssl_benchmark and wolfssl_test examples: + +- Benchmark example no longer runs tests. +- Fixed Test example that was missing code files. (no longer installed locally) +- Rename `benchmark/main` and `test/main` filenames from `helper.c` to `main.c`, cleaned up. +- Added `main.h` +- Revised `main/CMakeLists.txt` to use only `main.c` +- Set components `main` and `wolfssl` for project `CMakeLists.txt` +- Update wolfcrypt esp32_sha.c and sha256.c to now report unexpected reentry as verbose log rather than error message. +- `wolfcrypt/test.c` now returns `args.return_code` when `WOLFSSL_ESPIDF` is defined. +- `wolfcrypt/test.h` now declares `int wolf_test_task(void)` when `WOLFSSL_ESPIDF` is defined. +- `setup.sh` no longer copies benchmark.c(.h) to local project directory. +- Added `libs/Tigard.cfg` file for Tigard JTAG debugger. +- Update `sdkconfig.defaults` with compiler optimizations and stack check. +- Added VisualGDB Project file & Visual Studio solution file. +- Added optional `time_helper` for wolfssl_test +- Exclude `ssl_misc.c` in component cmake to fix warning: #warning ssl_misc.c does not need to be compiled separately from ssl.c diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/CMakeLists.txt b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/CMakeLists.txt index 98c19f5b3..430386e88 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/CMakeLists.txt +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/CMakeLists.txt @@ -3,4 +3,10 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +set(COMPONENTS + main + wolfssl +) # set components + project(wolfssl_benchmark) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/README.md b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/README.md index d8f5c9437..174851078 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/README.md +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/README.md @@ -14,3 +14,177 @@ When you want to run the benchmark program 2. `idf.py monitor` to see the message See the README.md file in the upper level 'examples' directory for more information about examples. + +## Performance + +Reminder than when building on WSL in `/mnt/c` there will be a noticeable performance degradation at compile time. Using `~/` will be faster at the cost of shared filesystems. + +Example build on WSL: + +``` +Optionally install wolfSSL component +# cd /mnt/c/workspace/wolfssl/IDE/Espressif/ESP-IDF +./setup.sh + +cd /mnt/c/workspace/wolfssl/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark + +# Pick ESP-IDF install directory, this one for v4.4.2 in VisualGDB +. /mnt/c/SysGCC/esp32/esp-idf/v4.4.2/export.sh + + +idf.py build flash -p /dev/ttyS20 -b 921600 monitor +``` + +## Example Output + +Note the default wolfSSL `user_settings.h` is configured by default to be the most +compatible across the widest ranges of targets. Contact wolfSSL at support@wolfssl.com +for help in optimizing for your particular application, or see the +[docs](https://www.wolfssl.com/documentation/manuals/wolfssl/index.html). + +Compiled and flashed with `idf.py build flash -p /dev/ttyS7 -b 921600 monitor`: + +``` +--- idf_monitor on /dev/ttyS7 115200 --- +--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H --- + (377) cpu_start: Starting scheduler ets Jun 8 2016 00:22:57 + +rst:0x1 (POWERON_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:6664 +load:0x40078000,len:14848 +load:0x40080400,len:3792 +0x40080400: _init at ??:? + +entry 0x40080694 +I (27) boot: ESP-IDF v4.4.2-dirty 2nd stage bootloader +I (27) boot: compile time 13:41:41 +I (27) boot: chip revision: 1 +I (30) boot_comm: chip revision: 1, min. bootloader chip revision: 0 +I (37) boot.esp32: SPI Speed : 40MHz +I (42) boot.esp32: SPI Mode : DIO +I (46) boot.esp32: SPI Flash Size : 2MB +I (51) boot: Enabling RNG early entropy source... +I (56) boot: Partition Table: +I (60) boot: ## Label Usage Type ST Offset Length +I (67) boot: 0 nvs WiFi data 01 02 00009000 00006000 +I (75) boot: 1 phy_init RF data 01 01 0000f000 00001000 +I (82) boot: 2 factory factory app 00 00 00010000 00100000 +I (90) boot: End of partition table +I (94) boot_comm: chip revision: 1, min. application chip revision: 0 +I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=12bf4h ( 76788) map +I (137) esp_image: segment 1: paddr=00022c1c vaddr=3ffb0000 size=02420h ( 9248) load +I (141) esp_image: segment 2: paddr=00025044 vaddr=40080000 size=0afd4h ( 45012) load +I (161) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=33148h (209224) map +I (237) esp_image: segment 4: paddr=00063170 vaddr=4008afd4 size=00550h ( 1360) load +I (238) esp_image: segment 5: paddr=000636c8 vaddr=50000000 size=00010h ( 16) load +I (249) boot: Loaded app from partition at offset 0x10000 +I (249) boot: Disabling RNG early entropy source... +I (266) cpu_start: Pro cpu up. +I (266) cpu_start: Starting app cpu, entry point is 0x40081098 +0x40081098: call_start_cpu1 at /mnt/c/SysGCC/esp32/esp-idf/v4.4.2/components/esp_system/port/cpu_start.c:160 + +I (0) cpu_start: App cpu up. +I (280) cpu_start: Pro cpu start user code +I (280) cpu_start: cpu freq: 240000000 +I (280) cpu_start: Application information: +I (285) cpu_start: Project name: wolfssl_benchmark +I (291) cpu_start: App version: v5.5.3-stable-108-gbd7b442df-di +I (298) cpu_start: Compile time: Nov 17 2022 14:10:03 +I (304) cpu_start: ELF file SHA256: fbb520f5bbf963a0... +I (310) cpu_start: ESP-IDF: v4.4.2-dirty +I (316) heap_init: Initializing. RAM available for dynamic allocation: +I (323) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM +I (329) heap_init: At 3FFB3DE8 len 0002C218 (176 KiB): DRAM +I (335) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM +I (341) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM +I (348) heap_init: At 4008B524 len 00014ADC (82 KiB): IRAM +I (355) spi_flash: detected chip: generic +I (359) spi_flash: flash io: dio +W (362) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. +I (377) cpu_start: Starting scheduler on PRO CPU. +I (0) cpu_start: Starting scheduler on APP CPU. +I (391) wolfssl_benchmark: app_main CONFIG_BENCH_ARGV = -lng 0 +I (397) wolfssl_benchmark: construct_argv arg:-lng 0 + +------------------------------------------------------------------------------ + wolfSSL version 5.5.3 +------------------------------------------------------------------------------ +wolfCrypt Benchmark (block bytes 1024, min 1.0 sec each) +RNG 1 MiB took 1.017 seconds, 1.320 MiB/s +AES-128-CBC-enc 6 MiB took 1.002 seconds, 5.726 MiB/s +AES-128-CBC-dec 5 MiB took 1.000 seconds, 5.347 MiB/s +AES-192-CBC-enc 6 MiB took 1.004 seconds, 5.714 MiB/s +AES-192-CBC-dec 5 MiB took 1.001 seconds, 5.341 MiB/s +AES-256-CBC-enc 6 MiB took 1.000 seconds, 5.713 MiB/s +AES-256-CBC-dec 5 MiB took 1.002 seconds, 5.336 MiB/s +AES-128-GCM-enc 300 KiB took 1.004 seconds, 298.805 KiB/s +AES-128-GCM-dec 300 KiB took 1.004 seconds, 298.805 KiB/s +AES-192-GCM-enc 300 KiB took 1.007 seconds, 297.915 KiB/s +AES-192-GCM-dec 300 KiB took 1.008 seconds, 297.619 KiB/s +AES-256-GCM-enc 300 KiB took 1.011 seconds, 296.736 KiB/s +AES-256-GCM-dec 300 KiB took 1.011 seconds, 296.736 KiB/s +GMAC Default 403 KiB took 1.002 seconds, 402.196 KiB/s +3DES 450 KiB took 1.028 seconds, 437.743 KiB/s +MD5 14 MiB took 1.001 seconds, 13.756 MiB/s +SHA 14 MiB took 1.001 seconds, 14.463 MiB/s +SHA-256 14 MiB took 1.000 seconds, 14.233 MiB/s +SHA-512 17 MiB took 1.000 seconds, 16.626 MiB/s +HMAC-MD5 14 MiB took 1.000 seconds, 13.599 MiB/s +HMAC-SHA 14 MiB took 1.000 seconds, 13.989 MiB/s +HMAC-SHA256 14 MiB took 1.000 seconds, 13.940 MiB/s +HMAC-SHA512 16 MiB took 1.000 seconds, 16.064 MiB/s +PBKDF2 640 bytes took 1.009 seconds, 634.291 bytes/s +RSA 2048 public 52 ops took 1.022 sec, avg 19.654 ms, 50.881 ops/sec +RSA 2048 private 4 ops took 1.056 sec, avg 264.000 ms, 3.788 ops/sec +ECC [ SECP256R1] 256 key gen 4 ops took 1.216 sec, avg 304.000 ms, 3.289 ops/sec +ECDHE [ SECP256R1] 256 agree 4 ops took 1.215 sec, avg 303.750 ms, 3.292 ops/sec +ECDSA [ SECP256R1] 256 sign 4 ops took 1.226 sec, avg 306.500 ms, 3.263 ops/sec +ECDSA [ SECP256R1] 256 verify 2 ops took 1.172 sec, avg 586.000 ms, 1.706 ops/sec +CURVE 25519 key gen 3 ops took 1.279 sec, avg 426.333 ms, 2.346 ops/sec +CURVE 25519 agree 4 ops took 1.701 sec, avg 425.250 ms, 2.352 ops/sec +ED 25519 key gen 46 ops took 1.008 sec, avg 21.913 ms, 45.635 ops/sec +ED 25519 sign 42 ops took 1.038 sec, avg 24.714 ms, 40.462 ops/sec +ED 25519 verify 26 ops took 1.009 sec, avg 38.808 ms, 25.768 ops/sec +Benchmark complete +``` + +## Known Issues and Common Issues + +### Permission denied + +Delete project directory `build`, `.visualgdb` and `.vs` directories. Ensure no other build +process is using the same files in Windows, WSL, Visual Studio, VSCode, etc. + +Example message: + +``` +-- Building ESP-IDF components for target esp32 +CMake Error at /mnt/c/SysGCC/esp32/esp-idf/v4.4.2/tools/cmake/component.cmake:131 (file): + file failed to open for writing (Permission denied): + + /mnt/c/workspace-pr/wolfssl/IDE/Espressif/ESP-IDF/examples/wolfssl_test/build/bootloader/component_properties.temp.cmake +``` + + +### user_settings.h: No such file or directory + +Ensure wolfSSL is installed in the ESP-IDF or local project `components` directory. + +Example message: + +``` + esp-idf/main/CMakeFiles/__idf_main.dir/main.c.obj -c ../main/main.c +../main/main.c:27:10: fatal error: user_settings.h: No such file or directory + #include + ^~~~~~~~~~~~~~~~~ +compilation terminated. +``` + +A 'clean` may be needed after freshly installing a new component: + +``` +idf.py clean build flash -p /dev/ttyS7 -b 921600 monitor +``` \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.sln b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.sln new file mode 100644 index 000000000..1b5b1e5b9 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32802.440 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "VisualGDB_wolfssl_benchmark", "VisualGDB_wolfssl_benchmark.vgdbproj", "{EADCC9AB-72B3-4B51-A838-593E5D80DDF7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CF8A8B6E-ECCF-481A-92AC-1E2F432816E8}" + ProjectSection(SolutionItems) = preProject + components\wolfssl\wolfcrypt\benchmark\benchmark.c = components\wolfssl\wolfcrypt\benchmark\benchmark.c + components\wolfssl\wolfcrypt\benchmark\benchmark.h = components\wolfssl\wolfcrypt\benchmark\benchmark.h + ..\..\README.md = ..\..\README.md + ..\..\UPDATE.md = ..\..\UPDATE.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|VisualGDB = Debug|VisualGDB + Release|VisualGDB = Release|VisualGDB + Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB + Tests (Release)|VisualGDB = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Debug|VisualGDB.Build.0 = Debug|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Release|VisualGDB.ActiveCfg = Release|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Release|VisualGDB.Build.0 = Release|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {969EF1DC-F8DA-46B8-A2AC-A7FDC3234245} + EndGlobalSection +EndGlobal diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.vgdbproj b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.vgdbproj new file mode 100644 index 000000000..a5631c488 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/VisualGDB_wolfssl_benchmark.vgdbproj @@ -0,0 +1,268 @@ + + + + + + Unknown + + true + + 7bbd1486-d457-4e49-92ba-0cfc9d80849e + true + true + SourceDirs + + + + + + com.visualgdb.xtensa-esp32-elf + + 8.4.0 + 8.1.0 + 9 + + + + DEBUG + build/$(PlatformName)/$(ConfigurationName) + + false + $(ToolchainNinja) + $(BuildDir) + + + + false + $(SYSPROGS_CMAKE_PATH) + + + true + false + false + Ninja + false + RemoveBuildDirectory + false + + + true + true + true + false + true + false + true + HideOuterProjectTargets + true + false + true + + + true + eadcc9ab-72b3-4b51-a838-593e5d80ddf7 + + Upper + HeaderDirectoryAndSubdirectories + true + + + esp-idf/v4.4.2 + ESPIDF + + COM7 + false + false + ESP32 + + + + + + + + + + + + + + + Default + + + + COM20 + + 115200 + 8 + None + One + None + + + 0 + false + false + false + ASCII + + + 255 + 0 + 0 + 0 + + + 255 + 169 + 169 + 169 + + + 255 + 211 + 211 + 211 + + + 255 + 144 + 238 + 144 + + + 255 + 169 + 169 + 169 + + + + 16 + true + true + true + true + 0 + + LF + false + false + false + + + + true + + + + + Unknown + + true + true + true + + + + false + + + + + Debug + + + + Release + + + + + + + + + false + false + false + false + false + false + false + false + false + + false + false + false + false + false + false + true + false + None + false + false + app_main + true + false + false + true + 0 + false + 0 + true + false + + + openocd + + -f interface/tigard.cfg -c "adapter_khz 15000" -f target/esp32.cfg + + + + false + + 131072 + Enabled + + set remotetimeout 60 + target remote :$$SYS:GDB_PORT$$ + mon gdb_breakpoint_override hard + mon reset halt + load + + false + 0 + 0 + false + + 5000 + 1 + true + + size2MB + freq40M + DIO + + true + + + true + Disabled + 0 + false + false + true + false + false + + _estack + 0 + false + + true + + \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/CMakeLists.txt b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/CMakeLists.txt index dd98b8a94..630a42ba3 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/CMakeLists.txt +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/CMakeLists.txt @@ -4,7 +4,7 @@ # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS") -set(COMPONENT_SRCS "benchmark.c" "helper.c") +set(COMPONENT_SRCS main.c) set(COMPONENT_ADD_INCLUDEDIRS ".") register_component() diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/helper.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.c similarity index 65% rename from IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/helper.c rename to IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.c index b8223b139..a3c51599b 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/helper.c +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.c @@ -1,4 +1,4 @@ -/* helper.c +/* benchmark main.c * * Copyright (C) 2006-2022 wolfSSL Inc. * @@ -18,24 +18,42 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ -#include -#include -#include +/* ESP-IDF */ +#include +#include "sdkconfig.h" + +/* wolfSSL */ +#include +#ifndef WOLFSSL_ESPIDF +#warning "problem with wolfSSL user_settings. Check components/wolfssl/include" +#endif #include #include #include -#include "sdkconfig.h" -#include "esp_log.h" +/* check BENCH_ARGV in sdkconfig to determine need to set WOLFSSL_BENCH_ARGV */ +#ifdef CONFIG_BENCH_ARGV +#define WOLFSSL_BENCH_ARGV CONFIG_BENCH_ARGV +#define WOLFSSL_BENCH_ARGV_MAX_ARGUMENTS 22 /* arbitrary number of max args */ +#endif -#define WOLFSSL_BENCH_ARGV CONFIG_BENCH_ARGV +/* +** the wolfssl component can be installed in either: +** +** - the ESP-IDF component directory +** +** ** OR ** +** +** - the local project component directory +** +** it is not recommended to install in both. +** +*/ -/* proto-type */ -extern void wolf_benchmark_task(); -extern void wolf_crypt_task(); -static const char* const TAG = "wolfbenchmark"; -char* __argv[22]; +#include "main.h" + +static const char* const TAG = "wolfssl_benchmark"; #if defined(WOLFSSL_ESPWROOM32SE) && defined(HAVE_PK_CALLBACKS) \ && defined(WOLFSSL_ATECC508A) @@ -98,22 +116,26 @@ void my_atmel_free(int slotId) #endif /* CUSTOM_SLOT_ALLOCATION */ #endif /* WOLFSSL_ESPWROOM32SE && HAVE_PK_CALLBACK && WOLFSSL_ATECC508A */ +/* the following are needed by benchmark.c with args */ +#ifdef WOLFSSL_BENCH_ARGV +char* __argv[WOLFSSL_BENCH_ARGV_MAX_ARGUMENTS]; + int construct_argv() { int cnt = 0; int i = 0; int len = 0; - char *_argv; /* buffer for copying the string */ - char *ch; /* char pointer to trace the string */ - char buff[16] = { 0 }; /* buffer for a argument copy */ + char *_argv; /* buffer for copying the string */ + char *ch; /* char pointer to trace the string */ + char buff[16] = { 0 }; /* buffer for a argument copy */ - printf("arg:%s\n", CONFIG_BENCH_ARGV); + ESP_LOGI(TAG, "construct_argv arg:%s\n", CONFIG_BENCH_ARGV); len = strlen(CONFIG_BENCH_ARGV); _argv = (char*)malloc(len + 1); if (!_argv) { return -1; } - memset(_argv, 0, len+1); + memset(_argv, 0, len + 1); memcpy(_argv, CONFIG_BENCH_ARGV, len); _argv[len] = '\0'; ch = _argv; @@ -123,8 +145,15 @@ int construct_argv() __argv[cnt][9] = '\0'; cnt = 1; - while (*ch != '\0') - { + while (*ch != '\0') { + /* check that we don't overflow manual arg assembly */ + if (cnt >= (WOLFSSL_BENCH_ARGV_MAX_ARGUMENTS)) { + ESP_LOGE(TAG, "Abort construct_argv;" + "Reached maximum defined arguments = %d", + WOLFSSL_BENCH_ARGV_MAX_ARGUMENTS); + break; + } + /* skip white-space */ while (*ch == ' ') { ++ch; } @@ -148,11 +177,12 @@ int construct_argv() return (cnt); } +#endif /* entry point */ void app_main(void) { - (void) TAG; + ESP_LOGI(TAG, "app_main CONFIG_BENCH_ARGV = %s", WOLFSSL_BENCH_ARGV); /* when using atecc608a on esp32-wroom-32se */ #if defined(WOLFSSL_ESPWROOM32SE) && defined(HAVE_PK_CALLBACKS) \ @@ -168,10 +198,22 @@ void app_main(void) #endif #endif -#ifndef NO_CRYPT_TEST - wolf_crypt_task(); -#endif -#ifndef NO_CRYPT_BENCHMARK +#ifdef NO_CRYPT_BENCHMARK + ESP_LOGI(TAG, "NO_CRYPT_BENCHMARK defined, skipping wolf_benchmark_task") +#else + + /* although wolfCrypt_Init() may be explicitly called above, + ** note it is still always called in wolf_benchmark_task. + */ wolf_benchmark_task(); -#endif -} + /* wolfCrypt_Cleanup should always be called at completion, + ** and is called in wolf_benchmark_task(). + */ + + /* after the test, we'll just wait */ + while (1) { + /* nothing */ + } + +#endif /* NO_CRYPT_BENCHMARK */ +} /* main */ diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.h b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.h new file mode 100644 index 000000000..963ad722d --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/main.h @@ -0,0 +1,29 @@ +#pragma once +/* benchmark main.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 + */ + +void app_main(void); + +/* see wolfssl/wolfcrypt/benchmark/benchmark.h */ +extern void wolf_benchmark_task(); + + + diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/sdkconfig.defaults b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/sdkconfig.defaults index 9a3430f01..a8e3efeb4 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/sdkconfig.defaults +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/sdkconfig.defaults @@ -1,6 +1,31 @@ CONFIG_BENCH_ARGV="-lng 0" -CONFIG_MAIN_TASK_STACK_SIZE=7500 CONFIG_FREERTOS_HZ=1000 -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0= CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y -170 CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240 + +# +# Default main stack size +# +# This is typically way bigger than needed for stack size. See user_settings.h +# +CONFIG_ESP_MAIN_TASK_STACK_SIZE=55500 + +# Legacy stack size for older ESP-IDF versions +CONFIG_MAIN_TASK_STACK_SIZE=55500 + +# +# Watchdog Timers +# +# We don't want to have the watchdog timeout during tests +# +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n + +# +# Compiler options +# +CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2 +CONFIG_COMPILER_HIDE_PATHS_MACROS=y +CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y +CONFIG_COMPILER_STACK_CHECK=y \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.sln b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.sln new file mode 100644 index 000000000..0db8292c3 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33027.164 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "VisualGDB_wolfssl_client", "VisualGDB_wolfssl_client.vgdbproj", "{E903E9CC-1A23-4B00-8914-7E45EC21E351}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|VisualGDB = Debug|VisualGDB + Release|VisualGDB = Release|VisualGDB + Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB + Tests (Release)|VisualGDB = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Debug|VisualGDB.Build.0 = Debug|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Release|VisualGDB.ActiveCfg = Release|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Release|VisualGDB.Build.0 = Release|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB + {E903E9CC-1A23-4B00-8914-7E45EC21E351}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D510376F-F313-4EF6-8EF5-248D1949DFEB} + EndGlobalSection +EndGlobal diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.vgdbproj b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.vgdbproj new file mode 100644 index 000000000..eb3097648 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_client/VisualGDB_wolfssl_client.vgdbproj @@ -0,0 +1,265 @@ + + + + + + Unknown + + true + + bdbba681-1213-45f8-a44e-4652fe489fe3 + true + true + SourceDirs + + + + + + com.visualgdb.xtensa-esp32-elf + + 8.4.0 + 8.1.0 + 9 + + + DEBUG + build/$(PlatformName)/$(ConfigurationName) + + false + $(ToolchainNinja) + $(BuildDir) + + + + false + $(SYSPROGS_CMAKE_PATH) + + + true + false + false + Ninja + false + RemoveBuildDirectory + false + + + true + true + true + false + true + false + true + HideOuterProjectTargets + true + false + true + + true + e903e9cc-1a23-4b00-8914-7e45ec21e351 + + Upper + HeaderDirectoryAndSubdirectories + true + + + v4.4.2 + esp-idf/v4.4.2 + ESPIDF + + COM20 + false + false + ESP32 + + + + + + + + + + + + + + + Default + + + + COM20 + + 115200 + 8 + None + One + None + + + 0 + false + false + false + ASCII + + + 255 + 0 + 0 + 0 + + + 255 + 169 + 169 + 169 + + + 255 + 211 + 211 + 211 + + + 255 + 144 + 238 + 144 + + + 255 + 169 + 169 + 169 + + + + 16 + true + true + true + true + 0 + + LF + false + false + false + + + + true + + + + Unknown + + true + true + true + + + + false + + + + + Debug + + + + Release + + + + + + + + false + false + false + false + false + false + false + false + false + + false + false + false + false + false + false + true + false + None + false + false + app_main + true + false + false + true + 0 + false + 0 + true + false + + + openocd + + -f interface/tigard.cfg -c "adapter_khz 3000" -f target/esp32.cfg + + + + false + + 131072 + Enabled + + set remotetimeout 60 + target remote :$$SYS:GDB_PORT$$ + mon gdb_breakpoint_override hard + mon reset halt + load + + false + 0 + 0 + false + + 5000 + 1 + true + + size2MB + freq40M + DIO + + true + + + true + Auto + 0 + false + false + true + false + false + + _estack + 0 + false + + true + + \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.sln b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.sln new file mode 100644 index 000000000..59a39fee2 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33027.164 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "VisualGDB_wolfssl_server", "VisualGDB_wolfssl_server.vgdbproj", "{CD5A90CA-2D40-461A-A0C3-27654371BB00}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|VisualGDB = Debug|VisualGDB + Release|VisualGDB = Release|VisualGDB + Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB + Tests (Release)|VisualGDB = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Debug|VisualGDB.Build.0 = Debug|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Release|VisualGDB.ActiveCfg = Release|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Release|VisualGDB.Build.0 = Release|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB + {CD5A90CA-2D40-461A-A0C3-27654371BB00}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {719A8CBE-E881-4B20-89F3-9910520E1067} + EndGlobalSection +EndGlobal diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.vgdbproj b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.vgdbproj new file mode 100644 index 000000000..6f8dc6052 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_server/VisualGDB_wolfssl_server.vgdbproj @@ -0,0 +1,269 @@ + + + + + + Unknown + + true + + 63883b8e-8fa2-4e2f-807c-31c07f619c51 + true + true + SourceDirs + + + + + + com.visualgdb.xtensa-esp32-elf + + 8.4.0 + 8.1.0 + 9 + + + + DEBUG + build/$(PlatformName)/$(ConfigurationName) + + false + $(ToolchainNinja) + $(BuildDir) + + + + false + $(SYSPROGS_CMAKE_PATH) + + + true + false + false + Ninja + false + RemoveBuildDirectory + false + + + true + true + true + false + true + false + true + HideOuterProjectTargets + true + false + true + + + true + cd5a90ca-2d40-461a-a0c3-27654371bb00 + + Upper + HeaderDirectoryAndSubdirectories + true + + + v4.4.2 + esp-idf/v4.4.2 + ESPIDF + + COM20 + false + false + ESP32 + + + + + + + + + + + + + + + Default + + + + COM20 + + 115200 + 8 + None + One + None + + + 0 + false + false + false + ASCII + + + 255 + 0 + 0 + 0 + + + 255 + 169 + 169 + 169 + + + 255 + 211 + 211 + 211 + + + 255 + 144 + 238 + 144 + + + 255 + 169 + 169 + 169 + + + + 16 + true + true + true + true + 0 + + LF + false + false + false + + + + true + + + + + Unknown + + true + true + true + + + + false + + + + + Debug + + + + Release + + + + + + + + + false + false + false + false + false + false + false + false + false + + false + false + false + false + false + false + true + false + None + false + false + app_main + true + false + false + true + 0 + false + 0 + true + false + + + openocd + + -f interface/tigard.cfg -c "adapter_khz 3000" -f target/esp32.cfg + + + + false + + 131072 + Enabled + + set remotetimeout 60 + target remote :$$SYS:GDB_PORT$$ + mon gdb_breakpoint_override hard + mon reset halt + load + + false + 0 + 0 + false + + 5000 + 1 + true + + size2MB + freq40M + DIO + + true + + + true + Auto + 0 + false + false + true + false + false + + _estack + 0 + false + + true + + \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/CMakeLists.txt b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/CMakeLists.txt index 26af0fe10..914efa6cb 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/CMakeLists.txt +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/CMakeLists.txt @@ -1,6 +1,12 @@ -# The following five lines of boilerplate have to be in your project's +# The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +set(COMPONENTS + main + wolfssl +) # set components + project(wolfssl_test) diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/README.md b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/README.md index 99a61e287..363d0b445 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/README.md +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/README.md @@ -1,10 +1,142 @@ # wolfSSL Crypt Test Example -The Example contains of wolfSSL test program. +The Example contains of wolfSSL benchmark program. + +1. `idf.py menuconfig` to configure the program. + 1-1. Example Configuration -> + + BENCH_ARG : argument that you want to use. Default is "-lng 0" + The list of argument can be find in help. When you want to run the benchmark program -1. `idf.py menuconfig` to configure the program,first -2. `idf.py build` to compile and `idf.py -p flash` to load the firmware -3. `idf.py monitor` to see the message + +1. `idf.py -p flash` to compile and load the firmware +2. `idf.py monitor` to see the message See the README.md file in the upper level 'examples' directory for more information about examples. + +Reminder than when building on WSL in `/mnt/c` there will be a noticeable performance degradation at compile time. Using `~/` will be faster at the cost of shared filesystems. + +Example build on WSL, assuming `git clone` from `c:\workspace`: + +``` +# Optionally install wolfSSL component +# cd /mnt/c/workspace/wolfssl/IDE/Espressif/ESP-IDF +./setup.sh + +# switch to test example +cd /mnt/c/workspace/wolfssl/IDE/Espressif/ESP-IDF/examples/wolfssl_test + +# Pick ESP-IDF install directory, this one for v4.4.2 in VisualGDB +. /mnt/c/SysGCC/esp32/esp-idf/v4.4.2/export.sh + +# build and flash, in this example to COM20 +idf.py build flash -p /dev/ttyS20 -b 921600 monitor +``` + +## Example Output + +Note the default wolfSSL `user_settings.h` is configured by default to be the most +compatible across the widest ranges of targets. Contact wolfSSL at support@wolfssl.com +for help in optimizing for your particular application, or see the +[docs](https://www.wolfssl.com/documentation/manuals/wolfssl/index.html). + +Compiled and flashed with `idf.py build flash -p /dev/ttyS7 -b 921600 monitor`: + +``` +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:6612 +load:0x40078000,len:14788 +load:0x40080400,len:3792 +entry 0x40080694 +I (26) boot: ESP-IDF v4.4.1-dirty 2nd stage bootloader +I (26) boot: compile time 15:25:38 +I (26) boot: chip revision: 1 +I (29) boot_comm: chip revision: 1, min. bootloader chip revision: 0 +I (37) boot.esp32: SPI Speed : 40MHz +I (41) boot.esp32: SPI Mode : DIO +I (46) boot.esp32: SPI Flash Size : 2MB +I (50) boot: Enabling RNG early entropy source... +I (56) boot: Partition Table: +I (59) boot: ## Label Usage Type ST Offset Length +I (67) boot: 0 nvs WiFi data 01 02 00009000 00006000 +I (74) boot: 1 phy_init RF data 01 01 0000f000 00001000 +I (81) boot: 2 factory factory app 00 00 00010000 00100000 +I (89) boot: End of partition table +I (93) boot_comm: chip revision: 1, min. application chip revision: 0 +I (100) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=16ca4h ( 93348) map +I (143) esp_image: segment 1: paddr=00026ccc vaddr=3ffb0000 size=024d4h ( 9428) load +I (147) esp_image: segment 2: paddr=000291a8 vaddr=40080000 size=06e70h ( 28272) load +I (160) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=412d8h (266968) map +I (257) esp_image: segment 4: paddr=00071300 vaddr=40086e70 size=045a8h ( 17832) load +I (265) esp_image: segment 5: paddr=000758b0 vaddr=50000000 size=00010h ( 16) load +I (270) boot: Loaded app from partition at offset 0x10000 +I (270) boot: Disabling RNG early entropy source... +I (285) cpu_start: Pro cpu up. +I (286) cpu_start: Starting app cpu, entry point is 0x40081088 +I (273) cpu_start: App cpu up. +I (300) cpu_start: Pro cpu start user code +I (300) cpu_start: cpu freq: 160000000 +I (300) cpu_start: Application information: +I (305) cpu_start: Project name: wolfssl_test +I (310) cpu_start: App version: v5.5.3-stable-108-gbd7b442df-di +I (317) cpu_start: Compile time: Nov 17 2022 15:24:40 +I (323) cpu_start: ELF file SHA256: 90957eeb4f0d2246... +I (329) cpu_start: ESP-IDF: v4.4.1-dirty +I (335) heap_init: Initializing. RAM available for dynamic allocation: +I (342) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM +I (348) heap_init: At 3FFB2DF0 len 0002D210 (180 KiB): DRAM +I (354) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM +I (360) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM +I (367) heap_init: At 4008B418 len 00014BE8 (82 KiB): IRAM +I (374) spi_flash: detected chip: generic +I (378) spi_flash: flash io: dio +W (382) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. +I (396) cpu_start: Starting scheduler on PRO CPU. +I (0) cpu_start: Starting scheduler on APP CPU. +------------------------------------------------------------------------------ + wolfSSL version 5.5.3 +------------------------------------------------------------------------------ +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 (136548) wolfcrypt_test: Exiting main with return code: 0 + +I (136548) wolfssl_test: wolf_test_task complete success result code = 0 +``` diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.sln b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.sln new file mode 100644 index 000000000..e875bb726 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.sln @@ -0,0 +1,42 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32802.440 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "VisualGDB_wolfssl_test", "VisualGDB_wolfssl_test.vgdbproj", "{EADCC9AB-72B3-4B51-A838-593E5D80DDF7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{35EEC1E7-13AB-4C74-BFCE-22142A10E1C1}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + sdkconfig = sdkconfig + sdkconfig.defaults = sdkconfig.defaults + build\config\sdkconfig.h = build\config\sdkconfig.h + ..\..\..\..\..\wolfcrypt\test\test.c = ..\..\..\..\..\wolfcrypt\test\test.c + ..\..\..\..\..\wolfcrypt\test\test.h = ..\..\..\..\..\wolfcrypt\test\test.h + ..\..\..\..\..\..\..\SysGCC\esp32\esp-idf\v4.4.1\components\wolfssl\include\user_settings.h = ..\..\..\..\..\..\..\SysGCC\esp32\esp-idf\v4.4.1\components\wolfssl\include\user_settings.h + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|VisualGDB = Debug|VisualGDB + Release|VisualGDB = Release|VisualGDB + Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB + Tests (Release)|VisualGDB = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Debug|VisualGDB.Build.0 = Debug|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Release|VisualGDB.ActiveCfg = Release|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Release|VisualGDB.Build.0 = Release|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB + {EADCC9AB-72B3-4B51-A838-593E5D80DDF7}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A0AC9105-F2CF-44E7-8032-3CD9E77EC9F6} + EndGlobalSection +EndGlobal diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.vgdbproj b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.vgdbproj new file mode 100644 index 000000000..383b5f538 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/VisualGDB_wolfssl_test.vgdbproj @@ -0,0 +1,269 @@ + + + + + + Unknown + + true + + 35e5525f-318a-466e-a8c7-36548547d801 + true + true + SourceDirs + + + + + + com.visualgdb.xtensa-esp32-elf + + 8.4.0 + 8.1.0 + 9 + + + + DEBUG + build/$(PlatformName)/$(ConfigurationName) + + false + $(ToolchainNinja) + $(BuildDir) + + + + false + $(SYSPROGS_CMAKE_PATH) + + + true + false + false + Ninja + false + RemoveBuildDirectory + false + + + true + true + true + false + true + false + true + HideOuterProjectTargets + true + false + true + + + true + eadcc9ab-72b3-4b51-a838-593e5d80ddf7 + + Upper + HeaderDirectoryAndSubdirectories + true + + + v4.4.2 + esp-idf/v4.4.2 + ESPIDF + + COM20 + false + false + ESP32 + + + + + + + + + + + + + + + Default + + + + COM20 + + 115200 + 8 + None + One + None + + + 0 + false + false + false + ASCII + + + 255 + 0 + 0 + 0 + + + 255 + 169 + 169 + 169 + + + 255 + 211 + 211 + 211 + + + 255 + 144 + 238 + 144 + + + 255 + 169 + 169 + 169 + + + + 16 + true + true + true + true + 0 + + LF + false + false + false + + + + true + + + + + Unknown + + true + true + true + + + + false + + + + + Debug + + + + Release + + + + + + + + + false + false + false + false + false + false + false + false + false + + false + false + false + false + false + false + true + false + None + false + false + app_main + true + false + false + true + 0 + false + 0 + true + false + + + openocd + + -f interface/tigard.cfg -c "adapter_khz 3000" -f target/esp32.cfg + + + + false + + 131072 + Enabled + + set remotetimeout 60 + target remote :$$SYS:GDB_PORT$$ + mon gdb_breakpoint_override hard + mon reset halt + load + + false + 0 + 0 + false + + 5000 + 1 + true + + size2MB + freq40M + DIO + + true + + + true + Auto + 0 + false + false + true + false + false + + _estack + 0 + false + + true + + \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/CMakeLists.txt b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/CMakeLists.txt index 20be3f093..9cf6b3937 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/CMakeLists.txt +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/CMakeLists.txt @@ -4,7 +4,11 @@ # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS") -set(COMPONENT_SRCS "test.c") +set(COMPONENT_SRCS "main.c") + +# when using time helper: +# set(COMPONENT_SRCS "main.c" "time_helper.c") + set(COMPONENT_ADD_INCLUDEDIRS ".") register_component() diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/Kconfig.projbuild b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/Kconfig.projbuild new file mode 100644 index 000000000..264c80883 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/Kconfig.projbuild @@ -0,0 +1,29 @@ +menu "Example Configuration" + +config BENCH_ARGV + string "Arguments for benchmark test" + default "-lng 0" + help + -? Help, print this usage + 0: English, 1: Japanese + -csv Print terminal output in csv format + -base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes) + -no_aad No additional authentication data passed. + -dgst_full Full digest operation performed. + -rsa_sign Measure RSA sign/verify instead of encrypt/decrypt. + - Algorithm to benchmark. Available algorithms include: + cipher aes-cbc aes-gcm chacha20 chacha20-poly1305 + digest md5 poly1305 sha sha2 sha224 sha256 sha384 sha512 sha3 + sha3-224 sha3-256 sha3-384 sha3-512 + mac hmac hmac-md5 hmac-sha hmac-sha224 hmac-sha256 hmac-sha384 + hmac-sha512 + asym rsa rsa-sz dh ecc-kg ecc + other rng + -lng Display benchmark result by specified language. + 0: English, 1: Japanese + Size of block in bytes + + e.g -lng 1 + e.g sha + +endmenu diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/main.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/main.c new file mode 100644 index 000000000..ea92452f6 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/main.c @@ -0,0 +1,172 @@ +/* main.c + * + * 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 + */ + +/* ESP-IDF */ +#include +#include "sdkconfig.h" + +/* wolfSSL */ +#include +#ifndef WOLFSSL_ESPIDF +#warning "problem with wolfSSL user settings. Check components/wolfssl/include" +#endif + +#include + +/* +** the wolfssl component can be installed in either: +** +** - the ESP-IDF component directory +** +** ** OR ** +** +** - the local project component directory +** +** it is not recommended to install in both. +** +*/ + +/* +** although the wolfcrypt/test includes a default time setting, +** see the enclosed optional time helper for adding NNTP. +** be sure to add "time_helper.c" in main/CMakeLists.txt +*/ +#undef WOLFSSL_USE_TIME_HELPER +#if defined(WOLFSSL_USE_TIME_HELPER) + #include "time_helper.h" */ +#endif + +/* see wolfssl/wolfcrypt/test/test.h */ +extern void wolf_crypt_task(); + + +static const char* const TAG = "wolfssl_test"; + +#if defined(WOLFSSL_ESPWROOM32SE) && defined(HAVE_PK_CALLBACKS) \ + && defined(WOLFSSL_ATECC508A) + +#include "wolfssl/wolfcrypt/port/atmel/atmel.h" + +/* when you need to use a custom slot allocation, */ +/* enable the definition CUSTOM_SLOT_ALLOCAION. */ +#if defined(CUSTOM_SLOT_ALLOCATION) + +static byte mSlotList[ATECC_MAX_SLOT]; + +/* initialize slot array */ +void my_atmel_slotInit() +{ + int i; + for (i = 0; i < ATECC_MAX_SLOT; i++) { + mSlotList[i] = ATECC_INVALID_SLOT; + } +} + +/* allocate slot depending on slotType */ +int my_atmel_alloc(int slotType) +{ + int i, slot = ATECC_INVALID_SLOT; + + switch (slotType) { + case ATMEL_SLOT_ENCKEY: + slot = 4; + break; + case ATMEL_SLOT_DEVICE: + slot = 0; + break; + case ATMEL_SLOT_ECDHE: + slot = 0; + break; + case ATMEL_SLOT_ECDHE_ENC: + slot = 4; + break; + case ATMEL_SLOT_ANY: + for (i = 0; i < ATECC_MAX_SLOT; i++) { + if (mSlotList[i] == ATECC_INVALID_SLOT) { + slot = i; + break; + } /* if */ + } /* for */ + } /* switch */ + + return slot; +} + +/* free slot array */ +void my_atmel_free(int slotId) +{ + if (slotId >= 0 && slotId < ATECC_MAX_SLOT) { + mSlotList[slotId] = ATECC_INVALID_SLOT; + } +} + +#endif /* CUSTOM_SLOT_ALLOCATION */ +#endif /* WOLFSSL_ESPWROOM32SE && HAVE_PK_CALLBACK && WOLFSSL_ATECC508A */ + + +/* entry point */ +void app_main(void) +{ + int rc = 0; + +#if defined (WOLFSSL_USE_TIME_HELPER) + set_time(); +#endif + +/* when using atecc608a on esp32-wroom-32se */ +#if defined(WOLFSSL_ESPWROOM32SE) && defined(HAVE_PK_CALLBACKS) \ + && defined(WOLFSSL_ATECC508A) + #if defined(CUSTOM_SLOT_ALLOCATION) + my_atmel_slotInit(); + /* to register the callback, it needs to be initialized. */ + if ((wolfCrypt_Init()) != 0) { + ESP_LOGE(TAG, "wolfCrypt_Init failed"); + return; + } + atmel_set_slot_allocator(my_atmel_alloc, my_atmel_free); + #endif +#endif + +#ifdef NO_CRYPT_TEST + ESP_LOGI(TAG, "NO_CRYPT_TEST defined, skipping wolf_test_task"); +#else + /* Although wolfCrypt_Init() may be explicitly called above, + ** Note it is still always called in wolf_test_task. + */ + rc = wolf_test_task(); + /* note wolfCrypt_Cleanup() should always be called when finished. + ** This is called at the end of wolf_test_task(); + */ + + if (rc == 0) { + ESP_LOGI(TAG, "wolf_test_task complete success result code = %d", rc); + } + else { + ESP_LOGE(TAG, "wolf_test_task FAIL result code = %d", rc); + /* see wolfssl/wolfcrypt/error-crypt.h */ + } + + /* after the test, we'll just wait */ + while (1) { + /* nothing */ + } +#endif +} diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.c b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.c new file mode 100644 index 000000000..4ca52e996 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.c @@ -0,0 +1,119 @@ +/* time_helper.c + * + * 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 + */ +#include +#include + +#include "sdkconfig.h" +#include "esp_log.h" + +#include "time_helper.h" + +const static char* TAG = "Time Helper"; + +#define TIME_ZONE "PST-8" +/* NELEMS(x) number of elements + * To determine the number of elements in the array, we can divide the total size of + * the array by the size of the array element + * See https://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c + **/ +#define NELEMS(x) ( (int)(sizeof(x) / sizeof((x)[0])) ) +#define NTP_SERVER_LIST ( (char*[]) { \ + "pool.ntp.org", \ + "time.nist.gov", \ + "utcnist.colorado.edu" \ + } \ + ) +/* #define NTP_SERVER_COUNT using NELEMS: + * + * (int)(sizeof(NTP_SERVER_LIST) / sizeof(NTP_SERVER_LIST[0])) + */ +#define NTP_SERVER_COUNT NELEMS(NTP_SERVER_LIST) +char* ntpServerList[NTP_SERVER_COUNT] = NTP_SERVER_LIST; + +/* our NTP server list is global info */ +extern char* ntpServerList[NTP_SERVER_COUNT]; + + +int set_time(void) +{ + /* we'll also return a result code of zero */ + int res = 0; + int i = 0; /* counter for time servers */ + time_t interim_time; + + /* ideally, we'd like to set time from network, + * but let's set a default time, just in case */ + struct tm timeinfo = { + .tm_year = 2022 - 1900, + .tm_mon = 11, + .tm_mday = 15, + .tm_hour = 3, + .tm_min = 25, + .tm_sec = 0 + }; + struct timeval now; + +#ifndef NTP_SERVER_COUNT + #define NTP_SERVER_COUNT 0 + char* ntpServerList[NTP_SERVER_COUNT]; +#endif /* not defined: NTP_SERVER_COUNT */ + +#ifndef TIME_ZONE + #define TIME_ZONE "PST-8" +#endif /* not defined: TIME_ZONE */ + + + /* set interim static time */ + interim_time = mktime(&timeinfo); + now = (struct timeval){ .tv_sec = interim_time }; + settimeofday(&now, NULL); + + + /* set timezone */ + setenv("TZ", TIME_ZONE, 1); + tzset(); + + if (NTP_SERVER_COUNT) { + /* next, let's setup NTP time servers + * + * see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#sntp-time-synchronization + */ + sntp_setoperatingmode(SNTP_OPMODE_POLL); + + ESP_LOGI(TAG, "sntp_setservername:"); + for (i = 0; i < NTP_SERVER_COUNT; i++) { + const char* thisServer = ntpServerList[i]; + if (strncmp(thisServer, "\x00", 1) == 0) { + /* just in case we run out of NTP servers */ + break; + } + ESP_LOGI(TAG, "%s", thisServer); + sntp_setservername(i, thisServer); + } + sntp_init(); + ESP_LOGI(TAG, "sntp_init done."); + } + else { + ESP_LOGI(TAG, "No sntp time servers found."); + } + return res; +} + diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.h b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.h new file mode 100644 index 000000000..179ae9730 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/main/time_helper.h @@ -0,0 +1,32 @@ +#ifndef _TIME_HELPER_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 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +int set_time(void); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* #ifndef _TIME_HELPER_H */ diff --git a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/sdkconfig.defaults b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/sdkconfig.defaults index 6b3cd8ea3..7a1edc8c3 100644 --- a/IDE/Espressif/ESP-IDF/examples/wolfssl_test/sdkconfig.defaults +++ b/IDE/Espressif/ESP-IDF/examples/wolfssl_test/sdkconfig.defaults @@ -1,2 +1,27 @@ +# +# Default main stack size +# +# This is typically way bigger than needed for stack size. See user_settings.h +# +CONFIG_ESP_MAIN_TASK_STACK_SIZE=55000 + +# Legacy stack size for older ESP-IDF versions CONFIG_MAIN_TASK_STACK_SIZE=11000 -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0= + +# +# Watchdog Timers +# +# We don't want to have the watchdog timeout during tests +# +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n + +# +# Compiler options +# +CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y +CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2 +CONFIG_COMPILER_HIDE_PATHS_MACROS=y +CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y +CONFIG_COMPILER_STACK_CHECK=y \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/libs/CMakeLists.txt b/IDE/Espressif/ESP-IDF/libs/CMakeLists.txt index 62072187c..4f0f4e8ae 100644 --- a/IDE/Espressif/ESP-IDF/libs/CMakeLists.txt +++ b/IDE/Espressif/ESP-IDF/libs/CMakeLists.txt @@ -30,6 +30,8 @@ set(COMPONENT_SRCDIRS "./src/" "./wolfcrypt/src/" "./wolfcrypt/src/port/Espressif/" "./wolfcrypt/src/port/atmel/" + "./wolfcrypt/benchmark/" + "./wolfcrypt/test/" # "$ENV{IDF_PATH}/components/soc/esp32s3/include/soc" ) @@ -69,6 +71,7 @@ set(COMPONENT_SRCEXCLUDE "./src/conf.c" "./src/misc.c" "./src/pk.c" + "./src/ssl_misc.c" # included by ssl.c "./src/x509.c" "./src/x509_str.c" "./wolfcrypt/src/evp.c" diff --git a/IDE/Espressif/ESP-IDF/libs/README.md b/IDE/Espressif/ESP-IDF/libs/README.md new file mode 100644 index 000000000..703baf1ea --- /dev/null +++ b/IDE/Espressif/ESP-IDF/libs/README.md @@ -0,0 +1,7 @@ +Files in IDE\Espressif\ESP-IDF\libs: + +`CMakeLists.txt` used in ESP-IDF `wolfssl` component directory + +`component.mk` used in ESP-IDF `wolfssl` component directory + +`tigard.cfg` Tigard JTAG config file \ No newline at end of file diff --git a/IDE/Espressif/ESP-IDF/libs/component.mk b/IDE/Espressif/ESP-IDF/libs/component.mk index 40cf62c82..26655b415 100644 --- a/IDE/Espressif/ESP-IDF/libs/component.mk +++ b/IDE/Espressif/ESP-IDF/libs/component.mk @@ -29,6 +29,8 @@ COMPONENT_ADD_INCLUDEDIRS += "$ENV{IDF_PATH}/components/freertos/include/freerto COMPONENT_SRCDIRS := src wolfcrypt/src COMPONENT_SRCDIRS += wolfcrypt/src/port/Espressif COMPONENT_SRCDIRS += wolfcrypt/src/port/atmel +COMPONENT_SRCDIRS += wolfcrypt/benchmark +COMPONENT_SRCDIRS += wolfcrypt/test CFLAGS +=-DWOLFSSL_USER_SETTINGS diff --git a/IDE/Espressif/ESP-IDF/libs/tigard.cfg b/IDE/Espressif/ESP-IDF/libs/tigard.cfg new file mode 100644 index 000000000..196e2d8e3 --- /dev/null +++ b/IDE/Espressif/ESP-IDF/libs/tigard.cfg @@ -0,0 +1,8 @@ +adapter driver ftdi +ftdi vid_pid 0x0403 0x6010 +ftdi channel 1 +adapter speed 29500 +ftdi layout_init 0x0038 0x003b +ftdi layout_signal nTRST -data 0x0010 +ftdi layout_signal nSRST -data 0x0020 +transport select jtag diff --git a/IDE/Espressif/ESP-IDF/setup.sh b/IDE/Espressif/ESP-IDF/setup.sh index 4e20bd89e..8d10a59b7 100755 --- a/IDE/Espressif/ESP-IDF/setup.sh +++ b/IDE/Espressif/ESP-IDF/setup.sh @@ -77,8 +77,8 @@ ${CPDCMD} ./src/*.c ${WOLFSSLLIB_TRG_DIR}/src/ ${CPDCMD} -r ./wolfcrypt/src/*.{c,i} ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/src/ ${CPDCMD} -r ./wolfcrypt/src/port ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/src/port/ ${CPDCMD} -r ./wolfcrypt/test ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/ -# Copy dummy test_paths.h to handle the case configure hasn't yet executed -${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/dummy_test_paths.h ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/test/test_paths.h +# Copy dummy test_paths.h to handle the case configure hasn't yet executed +${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/dummy_test_paths.h ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/test/test_paths.h ${CPDCMD} -r ./wolfcrypt/benchmark ${WOLFSSLLIB_TRG_DIR}/wolfcrypt/ ${CPDCMD} -r ./wolfssl/*.h ${WOLFSSLLIB_TRG_DIR}/wolfssl/ @@ -96,7 +96,7 @@ ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/dummy_config_h ${WOLFSSLLIB_TRG_DIR}/include/c # unit test app ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/test/* ${WOLFSSLLIB_TRG_DIR}/test/ -popd > /dev/null # +popd > /dev/null # ${CPDCMD} ./libs/CMakeLists.txt ${WOLFSSLLIB_TRG_DIR}/ ${CPDCMD} ./libs/component.mk ${WOLFSSLLIB_TRG_DIR}/ @@ -111,9 +111,6 @@ ${RMDCMD} ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/ ${MKDCMD} ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/ ${MKDCMD} ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/main/ -${CPDCMD} ${BASEDIR}/wolfcrypt/benchmark/benchmark.h ${BASEDIR}/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/benchmark.h -${CPDCMD} ${BASEDIR}/wolfcrypt/benchmark/benchmark.c ${BASEDIR}/IDE/Espressif/ESP-IDF/examples/wolfssl_benchmark/main/benchmark.c - ${CPDCMD} -r ./wolfcrypt/benchmark/benchmark.c ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/main/ ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/examples/wolfssl_benchmark/* ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/ ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/examples/wolfssl_benchmark/main/* ${WOLFSSLEXP_TRG_DIR}/wolfssl_benchmark/main/ @@ -156,7 +153,7 @@ ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/examples/wolfssl_server/* ${WOLFSSLEXP_TRG_DIR ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/examples/wolfssl_server/main/* ${WOLFSSLEXP_TRG_DIR}/wolfssl_server/main/ ${CPDCMD} -r ${WOLFSSL_ESPIDFDIR}/examples/wolfssl_server/main/include/* ${WOLFSSLEXP_TRG_DIR}/wolfssl_server/main/include/ -popd > /dev/null # +popd > /dev/null # if [ "${WOLFSSL_SETUP_VERBOSE}" == "true" ]; then echo "Copy complete!" diff --git a/IDE/Espressif/ESP-IDF/setup_win.bat b/IDE/Espressif/ESP-IDF/setup_win.bat index d5e125832..2e279ad94 100644 --- a/IDE/Espressif/ESP-IDF/setup_win.bat +++ b/IDE/Espressif/ESP-IDF/setup_win.bat @@ -308,11 +308,6 @@ if %errorlevel% NEQ 0 GOTO :COPYERR echo; echo Copying %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\ mkdir %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\ -xcopy %BASEDIR%\wolfcrypt\benchmark\benchmark.h %BASEDIR%\IDE\Espressif\ESP-IDF\examples\wolfssl_benchmark\main\benchmark.h /F /Y -if %errorlevel% NEQ 0 GOTO :COPYERR - -xcopy %BASEDIR%\wolfcrypt\benchmark\benchmark.c %BASEDIR%\IDE\Espressif\ESP-IDF\examples\wolfssl_benchmark\main\benchmark.c /F /Y -if %errorlevel% NEQ 0 GOTO :COPYERR xcopy %BASEDIR%\wolfcrypt\benchmark\benchmark.c %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\ /F /Y if %errorlevel% NEQ 0 GOTO :COPYERR diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index bcdded9dd..557bde8a9 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -179,7 +179,7 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) /* this could be a warning of wonkiness in RTOS environment. * we were successful, but not expected depth count*/ - ESP_LOGE(TAG, "warning lockDepth mismatch."); + ESP_LOGV(TAG, "warning lockDepth mismatch."); } ctx->lockDepth = 0; ctx->mode = ESP32_SHA_INIT; @@ -274,7 +274,7 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ESP_LOGV(TAG, "Hardware Mode, lock depth = %d", ctx->lockDepth); } else { - ESP_LOGI(TAG, ">>>> Hardware in use; Mode REVERT to ESP32_SHA_SW"); + ESP_LOGV(TAG, ">>>> Hardware in use; Mode REVERT to ESP32_SHA_SW"); ctx->mode = ESP32_SHA_SW; return 0; /* success, but revert to SW */ } diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index d7dacf09e..6c3116e01 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -1760,10 +1760,10 @@ void wc_Sha256Free(wc_Sha256* sha256) * should have already been released (lockDepth = 0) */ InitSha256(sha256); /* unlock mutex, set mode to ESP32_SHA_INIT */ - ESP_LOGE("sha256", "ERROR: hardware unlock needed in wc_Sha256Free"); + ESP_LOGV("sha256", "Alert: hardware unlock needed in wc_Sha256Free."); } else { - ESP_LOGV("sha256", "hardware unlock not needed in wc_Sha256Free"); + ESP_LOGV("sha256", "Hardware unlock not needed in wc_Sha256Free."); } #endif } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 7ce68117d..d888bc2f1 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -118,6 +118,7 @@ #elif defined(WOLFSSL_ESPIDF) #include #include + #include #elif defined(WOLFSSL_ZEPHYR) #include @@ -1640,11 +1641,20 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ printf("Testing complete. You may close the window now\n"); while (1); #endif -#ifndef WOLFSSL_ESPIDF - printf("Exiting main with return code: %d\n", args.return_code); - return args.return_code; + +#ifdef WOLFSSL_ESPIDF + /* ESP_LOGI to print takes up a lot less memory than printf */ + ESP_LOGI("wolfcrypt_test", "Exiting main with return code: % d\n", args.return_code); #endif - } + +/* everything else will use printf */ +#if !defined(WOLFSSL_ESPIDF) +/* gate this for target platforms wishing to avoid printf reference */ + printf("Exiting main with return code: %d\n", args.return_code); +#endif + + return args.return_code; + } /* wolfcrypt_test_main or wolf_test_task */ #endif /* NO_MAIN_DRIVER */ diff --git a/wolfcrypt/test/test.h b/wolfcrypt/test/test.h index 6ca21fcab..c5f92bcc6 100644 --- a/wolfcrypt/test/test.h +++ b/wolfcrypt/test/test.h @@ -33,10 +33,15 @@ THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args); #else int wolfcrypt_test(void* args); #endif + #ifndef NO_MAIN_DRIVER int wolfcrypt_test_main(int argc, char** argv); #endif +#if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE) +int wolf_test_task(void); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif