Skip to content

Make KEM abstract methods protected to allow external subclassing - #2290

Open
jmcrawford45 wants to merge 3186 commits into
bcgit:mainfrom
jmcrawford45:open-kem-for-external-subclassing
Open

Make KEM abstract methods protected to allow external subclassing#2290
jmcrawford45 wants to merge 3186 commits into
bcgit:mainfrom
jmcrawford45:open-kem-for-external-subclassing

Conversation

@jmcrawford45

Copy link
Copy Markdown
Contributor

Package-private abstract methods on KEM prevent users from implementing custom KEMs (e.g. XWing) outside the org.bouncycastle.crypto.hpke package, requiring them to place subclasses inside the BC package as a workaround.

Promote all abstract methods on KEM from package-private to protected. Update DHKEM.getEncryptionSize() to match — it was the only remaining package-private override; all other DHKEM overrides were already public or protected.

This is a source-compatible change: existing subclasses (DHKEM) that override with broader visibility (public/protected) are unaffected.

peterdettman and others added 30 commits February 4, 2026 20:09
- including more kyber name cleanup
- remove Symmetric, make MLKemEngine immutable
- avoid overproducing implicit-rejection data
- reduce memory usage
- "Kyber" cleanup
- unify MLKEM mappings using SpiUtil
- restrict keys by parameter set where appropriate
- use with ML-KEM (ensures ".OID." aliases are registered)
- unify HQC mappings using SpiUtil
- restrict keys by parameter set where appropriate
- unify NTRU mappings using SpiUtil
- unify NTRUPrime mappings using SpiUtil
Sm2 key exchange

See merge request root/bc-java!125
- add test classes missing from AllTests list
- fix roundtrip test that was sensitive to platform line endings
- avoid building complex error strings before errors occur
- add length check in internalGenerateEncapsulated
dghgit and others added 27 commits April 14, 2026 20:11
- more iterations validation
- more convertToDefiniteLength variants
- destroy PBE SecretKey
moved Mayo OIDs to OQS values
Package-private abstract methods on KEM prevent users from implementing
custom KEMs (e.g. XWing) outside the org.bouncycastle.crypto.hpke package,
requiring them to place subclasses inside the BC package as a workaround.

Promote all abstract methods on KEM from package-private to protected.
Update DHKEM.getEncryptionSize() to match — it was the only remaining
package-private override; all other DHKEM overrides were already public
or protected.

This is a source-compatible change: existing subclasses (DHKEM) that
override with broader visibility (public/protected) are unaffected.
@dghgit dghgit self-assigned this May 12, 2026
@dghgit

dghgit commented May 17, 2026

Copy link
Copy Markdown
Contributor

I'm not sure if this is really a good idea, I think you may, understandably, be looking at the wrong class for the job - we've found a better way (I'll admit the term is always a bit relative...) of describing KEM's which also works with the JCE, including the new KEM API which has been backported to Java 17. Would you have a look at the XWing implementation in core/src/main/java/org/bouncycastle/pqc/crypto/xwing and let me know what you think?

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.

10 participants