Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an XOF instead of a PRNG to derive ZK proof challenges. #45

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion synedrion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sha3 = { version = "0.10", default-features = false }
digest = { version = "0.10", default-features = false, features = ["alloc"]}
hex = { version = "0.4", default-features = false, features = ["alloc"] }
base64 = { version = "0.21", default-features = false, features = ["alloc"] }
rand_chacha = { version = "0.3", default-features = false }

crypto-bigint = { version = "0.5.3", features = ["serde"] }
crypto-primes = "0.5"
Expand Down
20 changes: 13 additions & 7 deletions synedrion/src/cggmp21/sigma/aff_g.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
Randomizer, RandomizerMod,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{FromScalar, NonZero, Signed};

const HASH_TAG: &[u8] = b"P_aff_g";
Expand Down Expand Up @@ -45,10 +45,13 @@ impl<P: SchemeParams> AffGProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());
let e_wide = e.into_wide();

let hat_cap_n = &aux_rp.public_key().modulus_nonzero();
Expand Down Expand Up @@ -128,12 +131,15 @@ impl<P: SchemeParams> AffGProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();

let aux_pk = aux_rp.public_key();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let aux_pk = aux_rp.public_key();

// C^{z_1} (1 + N_0)^{z_2} \omega^{N_0} = A D^e \mod N_0^2
// => C (*) z_1 (+) encrypt_0(z_2, \omega) = A (+) D (*) e
Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
Randomizer, RandomizerMod,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{FromScalar, NonZero, Signed};

const HASH_TAG: &[u8] = b"P_dec";
Expand All @@ -34,10 +34,13 @@ impl<P: SchemeParams> DecProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let hat_cap_n = &aux_rp.public_key().modulus_nonzero(); // $\hat{N}$

Expand Down Expand Up @@ -75,10 +78,13 @@ impl<P: SchemeParams> DecProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

// enc(z_1, \omega) == A (+) C (*) e
if Ciphertext::new_with_randomizer_signed(pk, &self.z1, &self.omega)
Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/enc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
Randomizer, RandomizerMod, SecretKeyPaillierPrecomputed,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{NonZero, Signed};

const HASH_TAG: &[u8] = b"P_enc";
Expand All @@ -32,10 +32,13 @@ impl<P: SchemeParams> EncProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let pk = sk.public_key();
let hat_cap_n = &aux_rp.public_key().modulus_nonzero(); // $\hat{N}$
Expand Down Expand Up @@ -72,10 +75,13 @@ impl<P: SchemeParams> EncProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $s$, $t$
aux: &impl Hashable, // CHECK: used to derive `\hat{N}, s, t`
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

// z_1 \in \pm 2^{\ell + \eps}
if !self.z1.in_range_bits(P::L_BOUND + P::EPS_BOUND) {
Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/fac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::paillier::{
PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
SecretKeyPaillierPrecomputed,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{HasWide, Integer, NonZero, Signed};

const HASH_TAG: &[u8] = b"P_fac";
Expand All @@ -35,10 +35,13 @@ impl<P: SchemeParams> FacProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());
let e_wide = e.into_wide();

let pk = sk.public_key();
Expand Down Expand Up @@ -109,10 +112,13 @@ impl<P: SchemeParams> FacProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $s$, $t$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let aux_pk = aux_rp.public_key();

Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/log_star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
Randomizer, RandomizerMod,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{FromScalar, NonZero, Signed};

const HASH_TAG: &[u8] = b"P_log*";
Expand All @@ -36,10 +36,13 @@ impl<P: SchemeParams> LogStarProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let hat_cap_n = &aux_rp.public_key().modulus_nonzero(); // $\hat{N}$

Expand Down Expand Up @@ -78,10 +81,13 @@ impl<P: SchemeParams> LogStarProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $s$, $t$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

// enc_0(z1, z2) == A (+) C (*) e
let c = Ciphertext::new_with_randomizer_signed(pk, &self.z1, &self.z2);
Expand Down
11 changes: 7 additions & 4 deletions synedrion/src/cggmp21/sigma/mod_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
use crate::paillier::{PaillierParams, PublicKeyPaillierPrecomputed, SecretKeyPaillierPrecomputed};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::uint::{JacobiSymbol, JacobiSymbolTrait, RandomMod, Retrieve, UintModLike};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{JacobiSymbol, JacobiSymbolTrait, RandomMod, Retrieve, UintLike, UintModLike};

const HASH_TAG: &[u8] = b"P_mod";

Expand All @@ -35,10 +35,13 @@ struct ModChallenge<P: SchemeParams>(Vec<<P::Paillier as PaillierParams>::Uint>)

impl<P: SchemeParams> ModChallenge<P> {
fn new(aux: &impl Hashable, pk: &PublicKeyPaillierPrecomputed<P::Paillier>) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

let modulus = pk.modulus_nonzero();
let ys = (0..P::SECURITY_PARAMETER)
.map(|_| <P::Paillier as PaillierParams>::Uint::random_mod(&mut aux_rng, &modulus))
.map(|_| <P::Paillier as PaillierParams>::Uint::from_xof(&mut reader, &modulus))
.collect();
Self(ys)
}
Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::super::SchemeParams;
use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, Randomizer, RandomizerMod,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{Bounded, NonZero, Retrieve, Signed};

const HASH_TAG: &[u8] = b"P_mul";
Expand All @@ -32,10 +32,13 @@ impl<P: SchemeParams> MulProof<P> {
cap_y: &Ciphertext<P::Paillier>, // $Y$
aux: &impl Hashable,
) -> Self {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let alpha_mod = pk.random_invertible_group_elem(rng);
let r_mod = RandomizerMod::random(rng, pk);
Expand Down Expand Up @@ -75,10 +78,13 @@ impl<P: SchemeParams> MulProof<P> {
cap_c: &Ciphertext<P::Paillier>, // $C = (Y (*) x) * \rho^N$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

// Y^z u^N = A * C^e \mod N^2
if cap_y
Expand Down
16 changes: 11 additions & 5 deletions synedrion/src/cggmp21/sigma/mul_star.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::paillier::{
Ciphertext, PaillierParams, PublicKeyPaillierPrecomputed, RPCommitment, RPParamsMod,
Randomizer, RandomizerMod,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{FromScalar, NonZero, Signed};

const HASH_TAG: &[u8] = b"P_mul*";
Expand Down Expand Up @@ -46,10 +46,13 @@ impl<P: SchemeParams> MulStarProof<P> {
(and judging by the condition the verifier checks, it should be == 0)
*/

let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let hat_cap_n = &aux_rp.public_key().modulus_nonzero(); // $\hat{N}$

Expand Down Expand Up @@ -90,10 +93,13 @@ impl<P: SchemeParams> MulStarProof<P> {
aux_rp: &RPParamsMod<P::Paillier>, // $\hat{N}$, $s$, $t$
aux: &impl Hashable,
) -> bool {
let mut aux_rng = Hash::new_with_dst(HASH_TAG).chain(aux).finalize_to_rng();
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.finalize_to_reader();

// Non-interactive challenge
let e = Signed::random_bounded(&mut aux_rng, &NonZero::new(P::CURVE_ORDER).unwrap());
let e =
Signed::from_xof_reader_bounded(&mut reader, &NonZero::new(P::CURVE_ORDER).unwrap());

let aux_pk = aux_rp.public_key();

Expand Down
12 changes: 6 additions & 6 deletions synedrion/src/cggmp21/sigma/prm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

use alloc::{vec, vec::Vec};

use rand_core::{CryptoRngCore, RngCore};

use digest::XofReader;
use rand_core::CryptoRngCore;
use serde::{Deserialize, Serialize};

use super::super::SchemeParams;
use crate::paillier::{
PaillierParams, PublicKeyPaillierPrecomputed, RPParamsMod, RPSecret,
SecretKeyPaillierPrecomputed,
};
use crate::tools::hashing::{Chain, Hash, Hashable};
use crate::tools::hashing::{Chain, Hashable, XofHash};
use crate::uint::{
subtle::{Choice, ConditionallySelectable},
Bounded, Retrieve, UintModLike,
Expand Down Expand Up @@ -73,12 +73,12 @@ struct PrmChallenge(Vec<bool>);
impl PrmChallenge {
fn new<P: SchemeParams>(aux: &impl Hashable, commitment: &PrmCommitment<P>) -> Self {
// TODO: generate m/8 random bytes instead and fill the vector bit by bit.
let mut aux_rng = Hash::new_with_dst(HASH_TAG)
let mut reader = XofHash::new_with_dst(HASH_TAG)
.chain(aux)
.chain(commitment)
.finalize_to_rng();
.finalize_to_reader();
let mut bytes = vec![0u8; P::SECURITY_PARAMETER];
aux_rng.fill_bytes(&mut bytes);
reader.read(&mut bytes);
Self(bytes.iter().map(|b| b & 1 == 1).collect())
}
}
Expand Down
Loading
Loading