diff --git a/crates/proof-of-sql/src/proof_primitive/dory/mod.rs b/crates/proof-of-sql/src/proof_primitive/dory/mod.rs index fc1659e22..7d312cb77 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/mod.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/mod.rs @@ -25,7 +25,7 @@ type GT = ark_ec::pairing::PairingOutput; mod rand_util; #[cfg(test)] use rand_util::rand_F_tensors; -#[cfg(any(test, feature = "test"))] +#[cfg(test)] use rand_util::rand_G_vecs; #[cfg(any(test, feature = "test"))] pub use rand_util::test_rng; diff --git a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs index 81e925761..2c28841c3 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs @@ -1,5 +1,9 @@ use super::{G1Affine, G2Affine}; use alloc::vec::Vec; +use ark_ff::UniformRand; +use ark_std::rand::{CryptoRng, Rng}; +use core::iter; + /// The public parameters for the Dory protocol. See section 5 of https://eprint.iacr.org/2020/1274.pdf for details. /// /// Note: even though H_1 and H_2 are marked as blue, they are still needed. @@ -21,14 +25,19 @@ pub struct PublicParameters { } impl PublicParameters { + /// Generate cryptographically secure random public parameters. + pub fn crypto_rand(max_nu: usize, rng: &mut R) -> Self { + Self::rand_impl(max_nu, rng) + } #[cfg(any(test, feature = "test"))] - /// Generate random public parameters for testing purposes. - pub fn rand(max_nu: usize, rng: &mut R) -> Self - where - R: ark_std::rand::Rng + ?Sized, - { - use ark_std::UniformRand; - let (Gamma_1, Gamma_2) = super::rand_G_vecs(max_nu, rng); + /// Generate random public parameters. + pub fn rand(max_nu: usize, rng: &mut R) -> Self { + Self::rand_impl(max_nu, rng) + } + fn rand_impl(max_nu: usize, rng: &mut R) -> Self { + let (Gamma_1, Gamma_2) = iter::repeat_with(|| (G1Affine::rand(rng), G2Affine::rand(rng))) + .take(1 << max_nu) + .unzip(); let (H_1, H_2) = (G1Affine::rand(rng), G2Affine::rand(rng)); let Gamma_2_fin = G2Affine::rand(rng); diff --git a/crates/proof-of-sql/src/proof_primitive/dory/rand_util.rs b/crates/proof-of-sql/src/proof_primitive/dory/rand_util.rs index cf7f7738d..9b31eeeab 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/rand_util.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/rand_util.rs @@ -16,6 +16,7 @@ pub fn test_seed_rng(seed: [u8; 32]) -> impl Rng { StdRng::from_seed(seed) } +#[allow(dead_code)] /// Creates two vectors of random G1 and G2 elements with length 2^nu. pub fn rand_G_vecs(nu: usize, rng: &mut R) -> (Vec, Vec) where