Skip to main content

Crate rtci_crypto

Crate rtci_crypto 

Source
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§

PublicKey
Borrowed public-key bytes with an explicit encoding.
SecretVec
An owned byte vector that zeroizes its allocation when dropped.

Enums§

AeadAlgorithm
Authenticated-encryption algorithms.
BlockCipherAlgorithm
Single-block encryption algorithms.
CbcAlgorithm
CBC algorithms.
CryptoAlgorithm
A provider capability identifier.
CryptoError
A provider-neutral cryptographic failure.
HashAlgorithm
Algorithms accepted by crate::RTCCrypto::hash.
HeaderMaskAlgorithm
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).
HmacAlgorithm
Algorithms accepted by the HMAC operations.
KeyExchangeAlgorithm
Ephemeral key-agreement algorithms.
PublicKeyEncoding
The encoding of public-key bytes.
SignatureScheme
Signature schemes currently used by DTLS.
StreamCipherAlgorithm
Stream-cipher algorithms.

Constants§

HEADER_MASK_LEN
The length of the mask a HeaderMask returns.
HEADER_MASK_SAMPLE_LEN
The length of the ciphertext sample a HeaderMask is computed from.

Traits§

ActiveKeyExchange
Provider-owned one-shot ephemeral key exchange.
AeadCipher
A keyed authenticated cipher with detached tags.
CbcCipher
A keyed CBC block cipher with a reusable expanded key.
HeaderMask
A keyed generator of record-number masks.
Mac
A keyed message authentication code with a reusable key schedule.
RTCCrypto
Provider-neutral cryptographic operations.
RTCCryptoProvider
A bundle of cryptographic operations and cryptographically secure randomness.
RTCRandom
A cryptographically secure random byte generator.
SigningKey
A provider-owned signing key, including external or non-exportable keys.
StreamCipher
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), info given in pieces.
hkdf_expand_label
HKDF-Expand-Label(Secret, Label, Context, Length) (RFC 8446 section 7.1): HKDF-Expand with the HkdfLabel structure as info. prefix is 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 work and overwrites the stack it ran on.
record_stack_erasure
Whether the stack overwrite after each record of set_record_stack_erasure is on.
rsa_pkcs1_hash
The hash an RSASSA-PKCS1-v1_5 scheme signs with; None for 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 aes under ccm, 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 signature over the message whose digest (made with rsa_pkcs1_hash of scheme) is given, for the DigestInfo encoding WITHOUT the NULL parameters (RFC 5246 section 4.7). public_key is the DER RSAPublicKey. The form with NULL parameters is the provider’s (crate::RTCCrypto::verify_signature); this one accepts only the other.