diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index d9f61af..a9f2e37 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rename `crossover` to `deposit` [#190] +### Removed + +- Remove `"getrandom"` feature from `aes-gcm` dependency [#195] + ## [0.28.1] - 2024-05-23 ### Changed @@ -321,6 +325,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Canonical implementation shielded by feature. +[#195]: https://github.com/dusk-network/phoenix/issues/195 [#190]: https://github.com/dusk-network/phoenix/issues/190 [#183]: https://github.com/dusk-network/phoenix/issues/183 [#179]: https://github.com/dusk-network/phoenix/issues/179 diff --git a/core/Cargo.toml b/core/Cargo.toml index 4e95719..c922a04 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -8,7 +8,7 @@ license = "MPL-2.0" exclude = [".github/workflows/dusk-ci.yml", ".gitignore"] [dependencies] -rand_core = { version = "0.6", default-features = false } +rand = { version = "0.8", default-features = false } dusk-bytes = "0.1" dusk-bls12_381 = { version = "0.13", default-features = false } bls12_381-bls = { version = "0.3", default-features = false } @@ -17,7 +17,7 @@ dusk-poseidon = "0.39" jubjub-schnorr = "0.4" subtle = { version = "^2.2.1", default-features = false } ff = { version = "0.13", default-features = false } -aes-gcm = "0.10" +aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "rand_core"] } zeroize = { version = "1", default-features = false, features = ["derive"] } rkyv = { version = "0.7", optional = true, default-features = false } bytecheck = { version = "0.6", optional = true, default-features = false } diff --git a/core/src/encryption/aes.rs b/core/src/encryption/aes.rs index 370c953..9a3a8bb 100644 --- a/core/src/encryption/aes.rs +++ b/core/src/encryption/aes.rs @@ -5,7 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_jubjub::JubJubAffine; -use rand_core::{CryptoRng, RngCore}; +use rand::{CryptoRng, RngCore}; use aes_gcm::{ aead::{Aead, AeadCore, KeyInit}, diff --git a/core/src/keys/secret.rs b/core/src/keys/secret.rs index 34bf87e..d81a971 100644 --- a/core/src/keys/secret.rs +++ b/core/src/keys/secret.rs @@ -14,7 +14,7 @@ use zeroize::Zeroize; use rkyv::{Archive, Deserialize, Serialize}; use dusk_bytes::{DeserializableSlice, Error, Serializable}; -use rand_core::{CryptoRng, RngCore}; +use rand::{CryptoRng, RngCore}; use subtle::{Choice, ConstantTimeEq}; /// Secret pair of `a` and `b` defining a [`SecretKey`] diff --git a/core/src/note.rs b/core/src/note.rs index bd402e0..d0b16fd 100644 --- a/core/src/note.rs +++ b/core/src/note.rs @@ -18,7 +18,7 @@ use crate::aes; use dusk_poseidon::{Domain, Hash}; use ff::Field; -use rand_core::{CryptoRng, RngCore}; +use rand::{CryptoRng, RngCore}; #[cfg(feature = "rkyv-impl")] use rkyv::{Archive, Deserialize, Serialize}; diff --git a/core/tests/encryption.rs b/core/tests/encryption.rs index 7a6252e..9d33574 100644 --- a/core/tests/encryption.rs +++ b/core/tests/encryption.rs @@ -6,10 +6,13 @@ use dusk_jubjub::{JubJubAffine, JubJubScalar, GENERATOR}; use phoenix_core::aes; -use rand_core::OsRng; +use rand::rngs::StdRng; +use rand::SeedableRng; #[test] fn test_aes_encrypt_and_decrypt() { + let mut rng = StdRng::seed_from_u64(0xc0b); + const PLAINTEXT_SIZE: usize = 20; const ENCRYPTION_SIZE: usize = PLAINTEXT_SIZE + aes::ENCRYPTION_EXTRA_SIZE; @@ -18,7 +21,7 @@ fn test_aes_encrypt_and_decrypt() { let plaintext = b"00112233445566778899"; let encryption: [u8; ENCRYPTION_SIZE] = - aes::encrypt(&shared_secret_key, plaintext, &mut OsRng) + aes::encrypt(&shared_secret_key, plaintext, &mut rng) .expect("Encrypted correctly."); let dec_plaintext = aes::decrypt(&shared_secret_key, &encryption) .expect("Decrypted correctly."); diff --git a/core/tests/keys.rs b/core/tests/keys.rs index 540b7a2..451aa27 100644 --- a/core/tests/keys.rs +++ b/core/tests/keys.rs @@ -8,12 +8,15 @@ use dusk_bytes::{DeserializableSlice, Serializable}; use dusk_jubjub::JubJubScalar; use ff::Field; use phoenix_core::{PublicKey, SecretKey, ViewKey}; -use rand_core::OsRng; +use rand::rngs::StdRng; +use rand::SeedableRng; use zeroize::Zeroize; #[test] fn sk_from_bytes() { - let sk = SecretKey::random(&mut OsRng); + let mut rng = StdRng::seed_from_u64(0xc0b); + + let sk = SecretKey::random(&mut rng); let sk_bytes = sk.to_bytes(); assert_eq!( @@ -24,7 +27,9 @@ fn sk_from_bytes() { #[test] fn sk_zeroize() { - let mut sk = SecretKey::random(&mut OsRng); + let mut rng = StdRng::seed_from_u64(0xc0b); + + let mut sk = SecretKey::random(&mut rng); let sk_zeroized = SecretKey::new(JubJubScalar::zero(), JubJubScalar::zero()); @@ -37,7 +42,9 @@ fn sk_zeroize() { #[test] fn keys_encoding() { - let sk = SecretKey::random(&mut OsRng); + let mut rng = StdRng::seed_from_u64(0xc0b); + + let sk = SecretKey::random(&mut rng); let vk = ViewKey::from(&sk); let pk = PublicKey::from(&sk); @@ -49,15 +56,17 @@ fn keys_encoding() { fn keys_consistency() { use dusk_jubjub::{JubJubScalar, GENERATOR_EXTENDED}; - let r = JubJubScalar::random(&mut OsRng); - let sk = SecretKey::random(&mut OsRng); + let mut rng = StdRng::seed_from_u64(0xc0b); + + let r = JubJubScalar::random(&mut rng); + let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); let vk = ViewKey::from(&sk); let sa = pk.gen_stealth_address(&r); assert!(vk.owns(&sa)); - let wrong_sk = SecretKey::random(&mut OsRng); + let wrong_sk = SecretKey::random(&mut rng); let wrong_vk = ViewKey::from(&wrong_sk); assert_ne!(sk, wrong_sk); diff --git a/core/tests/note_test.rs b/core/tests/note_test.rs index dc7cbcf..8a5c8f7 100644 --- a/core/tests/note_test.rs +++ b/core/tests/note_test.rs @@ -9,11 +9,12 @@ use ff::Field; use phoenix_core::{ Error, Note, NoteType, Ownable, PublicKey, SecretKey, ViewKey, }; -use rand_core::OsRng; +use rand::rngs::StdRng; +use rand::SeedableRng; #[test] fn transparent_note() -> Result<(), Error> { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); @@ -29,7 +30,7 @@ fn transparent_note() -> Result<(), Error> { #[test] fn transparent_stealth_note() -> Result<(), Error> { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); @@ -50,7 +51,7 @@ fn transparent_stealth_note() -> Result<(), Error> { #[test] fn obfuscated_note() -> Result<(), Error> { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); @@ -68,7 +69,7 @@ fn obfuscated_note() -> Result<(), Error> { #[test] fn obfuscated_deterministic_note() -> Result<(), Error> { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); @@ -88,7 +89,7 @@ fn obfuscated_deterministic_note() -> Result<(), Error> { #[test] fn value_commitment_transparent() { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let vk = ViewKey::from(&sk); @@ -115,7 +116,7 @@ fn value_commitment_transparent() { #[test] fn value_commitment_obfuscated() { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let vk = ViewKey::from(&sk); @@ -143,7 +144,7 @@ fn value_commitment_obfuscated() { #[test] fn note_keys_consistency() { - let mut rng = OsRng; + let mut rng = StdRng::seed_from_u64(0xc0b); let sk = SecretKey::random(&mut rng); let pk = PublicKey::from(&sk); diff --git a/core/tests/transaction.rs b/core/tests/transaction.rs index bf19e93..6f1695a 100644 --- a/core/tests/transaction.rs +++ b/core/tests/transaction.rs @@ -10,7 +10,7 @@ use dusk_bls12_381::BlsScalar; use dusk_jubjub::JubJubScalar; use ff::Field; use phoenix_core::{Error, Note, PublicKey, SecretKey, TxSkeleton}; -use rand_core::OsRng; +use rand::rngs::OsRng; #[test] fn transaction_parse() -> Result<(), Error> {