Skip to content

feat(tls,quic): add CryptoProvider injection seam (closes #6236)#6435

Open
v1p3r4llbl4ck-86 wants to merge 1 commit into
libp2p:masterfrom
v1p3r4llbl4ck-86:feat/inject-crypto-provider
Open

feat(tls,quic): add CryptoProvider injection seam (closes #6236)#6435
v1p3r4llbl4ck-86 wants to merge 1 commit into
libp2p:masterfrom
v1p3r4llbl4ck-86:feat/inject-crypto-provider

Conversation

@v1p3r4llbl4ck-86
Copy link
Copy Markdown

Summary

Lets consumers swap the default ring-based rustls::crypto::CryptoProvider for an alternative — notably rustls-post-quantum to enable the X25519MLKEM768 hybrid post-quantum key-exchange group (IANA codepoint 0x11EC, draft-ietf-tls-ecdhe-mlkem-04) on the libp2p TLS handshake — both the libp2p-tls TCP path and the libp2p-quic QUIC path.

Closes #6236.

API additions (all behaviour-preserving)

libp2p-tls:

  • make_client_config_with_provider(keypair, remote_peer_id, provider)
  • make_server_config_with_provider(keypair, provider)
  • Config::new_with_provider(identity, provider)
  • private default_libp2p_provider() helper that hoists the cipher-suite mutation previously duplicated at both make_*_config call sites

libp2p-quic:

  • Config::new_with_provider(keypair, provider)
  • private Self::new_inner(keypair, custom_provider) helper shared by Self::new and Self::new_with_provider

The existing make_client_config, make_server_config, Config::new (in both crates) become one-liners that delegate to the new _with_provider variants with None. A consumer that doesn't call the new APIs cannot tell the patch is in place.

Test plan

  • cargo build -p libp2p-tls -p libp2p-quic clean
  • cargo test -p libp2p-tls passes
  • Existing test matrix unchanged (no behaviour change for the upstream API)
  • Downstream verification: the same patch applied as a vendored fork in a production Rust blockchain project, with 4 integration tests asserting the patched configs offer X25519MLKEM768 in crypto_provider().kx_groups when given rustls_post_quantum::provider().clone(), and that classical X25519 stays present for back-compat

Why this shape

  • Threading Option<CryptoProvider> (rather than a builder/setter) keeps the public API surface minimal and matches the existing arity of make_*_config.
  • The default_libp2p_provider() helper de-duplicates the provider.cipher_suites = verifier::CIPHERSUITES.to_vec() mutation previously inline at both call sites — makes future provider swaps mechanically safe.
  • The QUIC patch piggybacks on the libp2p-tls patch via the same _with_provider helpers — no separate provider-injection logic in the QUIC layer.

Happy to split into per-crate commits or reshape the API (builder pattern instead of free functions, etc.) on review feedback.

Lets consumers swap the default `ring`-based `rustls::crypto::CryptoProvider`
for an alternative — notably `rustls-post-quantum` to enable the
X25519MLKEM768 hybrid post-quantum key-exchange group (IANA codepoint
0x11EC, draft-ietf-tls-ecdhe-mlkem-04) on the libp2p TLS handshake (both
the libp2p-tls TCP path and the libp2p-quic QUIC path).

API additions (all behaviour-preserving — existing call sites unchanged):

  libp2p-tls
    + make_client_config_with_provider(keypair, remote_peer_id, provider)
    + make_server_config_with_provider(keypair, provider)
    + Config::new_with_provider(identity, provider)
    + private default_libp2p_provider() helper that hoists the cipher-suite
      mutation previously duplicated at both make_*_config call sites

  libp2p-quic
    + Config::new_with_provider(keypair, provider)
    + private Self::new_inner(keypair, custom_provider) helper shared by
      Self::new and Self::new_with_provider

The existing `make_client_config`, `make_server_config`, `Config::new` (in
both crates) become one-liners that delegate to the new `_with_provider`
variants with `None`. A consumer that doesn't call the new APIs cannot
tell the patch is in place — `cargo test` against the upstream test
matrix passes unchanged.

Why this shape:
- Threading `Option<CryptoProvider>` (rather than a builder/setter) keeps
  the public API surface minimal and matches the existing arity of
  `make_*_config`.
- The `default_libp2p_provider()` helper de-duplicates the
  `provider.cipher_suites = verifier::CIPHERSUITES.to_vec()` mutation that
  used to appear inline at both call sites, which makes future provider
  swaps mechanically safe.
- The QUIC patch piggybacks on the libp2p-tls patch via the same
  `_with_provider` helpers — no separate provider-injection logic in the
  QUIC layer.

Closes libp2p#6236.
Copy link
Copy Markdown
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you not bypass the PR template and answer it?
thanks

@jxs jxs added the need/author-input Needs input from the original author label May 16, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 16, 2026

This pull request has merge conflicts. Could you please resolve them @v1p3r4llbl4ck-86? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need/author-input Needs input from the original author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post-Quantum Key Exchange

2 participants