Skip to content

Add X25519 non-blocking support and async example improvements#9721

Open
dgarske wants to merge 3 commits intowolfSSL:masterfrom
dgarske:x25519_nb
Open

Add X25519 non-blocking support and async example improvements#9721
dgarske wants to merge 3 commits intowolfSSL:masterfrom
dgarske:x25519_nb

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Jan 29, 2026

Description

Add non-blocking (non-blocking crypto) support for Curve25519 (X25519) key generation and shared secret. This enables WC_X25519_NONBLOCK for use with TLS, similar to the existing WC_ECC_NONBLOCK support. Requires CURVE25519_SMALL (the small fe_low_mem.c implementation).

New Features

  • X25519 non-blocking key gen (wc_curve25519_make_key) and shared secret (wc_curve25519_shared_secret) using FP_WOULDBLOCK yield pattern.
  • Non-blocking curve25519_nb() function in fe_low_mem.c with state machine for iterative scalar multiplication.
  • TLS integration: WC_X25519_NONBLOCK support in src/tls.c and src/internal.c for key gen and ECDH during handshake.
  • New async TLS client/server examples (examples/async/) with standalone Makefile (no configure needed).
  • user_settings_curve25519nonblock.h example config.
  • Async examples CI workflow (.github/workflows/async-examples.yml).
  • WOLFSSL_STATIC_MEMORY support in async examples using wolfSSL_CTX_load_static_memory.

Fixes

  • Fix async SW guard in curve25519.c — require WOLFSSL_ASYNC_CRYPT_SW for software async simulation symbols.
  • Fix mutual auth in async examples — server loads self-signed client certs (ECC/ED25519) as their own CA.
  • Fix C90 mixed-declaration violations in SP ECC non-blocking code (sp_c32.c, sp_c64.c, sp_x86_64.c, sp_arm32.c, sp_arm64.c, sp_armthumb.c, sp_cortexm.c) — move typedef before statements.
  • Fix register ... asm() pedantic warning on macOS in sp_x86_64.c with __APPLE__ && __MACH__ guard.
  • Add missing user_settings_curve25519nonblock.h to examples/configs/include.am.

Testing

  • CI matrix tests async examples with: default, WOLFSSL_SMALL_CERT_VERIFY, WOLFSSL_STATIC_MEMORY.
  • 8 TLS test combinations per matrix entry: ECC/X25519 x TLS 1.2/1.3 x normal/mutual auth.
  • Validates WC_PENDING_E count >= 100 per test to confirm async crypto is exercised.
  • Static memory prints per-connection memory stats (peak mem, allocs, frees).
  • wolfcrypt/test/test.c updated with X25519 non-blocking test cases.
  • Tested: ./configure --enable-curve25519=small CFLAGS="-DWC_X25519_NONBLOCK" and ./configure CFLAGS="-DWC_X25519_NONBLOCK" --enable-curve25519=small --enable-asynccrypt.

@dgarske dgarske self-assigned this Jan 29, 2026
@dgarske dgarske marked this pull request as ready for review January 29, 2026 20:06
@dgarske dgarske force-pushed the x25519_nb branch 4 times, most recently from e8fc0a8 to 50dea8f Compare February 2, 2026 17:40
@night1rider
Copy link
Contributor

Jenkins retest this please - CI issue PRB-Master-Job

@dgarske
Copy link
Contributor Author

dgarske commented Feb 4, 2026

Jenkins retest this please

## Summary
- Add non-blocking (incremental) Curve25519 key generation and shared secret via `WC_X25519_NONBLOCK`, modeled after the existing ECC non-blocking pattern (`WC_ECC_NONBLOCK`)
- Implement `curve25519_nb()` and `fe_inv__distinct_nb()` in `fe_low_mem.c` as state-machine variants that return `FP_WOULDBLOCK` to yield after each field multiply
- Add `wc_curve25519_set_nonblock()` API to attach/detach non-blocking context to a key
- Integrate X25519 non-blocking with TLS 1.2/1.3 key share generation and shared secret in `tls.c` and `internal.c` (behind `WC_X25519_NONBLOCK && WOLFSSL_ASYNC_CRYPT_SW`)
- Add `--enable-curve25519=nonblock` configure option (auto-enables `--enable-asynccrypt` and `--enable-asynccrypt-sw`)
- Add X25519 async software dispatch cases in `async.c` and types in `async.h`
- Fix async guard in `curve25519.c` to require `WOLFSSL_ASYNC_CRYPT_SW` (matching other algorithms)
- Overhaul `examples/async/` client/server: non-blocking I/O via `WOLFSSL_USER_IO`, standalone `Makefile`, X25519/ECC mode selection, CI-friendly ready-file sync
- Add `examples/configs/user_settings_curve25519nonblock.h` and CI coverage in `os-check.yml` and new `async-examples.yml` workflow
- Add wolfcrypt test and API test coverage for X25519 non-blocking
@dgarske dgarske changed the title Support for Curve25519 non-blocking cryptography (based on PR #5764) Add X25519 non-blocking support and async example improvements Feb 5, 2026
@dgarske
Copy link
Contributor Author

dgarske commented Feb 5, 2026

Jenkins retest this please: "EOFException"

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.

3 participants