Expand description
Provider-neutral cryptography for the webrtc-rs RTC stack.
The open traits in this crate allow applications to supply cryptography and randomness without registering global state. Built-in providers are selected with additive Cargo features.
Key material: every struct holding secret key material derives Zeroize and
ZeroizeOnDrop, or holds each secret in SecretVec; secret keys are drawn with
RTCRandom::fill_secret; on_erased_stack runs key set-up and overwrites the stack it
ran on, and scrub_stack is the overwrite by itself. The RustCrypto primitives the
built-in providers use (aes, ctr, and the hmac / sha1 of the ring provider’s
HMAC-SHA1) erase their key schedules and hash states when dropped, and their keyed objects
are used in place: an AES-CTR keystream runs over a reference to the boxed schedule, an
HMAC-SHA1 is computed in the boxed keyed object. ring’s own key objects (AEAD,
header-protection and HMAC keys) do not erase themselves, so the ring provider keeps each in
an allocation of its own and overwrites it after the drop (docs/key-erasure.md).
Modules§
- conformance
- Reusable conformance assertions for built-in and application-provided crypto providers.
- providers
- rfc6979
- Deterministic ECDSA (RFC 6979) for a certificate’s signing key.
Structs§
- Public
Key - Borrowed public-key bytes with an explicit encoding.
- Secret
Vec - An owned byte vector that zeroizes its allocation when dropped.
Enums§
- Aead
Algorithm - Authenticated-encryption algorithms.
- Block
Cipher Algorithm - Single-block encryption algorithms.
- CbcAlgorithm
- CBC algorithms.
- Crypto
Algorithm - A provider capability identifier.
- Crypto
Error - A provider-neutral cryptographic failure.
- Hash
Algorithm - Algorithms accepted by
crate::RTCCrypto::hash. - Header
Mask Algorithm - The ciphers a record-number (header-protection) mask is made with: the block cipher or stream cipher underneath an AEAD, keyed separately (RFC 9147 section 4.2.3; the same construction as QUIC header protection, RFC 9001 section 5.4).
- Hmac
Algorithm - Algorithms accepted by the HMAC operations.
- KeyExchange
Algorithm - Ephemeral key-agreement algorithms.
- Public
KeyEncoding - The encoding of public-key bytes.
- Signature
Scheme - Signature schemes currently used by DTLS.
- Stream
Cipher Algorithm - Stream-cipher algorithms.
Constants§
- HEADER_
MASK_ LEN - The length of the mask a
HeaderMaskreturns. - HEADER_
MASK_ SAMPLE_ LEN - The length of the ciphertext sample a
HeaderMaskis computed from.
Traits§
- Active
KeyExchange - Provider-owned one-shot ephemeral key exchange.
- Aead
Cipher - A keyed authenticated cipher with detached tags.
- CbcCipher
- A keyed CBC block cipher with a reusable expanded key.
- Header
Mask - A keyed generator of record-number masks.
- Mac
- A keyed message authentication code with a reusable key schedule.
- RTCCrypto
- Provider-neutral cryptographic operations.
- RTCCrypto
Provider - A bundle of cryptographic operations and cryptographically secure randomness.
- RTCRandom
- A cryptographically secure random byte generator.
- Signing
Key - A provider-owned signing key, including external or non-exportable keys.
- Stream
Cipher - A keyed stream cipher with a reusable expanded key.
Functions§
- constant_
time_ eq - Compares equal-length byte strings without data-dependent early exit.
- default_
provider - Constructs the built-in default provider.
- hkdf_
expand HKDF-Expand(PRK, info, L)(RFC 5869 section 2.3),infogiven in pieces.- hkdf_
expand_ label HKDF-Expand-Label(Secret, Label, Context, Length)(RFC 8446 section 7.1): HKDF-Expand with theHkdfLabelstructure as info.prefixis what the label is prefixed with on the wire:"tls13 "for TLS 1.3 and"dtls13"for DTLS 1.3 (RFC 9147 section 5.9).- hkdf_
extract HKDF-Extract(salt, IKM)(RFC 5869 section 2.2): the pseudorandom key, one digest long.- on_
erased_ stack - Runs
workand overwrites the stack it ran on. - record_
stack_ erasure - Whether the stack overwrite after each record of
set_record_stack_erasureis on. - rsa_
pkcs1_ hash - The hash an RSASSA-PKCS1-v1_5 scheme signs with;
Nonefor any other scheme. - scrub_
stack - Overwrites the stack below the caller’s frame (32 KiB of it in an optimised build, 128 KiB in an unoptimised one).
- set_
record_ stack_ erasure - Turns on or off, for the whole process, the stack overwrite after each record operation of
the paths that leave key copies in dead stack frames of code the crate cannot change: the
AWS-LC provider’s AEAD (its AES-GCM leaves a GHASH table entry) and HMAC (each MAC is
computed on a copy of the keyed context, HMAC-SHA1 for SRTP and the DTLS AES-CBC suites);
the ring provider’s ChaCha20-Poly1305 (the key is copied to the stack per record); and
AES-CCM (RustCrypto’s
aesunderccm, which left round keys with compilers older than rustc 1.99.1 in an optimised build). Each such call then runs in a frame of its own and the stack below it is overwritten afterwards, as deep as that path was measured to use (record_depth: a few KiB optimised; 128 KiB unoptimised), so no key is left in a dead stack frame (RFC 7714 section 13.1: “All keys MUST be properly erased when no longer needed”;rtci-srtp/tests/key_residue.rs,rtci-dtls/tests/key_residue.rs). On by default. - verify_
rsa_ pkcs1_ without_ digest_ parameters - Verifies an RSASSA-PKCS1-v1_5
signatureover the message whosedigest(made withrsa_pkcs1_hashofscheme) is given, for the DigestInfo encoding WITHOUT the NULL parameters (RFC 5246 section 4.7).public_keyis the DERRSAPublicKey. The form with NULL parameters is the provider’s (crate::RTCCrypto::verify_signature); this one accepts only the other.