Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 = []

Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 27 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
};

});
}
);
}
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[toolchain]
profile = "default"
channel = "1.85.0"
components = ["rust-src", "rust-analyzer"]
14 changes: 6 additions & 8 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -48,11 +47,10 @@ impl Recrypt<Sha256, Ed25519, RandomBytes<DefaultRng>> {
pub fn new() -> Recrypt<Sha256, Ed25519, RandomBytes<DefaultRng>> {
// 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::<ChaCha20Core, _>::new(BYTES_BEFORE_RESEEDING, rand::rngs::OsRng)
.expect("Calling OsRng failed to seed Rng."),
)
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/api_480.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,11 +47,10 @@ impl Recrypt480<Sha256, Ed25519, RandomBytes<DefaultRng>> {
pub fn new() -> Recrypt480<Sha256, Ed25519, RandomBytes<DefaultRng>> {
// 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::<ChaCha20Core, _>::new(BYTES_BEFORE_RESEEDING, rand::rngs::OsRng)
.expect("Calling OsRng failed to seed Rng."),
)
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/api_common.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ where
/// }; // lock released here
/// ```
///
pub(crate) fn take_lock<T>(m: &Mutex<T>) -> MutexGuard<T> {
pub(crate) fn take_lock<T>(m: &Mutex<T>) -> MutexGuard<'_, T> {
m.lock().unwrap_or_else(|e| {
let error = format!("Error when acquiring lock: {}", e);
error!("{}", error);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/rand_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct RandomBytes<T: CryptoRng + RngCore> {

impl Default for RandomBytes<rand_chacha::ChaChaRng> {
fn default() -> Self {
RandomBytes::new(rand_chacha::ChaChaRng::from_entropy())
RandomBytes::new(rand_chacha::ChaChaRng::from_os_rng())
}
}

Expand Down
4 changes: 1 addition & 3 deletions tests/concurrency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading