Skip to content

Commit

Permalink
Change point generator to accept range and properly fix issue from pr…
Browse files Browse the repository at this point in the history
…evious commit

Signed-off-by: lovesh <[email protected]>
  • Loading branch information
lovesh committed Sep 7, 2023
1 parent de8eb14 commit f00a481
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 4 additions & 6 deletions bbs_plus/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ macro_rules! impl_sig_params {
&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
// h_i for i in 0 to message_count
let h = n_projective_group_elements::<E::$group_affine, D>(
1 + message_count,
0..message_count + 1,
&h_bytes,
);
let g1_and_h: Vec<_> = iter::once(g1).chain(h).collect();
Expand Down Expand Up @@ -523,13 +523,11 @@ impl<E: Pairing> SignatureParams23G1<E> {
affine_group_element_from_byte_slices!(label, b" : g1"),
affine_group_element_from_byte_slices!(label, b" : g2"),
{
let mut h: Vec<_> = n_projective_group_elements::<E::G1Affine, D>(
1 + message_count,
let h: Vec<_> = n_projective_group_elements::<E::G1Affine, D>(
1..message_count + 1,
&concat_slices!(label, b" : h_"),
)
.collect();
// TODO: Fix me by making above point generator accept a range
h.remove(0);
E::G1::normalize_batch(&h)
}
);
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>(0..message_count, &concat_slices!(label, b" : h_"))
.collect()
);

Expand Down
17 changes: 12 additions & 5 deletions utils/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,30 @@ 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.
/// Produces an iterator of little endian bytes of each element contained in the range `counter_range`
pub fn le_bytes_iter_from_given_range(
counter_range: Range<u32>,
) -> impl_indexed_iter!(<Item = [u8; 4]>) {
cfg_into_iter!(counter_range).map(u32::to_le_bytes)
}

/// Produces an iterator of projective group elements created by hashing a label and a counter in the range `counter_range`
pub fn n_projective_group_elements<'iter, G, D>(
n: u32,
counter_range: Range<u32>,
bytes: &'iter [u8],
) -> impl_indexed_iter!(<Item = G::Group> + 'iter)
where
G: AffineRepr + SendIfParallel,
D: Digest,
{
le_bytes_iter(n).map(move |ctr_bytes| -> G::Group {
le_bytes_iter_from_given_range(counter_range).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.
/// Produces an iterator affine group elements created by hashing a label and a counter in the range `counter_range`
pub fn n_affine_group_elements<'iter, G, D>(
n: u32,
n: Range<u32>,
bytes: &'iter [u8],
) -> impl_indexed_iter!(<Item = G> + 'iter)
where
Expand Down

0 comments on commit f00a481

Please sign in to comment.