Migrate zcash_primitives to rand_core 0.4
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -621,7 +621,8 @@ dependencies = [
|
|||||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"pairing 0.14.2",
|
"pairing 0.14.2",
|
||||||
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"sapling-crypto 0.0.1",
|
"sapling-crypto 0.0.1",
|
||||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ fpe = "0.1"
|
|||||||
hex = "0.3"
|
hex = "0.3"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
pairing = { path = "../pairing" }
|
pairing = { path = "../pairing" }
|
||||||
rand = "0.5"
|
rand_core = "0.4"
|
||||||
|
rand_os = "0.1"
|
||||||
sapling-crypto = { path = "../sapling-crypto" }
|
sapling-crypto = { path = "../sapling-crypto" }
|
||||||
sha2 = "0.8"
|
sha2 = "0.8"
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ extern crate ff;
|
|||||||
extern crate fpe;
|
extern crate fpe;
|
||||||
extern crate hex;
|
extern crate hex;
|
||||||
extern crate pairing;
|
extern crate pairing;
|
||||||
extern crate rand;
|
extern crate rand_core;
|
||||||
|
extern crate rand_os;
|
||||||
extern crate sapling_crypto;
|
extern crate sapling_crypto;
|
||||||
extern crate sha2;
|
extern crate sha2;
|
||||||
|
|
||||||
|
|||||||
@@ -202,12 +202,12 @@ impl<Node: Hashable> CommitmentTree<Node> {
|
|||||||
/// ```
|
/// ```
|
||||||
/// extern crate ff;
|
/// extern crate ff;
|
||||||
/// extern crate pairing;
|
/// extern crate pairing;
|
||||||
/// extern crate rand;
|
/// extern crate rand_os;
|
||||||
/// extern crate zcash_primitives;
|
/// extern crate zcash_primitives;
|
||||||
///
|
///
|
||||||
/// use ff::{Field, PrimeField};
|
/// use ff::{Field, PrimeField};
|
||||||
/// use pairing::bls12_381::Fr;
|
/// use pairing::bls12_381::Fr;
|
||||||
/// use rand::OsRng;
|
/// use rand_os::OsRng;
|
||||||
/// use zcash_primitives::{
|
/// use zcash_primitives::{
|
||||||
/// merkle_tree::{CommitmentTree, IncrementalWitness},
|
/// merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||||
/// sapling::Node,
|
/// sapling::Node,
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
|||||||
use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
|
use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
|
||||||
use ff::{PrimeField, PrimeFieldRepr};
|
use ff::{PrimeField, PrimeFieldRepr};
|
||||||
use pairing::bls12_381::{Bls12, Fr};
|
use pairing::bls12_381::{Bls12, Fr};
|
||||||
use rand::{OsRng, Rng};
|
use rand_core::RngCore;
|
||||||
|
use rand_os::OsRng;
|
||||||
use sapling_crypto::{
|
use sapling_crypto::{
|
||||||
jubjub::{
|
jubjub::{
|
||||||
edwards,
|
edwards,
|
||||||
@@ -138,9 +139,7 @@ fn generate_esk() -> Fs {
|
|||||||
// create random 64 byte buffer
|
// create random 64 byte buffer
|
||||||
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
let mut buffer = [0u8; 64];
|
let mut buffer = [0u8; 64];
|
||||||
for i in 0..buffer.len() {
|
rng.fill_bytes(&mut buffer);
|
||||||
buffer[i] = rng.gen();
|
|
||||||
}
|
|
||||||
|
|
||||||
// reduce to uniform value
|
// reduce to uniform value
|
||||||
Fs::to_uniform(&buffer[..])
|
Fs::to_uniform(&buffer[..])
|
||||||
@@ -213,12 +212,12 @@ fn prf_ock(
|
|||||||
/// ```
|
/// ```
|
||||||
/// extern crate ff;
|
/// extern crate ff;
|
||||||
/// extern crate pairing;
|
/// extern crate pairing;
|
||||||
/// extern crate rand;
|
/// extern crate rand_os;
|
||||||
/// extern crate sapling_crypto;
|
/// extern crate sapling_crypto;
|
||||||
///
|
///
|
||||||
/// use ff::Field;
|
/// use ff::Field;
|
||||||
/// use pairing::bls12_381::Bls12;
|
/// use pairing::bls12_381::Bls12;
|
||||||
/// use rand::OsRng;
|
/// use rand_os::OsRng;
|
||||||
/// use sapling_crypto::{
|
/// use sapling_crypto::{
|
||||||
/// jubjub::fs::Fs,
|
/// jubjub::fs::Fs,
|
||||||
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
|
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
|
||||||
@@ -562,7 +561,8 @@ mod tests {
|
|||||||
use crypto_api_chachapoly::ChachaPolyIetf;
|
use crypto_api_chachapoly::ChachaPolyIetf;
|
||||||
use ff::{Field, PrimeField, PrimeFieldRepr};
|
use ff::{Field, PrimeField, PrimeFieldRepr};
|
||||||
use pairing::bls12_381::{Bls12, Fr, FrRepr};
|
use pairing::bls12_381::{Bls12, Fr, FrRepr};
|
||||||
use rand::{thread_rng, RngCore};
|
use rand_core::RngCore;
|
||||||
|
use rand_os::OsRng;
|
||||||
use sapling_crypto::{
|
use sapling_crypto::{
|
||||||
jubjub::{
|
jubjub::{
|
||||||
edwards,
|
edwards,
|
||||||
@@ -848,7 +848,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_ivk() {
|
fn decryption_with_invalid_ivk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, _, _, cmu, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, _, _, cmu, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -860,7 +860,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_epk() {
|
fn decryption_with_invalid_epk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, ivk, _, cmu, _, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, ivk, _, cmu, _, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -877,7 +877,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_cmu() {
|
fn decryption_with_invalid_cmu() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, ivk, _, _, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, ivk, _, _, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -889,7 +889,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_tag() {
|
fn decryption_with_invalid_tag() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, ivk, _, cmu, epk, mut enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, ivk, _, cmu, epk, mut enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -902,7 +902,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_version_byte() {
|
fn decryption_with_invalid_version_byte() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -924,7 +924,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_invalid_diversifier() {
|
fn decryption_with_invalid_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -946,7 +946,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decryption_with_incorrect_diversifier() {
|
fn decryption_with_incorrect_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -968,7 +968,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_invalid_ivk() {
|
fn compact_decryption_with_invalid_ivk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, _, _, cmu, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, _, _, cmu, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -985,7 +985,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_invalid_epk() {
|
fn compact_decryption_with_invalid_epk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, ivk, _, cmu, _, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, ivk, _, cmu, _, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -1002,7 +1002,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_invalid_cmu() {
|
fn compact_decryption_with_invalid_cmu() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (_, ivk, _, _, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
let (_, ivk, _, _, epk, enc_ciphertext, _) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -1019,7 +1019,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_invalid_version_byte() {
|
fn compact_decryption_with_invalid_version_byte() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1046,7 +1046,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_invalid_diversifier() {
|
fn compact_decryption_with_invalid_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1073,7 +1073,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compact_decryption_with_incorrect_diversifier() {
|
fn compact_decryption_with_incorrect_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, ivk, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1100,7 +1100,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_ovk() {
|
fn recovery_with_invalid_ovk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (mut ovk, _, cv, cmu, epk, enc_ciphertext, out_ciphertext) =
|
let (mut ovk, _, cv, cmu, epk, enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1114,7 +1114,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_cv() {
|
fn recovery_with_invalid_cv() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, _, cmu, epk, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
let (ovk, _, _, cmu, epk, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -1133,7 +1133,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_cmu() {
|
fn recovery_with_invalid_cmu() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, _, epk, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
let (ovk, _, cv, _, epk, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -1152,7 +1152,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_epk() {
|
fn recovery_with_invalid_epk() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, _, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
let (ovk, _, cv, cmu, _, enc_ciphertext, out_ciphertext) = random_enc_ciphertext(&mut rng);
|
||||||
|
|
||||||
@@ -1171,7 +1171,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_enc_tag() {
|
fn recovery_with_invalid_enc_tag() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1185,7 +1185,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_out_tag() {
|
fn recovery_with_invalid_out_tag() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, epk, enc_ciphertext, mut out_ciphertext) =
|
let (ovk, _, cv, cmu, epk, enc_ciphertext, mut out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1199,7 +1199,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_version_byte() {
|
fn recovery_with_invalid_version_byte() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1221,7 +1221,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_invalid_diversifier() {
|
fn recovery_with_invalid_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
@@ -1243,7 +1243,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recovery_with_incorrect_diversifier() {
|
fn recovery_with_incorrect_diversifier() {
|
||||||
let mut rng = thread_rng();
|
let mut rng = OsRng::new().expect("should be able to construct RNG");
|
||||||
|
|
||||||
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
let (ovk, _, cv, cmu, epk, mut enc_ciphertext, out_ciphertext) =
|
||||||
random_enc_ciphertext(&mut rng);
|
random_enc_ciphertext(&mut rng);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ff::{BitIterator, PrimeField, PrimeFieldRepr};
|
use ff::{BitIterator, PrimeField, PrimeFieldRepr};
|
||||||
use pairing::bls12_381::{Bls12, Fr, FrRepr};
|
use pairing::bls12_381::{Bls12, Fr, FrRepr};
|
||||||
use rand::OsRng;
|
use rand_os::OsRng;
|
||||||
use sapling_crypto::{
|
use sapling_crypto::{
|
||||||
jubjub::{fs::Fs, FixedGenerators, JubjubBls12},
|
jubjub::{fs::Fs, FixedGenerators, JubjubBls12},
|
||||||
pedersen_hash::{pedersen_hash, Personalization},
|
pedersen_hash::{pedersen_hash, Personalization},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use ff::Field;
|
use ff::Field;
|
||||||
use pairing::bls12_381::Bls12;
|
use pairing::bls12_381::Bls12;
|
||||||
use rand::thread_rng;
|
use rand_os::OsRng;
|
||||||
use sapling_crypto::{
|
use sapling_crypto::{
|
||||||
jubjub::{fs::Fs, FixedGenerators},
|
jubjub::{fs::Fs, FixedGenerators},
|
||||||
redjubjub::PrivateKey,
|
redjubjub::PrivateKey,
|
||||||
@@ -197,7 +197,7 @@ fn tx_write_rejects_unexpected_binding_sig() {
|
|||||||
|
|
||||||
// Fails with an unexpected binding signature
|
// Fails with an unexpected binding signature
|
||||||
{
|
{
|
||||||
let rng = &mut thread_rng();
|
let rng = &mut OsRng::new().expect("should be able to construct RNG");
|
||||||
let sk = PrivateKey::<Bls12>(Fs::random(rng));
|
let sk = PrivateKey::<Bls12>(Fs::random(rng));
|
||||||
let sig = sk.sign(
|
let sig = sk.sign(
|
||||||
b"Foo bar",
|
b"Foo bar",
|
||||||
|
|||||||
Reference in New Issue
Block a user