Skip to main content

crypto_provider

Function crypto_provider 

pub fn crypto_provider() -> Arc<CryptoProvider> ⓘ
Expand description

Returns the rustls crypto provider for iroh’s and moq’s TLS.

A cargo feature picks the backend: crypto-ring, crypto-aws-lc-rs, the default, or crypto-rind. Features are additive, so more than one can be on in a build. The first of ring, aws-lc-rs and rind that is on wins, in that order, which is the order iroh’s own presets prefer, so crypto-rind takes effect only with default features off. rind is also what a build gets with none of them on, since moq compiles it in either way. The default moves to crypto-rind once rind-rustls releases per-path QUIC keys (kixel-ai/rind#1278).

The first call installs the backend as rustls’s process default. If the process installed a provider before, that one stays and is returned instead, so an application that installs its own provider first runs iroh-live on it. Every call returns the same Arc. Two installs happen without the application asking for them: moq code that runs first, such as a hand-built moq_tokio::client::Config, installs rind, and rustls’s ClientConfig::builder() installs ring when rustls has only its ring feature on, as through reqwest’s rustls-tls. The first call logs a warning when the provider it finds is not the selected backend.

iroh seals its QUIC tokens with the first TLS 1.3 suite under a 32-byte key, so the provider lists such a suite first: rind’s AES-256-GCM goes before its AES-128-GCM. When the provider installed first lists a suite with a shorter key first, as rind’s default does on CPUs with AES instructions, this returns a reordered copy instead of the process default, and moq keeps the process default.

MoqPreset, MinimalPreset and EndpointConfig hand it to iroh. moq’s QUIC, WebTransport and media relay configs read the process default when they are built, and moq installs rind there if nothing is installed yet. Call this before building a moq config by hand, so the selected backend is installed before moq installs its fallback. Relay links do so before they build a moq client.

§Panics

Panics if a QUIC suite of the provider cannot seal packets per path, which iroh’s multipath QUIC needs on every packet. rind-rustls 0.23.4 from crates.io cannot; the message names the [patch.crates-io] block that fixes it.

§Examples

An application that installs its own provider first runs on it:

let _ = rustls::crypto::ring::default_provider().install_default();
let provider = iroh_live_node::crypto_provider();
assert!(std::sync::Arc::ptr_eq(
    &provider,
    rustls::crypto::CryptoProvider::get_default().unwrap()
));