From 86b725884fdcd71ef3b67306116b6e7ce29ed4dc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 20:47:52 -0800 Subject: [PATCH 1/2] perf(quic): bump rind to 0.3 and hold DIT across each driver poll Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 32 +++++++++++++++------- Cargo.toml | 10 +++---- rs/moq-auth/src/crypto.rs | 9 ++++-- rs/moq-auth/src/generate.rs | 5 ++-- rs/moq-auth/src/key.rs | 4 +-- rs/moq-crypto/src/cpu.rs | 6 ++++ rs/moq-crypto/src/provider.rs | 7 ++++- rs/moq-tokio/src/quic/driver/connection.rs | 2 ++ rs/moq-uring/src/quic/driver/connection.rs | 2 ++ rs/moq-uring/src/quic/driver/endpoint.rs | 2 ++ 10 files changed, 56 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7aa7d9729c7..e8d14236647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3952,6 +3952,17 @@ dependencies = [ "hax-lib 0.4.2", ] +[[package]] +name = "libcrux-sha2" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86aa35d8fc9576a41df34af4d95d1f11186c1f65cd6c829329748915ea556d71" +dependencies = [ + "libcrux-hacl-rs", + "libcrux-macros", + "libcrux-traits", +] + [[package]] name = "libcrux-traits" version = "0.0.9" @@ -7514,9 +7525,9 @@ dependencies = [ [[package]] name = "rind" -version = "0.1.12" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422500e50252ad3bd319f359c54431441711a8fd55cb228973dde123ff8c2039" +checksum = "5b1b559e7ba7aa39bc4aa9b581dd2254919b3434d50669898bb8c8e7b154cfb8" dependencies = [ "cfg-if", "curve25519-dalek", @@ -7527,14 +7538,15 @@ dependencies = [ "libcrux-hacl-rs", "libcrux-macros", "libcrux-poly1305", + "libcrux-sha2", "libcrux-traits", ] [[package]] name = "rind-jsonwebtoken" -version = "0.1.2" +version = "11.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3dbbb3e3d229205e18f9a5b3ee418071a29eacdb61aec66a5f34eeffef8e55f" +checksum = "dd34e9d4695a1a34a4d8fc31d3db5acda9a24cfd2ca90ffbd36f7c62dc4bb7eb" dependencies = [ "jsonwebtoken", "pkcs1", @@ -7543,9 +7555,9 @@ dependencies = [ [[package]] name = "rind-object-store" -version = "0.1.2" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6733c2630ffae76432b1d1a9c4e43febf2a4959292e43c9a922978f11b550a" +checksum = "9150c3274a6f8789e0cb6a971cd22bae40698df54f596b9b663c18088ad144d5" dependencies = [ "object_store", "rind", @@ -7554,9 +7566,9 @@ dependencies = [ [[package]] name = "rind-rcgen" -version = "0.1.12" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0f7d386858c030aff879c224a0c3d59b02e7ff953ca96214825a3e77ecba76" +checksum = "8c29833453b6f7def587d905c234d65e9172045504b77300084614d5df23dfdf" dependencies = [ "rcgen", "rind", @@ -7566,9 +7578,9 @@ dependencies = [ [[package]] name = "rind-rustls" -version = "0.1.12" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e67845e30d1c9a194485cdcb585abf7dcc011a4413488d57634ec39d7e832f0" +checksum = "8f91c7ed15f653d52782f482dbea8d2ec350b49ee88a911660acf539e7cf6752" dependencies = [ "rind", "rustls", diff --git a/Cargo.toml b/Cargo.toml index 970cb4f8a12..5e74ab9d618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -214,11 +214,11 @@ rcgen = { version = "0.14", default-features = false } # default-features off so each consumer picks its own TLS backend and body # features; nothing here wants the default native-tls stack. reqwest = { version = "0.13", default-features = false } -rind = "0.1.12" -rind-jsonwebtoken = "0.1.2" -rind-object-store = "0.1.2" -rind-rcgen = "0.1.12" -rind-rustls = "0.1.12" +rind = "0.3.1" +rind-jsonwebtoken = "11.0.2" +rind-object-store = "0.14.2" +rind-rcgen = "0.14.2" +rind-rustls = "0.23.2" rustc-hash = "2.1.3" rustls-native-certs = "0.8.5" sd-notify = "0.5" diff --git a/rs/moq-auth/src/crypto.rs b/rs/moq-auth/src/crypto.rs index 5355debeb88..147bd24f4ec 100644 --- a/rs/moq-auth/src/crypto.rs +++ b/rs/moq-auth/src/crypto.rs @@ -4,8 +4,10 @@ /// rind panics on such a CPU instead, so every key runs this before its first operation. pub(crate) fn init() -> crate::Result<()> { moq_crypto::cpu::check()?; + let provider = rind_jsonwebtoken::default_provider() + .expect("rind-jsonwebtoken refuses only the CPUs rind::cpu::check refuses"); // An error means the process already picked a provider, which it is entitled to. - let _ = rind_jsonwebtoken::DEFAULT_PROVIDER.install_default(); + let _ = provider.install_default(); Ok(()) } @@ -32,7 +34,8 @@ mod tests { #[test] fn installs_rind_when_none_is_installed() { super::init().unwrap(); - let installed = rind_jsonwebtoken::DEFAULT_PROVIDER.install_default().unwrap_err(); - assert!(std::ptr::eq(installed, &rind_jsonwebtoken::DEFAULT_PROVIDER)); + let rind = rind_jsonwebtoken::default_provider().unwrap(); + let installed = rind.install_default().unwrap_err(); + assert!(std::ptr::eq(installed, rind)); } } diff --git a/rs/moq-auth/src/generate.rs b/rs/moq-auth/src/generate.rs index 72f9eb2007f..2c3b3f968de 100644 --- a/rs/moq-auth/src/generate.rs +++ b/rs/moq-auth/src/generate.rs @@ -1,7 +1,8 @@ use crate::{Algorithm, EllipticCurve, Error, Jwk, Key, KeyMaterial, RsaPublicKey}; use pkcs1::der::Decode as _; use pkcs8::der::Decode as _; -use rind::signature::{EcdsaKeyPair, EcdsaSigningAlgorithm, Ed25519KeyPair, RsaKeyPair, RsaKeySize, sign}; +use rind::rsa::KeySize; +use rind::signature::{EcdsaKeyPair, EcdsaSigningAlgorithm, Ed25519KeyPair, RsaKeyPair, sign}; /// Generate a key pair for the given algorithm, returning the private and public keys. pub fn generate(algorithm: Algorithm, id: Option) -> crate::Result { @@ -35,7 +36,7 @@ fn generate_hmac_key() -> crate::Result { // rind exports an RSA private key only as PKCS#8, so each JWK field is read back out of it. fn generate_rsa_key() -> crate::Result { - let pkcs8 = RsaKeyPair::generate(RsaKeySize::Rsa2048) + let pkcs8 = RsaKeyPair::generate(KeySize::Rsa2048) .map_err(Error::crypto)? .to_pkcs8(); let info = pkcs8::PrivateKeyInfoRef::from_der(pkcs8.as_ref()).map_err(Error::crypto)?; diff --git a/rs/moq-auth/src/key.rs b/rs/moq-auth/src/key.rs index 1c559e049c9..76905d8ee19 100644 --- a/rs/moq-auth/src/key.rs +++ b/rs/moq-auth/src/key.rs @@ -569,8 +569,8 @@ impl Key { // rind refuses a `d` whose public key is not this `x` and `y`. let point = [&[0x04][..], x.as_slice(), y.as_slice()].concat(); - let pair = EcdsaKeyPair::from_private_key_and_public_key(algorithm, d, &point) - .map_err(crate::Error::crypto)?; + let pair = + EcdsaKeyPair::from_scalar_and_public_key(algorithm, d, &point).map_err(crate::Error::crypto)?; EncodingKey::from_ec_der(pair.to_pkcs8().as_ref()) } KeyMaterial::OKP { diff --git a/rs/moq-crypto/src/cpu.rs b/rs/moq-crypto/src/cpu.rs index 98ba51451f9..e6fe19f8c9e 100644 --- a/rs/moq-crypto/src/cpu.rs +++ b/rs/moq-crypto/src/cpu.rs @@ -5,6 +5,12 @@ #[error("unsupported CPU: {0}")] pub struct UnsupportedCpu(pub(crate) rind::cpu::MissingFeature); +/// Holds data-independent timing on for this thread until dropped. +/// +/// rind otherwise turns DIT on and off around every call that handles a secret, which costs +/// about 50 ns a call on Apple silicon, so a transport holds one across each batch of packets. +pub use rind::cpu::Dit; + /// Refuse a CPU that rind cannot run on, naming the missing feature. /// /// Call this before using rind's primitives directly; the rustls provider checks it too. diff --git a/rs/moq-crypto/src/provider.rs b/rs/moq-crypto/src/provider.rs index 80bdbfe2849..3bc7734810c 100644 --- a/rs/moq-crypto/src/provider.rs +++ b/rs/moq-crypto/src/provider.rs @@ -18,7 +18,12 @@ pub fn provider() -> Result { // CPU features never change while the process runs, so the first answer is the answer. static PROVIDER: OnceLock> = OnceLock::new(); PROVIDER - .get_or_init(|| rind_rustls::default_provider().map(Arc::new).map_err(UnsupportedCpu)) + .get_or_init(|| { + crate::cpu::check()?; + let provider = + rind_rustls::default_provider().expect("rind-rustls refuses only the CPUs rind::cpu::check refuses"); + Ok(Arc::new(provider)) + }) .clone() } diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index 3138fa4b741..95205f3bbc1 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -174,6 +174,8 @@ impl Future for ConnectionDriver { let waiter = this.park.hold(cx); let conn = &mut *this.conn.state.lock(); let _guard = this.span.enter(); + // Every packet this poll opens or seals pays one DIT toggle rather than one per rind call. + let _dit = moq_crypto::cpu::Dit::hold(); if let Err(e) = conn.process_conn_events(cx) { conn.terminate(e); diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index 163570a8a28..8c890a9013b 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -705,6 +705,8 @@ impl Driver { // connection after this turn's checks still re-polls us. waiter.register(&mut state.driver); } + // Every packet this turn seals pays one DIT toggle rather than one per rind call. + let _dit = moq_crypto::cpu::Dit::hold(); loop { self.endpoint_events(); diff --git a/rs/moq-uring/src/quic/driver/endpoint.rs b/rs/moq-uring/src/quic/driver/endpoint.rs index 914d776b1af..5c68534decc 100644 --- a/rs/moq-uring/src/quic/driver/endpoint.rs +++ b/rs/moq-uring/src/quic/driver/endpoint.rs @@ -280,6 +280,8 @@ impl Inner { let mut buf = Vec::new(); let mut fed = Fed::default(); + // Every datagram in this receive opens under one DIT toggle rather than one per rind call. + let _dit = moq_crypto::cpu::Dit::hold(); // moq-quic takes each datagram as an owned `BytesMut`: copy the whole // completion out of the receive pool once and split it per datagram. From 2993b06911222a9442f299f678fd7a2c4e2d9305 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 10:08:12 -0800 Subject: [PATCH 2/2] fix(webrtc): migrate SRTP AES-CM to rind 0.3, keep rind's key wipe rind 0.3's AesCtr takes the whole counter block and a fixed counter width; SRTP AES-CM counts over the IV's low 16 bits. rind 0.3 also makes drop-time key wiping opt-in, so enable `wipe` to keep what 0.1.12 did. Co-Authored-By: Claude Opus 5.5 --- Cargo.toml | 2 +- rs/moq-webrtc/src/vendor/str0m_rind/srtp.rs | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 500d63baa2e..f0773fa280a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,7 +212,7 @@ rcgen = { version = "0.14", default-features = false } # default-features off so each consumer picks its own TLS backend and body # features; nothing here wants the default native-tls stack. reqwest = { version = "0.13", default-features = false } -rind = "0.3.1" +rind = { version = "0.3.1", features = ["wipe"] } rind-jsonwebtoken = "11.0.2" rind-object-store = "0.14.2" rind-rcgen = "0.14.2" diff --git a/rs/moq-webrtc/src/vendor/str0m_rind/srtp.rs b/rs/moq-webrtc/src/vendor/str0m_rind/srtp.rs index ef74709c625..f381537ad08 100644 --- a/rs/moq-webrtc/src/vendor/str0m_rind/srtp.rs +++ b/rs/moq-webrtc/src/vendor/str0m_rind/srtp.rs @@ -56,7 +56,7 @@ fn ecb_round(algorithm: &'static cipher::Algorithm, key: &[u8], input: &[u8], ou impl SupportedAes128CmSha1_80 for RindSrtp { fn create_cipher(&self, key: [u8; 16], _encrypt: bool) -> Box { - Box::new(Cm(AesCtr::new(&cipher::AES_128, &key).unwrap())) + Box::new(Cm(AesCtr::new(&cipher::AES_128, &key, 16).unwrap())) } } @@ -88,13 +88,10 @@ impl Cm { .ok_or_else(|| CryptoError::Other("AES-CM output too short".into()))?; output.copy_from_slice(input); - // SRTP's 128-bit counter block splits into rind's 96-bit nonce and - // 32-bit counter. str0m's IVs leave the low 16 bits zero, so a packet - // never carries past the counter; one that would is refused. - let (nonce, counter) = iv.split_first_chunk::<12>().unwrap(); - let counter = u32::from_be_bytes(counter.try_into().unwrap()); + // SRTP AES-CM counts over the IV's low 16 bits, which str0m leaves + // zero, so rind refuses a packet past 2^16 blocks rather than wrap. self.0 - .apply_keystream(nonce, counter, output) + .apply_keystream(iv, output) .map_err(|e| CryptoError::Other(format!("AES-CM failed: {e:?}"))) } }