Convert non-BC ML-KEM keys in the legacy KEM code path - #2466
Draft
WillChilds-Klein wants to merge 1 commit into
Draft
WillChilds-Klein wants to merge 1 commit into
WillChilds-Klein wants to merge 1 commit into
Conversation
KemUtil resolves the key objects and the KeyGenerator from the JCA separately, so a provider ahead of BC can decode a peer's ML-KEM public key while BC still serves the encapsulation. MLKEMKeyGeneratorSpi casts to BC's own key types, so that split fails every handshake with internal_error(80).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Written by Claude Opus 5 (Claude Code) on my behalf.
Description
KemUtillooks up the ML-KEM key objects and theKeyGeneratorfrom the JCA independently, so a provider ahead of BC can decode the peer's public key while BC still serves the encapsulation.MLKEMKeyGeneratorSpicasts toBCMLKEMPublicKey, so that split fails every handshake withinternal_error(80)and no chained cause on the wire.encapsulateanddecapsulatenow re-import a foreign key through theKeyGenerator's own provider.decodePublicKeyalready does the equivalent when theKeyFactoryis not BC's.SpiUtil.hasKEM()is true,javax.crypto.KEMaccepts a foreign key already.BouncyCastleProviderand the key not already implementingMLKEMPublicKey/MLKEMPrivateKey, so an all-BC classpath runs the same code as before.KemUtilcarry the fix, because the base copy is what runs when a repackaged jar leaves the multi-release overlay unreachable andSpiUtil.hasKEM()reports false on a KEM-capable JDK.Testing / verification
X25519MLKEM768,MLKEM768andMLKEM1024. Each aborts withinternal_error(80)before this change and completes after it.versions/17SpiUtiloverlay next to a current bctls, and a fully flattened classpath where the baseKemUtilruns.decapsulateas well, since the client generates its ephemeral keypair through the foreign provider and then extracts with BC.tlstests behind a stub provider if you would like it in the suite.