@@ -63,6 +63,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
6363
6464use core:: iter:: once;
6565use dock_crypto_utils:: {
66+ affine_group_from_slices,
6667 concat_slices, hashing_utils:: projective_group_elem_from_try_and_incr, iter:: * ,
6768 misc:: seq_pairs_satisfy, serde_utils:: * , try_iter:: CheckLeft ,
6869} ;
@@ -244,21 +245,19 @@ macro_rules! impl_sig_params {
244245 /// Generate params by hashing a known string. The hash function is vulnerable to timing
245246 /// attack but since all this is public knowledge, it is fine.
246247 /// This is useful if people need to be convinced that the discrete log of group elements wrt each other is not known.
247- pub fn new<D : Digest >( label: & [ u8 ] , message_count: usize ) -> Self {
248+ pub fn new<D : Digest >( label: & [ u8 ] , message_count: u32 ) -> Self {
248249 assert_ne!( message_count, 0 ) ;
249250 // Need message_count+2 elements of signature group and 1 element of other group
250- let mut sig_group_elems = Vec :: with_capacity( message_count + 2 ) ;
251+ let mut sig_group_elems = Vec :: with_capacity( message_count as usize + 2 ) ;
251252 // Group element by hashing `label`||`g1` as string.
252253 let g1 = projective_group_elem_from_try_and_incr:: <E :: $group_affine, D >(
253254 & concat_slices![ label, b" : g1" ] ,
254255 ) ;
255256 // h_0 and h[i] for i in 1 to message_count
256257 let mut h = cfg_into_iter!( ( 0 ..=message_count) )
257- . map( |i| {
258- projective_group_elem_from_try_and_incr:: <E :: $group_affine, D >(
259- & concat_slices![ label, b" : h_" , ( i as u32 ) . to_le_bytes( ) ] ,
260- )
261- } )
258+ . map( u32 :: to_le_bytes)
259+ . map( |i| affine_group_from_slices!( label, b" : h_" , i) )
260+ . map( E :: $group_affine:: into)
262261 . collect:: <Vec <E :: $group_projective>>( ) ;
263262 sig_group_elems. push( g1) ;
264263 sig_group_elems. append( & mut h) ;
@@ -268,10 +267,8 @@ macro_rules! impl_sig_params {
268267 let g1 = sig_group_elems. remove( 0 ) ;
269268 let h_0 = sig_group_elems. remove( 0 ) ;
270269
271- let g2 = projective_group_elem_from_try_and_incr:: <E :: $other_group_affine, D >(
272- & concat_slices![ label, b" : g2" ] ,
273- )
274- . into_affine( ) ;
270+ let g2: E :: $other_group_affine = affine_group_from_slices!( label, b" : g2" ) ;
271+
275272 Self {
276273 g1,
277274 g2,
@@ -281,7 +278,7 @@ macro_rules! impl_sig_params {
281278 }
282279
283280 /// Generate params using a random number generator
284- pub fn generate_using_rng<R >( rng: & mut R , message_count: usize ) -> Self
281+ pub fn generate_using_rng<R >( rng: & mut R , message_count: u32 ) -> Self
285282 where
286283 R : RngCore ,
287284 {
@@ -516,7 +513,7 @@ impl<E: Pairing> SignatureParams23G1<E> {
516513 /// Generate params by hashing a known string. The hash function is vulnerable to timing
517514 /// attack but since all this is public knowledge, it is fine.
518515 /// This is useful if people need to be convinced that the discrete log of group elements wrt each other is not known.
519- pub fn new < D : Digest > ( label : & [ u8 ] , message_count : usize ) -> Self {
516+ pub fn new < D : Digest > ( label : & [ u8 ] , message_count : u32 ) -> Self {
520517 assert_ne ! ( message_count, 0 ) ;
521518 // Group element by hashing `label`||`g1` as string.
522519 let g1 = projective_group_elem_from_try_and_incr :: < E :: G1Affine , D > ( & concat_slices ! [
@@ -545,7 +542,7 @@ impl<E: Pairing> SignatureParams23G1<E> {
545542 }
546543
547544 /// Generate params using a random number generator
548- pub fn generate_using_rng < R > ( rng : & mut R , message_count : usize ) -> Self
545+ pub fn generate_using_rng < R > ( rng : & mut R , message_count : u32 ) -> Self
549546 where
550547 R : RngCore ,
551548 {
@@ -636,7 +633,7 @@ mod tests {
636633 let label_1 = "test1" . as_bytes( ) ;
637634 let params_1 = $params:: <Bls12_381 >:: new:: <Blake2b512 >( & label_1, $message_count) ;
638635 assert!( params_1. is_valid( ) ) ;
639- assert_eq!( params_1. h. len( ) , $message_count) ;
636+ assert_eq!( params_1. h. len( ) , $message_count as usize ) ;
640637
641638 // Same label should generate same params
642639 let params_1_again = $params:: <Bls12_381 >:: new:: <Blake2b512 >( & label_1, $message_count) ;
0 commit comments