Skip to content

Add Nuvoton NuMaker-M2354 wolfCrypt test and benchmark example - #628

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:nuvoton_m2354
Open

Add Nuvoton NuMaker-M2354 wolfCrypt test and benchmark example#628
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:nuvoton_m2354

Conversation

@dgarske

@dgarske dgarske commented Sep 11, 2026

Copy link
Copy Markdown
Member

Summary

Runnable wolfcrypt_test and benchmark for the NuMaker-M2354 (NuMicro M2354KJFAE, Arm Cortex-M23 with TrustZone), exercising the wolfCrypt Nuvoton port that drives the part's CRPT accelerator, TRNG and Key Store.

What it adds

  • app.c - clocks, UART0 console, the CRPT interrupt handler, a bounded _sbrk, and main()
  • keystore_test.c - a Key Store round trip, covering a path wolfcrypt_test does not reach: a key written to a slot, used by handle for AES, read back where that is allowed, and erased
  • user_settings.h - wolfCrypt configuration to start from
  • secure/nuvoton_nsc.c - non-secure callable veneers for a TrustZone build
  • build.sh - cross build for either TrustZone world
  • run_test.sh - flash and capture on a real board, with a bench lock and a check that the running image is the one just built

Requires a wolfSSL checkout carrying the Nuvoton port. build.sh looks in ../../../wolfssl by default; --wolfssl PATH or WOLFSSL_ROOT override it.

Hardware / test status

Validated on a NuMaker-M2354 (96 MHz, Nu-Link2-Me CMSIS-DAP, UART0 on PA6/PA7 at 115200), flashed with pyocd against its builtin m2354kjfae target. wolfcrypt_test completes with 42 tests passing and none failing, and the Key Store round trip passes. The benchmark completes; the port README in wolfSSL carries the throughput table.

build.sh --tz is a compile check of both halves rather than a linked image, because a working TrustZone application also needs a partition layout and a secure bootstrap belonging to the user's project. A two-image build has been run on the board separately; the wolfSSL PR and the port README carry what it showed.

Scope

The Key Store round trip uses volatile SRAM slots. A Flash slot has no per-key erase, only an irreversible revoke, so a run would spend one for good; -DM2354_KS_TEST_FLASH includes that leg for anyone who wants it deliberately.

Related

wolfBoot's M2354 target, which uses the same port: wolfSSL/wolfBoot#884

@dgarske dgarske self-assigned this Sep 11, 2026
Copilot AI lite review requested due to automatic review settings September 11, 2026 21:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

TrustZone security validation and test-runner correctness issues must be addressed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds a NuMaker-M2354 wolfCrypt test and benchmark example with Key Store coverage, TrustZone support, and board tooling.

Changes:

  • Adds board initialization, tests, benchmarks, and wolfCrypt configuration.
  • Adds Key Store AES round-trip testing and TrustZone veneers.
  • Adds build, flash, capture, and validation documentation.
File summaries
File Summary
embedded/nuvoton_m2354/user_settings.h wolfCrypt configuration
embedded/nuvoton_m2354/secure/nuvoton_nsc.c TrustZone veneers; ECC validation, CCM sizing, and key ownership require changes
embedded/nuvoton_m2354/run_test.sh Flashing and capture; output normalization and stage-result checks require changes
embedded/nuvoton_m2354/README.md Usage and validation documentation; reported results need reconciliation
embedded/nuvoton_m2354/keystore_test.c Key Store AES round-trip test
embedded/nuvoton_m2354/build.sh Secure and TrustZone build logic
embedded/nuvoton_m2354/app.c Board setup and test application
embedded/nuvoton_m2354/.gitignore Ignores generated artifacts and logs
Review details

Suppressed comments (2)

embedded/nuvoton_m2354/run_test.sh:215

  • app.c emits CRLF by writing \r before every newline, so the captured TrustZone: value retains a trailing carriage return. As a result, the documented EXPECT_WORLD value never equals WORLD even for the correct image. Strip \r before comparing.
WORLD=$(sed -n 's/^TrustZone: //p' "$OUT" | head -1)
echo "image reported: TrustZone: ${WORLD:-unknown}"
if [ -n "$EXPECT_WORLD" ] && [ "$WORLD" != "$EXPECT_WORLD" ]; then

embedded/nuvoton_m2354/secure/nuvoton_nsc.c:239

  • The port's ECC request fields are 144 bytes wide, enough for P-521's 132 hex digits plus the NUL, but this veneer validates every output with 160 bytes. For the final field that range runs past the request allocation, so non-secure ECC calls are rejected by cmse_check_address_range before reaching the hardware. Keep the bound at the port's field width or derive a curve-specific output span.
/* Longest string the ECC requests carry: P-521 is 132 hex characters. */
#define NSC_ECC_STR_MAX 160
  • Files reviewed: 8/8 changed files
  • Comments generated: 6
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

/* Longest string the ECC requests carry: P-521 is 132 hex characters. */
#define NSC_ECC_STR_MAX 160

static int nsc_ecc_strings_ok(wc_NuvotonEccReq* r)
Comment on lines +399 to +402
NSC_ENTRY int wc_nuvoton_hw_ks_erase(int keyMem, int keySlot)
{
return wc_nuvoton_hw_ks_erase_s(keyMem, keySlot);
}
Comment thread embedded/nuvoton_m2354/run_test.sh Outdated
Comment on lines +220 to +224
if ! grep -q "wolfcrypt_test returned" "$OUT"; then
echo "NOTE: capture ended before wolfcrypt_test finished - raise --seconds"
elif ! grep -q "benchmark_test returned" "$OUT"; then
echo "NOTE: test finished; benchmark truncated by the window"
fi
Comment on lines +218 to +219
word32 ivSz = (local.mode == WC_NUVOTON_AES_GCM) ?
local.ivSz : (word32)WC_AES_BLOCK_SIZE;
Comment thread embedded/nuvoton_m2354/README.md Outdated
Comment on lines +107 to +109
`wolfcrypt_test` completes on a NuMaker-M2354 with 29 of 29 tests passing and
none failing, and the benchmark runs to completion. The port README in wolfSSL
carries the throughput table.
Comment thread embedded/nuvoton_m2354/README.md Outdated
Comment on lines +111 to +115
:warning: **The TrustZone leg is compile-checked only.** `--tz` builds both
halves but does not link or run, and nothing in `secure/nuvoton_nsc.c` has
executed on hardware. The veneers are pure request validation over wolfSSL
types, and a review of them found two defects that a functional test would have
caught at once, so treat that path as unvalidated until someone brings up a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants