Skip to content

Commit

Permalink
Merge branch 'alex/rm-csprng-seed-from-random-tape' into 'master'
Browse files Browse the repository at this point in the history
chore(crypto): CRP-2106 remove unused `Csprng::seed_from_random_tape`

Closes CRP-2106. 

Closes CRP-2106

See merge request dfinity-lab/public/ic!19290
  • Loading branch information
altkdf committed May 15, 2024
2 parents 609e0c8 + 5f8f40f commit 356b88c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 59 deletions.
10 changes: 1 addition & 9 deletions rs/crypto/prng/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Offers cryptographically secure pseudorandom number generation (CSPRNG).
use ic_crypto_sha2::{DomainSeparationContext, Sha256};
use ic_types::consensus::{RandomBeacon, RandomTape};
use ic_types::consensus::RandomBeacon;
use ic_types::crypto::CryptoHashable;
use ic_types::Randomness;
use rand::{CryptoRng, Error, RngCore, SeedableRng};
Expand Down Expand Up @@ -54,14 +54,6 @@ impl Csprng {
}
}

/// Creates a CSPRNG seed from the given random tape.
///
/// The returned seed can be used to create a CSPRNG with
/// `Csprng::from_seed_and_purpose`.
pub fn seed_from_random_tape(random_tape: &RandomTape) -> Randomness {
Csprng::seed_from_crypto_hashable(random_tape)
}

/// Creates a CSPRNG seed from the given crypto hashable.
fn seed_from_crypto_hashable<T: CryptoHashable>(crypto_hashable: &T) -> Randomness {
let mut hasher =
Expand Down
52 changes: 2 additions & 50 deletions rs/crypto/prng/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use ic_crypto_prng::RandomnessPurpose::{
BlockmakerRanking, CommitteeSampling, DkgCommitteeSampling, ExecutionThread,
};
use ic_crypto_prng::{Csprng, RandomnessPurpose};
use ic_types::consensus::{RandomBeacon, RandomTape};
use ic_types::consensus::{RandomBeaconContent, RandomTapeContent};
use ic_types::consensus::RandomBeacon;
use ic_types::consensus::RandomBeaconContent;
use ic_types::crypto::{
CombinedThresholdSig, CombinedThresholdSigOf, CryptoHash, CryptoHashOf, Signed,
};
Expand Down Expand Up @@ -62,23 +62,6 @@ fn should_produce_deterministic_randomness_from_seed_and_purpose() {
assert_eq!(rng.next_u32(), 196_996_056);
}

#[test]
fn should_produce_deterministic_randomness_from_seed_from_random_tape() {
fix_replica_version();

let random_tape = fake_random_tape(1);

let randomness = Csprng::seed_from_random_tape(&random_tape);

assert_eq!(
randomness.get(),
[
109, 145, 169, 77, 62, 78, 152, 146, 147, 81, 94, 181, 213, 81, 105, 131, 60, 109, 217,
138, 33, 26, 94, 209, 110, 76, 228, 189, 126, 119, 13, 2
]
);
}

#[test]
fn should_offer_methods_of_rng_trait() {
use rand::Rng;
Expand Down Expand Up @@ -181,19 +164,6 @@ fn should_produce_different_randomness_for_different_execution_threads_for_rando
assert_ne!(csprng1.next_u32(), csprng2.next_u32());
}

#[test]
fn should_produce_different_seeds_for_different_random_tapes() {
fix_replica_version();

let (tape_1, tape_2) = (random_tape(), random_tape_2());
assert_ne!(tape_1, tape_2);

let seed_1 = Csprng::seed_from_random_tape(&tape_1);
let seed_2 = Csprng::seed_from_random_tape(&tape_2);

assert_ne!(seed_1, seed_2);
}

fn fake_random_beacon(height: u64) -> RandomBeacon {
Signed {
content: RandomBeaconContent::new(
Expand All @@ -215,14 +185,6 @@ fn random_beacon_2() -> RandomBeacon {
fake_random_beacon(2)
}

fn random_tape() -> RandomTape {
fake_random_tape(1)
}

fn random_tape_2() -> RandomTape {
fake_random_tape(2)
}

fn seed() -> Randomness {
Randomness::new([123; 32])
}
Expand All @@ -239,13 +201,3 @@ fn fake_dkg_id(h: u64) -> NiDkgId {
target_subnet: NiDkgTargetSubnet::Local,
}
}

fn fake_random_tape(height: u64) -> RandomTape {
Signed {
content: RandomTapeContent::new(Height::from(height)),
signature: ThresholdSignature {
signer: fake_dkg_id(0),
signature: CombinedThresholdSigOf::new(CombinedThresholdSig(vec![])),
},
}
}

0 comments on commit 356b88c

Please sign in to comment.