arnaucube
arnaucube/testudoPublic Self-hosted repository
testudo/src/random.rs
src/random.rsRaw
 1use super::scalar::Scalar;
 2use super::transcript::ProofTranscript;
 3use merlin::Transcript;
 4use ark_std::{UniformRand};
 5
 6pub struct RandomTape {
 7  tape: Transcript,
 8}
 9
10impl RandomTape {
11  pub fn new(name: &'static [u8]) -> Self {
12    let tape = {
13    let mut rng = ark_std::rand::thread_rng();
14      let mut tape = Transcript::new(name);
15      tape.append_scalar(b"init_randomness", &Scalar::rand(&mut rng));
16      tape
17    };
18    Self { tape }
19  }
20
21  pub fn random_scalar(&mut self, label: &'static [u8]) -> Scalar {
22    self.tape.challenge_scalar(label)
23  }
24
25  pub fn random_vector(&mut self, label: &'static [u8], len: usize) -> Vec<Scalar> {
26    self.tape.challenge_vector(label, len)
27  }
28}