@@ -246,22 +246,39 @@ fn combine_shares(shares: &[SSKRShare]) -> Result<Secret, SSKRError> {
246
246
}
247
247
}
248
248
249
+ // Check that we have enough groups to recover the master secret
249
250
if next_group < group_threshold {
250
251
return Err ( SSKRError :: NotEnoughGroups ) ;
251
252
}
252
253
253
- // here , all of the shares are unpacked into member groups. Now we go through each
254
+ // Here , all of the shares are unpacked into member groups. Now we go through each
254
255
// group and recover the group secret, and then use the result to recover the
255
256
// master secret
256
257
let mut master_indexes = Vec :: with_capacity ( 16 ) ;
257
258
let mut master_shares = Vec :: with_capacity ( 16 ) ;
258
259
259
260
for group in groups {
260
- let group_secret = recover_secret ( & group. member_indexes , & group. member_shares ) ?;
261
- master_indexes. push ( group. group_index ) ;
262
- master_shares. push ( group_secret) ;
261
+ // Only attempt to recover the group secret if we have enough shares
262
+ if group. member_indexes . len ( ) < group. member_threshold {
263
+ continue ;
264
+ }
265
+ // Recover the group secret
266
+ if let Ok ( group_secret) = recover_secret ( & group. member_indexes , & group. member_shares ) {
267
+ master_indexes. push ( group. group_index ) ;
268
+ master_shares. push ( group_secret) ;
269
+ }
270
+ // Stop if we have enough groups to recover the master secret
271
+ if master_indexes. len ( ) == group_threshold {
272
+ break ;
273
+ }
274
+ }
275
+
276
+ // If we don't have enough groups to recover the master secret, return an error
277
+ if master_indexes. len ( ) < group_threshold {
278
+ return Err ( SSKRError :: NotEnoughGroups ) ;
263
279
}
264
280
281
+ // Recover the master secret
265
282
let master_secret = recover_secret ( & master_indexes, & master_shares) ?;
266
283
let master_secret = Secret :: new ( master_secret) ?;
267
284
0 commit comments