@@ -209,11 +209,11 @@ impl<C: CurveGroup> ShoupVess<C> {
209
209
210
210
// deterministically generate the `i`-th dealing from a random seed
211
211
// each dealing contains (Shamir poly + Feldman commitment + MRE ciphertext)
212
- fn new_dealing (
212
+ fn new_dealing < ' a , I > (
213
213
& self ,
214
214
ith : usize ,
215
215
seed : & [ u8 ; 32 ] ,
216
- recipients : & [ mre :: EncryptionKey < C > ] ,
216
+ recipients : I ,
217
217
aad : & [ u8 ] ,
218
218
) -> Result <
219
219
(
@@ -222,7 +222,11 @@ impl<C: CurveGroup> ShoupVess<C> {
222
222
MultiRecvCiphertext < C , sha2:: Sha256 > ,
223
223
) ,
224
224
VessError ,
225
- > {
225
+ >
226
+ where
227
+ I : IntoIterator < Item = & ' a mre:: EncryptionKey < C > > ,
228
+ I :: IntoIter : ExactSizeIterator ,
229
+ {
226
230
let mut rng = ChaCha20Rng :: from_seed ( * seed) ;
227
231
let vss_secret = C :: ScalarField :: rand ( & mut rng) ;
228
232
@@ -231,7 +235,7 @@ impl<C: CurveGroup> ShoupVess<C> {
231
235
let serialized_shares: Vec < Vec < u8 > > =
232
236
FeldmanVss :: < C > :: compute_serialized_shares ( & self . vss_pp , & poly) . collect ( ) ;
233
237
234
- let mre_ct = mre:: encrypt :: < C , sha2:: Sha256 , _ > (
238
+ let mre_ct = mre:: encrypt :: < C , sha2:: Sha256 , _ , _ > (
235
239
recipients,
236
240
& serialized_shares,
237
241
& self . indexed_aad ( aad, ith) ,
@@ -258,9 +262,9 @@ impl<C: CurveGroup> ShoupVess<C> {
258
262
/// step 1.a is split as two internal steps in the two APIs above. r_k is 32 bytes and
259
263
/// SpongeFish's built-in prover private coin toss.
260
264
/// - random subset seed s: see [`Self::map_subset_seed()`]
261
- pub fn encrypted_shares (
265
+ pub fn encrypted_shares < ' a , I > (
262
266
& self ,
263
- recipients : & [ mre :: EncryptionKey < C > ] ,
267
+ recipients : I ,
264
268
secret : C :: ScalarField ,
265
269
aad : & [ u8 ] ,
266
270
) -> Result <
@@ -269,11 +273,16 @@ impl<C: CurveGroup> ShoupVess<C> {
269
273
<FeldmanVss < C > as VerifiableSecretSharing >:: Commitment ,
270
274
) ,
271
275
VessError ,
272
- > {
273
- // input validation
276
+ >
277
+ where
278
+ I : IntoIterator < Item = & ' a mre:: EncryptionKey < C > > ,
279
+ I :: IntoIter : ExactSizeIterator + Clone + Sync ,
280
+ {
281
+ // input validation - check length without consuming the iterator
282
+ let recipients_iter = recipients. into_iter ( ) ;
274
283
let n = self . vss_pp . n . get ( ) ;
275
- if recipients . len ( ) != n {
276
- return Err ( VessError :: WrongRecipientsLength ( n, recipients . len ( ) ) ) ;
284
+ if recipients_iter . len ( ) != n {
285
+ return Err ( VessError :: WrongRecipientsLength ( n, recipients_iter . len ( ) ) ) ;
277
286
}
278
287
279
288
let mut prover_state = self . io_pattern ( aad) . to_prover_state ( ) ;
@@ -293,7 +302,7 @@ impl<C: CurveGroup> ShoupVess<C> {
293
302
) > = seeds
294
303
. par_iter ( )
295
304
. enumerate ( )
296
- . map ( |( i, r) | self . new_dealing ( i, r, recipients , aad) )
305
+ . map ( |( i, r) | self . new_dealing ( i, r, recipients_iter . clone ( ) , aad) )
297
306
. collect :: < Result < _ , VessError > > ( ) ?;
298
307
299
308
// compute h:= H_compress(aad, dealings)
@@ -392,13 +401,17 @@ impl<C: CurveGroup> ShoupVess<C> {
392
401
393
402
/// Verify if the ciphertext (for all recipients) correctly encrypting valid secret shares,
394
403
/// verifiable by anyone.
395
- pub fn verify (
404
+ pub fn verify < ' a , I > (
396
405
& self ,
397
- recipients : & [ mre :: EncryptionKey < C > ] ,
406
+ recipients : I ,
398
407
ct : & VessCiphertext ,
399
408
comm : & <FeldmanVss < C > as VerifiableSecretSharing >:: Commitment ,
400
409
aad : & [ u8 ] ,
401
- ) -> Result < ( ) , VessError > {
410
+ ) -> Result < ( ) , VessError >
411
+ where
412
+ I : IntoIterator < Item = & ' a mre:: EncryptionKey < C > > + Clone ,
413
+ I :: IntoIter : ExactSizeIterator ,
414
+ {
402
415
let mut verifier_state = self . io_pattern ( aad) . to_verifier_state ( & ct. transcript ) ;
403
416
404
417
// verifier logic until Step 4b
@@ -454,7 +467,8 @@ impl<C: CurveGroup> ShoupVess<C> {
454
467
let seed = seeds
455
468
. pop_front ( )
456
469
. expect ( "subset_size < num_repetitions, so seeds.len() > 0" ) ;
457
- let ( _poly, cm, mre_ct) = self . new_dealing ( i, & seed, recipients, aad) ?;
470
+ let ( _poly, cm, mre_ct) =
471
+ self . new_dealing ( i, & seed, recipients. clone ( ) , aad) ?;
458
472
459
473
hasher. update ( serialize_to_vec ! [ cm] ?) ;
460
474
hasher. update ( mre_ct. to_bytes ( ) ) ;
@@ -703,7 +717,11 @@ mod tests {
703
717
UniformRand ,
704
718
rand:: { SeedableRng , rngs:: StdRng } ,
705
719
} ;
706
- use std:: { collections:: BTreeSet , iter:: repeat_with, num:: NonZeroUsize } ;
720
+ use std:: {
721
+ collections:: { BTreeMap , BTreeSet } ,
722
+ iter:: repeat_with,
723
+ num:: NonZeroUsize ,
724
+ } ;
707
725
708
726
type H = sha2:: Sha256 ;
709
727
type Vss = FeldmanVss < G1Projective > ;
@@ -717,18 +735,23 @@ mod tests {
717
735
repeat_with ( || mre:: DecryptionKey :: rand ( rng) )
718
736
. take ( n)
719
737
. collect ( ) ;
720
- let recv_pks: Vec < mre:: EncryptionKey < G1Projective > > =
721
- recv_sks. iter ( ) . map ( mre:: EncryptionKey :: from) . collect ( ) ;
738
+ let recv_pks: BTreeMap < usize , mre:: EncryptionKey < G1Projective > > = recv_sks
739
+ . iter ( )
740
+ . enumerate ( )
741
+ . map ( |( i, sk) | ( i, mre:: EncryptionKey :: from ( sk) ) )
742
+ . collect ( ) ;
722
743
let labeled_sks: Vec < LabeledDecryptionKey < G1Projective > > = recv_sks
723
744
. into_iter ( )
724
745
. enumerate ( )
725
746
. map ( |( i, sk) | sk. label ( i) )
726
747
. collect ( ) ;
727
748
728
749
let aad = b"Associated data" ;
729
- let ( ct, comm) = vess. encrypted_shares ( & recv_pks, secret, aad) . unwrap ( ) ;
750
+ let ( ct, comm) = vess
751
+ . encrypted_shares ( recv_pks. values ( ) , secret, aad)
752
+ . unwrap ( ) ;
730
753
731
- assert ! ( vess. verify( & recv_pks, & ct, & comm, aad) . is_ok( ) ) ;
754
+ assert ! ( vess. verify( recv_pks. values ( ) , & ct, & comm, aad) . is_ok( ) ) ;
732
755
for labeled_recv_sk in labeled_sks {
733
756
let share = vess. decrypt_share ( & labeled_recv_sk, & ct, aad) . unwrap ( ) ;
734
757
assert ! ( Vss :: verify( & vess. vss_pp, labeled_recv_sk. node_idx, & share, & comm) . is_ok( ) ) ;
0 commit comments