Skip to content

Commit ec21172

Browse files
Get rid of rand dependencies
1 parent 380379a commit ec21172

8 files changed

Lines changed: 62 additions & 101 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ clap = { version = "4.5", features = [ "cargo", "derive" ] }
3232
futures-channel = "0.3"
3333
futures-lite = "2.6"
3434
futures-util = "0.3"
35-
num-bigint-dig = { version = "0.8", features = ["zeroize"] }
35+
num-bigint-dig = { version = "0.9", features = ["zeroize"] }
3636
oo7 = { path = "client", version = "0.6", default-features = false, features = ["unstable", "tracing"]}
3737
serde = { version = "1.0", features = ["derive"] }
3838
tokio = { version = "1.48", default-features = false }

client/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ async-io = { version = "2.6.0", optional = true }
2020
async-lock = { version = "3.4.2", optional = true }
2121
blocking = { version = "1.5.1", optional = true }
2222
cbc = { version = "0.1", features = ["zeroize"], optional = true }
23-
cipher = { version = "0.4", features = [
24-
"rand_core",
25-
"zeroize",
26-
], optional = true }
23+
cipher = { version = "0.4", features = ["zeroize"], optional = true }
2724
digest = { version = "0.10", optional = true }
2825
endi.workspace = true
2926
futures-lite = { workspace = true, optional = true }
@@ -37,7 +34,6 @@ num = "0.4.0"
3734
num-bigint-dig.workspace = true
3835
openssl = { version = "0.10", optional = true }
3936
pbkdf2 = { version = "0.12", optional = true }
40-
rand = { version = "0.9", default-features = false, features = ["thread_rng"] }
4137
serde.workspace = true
4238
serde_bytes = "0.11"
4339
sha2 = { version = "0.10", optional = true }

client/src/crypto/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub enum Error {
77
PadError(cipher::inout::PadError),
88
#[cfg(feature = "native_crypto")]
99
UnpadError(cipher::block_padding::UnpadError),
10+
Getrandom(getrandom::Error),
1011
}
1112

1213
#[cfg(feature = "openssl_crypto")]
@@ -30,13 +31,20 @@ impl From<cipher::inout::PadError> for Error {
3031
}
3132
}
3233

34+
impl From<getrandom::Error> for Error {
35+
fn from(value: getrandom::Error) -> Self {
36+
Self::Getrandom(value)
37+
}
38+
}
39+
3340
impl std::error::Error for Error {
3441
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
3542
match self {
3643
#[cfg(feature = "openssl_crypto")]
3744
Self::Openssl(e) => Some(e),
3845
#[cfg(feature = "native_crypto")]
3946
Self::UnpadError(_) | Self::PadError(_) => None,
47+
Self::Getrandom(_) => None,
4048
}
4149
}
4250
}
@@ -50,6 +58,7 @@ impl std::fmt::Display for Error {
5058
Self::UnpadError(e) => f.write_fmt(format_args!("Wrong padding error: {e}")),
5159
#[cfg(feature = "native_crypto")]
5260
Self::PadError(e) => f.write_fmt(format_args!("Wrong padding error: {e}")),
61+
Self::Getrandom(e) => f.write_fmt(format_args!("Random number generation error: {e}")),
5362
}
5463
}
5564
}

client/src/crypto/native.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ pub(crate) fn iv_len() -> usize {
7474
}
7575

7676
pub(crate) fn generate_private_key() -> Result<Zeroizing<Vec<u8>>, super::Error> {
77-
let generic_array = EncAlg::generate_key(cipher::rand_core::OsRng);
78-
Ok(Zeroizing::new(generic_array.to_vec()))
77+
let mut key = vec![0u8; EncAlg::key_size()];
78+
getrandom::fill(&mut key)?;
79+
Ok(Zeroizing::new(key))
7980
}
8081

8182
pub(crate) fn generate_public_key(private_key: impl AsRef<[u8]>) -> Result<Vec<u8>, super::Error> {
@@ -116,7 +117,9 @@ pub(crate) fn generate_aes_key(
116117
}
117118

118119
pub fn generate_iv() -> Result<Vec<u8>, super::Error> {
119-
Ok(EncAlg::generate_iv(cipher::rand_core::OsRng).to_vec())
120+
let mut iv = vec![0u8; EncAlg::iv_size()];
121+
getrandom::fill(&mut iv)?;
122+
Ok(iv)
120123
}
121124

122125
pub(crate) fn mac_len() -> usize {

0 commit comments

Comments
 (0)