diff --git a/Cargo.lock b/Cargo.lock index 9207417..0862199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -274,7 +274,7 @@ dependencies = [ "json-codec", "quickcheck", "quickcheck_macros", - "rand", + "rand 0.9.2", ] [[package]] @@ -546,7 +546,7 @@ dependencies = [ "curve25519-dalek", "ed25519", "merlin", - "rand_core", + "rand_core 0.6.4", "serde", "sha2", "subtle", @@ -704,9 +704,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "wasip2", "wasm-bindgen", ] @@ -842,10 +854,11 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -926,7 +939,7 @@ checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d" dependencies = [ "byteorder", "keccak", - "rand_core", + "rand_core 0.6.4", "zeroize", ] @@ -1068,7 +1081,7 @@ dependencies = [ [[package]] name = "proteus" version = "1.0.3" -source = "git+https://github.com/wireapp//proteus?branch=otak/fix-1.0.3#f3cd17da5f788d243a17bf624be71794358724f8" +source = "git+https://github.com/wireapp//proteus?branch=otak%2Ffix-1.0.3#f3cd17da5f788d243a17bf624be71794358724f8" dependencies = [ "cbor-codec 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "hkdf 0.3.2", @@ -1097,7 +1110,7 @@ dependencies = [ "ed25519-dalek", "eyre", "generic-array", - "getrandom", + "getrandom 0.3.4", "hex", "hkdf 0.12.4", "hmac", @@ -1105,9 +1118,8 @@ dependencies = [ "proteus", "proteus-traits", "proteus-wasm", - "rand", + "rand 0.9.2", "rand_chacha", - "rand_core", "serde", "sha2", "subtle", @@ -1125,7 +1137,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger", "log", - "rand", + "rand 0.8.5", ] [[package]] @@ -1148,25 +1160,39 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.5", ] [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.5", ] [[package]] @@ -1175,7 +1201,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", ] [[package]] @@ -1243,6 +1278,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.18" @@ -1319,7 +1360,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -1482,28 +1523,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasm-bindgen" -version = "0.2.93" +name = "wasip2" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", + "wit-bindgen", ] [[package]] -name = "wasm-bindgen-backend" -version = "0.2.93" +name = "wasm-bindgen" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" dependencies = [ - "bumpalo", - "log", + "cfg-if", "once_cell", - "proc-macro2", - "quote", - "syn 2.0.74", + "rustversion", + "wasm-bindgen-macro", "wasm-bindgen-shared", ] @@ -1521,9 +1558,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1531,22 +1568,25 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn 2.0.74", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-bindgen-test" @@ -1763,6 +1803,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" + [[package]] name = "x25519-dalek" version = "2.0.1" @@ -1770,7 +1816,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" dependencies = [ "curve25519-dalek", - "rand_core", + "rand_core 0.6.4", "serde", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index ce65ff9..2156949 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,23 @@ [package] -name = "proteus-wasm" -version = "2.1.0" -authors = ["Wire Swiss GmbH "] -description = "Axolotl protocol implementation" -homepage = "https://github.com/wireapp/proteus" -repository = "https://github.com/wireapp/proteus.git" -license = "GPL-3.0" -edition = "2021" +name = "proteus-wasm" +version = "2.1.0" +authors = ["Wire Swiss GmbH "] +description = "Axolotl protocol implementation" +homepage = "https://github.com/wireapp/proteus" +repository = "https://github.com/wireapp/proteus.git" +license = "GPL-3.0" +edition = "2021" [workspace] -members = [ - "crates/proteus-traits", - "crates/cbor-codec", -] +members = ["crates/proteus-traits", "crates/cbor-codec"] + +[workspace.lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(wasm_bindgen_unstable_test_coverage)', +] } + +[lints] +workspace = true [patch.'https://github.com/wireapp/proteus'.proteus] package = "proteus" @@ -26,17 +31,22 @@ default = [] cryptobox-identity = [] public-key-batch-verification = ["ed25519-dalek/batch"] hazmat = [] -serde = ["dep:serde", "ed25519-dalek/serde", "zeroize/serde", "generic-array/serde", "hex/serde"] +serde = [ + "dep:serde", + "ed25519-dalek/serde", + "zeroize/serde", + "generic-array/serde", + "hex/serde", +] [dependencies] thiserror = "1.0" proteus-traits = { version = "2.1", path = "crates/proteus-traits" } # CSPRNG -rand = { version = "0.8", features = ["getrandom"] } -rand_core = "0.6" -getrandom = { version = "0.2", features = ["js"] } -rand_chacha = "0.3" +rand = { version = "0.9", features = ["os_rng"] } +getrandom = { version = "0.3.4", features = ["wasm_js"] } +rand_chacha = "0.9" # Crypto zeroize = { version = "1.6", features = ["zeroize_derive"] } @@ -46,8 +56,15 @@ hmac = "0.12" chacha20 = "0.9" generic-array = "0.14" ed25519-dalek = { version = "2.0.0-rc.3", features = ["zeroize", "fast"] } -x25519-dalek = { version = "2.0.0-rc.3", features = ["precomputed-tables", "static_secrets", "zeroize"] } -curve25519-dalek = { version = "4.0.0-rc.3", features = ["precomputed-tables", "zeroize"] } +x25519-dalek = { version = "2.0.0-rc.3", features = [ + "precomputed-tables", + "static_secrets", + "zeroize", +] } +curve25519-dalek = { version = "4.0.0-rc.3", features = [ + "precomputed-tables", + "zeroize", +] } subtle = "2.5" # Utils @@ -59,7 +76,11 @@ serde = { version = "1", features = ["derive"], optional = true } [dev-dependencies] criterion = { version = "0.5", default-features = false } pretty_assertions = "1.3" -proteus-wasm = { path = ".", package = "proteus-wasm", features = ["hazmat", "cryptobox-identity", "public-key-batch-verification"] } +proteus-wasm = { path = ".", package = "proteus-wasm", features = [ + "hazmat", + "cryptobox-identity", + "public-key-batch-verification", +] } wasm-bindgen-test = "0.3" ciborium = "0.2" async-std = { version = "1.12", features = ["attributes"] } diff --git a/benches/benchmarks.rs b/benches/benchmarks.rs index 2b5a802..484ada5 100644 --- a/benches/benchmarks.rs +++ b/benches/benchmarks.rs @@ -73,8 +73,8 @@ fn bench_verify_batched(c: &mut Criterion) { let mut inputs = std::collections::HashMap::new(); use rand::Rng as _; for _ in 0..ITEMS { - let message: String = rand::thread_rng() - .sample_iter(&rand::distributions::Alphanumeric) + let message: String = rand::rng() + .sample_iter(&rand::distr::Alphanumeric) .take(30) .map(char::from) .collect(); diff --git a/crates/cbor-codec/Cargo.toml b/crates/cbor-codec/Cargo.toml index beb5835..85f22b0 100644 --- a/crates/cbor-codec/Cargo.toml +++ b/crates/cbor-codec/Cargo.toml @@ -16,7 +16,7 @@ name = "cbor" [dependencies] byteorder = "1.4" half = "2.1" -rand = "0.8" +rand = "0.9" [dependencies.quickcheck] version = "1.0" @@ -26,6 +26,6 @@ optional = true json-codec = ">= 0.3" quickcheck = "1.0" quickcheck_macros = "1.0" -rand = "0.8" +rand = "0.9" hex = "0.4" base64 = "0.21" diff --git a/crates/cbor-codec/src/decoder.rs b/crates/cbor-codec/src/decoder.rs index 96730b7..499b4c4 100644 --- a/crates/cbor-codec/src/decoder.rs +++ b/crates/cbor-codec/src/decoder.rs @@ -15,10 +15,10 @@ //! The module is structured as follows: //! //! 1. `Kernel` contains the basic decoding functionality, capable of -//! decoding simple unstructured types. +//! decoding simple unstructured types. //! 2. `Decoder` directly decodes into native Rust types. //! 3. `GenericDecoder` handles arbitrary CBOR items and decodes them -//! into an `Value` AST. +//! into an `Value` AST. //! //! # Example 1: Direct decoding //! @@ -773,7 +773,7 @@ impl Decoder { } /// Decode an indefinite byte string. - pub fn bytes_iter(&mut self) -> DecodeResult> { + pub fn bytes_iter(&mut self) -> DecodeResult> { match self.typeinfo()? { (Type::Bytes, 31) => Ok(BytesIter { decoder: self }), ti => unexpected_type(&ti), @@ -797,7 +797,7 @@ impl Decoder { } /// Decode an indefinite string. - pub fn text_iter(&mut self) -> DecodeResult> { + pub fn text_iter(&mut self) -> DecodeResult> { match self.typeinfo()? { (Type::Text, 31) => Ok(TextIter { decoder: self }), ti => unexpected_type(&ti), diff --git a/crates/cbor-codec/src/skip.rs b/crates/cbor-codec/src/skip.rs index b42a93b..e2917c2 100644 --- a/crates/cbor-codec/src/skip.rs +++ b/crates/cbor-codec/src/skip.rs @@ -5,7 +5,7 @@ //! `Skip` trait to allow efficient skipping of consecutive bytes. -use std::io::{Error, ErrorKind, Result, Seek, SeekFrom}; +use std::io::{Error, Result, Seek, SeekFrom}; /// Type which supports skipping a number of bytes. /// @@ -20,7 +20,7 @@ impl Skip for A { /// `n` must be in range `[0, i64::MAX]`. fn skip(&mut self, n: u64) -> Result<()> { if n > i64::MAX as u64 { - return Err(Error::new(ErrorKind::Other, "n too large")); + return Err(Error::other("n too large")); } self.seek(SeekFrom::Current(n as i64)).and(Ok(())) } diff --git a/crates/cbor-codec/src/slice.rs b/crates/cbor-codec/src/slice.rs index 21a54d3..d5e9d4f 100644 --- a/crates/cbor-codec/src/slice.rs +++ b/crates/cbor-codec/src/slice.rs @@ -25,7 +25,7 @@ impl ReadSlice for Cursor> { } } -impl<'r> ReadSlice for Cursor<&'r [u8]> { +impl ReadSlice for Cursor<&[u8]> { fn read_slice(&mut self, n: usize) -> Result<&[u8], ReadSliceError> { let start = self.position() as usize; if self.get_ref().len() - start < n { diff --git a/src/internal/keys.rs b/src/internal/keys.rs index 55b9ad0..5ddb876 100644 --- a/src/internal/keys.rs +++ b/src/internal/keys.rs @@ -94,7 +94,7 @@ impl IdentityKeyPair { } #[must_use] - pub fn new_with_rng(csprng: &mut dyn rand_core::CryptoRngCore) -> IdentityKeyPair { + pub fn new_with_rng(csprng: &mut dyn rand::CryptoRng) -> IdentityKeyPair { Self::from_keypair(KeyPair::new_with_rng(csprng)) } @@ -225,7 +225,7 @@ impl PreKey { #[must_use] pub fn gen_prekeys(start: PreKeyId, size: u16) -> Vec { (1..) - .map(|i| ((u32::from(start.value()) + i) % u32::from(MAX_PREKEY_ID.value()))) + .map(|i| (u32::from(start.value()) + i) % u32::from(MAX_PREKEY_ID.value())) .map(|i| PreKey::new(PreKeyId::new(i as u16))) .take(size as usize) .collect() @@ -400,14 +400,14 @@ impl KeyPair { let mut rng = if let Some(seed) = seed.take() { rand_chacha::ChaCha20Rng::from_seed(*seed) } else { - rand_chacha::ChaCha20Rng::from_entropy() + rand_chacha::ChaCha20Rng::from_os_rng() }; KeyPair::new_with_rng(&mut rng) } #[must_use] - pub fn new_with_rng(csprng: &mut dyn rand_core::CryptoRngCore) -> KeyPair { + pub fn new_with_rng(csprng: &mut dyn rand::CryptoRng) -> KeyPair { let mut seed = zeroize::Zeroizing::new(ed25519_dalek::SecretKey::default()); csprng.fill_bytes(&mut *seed); @@ -692,7 +692,7 @@ impl PublicKey { pub fn rand_bytes(size: usize) -> Vec { let mut buf = Vec::with_capacity(size); use rand::{RngCore as _, SeedableRng as _}; - let mut rng = rand_chacha::ChaCha12Rng::from_entropy(); + let mut rng = rand_chacha::ChaCha12Rng::from_os_rng(); rng.fill_bytes(&mut buf); buf } diff --git a/src/internal/message.rs b/src/internal/message.rs index 9a5352b..9f47eac 100644 --- a/src/internal/message.rs +++ b/src/internal/message.rs @@ -85,7 +85,7 @@ impl SessionTag { pub fn new() -> SessionTag { let mut bytes = [0; 16]; use rand::{RngCore as _, SeedableRng as _}; - let mut rng = rand_chacha::ChaCha12Rng::from_entropy(); + let mut rng = rand_chacha::ChaCha12Rng::from_os_rng(); rng.fill_bytes(&mut bytes); SessionTag(bytes) } @@ -350,7 +350,7 @@ impl<'r> Envelope<'r> { } #[must_use] - pub fn message(&self) -> &Message { + pub fn message(&self) -> &Message<'_> { &self.message } diff --git a/src/internal/session.rs b/src/internal/session.rs index 1cf78f8..340a2dc 100644 --- a/src/internal/session.rs +++ b/src/internal/session.rs @@ -216,7 +216,7 @@ impl RecvChain { let too_old = self .message_keys .front() - .map_or(false, |k| k.counter > mesg.counter); + .is_some_and(|k| k.counter > mesg.counter); if too_old { return Err(SessionError::OutdatedMessage); @@ -516,7 +516,7 @@ impl> Session { &mut self.session_states } - pub fn encrypt(&mut self, plain: &[u8]) -> EncodeResult { + pub fn encrypt(&mut self, plain: &[u8]) -> EncodeResult> { let state = self .session_states .get_mut(&self.session_tag) @@ -605,9 +605,7 @@ impl> Session { alice_ident: &m.identity_key, alice_base: &m.base_key, }) - .map(Some) - .map_err(Into::into) - } else { + .map(Some)} else { Ok(None) } } @@ -889,7 +887,7 @@ impl SessionState { pending: &'r Option<(PreKeyId, PublicKey)>, tag: SessionTag, plain: &[u8], - ) -> EncodeResult { + ) -> EncodeResult> { let msgkeys = self.send_chain.chain_key.message_keys()?; let cmessage = CipherMessage { @@ -1429,7 +1427,7 @@ mod tests { .len() ); - for m in &vec![hello1, hello2, hello3, hello4, hello5] { + for m in &[hello1, hello2, hello3, hello4, hello5] { assert_eq!( Some(SessionError::DuplicateMessage), alice.decrypt(&mut alice_store, m).await.err()