Improve Curve25519 Public Key Handling #959
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 of44
. Java 17 and 21 also return encoded public keys of the same length. The Java 11 implementation ofX25519
returns the encoded public key with a length of46
, 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.