diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..0e465b2 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""] diff --git a/Cargo.toml b/Cargo.toml index 0834c44..345cf1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,21 +28,20 @@ winapi = { version = "0.3", features = ["memoryapi", "sysinfoapi"] } cfg-if = "1" clear_on_drop = "0.2" derivative = "2.1" -ed25519-dalek = { version = "2.1.1", default-features = false, features = [ - "std", +ed25519-dalek = { version = "3.0.0-pre.1", default-features = false, features = [ "rand_core", "fast", ] } # Explicit dependency so we can pass the wasm-bindgen flag to it -getrandom = { version = "0.2", optional = true } -gridiron = "0.10" +getrandom = { version = "0.3", optional = true } +gridiron = "0.11" hex = "0.4" lazy_static = "1.4" log = "0.4" num-traits = "0.2" quick-error = "2" -rand = "0.8" -rand_chacha = "0.3" +rand = "0.9" +rand_chacha = "0.9" sha2 = "0.10" [dev-dependencies] @@ -64,7 +63,7 @@ debug = false lto = true [features] -wasm = ["clear_on_drop/no_cc", "getrandom/js"] +wasm = ["clear_on_drop/no_cc", "getrandom/wasm_js"] #Can be used to disable the automatic mlock detection for architectures. disable_memlock = [] diff --git a/flake.lock b/flake.lock index b7259d2..5a95c98 100644 --- a/flake.lock +++ b/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1740367490, - "narHash": "sha256-WGaHVAjcrv+Cun7zPlI41SerRtfknGQap281+AakSAw=", + "lastModified": 1760038930, + "narHash": "sha256-Oncbh0UmHjSlxO7ErQDM3KM0A5/Znfofj2BSzlHLeVw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0196c0175e9191c474c26ab5548db27ef5d34b05", + "rev": "0b4defa2584313f3b781240b29d61f6f9f7e0df3", "type": "github" }, "original": { @@ -36,11 +36,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1736320768, - "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "type": "github" }, "original": { @@ -62,11 +62,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1740536993, - "narHash": "sha256-3YI+1ONZ28chM19Hep9Z+TSyiybYf/1VC/gwImVZKUw=", + "lastModified": 1760063676, + "narHash": "sha256-s5Fjh43skH2L+avOGioLmEHoYZffDbg3abV5h0gjeew=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "9f05c0655de9dc2c7b60b689447c48abb9190bf8", + "rev": "897deed0923cc5a1d560c5176abe0d172ec9716d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 3d780ac..a69d832 100644 --- a/flake.nix +++ b/flake.nix @@ -7,21 +7,38 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + rust-overlay, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; - rusttoolchain = - pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - in rec { + rusttoolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustWithWasm = rusttoolchain.override { + targets = [ "wasm32-unknown-unknown" ]; + }; + in + rec { # nix develop devShell = pkgs.mkShell { - buildInputs = with pkgs; - [ rusttoolchain pkg-config ] - ++ pkgs.lib.optionals pkgs.stdenv.isDarwin - [ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ]; + buildInputs = + with pkgs; + [ + rusttoolchain + # If you want to do rust wasm builds, comment out rust toolchain and uncomment this rustWithWasm + # rustWithWasm + pkg-config + libiconv + ]; }; - }); + } + ); } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index c2324b9..9d5d227 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,4 @@ [toolchain] profile = "default" channel = "1.85.0" +components = ["rust-src", "rust-analyzer"] diff --git a/src/api.rs b/src/api.rs index 54d8621..7de7e6f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -24,9 +24,8 @@ use derivative::Derivative; use gridiron::fp_256::Fp256; use gridiron::fp_256::Monty as Monty256; use rand; -use rand::SeedableRng; -use rand::rngs::adapter::ReseedingRng; -use rand_chacha; +use rand::rngs::ReseedingRng; +use rand_chacha::ChaCha20Core; use std; use std::fmt; @@ -48,11 +47,10 @@ impl Recrypt> { pub fn new() -> Recrypt> { // 1 MB const BYTES_BEFORE_RESEEDING: u64 = 1024 * 1024; - Recrypt::new_with_rand(ReseedingRng::new( - rand_chacha::ChaChaCore::from_entropy(), - BYTES_BEFORE_RESEEDING, - rand::rngs::OsRng, - )) + Recrypt::new_with_rand( + ReseedingRng::::new(BYTES_BEFORE_RESEEDING, rand::rngs::OsRng) + .expect("Calling OsRng failed to seed Rng."), + ) } } diff --git a/src/api_480.rs b/src/api_480.rs index 7d23cd4..457d9e7 100644 --- a/src/api_480.rs +++ b/src/api_480.rs @@ -24,8 +24,8 @@ use derivative::Derivative; use gridiron::fp_480::Fp480; use gridiron::fp_480::Monty as Monty480; use rand; -use rand::SeedableRng; -use rand::rngs::adapter::ReseedingRng; +use rand::rngs::ReseedingRng; +use rand_chacha::ChaCha20Core; use std; use std::fmt; /// Recrypt public API - 480-bit @@ -47,11 +47,10 @@ impl Recrypt480> { pub fn new() -> Recrypt480> { // 2 MB const BYTES_BEFORE_RESEEDING: u64 = 2 * 1024 * 1024; - Recrypt480::new_with_rand(ReseedingRng::new( - rand_chacha::ChaChaCore::from_entropy(), - BYTES_BEFORE_RESEEDING, - rand::rngs::OsRng, - )) + Recrypt480::new_with_rand( + ReseedingRng::::new(BYTES_BEFORE_RESEEDING, rand::rngs::OsRng) + .expect("Calling OsRng failed to seed Rng."), + ) } } diff --git a/src/api_common.rs b/src/api_common.rs index 6c539ce..82f9fb9 100644 --- a/src/api_common.rs +++ b/src/api_common.rs @@ -1,7 +1,6 @@ use crate::internal; use quick_error::quick_error; -use rand::rngs::OsRng; -use rand::rngs::adapter::ReseedingRng; +use rand::rngs::{OsRng, ReseedingRng}; quick_error! { /// Errors generated by the API diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 6d6cde9..89b8001 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -1133,7 +1133,7 @@ where /// }; // lock released here /// ``` /// -pub(crate) fn take_lock(m: &Mutex) -> MutexGuard { +pub(crate) fn take_lock(m: &Mutex) -> MutexGuard<'_, T> { m.lock().unwrap_or_else(|e| { let error = format!("Error when acquiring lock: {}", e); error!("{}", error); diff --git a/src/internal/rand_bytes.rs b/src/internal/rand_bytes.rs index ca676bb..2a1836b 100644 --- a/src/internal/rand_bytes.rs +++ b/src/internal/rand_bytes.rs @@ -19,7 +19,7 @@ pub struct RandomBytes { impl Default for RandomBytes { fn default() -> Self { - RandomBytes::new(rand_chacha::ChaChaRng::from_entropy()) + RandomBytes::new(rand_chacha::ChaChaRng::from_os_rng()) } } diff --git a/tests/concurrency.rs b/tests/concurrency.rs index 7250b0c..092cf7d 100644 --- a/tests/concurrency.rs +++ b/tests/concurrency.rs @@ -5,9 +5,7 @@ use std::sync::Arc; use std::thread; #[test] fn generate_plaintexts() { - let recrypt = Arc::new(Recrypt::new_with_rand( - rand_chacha::ChaChaRng::from_entropy(), - )); + let recrypt = Arc::new(Recrypt::new_with_rand(rand_chacha::ChaChaRng::from_os_rng())); let mut threads = vec![]; for _i in 0..10 {