Skip to content

Make KEM abstract methods protected to allow external subclassing#2290

Open
jmcrawford45 wants to merge 1 commit into
bcgit:mainfrom
jmcrawford45:open-kem-for-external-subclassing
Open

Make KEM abstract methods protected to allow external subclassing#2290
jmcrawford45 wants to merge 1 commit 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.

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
Copy link
Copy Markdown
Contributor

dghgit commented May 17, 2026

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 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.

2 participants