Migrate zcash_primitives to rand_core 0.4

This commit is contained in:
Jack Grigg 2019-07-13 00:16:54 -04:00
parent 60d344a0a7
commit 8f7adec0d9
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
7 changed files with 40 additions and 37 deletions

3
Cargo.lock generated
View File

@ -621,7 +621,8 @@ dependencies = [
"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)",
"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",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -15,6 +15,7 @@ fpe = "0.1"
hex = "0.3"
lazy_static = "1"
pairing = { path = "../pairing" }
rand = "0.5"
rand_core = "0.4"
rand_os = "0.1"
sapling-crypto = { path = "../sapling-crypto" }
sha2 = "0.8"

View File

@ -9,7 +9,8 @@ extern crate ff;
extern crate fpe;
extern crate hex;
extern crate pairing;
extern crate rand;
extern crate rand_core;
extern crate rand_os;
extern crate sapling_crypto;
extern crate sha2;

View File

@ -202,12 +202,12 @@ impl<Node: Hashable> CommitmentTree<Node> {
/// ```
/// extern crate ff;
/// extern crate pairing;
/// extern crate rand;
/// extern crate rand_os;
/// extern crate zcash_primitives;
///
/// use ff::{Field, PrimeField};
/// use pairing::bls12_381::Fr;
/// use rand::OsRng;
/// use rand_os::OsRng;
/// use zcash_primitives::{
/// merkle_tree::{CommitmentTree, IncrementalWitness},
/// sapling::Node,

View File

@ -5,7 +5,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use crypto_api_chachapoly::{ChaCha20Ietf, ChachaPolyIetf};
use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr};
use rand::{OsRng, Rng};
use rand_core::RngCore;
use rand_os::OsRng;
use sapling_crypto::{
jubjub::{
edwards,
@ -138,9 +139,7 @@ fn generate_esk() -> Fs {
// create random 64 byte buffer
let mut rng = OsRng::new().expect("should be able to construct RNG");
let mut buffer = [0u8; 64];
for i in 0..buffer.len() {
buffer[i] = rng.gen();
}
rng.fill_bytes(&mut buffer);
// reduce to uniform value
Fs::to_uniform(&buffer[..])
@ -213,12 +212,12 @@ fn prf_ock(
/// ```
/// extern crate ff;
/// extern crate pairing;
/// extern crate rand;
/// extern crate rand_os;
/// extern crate sapling_crypto;
///
/// use ff::Field;
/// use pairing::bls12_381::Bls12;
/// use rand::OsRng;
/// use rand_os::OsRng;
/// use sapling_crypto::{
/// jubjub::fs::Fs,
/// primitives::{Diversifier, PaymentAddress, ValueCommitment},
@ -562,7 +561,8 @@ mod tests {
use crypto_api_chachapoly::ChachaPolyIetf;
use ff::{Field, PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr};
use rand::{thread_rng, RngCore};
use rand_core::RngCore;
use rand_os::OsRng;
use sapling_crypto::{
jubjub::{
edwards,
@ -848,7 +848,7 @@ mod tests {
#[test]
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);
@ -860,7 +860,7 @@ mod tests {
#[test]
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);
@ -877,7 +877,7 @@ mod tests {
#[test]
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);
@ -889,7 +889,7 @@ mod tests {
#[test]
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);
@ -902,7 +902,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -924,7 +924,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -946,7 +946,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -968,7 +968,7 @@ mod tests {
#[test]
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);
@ -985,7 +985,7 @@ mod tests {
#[test]
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);
@ -1002,7 +1002,7 @@ mod tests {
#[test]
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);
@ -1019,7 +1019,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1046,7 +1046,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1073,7 +1073,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1100,7 +1100,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1114,7 +1114,7 @@ mod tests {
#[test]
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);
@ -1133,7 +1133,7 @@ mod tests {
#[test]
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);
@ -1152,7 +1152,7 @@ mod tests {
#[test]
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);
@ -1171,7 +1171,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1185,7 +1185,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1199,7 +1199,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1221,7 +1221,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);
@ -1243,7 +1243,7 @@ mod tests {
#[test]
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) =
random_enc_ciphertext(&mut rng);

View File

@ -2,7 +2,7 @@
use ff::{BitIterator, PrimeField, PrimeFieldRepr};
use pairing::bls12_381::{Bls12, Fr, FrRepr};
use rand::OsRng;
use rand_os::OsRng;
use sapling_crypto::{
jubjub::{fs::Fs, FixedGenerators, JubjubBls12},
pedersen_hash::{pedersen_hash, Personalization},

View File

@ -1,6 +1,6 @@
use ff::Field;
use pairing::bls12_381::Bls12;
use rand::thread_rng;
use rand_os::OsRng;
use sapling_crypto::{
jubjub::{fs::Fs, FixedGenerators},
redjubjub::PrivateKey,
@ -197,7 +197,7 @@ fn tx_write_rejects_unexpected_binding_sig() {
// 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 sig = sk.sign(
b"Foo bar",