Skip to content

API design: Curve25519 blinding forces throwaway RNG creation per shared_secret call #10587

Description

@MarkAtwood

wolfSSL's Curve25519 scalar-multiply blinding (enabled by default) requires an RNG to be attached to the private-key struct via wc_curve25519_set_rng() before each scalar multiply. wc_curve25519_shared_secret_ex does not accept an RNG parameter inline.

This forces every DH operation to initialize a throwaway RNG, set it on the key, perform the multiply, and free the RNG — four extra steps per call, one of which (wc_InitRng) may touch the entropy source.

Current code required for every DH call:

WC_RNG rng;
wc_InitRng(&rng);
wc_curve25519_set_rng(&private_key, &rng);
wc_curve25519_shared_secret_ex(&private_key, &public_key, out, &outlen, EC25519_LITTLE_ENDIAN);
wc_FreeRng(&rng);

For high-throughput servers or entropy-constrained platforms (HSMs, TPMs, embedded), this is unnecessary overhead. Callers already have an RNG instance they would naturally reuse.

Requested fix: Accept an optional WC_RNG* parameter in wc_curve25519_shared_secret_ex so callers can pass an existing RNG rather than constructing a temporary one per operation. A NULL parameter could fall back to the current behavior for backward compatibility.

Migrated from internal tracking (ZD-21738).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions