Skip to content

[cryptotest] Add Ed25519 tests using ACVP test vectors #229

Merged
mkannwischer merged 4 commits intomasterfrom
mjk/ed25519-testvectors
Apr 9, 2026
Merged

[cryptotest] Add Ed25519 tests using ACVP test vectors #229
mkannwischer merged 4 commits intomasterfrom
mjk/ed25519-testvectors

Conversation

@mkannwischer
Copy link
Copy Markdown
Contributor

This PR adds ACVP-based Ed25519 tests. As of now the cryptolib only implements HashEd25519.
ACVP has testvectors for both pure Ed25519 and HashEd25519, while Wycheproof only has pure Ed25519 vectors.

The ACVP testvectors revealed two minor bugs regarding the context strings that the cryptolib could handle; those are fixed in separate commits.
See individual commit messages for the details.

@mkannwischer mkannwischer force-pushed the mjk/ed25519-testvectors branch from d8441e5 to 5f2f48b Compare March 27, 2026 09:33
@mkannwischer mkannwischer marked this pull request as ready for review March 27, 2026 10:36
@mkannwischer mkannwischer force-pushed the mjk/ed25519-testvectors branch from 5f2f48b to 580cdb3 Compare April 7, 2026 01:09
The context length check in set_context compared context_length
(in bytes) against kEd25519ContextWords (64 words), rejecting any
context longer than 64 bytes.  The correct limit is 255 bytes as
specified by RFC 8032.

Change kEd25519ContextBytes to 255 (was 256) and compare against it.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
If the context length is not a multiple of 32 bytes, the bytes up
to the next multiple of 32 must be initialized to prevent DMEM read
errors in ACC. set_context only wrote the exact context words,
causing occasional failures when signing with context strings
of size not divisible by 32.
This commit adds zero padding the write to the next multiple of
32 bytes.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
Extend the test to sign and verify with various context lengths.
This covers both context lengths larger than 64 bytes, and
context lengths not divisible by 32.
This acts as a regression tests for the two bugs fixed in
previous commits.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
@mkannwischer mkannwischer force-pushed the mjk/ed25519-testvectors branch from 580cdb3 to 5a1938f Compare April 8, 2026 10:20
Copy link
Copy Markdown
Collaborator

@jadephilipoom jadephilipoom left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Matthias!

Comment thread sw/device/lib/crypto/impl/ecc/ed25519.c
Copy link
Copy Markdown
Contributor

@pqcfox pqcfox left a comment

Choose a reason for hiding this comment

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

Looks excellent! Left a few small notes.

Comment thread sw/device/lib/crypto/impl/ecc/ed25519.c
Comment thread sw/device/lib/crypto/impl/ecc/ed25519.h Outdated
Comment thread sw/device/tests/crypto/ed25519_functest.c
Comment thread sw/host/cryptotest/testvectors/parsers/nist_acvp_eddsa_parser.py Outdated
Wire up ACVP EDDSA-SigVer and EDDSA-SigGen test vectors for
Ed25519ph (HashEdDSA). The parser pre-hashes messages with SHA-512
since the cryptolib only supports the pre-hashed mode.

Included:
  SigVer: 5 tests (15 skipped - pure Ed25519 and Ed448).
  SigGen: 42 tests (126 skipped - pure Ed25519 and Ed448).

Not included:
  KeyGen: 6 tests - cryptolib does not support keygen yet.
  KeyVer: 8 tests - cryptolib does not have a pk validation API.

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
@mkannwischer mkannwischer force-pushed the mjk/ed25519-testvectors branch from 5a1938f to 71f66ce Compare April 9, 2026 05:28
@mkannwischer mkannwischer merged commit 36e0968 into master Apr 9, 2026
28 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants