Skip to content

testing/crypto: add ECDH test to dhm - #4089

Merged
GUIDINGLI merged 1 commit into
apache:masterfrom
ThePassionate:crypto-ecdh-test
Nov 20, 2026
Merged

GUIDINGLI merged 1 commit into
apache:masterfrom
ThePassionate:crypto-ecdh-test

Conversation

@ThePassionate

@ThePassionate ThePassionate commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a standalone ecdh test program for the ECDH key agreement commands of apache/nuttx#22054 (CRK_ECDH_GEN_PUBLIC / CRK_ECDH_COMPUTE_SHARED):

  • Fixed vectors: private keys dA/dB and public keys QA/QB generated with pure Python affine EC arithmetic, cross-checked bidirectionally against the python cryptography package; both directions must derive the same shared secret Z.
  • Ephemeral key pairs generated through the kernel commands must also agree in both directions.

The existing dhm program keeps the RFC 5114 modp DH test only (both programs build from the existing TESTING_CRYPTO_ECDH option, which previously produced only dhm). Also fixes test_dh_compute_key() swallowing errors (it returned 0 unconditionally) and adds setbuf(stdout, NULL).

Impact

  • Testing only.

Testing

Depends on apache/nuttx#22054. On sim:sim/crypto with that kernel PR:

nsh> dhm
test dh compute key ok
nsh> ecdh
test ecdh compute key ok

tools/checkpatch.sh -c -u -m -g <base>..HEAD (via the paired nuttx tree) passes.

@ThePassionate
ThePassionate force-pushed the crypto-ecdh-test branch 2 times, most recently from da5a60e to 2dbb0aa Compare November 19, 2026 13:38
Exercise the ECDH key agreement commands (CRK_ECDH_GEN_PUBLIC /
CRK_ECDH_COMPUTE_SHARED) as a standalone `ecdh` program:

* Fixed vectors: private keys dA/dB and public keys QA/QB generated
  with pure Python affine EC arithmetic, cross-checked bidirectionally
  against the python cryptography package; both directions must derive
  the same shared secret Z.
* Ephemeral key pairs generated through the kernel commands must also
  agree in both directions.

The dhm program keeps the RFC 5114 modp DH test only; both programs
are built from the existing TESTING_CRYPTO_ECDH option. Also fixes
test_dh_compute_key() swallowing errors (it returned 0 unconditionally)
and adds setbuf(stdout, NULL) to both programs.

Signed-off-by: makejian <makejian <makejian@xiaomi.com>
@GUIDINGLI
GUIDINGLI merged commit b8fd354 into apache:master Nov 20, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants