Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Curve25519 Public Key Handling #959

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

exceptionfactory
Copy link
Contributor

This pull request improves public key handling for Curve25519 key agreement when running on Java 11 without the Bouncy Castle Security Provider registered.

The Bouncy Castle Security Provider supports X25519 and returns the encoded public key with a length of 44. Java 17 and 21 also return encoded public keys of the same length. The Java 11 implementation of X25519 returns the encoded public key with a length of 46, where the DER header contains 14 bytes instead of 12. This results in exceptions at runtime as described in #957.

Adjusting the behavior of Curve25519DH to calculate the DER header and algorithm identifier based on the length of the encoded public key provides a solution that works across Java versions, with or without the Bouncy Castle Provider.

Changes include unit test improvements to exercise the Curve25519DH methods with and without the Bouncy Castle Provider.

- Modified Curve25519 negotiation to determine algorithm identifier length based on PublicKey.getEncoded() length instead of hard-coded value of 44
- Runtime length determination avoids differences in X25519 implementations on Java 11
@hierynomus hierynomus merged commit f4f8071 into hierynomus:master Sep 13, 2024
4 checks passed
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.

2 participants