Skip to content

feat: add Signature and KEM factory enums - #85

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

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

Conversation

@VedantMadane

Copy link
Copy Markdown

Summary

Implements Signature and KEM factories in bouncycastle-factory, addressing maintainer feedback on closed PR #84 / issue #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 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.

Fixes #68

Supersedes #84

Implement SignatureFactory and KEMFactory in bouncycastle-factory as
enums that encapsulate all supported ML-DSA / ML-KEM parameter sets,
following the existing Hash/MAC/RNG factory pattern.

- SignatureFactory / KEMFactory implement AlgorithmFactory (defaults,
  128/256-bit defaults, construction by algorithm name)
- Key enums wrap public/private keys with encode/from_bytes pass-through
- SignatureSigner / SignatureVerifierEngine wrap streaming engines
- Inherent methods mirror Signer/SignatureVerifier/KEMEncapsulator/
  KEMDecapsulator and dispatch to the underlying types

Const-generic sizes on the core traits prevent a single enum from
implementing those traits directly; the factory APIs pass through with
type-erased keys and Vec encodings instead.

Fixes bcgit#68

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@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

1 participant