Skip to content

Commit

Permalink
Tweaks, simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn authored and lovesh committed Sep 1, 2023
1 parent 7a68563 commit bbbc53b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
9 changes: 5 additions & 4 deletions bbs_plus/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ macro_rules! impl_sig_params {
let g1 = projective_group_elem_from_try_and_incr::<E::$group_affine, D>(
&concat_slices!(label, b" : g1"),
);
let h_bytes = concat_slices!(label, b" : h_");
// h_0 and h[i] for i in 1 to message_count
let h = n_projective_group_elements::<E::$group_affine, D, _>(
let h = n_projective_group_elements::<E::$group_affine, D>(
1 + message_count,
concat_slices!(label, b" : h_"),
&h_bytes,
);
let g1_and_h: Vec<_> = iter::once(g1).chain(h).collect();

Expand Down Expand Up @@ -522,9 +523,9 @@ impl<E: Pairing> SignatureParams23G1<E> {
affine_group_element_from_byte_slices!(label, b" : g1"),
affine_group_element_from_byte_slices!(label, b" : g2"),
{
let h: Vec<_> = n_projective_group_elements::<E::G1Affine, D, _>(
let h: Vec<_> = n_projective_group_elements::<E::G1Affine, D>(
message_count,
concat_slices!(label, b" : h_"),
&concat_slices!(label, b" : h_"),
)
.collect();

Expand Down
4 changes: 2 additions & 2 deletions coconut/src/setup/keypair/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ark_serialize::*;
use ark_std::rand::RngCore;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use utils::{misc::n_bytes_iter, serde_utils::ArkObjectBytes};
use utils::{misc::le_bytes_iter, serde_utils::ArkObjectBytes};
use zeroize::{Zeroize, ZeroizeOnDrop};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<F: PrimeField> SecretKey<F> {
{
let hasher = new_hasher(Self::Y_SALT);

n_bytes_iter(message_count)
le_bytes_iter(message_count)
.map(|ctr| concat_slices!(seed, ctr))
.map(|seed| hasher.hash_to_field(&seed, 1).pop().unwrap())
.collect()
Expand Down
2 changes: 1 addition & 1 deletion coconut/src/setup/signature_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<E: Pairing> SignatureParams<E> {
let (g, g_tilde, h) = join!(
affine_group_element_from_byte_slices!(label, b" : g"),
affine_group_element_from_byte_slices!(label, b" : g_tilde"),
n_affine_group_elements::<_, D, _>(message_count, concat_slices!(label, b" : h_"))
n_affine_group_elements::<_, D>(message_count, &concat_slices!(label, b" : h_"))
.collect()
);

Expand Down
4 changes: 2 additions & 2 deletions delegatable_credentials/src/set_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
util::{generator_pair, generator_pair_deterministic},
};
use dock_crypto_utils::{
ff::powers, hashing_utils::field_elem_from_try_and_incr, misc::n_bytes_iter, msm::WindowTable,
ff::powers, hashing_utils::field_elem_from_try_and_incr, misc::le_bytes_iter, msm::WindowTable,
poly::poly_from_roots, serde_utils::*,
};

Expand Down Expand Up @@ -596,7 +596,7 @@ impl<E: Pairing> AggregateSubsetWitness<E> {
commitments: &[SetCommitment<E>],
subsets: &[BTreeSet<E::ScalarField>],
) -> Vec<E::ScalarField> {
n_bytes_iter(n)
le_bytes_iter(n)
.zip(commitments)
.zip(subsets)
.map(|((ctr_bytes, c), s)| {
Expand Down
21 changes: 11 additions & 10 deletions utils/src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ops::Range;

use crate::{
aliases::{DoubleEndedExactSizeIterator, SendIfParallel, SyncIfParallel},
aliases::{DoubleEndedExactSizeIterator, SendIfParallel},
concat_slices,
hashing_utils::projective_group_elem_from_try_and_incr,
impl_indexed_iter,
Expand Down Expand Up @@ -75,33 +75,34 @@ where
}

/// Produces an iterator emitting `n` items `u32::to_le_bytes` of the counter starting from zero.
pub fn n_bytes_iter(n: u32) -> impl_indexed_iter!(<Item = [u8; 4]>) {
pub fn le_bytes_iter(n: u32) -> impl_indexed_iter!(<Item = [u8; 4]>) {
cfg_into_iter!(0..n).map(u32::to_le_bytes)
}

/// Produces `n` projective group elements by combining the supplied bytes with the `u32::to_le_bytes` counter bytes.
pub fn n_projective_group_elements<G, D, B>(
pub fn n_projective_group_elements<'iter, G, D>(
n: u32,
bytes: B,
) -> impl_indexed_iter!(<Item = G::Group>)
bytes: &'iter [u8],
) -> impl_indexed_iter!(<Item = G::Group> + 'iter)
where
G: AffineRepr + SendIfParallel,
D: Digest,
B: AsRef<[u8]> + SendIfParallel + SyncIfParallel,
{
n_bytes_iter(n).map(move |ctr_bytes| -> G::Group {
le_bytes_iter(n).map(move |ctr_bytes| -> G::Group {
projective_group_elem_from_try_and_incr::<G, D>(&concat_slices!(bytes.as_ref(), ctr_bytes))
})
}

/// Produces `n` affine group elements by combining the supplied bytes with the `u32::to_le_bytes` counter bytes.
pub fn n_affine_group_elements<G, D, B>(n: u32, bytes: B) -> impl_indexed_iter!(<Item = G>)
pub fn n_affine_group_elements<'iter, G, D>(
n: u32,
bytes: &'iter [u8],
) -> impl_indexed_iter!(<Item = G> + 'iter)
where
G: AffineRepr + SendIfParallel,
D: Digest,
B: AsRef<[u8]> + SendIfParallel + SyncIfParallel,
{
n_projective_group_elements::<G, D, B>(n, bytes).map(CurveGroup::into_affine)
n_projective_group_elements::<G, D>(n, bytes).map(CurveGroup::into_affine)
}

/// Generates a random using given `rng`.
Expand Down

0 comments on commit bbbc53b

Please sign in to comment.