@@ -62,7 +62,7 @@ pub trait VidpfValue: IdpfValue + Clone + Debug + PartialEq + ConstantTimeEq {}
6262/// An instance of the VIDPF.
6363pub struct Vidpf < W : VidpfValue > {
6464 pub ( crate ) bits : u16 ,
65- pub ( crate ) weight_parameter : W :: ValueParameter ,
65+ pub ( crate ) weight_len : W :: ValueParameter ,
6666}
6767
6868impl < W : VidpfValue > Vidpf < W > {
@@ -71,13 +71,10 @@ impl<W: VidpfValue> Vidpf<W> {
7171 /// # Arguments
7272 ///
7373 /// * `bits`, the length of the input in bits.
74- /// * `weight_parameter `, the length of the weight in number of field elements.
75- pub fn new ( bits : usize , weight_parameter : W :: ValueParameter ) -> Result < Self , VidpfError > {
74+ /// * `weight_len `, the length of the weight in number of field elements.
75+ pub fn new ( bits : usize , weight_len : W :: ValueParameter ) -> Result < Self , VidpfError > {
7676 let bits = u16:: try_from ( bits) . map_err ( |_| VidpfError :: BitLengthTooLong ) ?;
77- Ok ( Self {
78- bits,
79- weight_parameter,
80- } )
77+ Ok ( Self { bits, weight_len } )
8178 }
8279
8380 /// Splits an incremental point function `F` into two private keys
@@ -201,7 +198,7 @@ impl<W: VidpfValue> Vidpf<W> {
201198
202199 let mut r = VidpfEvalResult {
203200 state : VidpfEvalState :: init_from_key ( id, key) ,
204- share : W :: zero ( & self . weight_parameter ) , // not used
201+ share : W :: zero ( & self . weight_len ) , // not used
205202 } ;
206203
207204 if input. len ( ) > public. cw . len ( ) {
@@ -247,7 +244,7 @@ impl<W: VidpfValue> Vidpf<W> {
247244 // Convert and correct the payload.
248245 let ( next_seed, w) = self . convert ( seed_keep, ctx, nonce) ;
249246 let mut weight = <W as IdpfValue >:: conditional_select (
250- & <W as IdpfValue >:: zero ( & self . weight_parameter ) ,
247+ & <W as IdpfValue >:: zero ( & self . weight_len ) ,
251248 & cw. weight ,
252249 next_ctrl,
253250 ) ;
@@ -322,7 +319,7 @@ impl<W: VidpfValue> Vidpf<W> {
322319 let mut sub_tree = prefix_tree. root . get_or_insert_with ( || {
323320 Box :: new ( Node :: new ( VidpfEvalResult {
324321 state : VidpfEvalState :: init_from_key ( id, key) ,
325- share : W :: zero ( & self . weight_parameter ) , // not used
322+ share : W :: zero ( & self . weight_len ) , // not used
326323 } ) )
327324 } ) ;
328325
@@ -398,7 +395,7 @@ impl<W: VidpfValue> Vidpf<W> {
398395
399396 let mut next_seed = VidpfSeed :: default ( ) ;
400397 seed_stream. fill_bytes ( & mut next_seed) ;
401- let weight = W :: generate ( & mut seed_stream, & self . weight_parameter ) ;
398+ let weight = W :: generate ( & mut seed_stream, & self . weight_len ) ;
402399 ( next_seed, weight)
403400 }
404401
@@ -527,23 +524,23 @@ impl<W: VidpfValue> Encode for VidpfPublicShare<W> {
527524
528525 fn encoded_len ( & self ) -> Option < usize > {
529526 // We assume the weight has the same length at each level of the tree.
530- let weight_parameter = self
527+ let weight_len = self
531528 . cw
532529 . first ( )
533530 . map_or ( Some ( 0 ) , |cw| cw. weight . encoded_len ( ) ) ?;
534531
535532 let mut len = 0 ;
536533 len += ( 2 * self . cw . len ( ) + 7 ) / 8 ; // packed control bits
537534 len += self . cw . len ( ) * VIDPF_SEED_SIZE ; // seeds
538- len += self . cw . len ( ) * weight_parameter ; // weights
535+ len += self . cw . len ( ) * weight_len ; // weights
539536 len += self . cw . len ( ) * VIDPF_PROOF_SIZE ; // nod proofs
540537 Some ( len)
541538 }
542539}
543540
544541impl < W : VidpfValue > ParameterizedDecode < ( usize , W :: ValueParameter ) > for VidpfPublicShare < W > {
545542 fn decode_with_param (
546- ( bits, weight_parameter ) : & ( usize , W :: ValueParameter ) ,
543+ ( bits, weight_len ) : & ( usize , W :: ValueParameter ) ,
547544 bytes : & mut Cursor < & [ u8 ] > ,
548545 ) -> Result < Self , CodecError > {
549546 let packed_control_len = ( bits + 3 ) / 4 ;
@@ -568,7 +565,7 @@ impl<W: VidpfValue> ParameterizedDecode<(usize, W::ValueParameter)> for VidpfPub
568565 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
569566
570567 // Weights
571- let weights = std:: iter:: repeat_with ( || W :: decode_with_param ( weight_parameter , bytes) )
568+ let weights = std:: iter:: repeat_with ( || W :: decode_with_param ( weight_len , bytes) )
572569 . take ( * bits)
573570 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
574571
@@ -1006,7 +1003,7 @@ mod tests {
10061003 let weight = TestWeight :: from ( vec ! [ 21 . into( ) , 22 . into( ) , 23 . into( ) ] ) ;
10071004 let ( vidpf, public, _, _) = vidpf_gen_setup ( b"some application" , & input, & weight) ;
10081005 for VidpfCorrectionWord { weight, .. } in public. cw {
1009- assert_eq ! ( weight. 0 . len( ) , vidpf. weight_parameter ) ;
1006+ assert_eq ! ( weight. 0 . len( ) , vidpf. weight_len ) ;
10101007 }
10111008 }
10121009 }
0 commit comments