Skip to content

feat: add Signature and KEM factory enums - #84

Closed
VedantMadane wants to merge 1 commit into
bcgit:mainfrom
VedantMadane:fix/issue-68
Closed

feat: add Signature and KEM factory enums#84
VedantMadane wants to merge 1 commit into
bcgit:mainfrom
VedantMadane:fix/issue-68

Conversation

@VedantMadane

@VedantMadane VedantMadane commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Implements Signature and KEM factories in bouncycastle-factory, addressing maintainer feedback on #84 / #68.

The previous PR only added empty stub structs at the workspace root. This replaces that with full enum factories that follow the existing HashFactory / MACFactory / RNGFactory pattern.

Design

Core Signer / SignatureVerifier / KEMEncapsulator / KEMDecapsulator traits are parameterized by const-generic key and ciphertext/signature sizes. A single enum wrapping ML-DSA-44/65/87 (or ML-KEM-512/768/1024) cannot implement those traits with one fixed size set.

So this PR:

  1. SignatureFactory / KEMFactory enums — algorithm selectors implementing AlgorithmFactory (Default / Default128Bit / Default256Bit / new(name)).
  2. Key enums (SignaturePublicKey, SignaturePrivateKey, KEMPublicKey, KEMPrivateKey) that encapsulate all supported key objects with encode / from_bytes pass-through.
  3. Streaming engine enums (SignatureSigner, SignatureVerifierEngine) that encapsulate the underlying ML-DSA state machines after sign_init / verify_init.
  4. Inherent methods with the same shape as the core traits (keygen, sign, verify, sign_init/sign_update/sign_final, encaps, decaps, …) that match and pass through to the underlying types.

Defaults

Helper Signature KEM
default() ML-DSA-65 ML-KEM-768
default_128_bit() ML-DSA-44 ML-KEM-512
default_256_bit() ML-DSA-87 ML-KEM-1024

Tests

crypto/factory/tests/signature_kem_factory_tests.rs covers defaults, name lookup, full sign/verify and encaps/decaps round-trips for every parameter set, streaming sign/verify, and algorithm/key mismatch errors.

cargo test -p bouncycastle-factory

Fixes #68

- src\signature.rs
- src\kem.rs
- src\lib.rs

Fixes bcgit#68

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@ounsworth

Copy link
Copy Markdown
Contributor

Thank you for your contribution, but this is extremely incomplete. The Signature and KEM factories need to be enums that encapsulate all the supported objects, and those enums need to impl the relevant traits, passing them through to the underlying types. Please take a look at the other factory modules as examples.

I am going to close this PR, but I would welcome another PR from you that is more complete. :)

@ounsworth ounsworth closed this Aug 23, 2026
@VedantMadane VedantMadane changed the title fix: feat: add default Signature and KEM factory objects feat: add Signature and KEM factory enums Aug 24, 2026
@VedantMadane

Copy link
Copy Markdown
Author

Thanks for the clear feedback on the earlier incomplete draft — completely fair to close it.

I've force-pushed a full rewrite on this branch (happy to open a fresh PR if you prefer):

What changed vs the stubs

  • Factories now live in bouncycastle-factory (not the workspace root), alongside hash_factory / mac_factory / etc.
  • SignatureFactory and KEMFactory are enums over all supported parameter sets (ML-DSA-44/65/87 and ML-KEM-512/768/1024).
  • They implement AlgorithmFactory with the usual Default / Default128Bit / Default256Bit / new(name) construction.
  • Supporting enums encapsulate the keys and streaming engines, with methods that pass through to the underlying ML-DSA / ML-KEM types (same shape as Signer / SignatureVerifier / KEMEncapsulator / KEMDecapsulator).

Why not impl Signer / impl KEMEncapsulator on the factory enum directly?

Those traits take const-generic PK_LEN / SK_LEN / SIG_LEN / CT_LEN. One enum that holds all three parameter sets cannot pick a single const size, so the pass-through API is expressed as inherent methods + key/engine enums (documented in the module docs). Happy to adjust if you'd rather see a different erasure strategy.

Ready for another look whenever you have time — thanks again.

@VedantMadane

Copy link
Copy Markdown
Author

Follow-up: reopen was blocked after the force-push (GitHub 422), so the complete implementation is in #85 on the same branch fix/issue-68. Thanks again for the guidance.

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.

Fill in missing Factory objects

2 participants