Skip to content

Conversation

@dgarske
Copy link
Contributor

@dgarske dgarske commented Jan 29, 2026

Add X25519 Non-Blocking Support

Description

This PR adds non-blocking (yield) support for X25519 (Curve25519) key generation and shared secret operations, similar to the existing WC_ECC_NONBLOCK support for ECC operations.

Changes

New Features:

  • Added WC_X25519_NONBLOCK configuration macro to enable non-blocking X25519 operations
  • Added x25519_nb_ctx_t context structure to track non-blocking operation state
  • Added wc_curve25519_set_nonblock() API to configure non-blocking mode on a key
  • Added non-blocking implementations for:
    • wc_curve25519_make_key() - key generation
    • wc_curve25519_shared_secret() - ECDH shared secret computation

Files Modified:

  • src/internal.c - Added X25519 non-blocking context allocation/deallocation in TLS AllocKey/FreeKey
  • wolfcrypt/src/curve25519.c - Added non-blocking key generation and shared secret functions
  • wolfcrypt/src/fe_low_mem.c - Added curve25519_nb() and fe_inv__distinct_nb() non-blocking implementations
  • wolfcrypt/test/test.c - Added x25519_nonblock_test() and async wait calls for X25519 operations
  • wolfssl/wolfcrypt/curve25519.h - Added x25519_nb_ctx_t struct and wc_curve25519_set_nonblock() API
  • wolfssl/wolfcrypt/fe_operations.h - Added non-blocking function declarations

Requirements

  • Requires CURVE25519_SMALL (enabled via --enable-curve25519=small)
  • Build error will be generated if WC_X25519_NONBLOCK is used without CURVE25519_SMALL

Testing

Build command:

./configure CFLAGS="-g3 -O0" CPPFLAGS="-DWC_X25519_NONBLOCK" \
    --enable-curve25519=small --enable-asynccrypt --enable-asynccrypt-sw && make

Run tests:

./wolfcrypt/test/testwolfcrypt

Expected output should include:

CURVE25519 test passed!

Alternative build (with debugging output):

./configure CFLAGS="-g3 -O0" CPPFLAGS="-DWC_X25519_NONBLOCK" \
    --enable-curve25519=small --enable-asynccrypt --enable-asynccrypt-sw \
    --enable-debug && make

This will print iteration counts for non-blocking operations:

CURVE25519 non-block key gen: <N> times
CURVE25519 non-block shared secret: <N> times

API Usage Example

#include <wolfssl/wolfcrypt/curve25519.h>

curve25519_key key;
x25519_nb_ctx_t nbCtx;
int ret;

/* Initialize key */
wc_curve25519_init(&key);

/* Set non-blocking context */
wc_curve25519_set_nonblock(&key, &nbCtx);

/* Generate key with non-blocking loop */
do {
    ret = wc_curve25519_make_key(rng, 32, &key);
} while (ret == FP_WOULDBLOCK);

if (ret != 0) {
    /* Handle error */
}

/* Key is now ready for use */

@dgarske dgarske self-assigned this Jan 29, 2026
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.

1 participant