Skip to content

Check length when importing raw X25519 and Ed25519 keys#410

Merged
twiss merged 4 commits intow3c:mainfrom
hopafoot:patch/reject-x25519-import-wrong-raw-length
Jul 30, 2025
Merged

Check length when importing raw X25519 and Ed25519 keys#410
twiss merged 4 commits intow3c:mainfrom
hopafoot:patch/reject-x25519-import-wrong-raw-length

Conversation

@hopafoot
Copy link
Contributor

@hopafoot hopafoot commented Jul 24, 2025

Closes #409

Section 5 of RFC7748 specifies that X25519 private and public keys are 32 bytes/256 bits. The spec, however, does not explicitly reject raw keys of different lengths.
This behaviour is already being tested for by WPT and common implementations already throw a DataError in such cases.


Preview | Diff

@panva
Copy link
Member

panva commented Jul 24, 2025

Should ed25519 get the same treatment?

@hopafoot
Copy link
Contributor Author

Should ed25519 get the same treatment?

@panva, According to RFC8032, I think so. WPT tests also currently expect them to be rejected and common implementations seem to pass these tests. Would you prefer I add these changes here, or keep them separate?

@panva
Copy link
Member

panva commented Jul 24, 2025

might as well be done in this very PR

@hopafoot hopafoot changed the title Add step to reject raw x25519 keys that are not 256 bits Add step to reject raw x25519 and ed25519 keys that are not 256 bits Jul 24, 2025
@hopafoot
Copy link
Contributor Author

might as well be done in this very PR

done.

Copy link
Collaborator

@davidben davidben left a comment

Choose a reason for hiding this comment

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

The "length in bits" thing threw me off at first, but I see it's just byte length * 8 and not something cursed like "check that the high bit is set". :-)

@w3cbot
Copy link

w3cbot commented Jul 25, 2025

plehegar marked as non substantive for IPR from ash-nazg.

Copy link
Member

@twiss twiss left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Small nitpick below.

Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
@hopafoot
Copy link
Contributor Author

@twiss Thanks for the suggestion, committed! I did get a little too verbose.

Copy link
Member

@twiss twiss left a comment

Choose a reason for hiding this comment

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

👍 Thanks!

@twiss twiss changed the title Add step to reject raw x25519 and ed25519 keys that are not 256 bits Check length when importing raw X25519 and Ed25519 keys Jul 30, 2025
Co-authored-by: Daniel Huigens <d.huigens@protonmail.com>
@twiss twiss force-pushed the patch/reject-x25519-import-wrong-raw-length branch from 60bb8fd to 7173306 Compare July 30, 2025 14:39
@twiss twiss merged commit 432f094 into w3c:main Jul 30, 2025
1 check passed
github-actions bot added a commit that referenced this pull request Jul 30, 2025
SHA: 432f094
Reason: push, by twiss

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Frosne
Copy link
Member

Frosne commented Jul 31, 2025

Ok, I'm a bit lost now.
Some time ago I've implemented github.com/WICG/webcrypto-secure-curves/pull/35.

This patch does the same thing?

@twiss
Copy link
Member

twiss commented Jul 31, 2025

Yes; due to me being slow in merging WICG/webcrypto-secure-curves#35 (and updating this repo) we got an equivalent PR in both repos (apologies for the duplicate work!)

The root issue is that Curve25519 is still in both repos. Perhaps we can remove Curve25519 from WICG/webcrypto-secure-curves to prevent this from happening (or more ideally, also merge Curve448 into this repo, and just archive WICG/webcrypto-secure-curves..)

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.

Importing a raw X25519 key with an incorrect number of bytes does not throw an throw an error

6 participants