diff --git a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs index 014a13b0..f9320f12 100644 --- a/src/cryptographic_primitives/secret_sharing/feldman_vss.rs +++ b/src/cryptographic_primitives/secret_sharing/feldman_vss.rs @@ -7,6 +7,7 @@ */ use std::convert::{TryFrom, TryInto}; +use std::num::NonZeroU16; use std::{fmt, ops}; use serde::{Deserialize, Serialize}; @@ -102,18 +103,24 @@ impl VerifiableSS { ) } - // generate VerifiableSS from a secret and user defined x values (in case user wants to distribute point f(1), f(4), f(6) and not f(1),f(2),f(3)) - pub fn share_at_indices( + /// generate VerifiableSS from a secret and user defined x values (in case user wants to distribute point f(1), f(4), f(6) and not f(1),f(2),f(3)) + /// NOTE: The caller should make sure that `t`, `n` and the contents of `index_vec` can't be controlled by a malicious party. + pub fn share_at_indices( t: u16, n: u16, secret: &Scalar, - index_vec: &[u16], - ) -> (VerifiableSS, SecretShares) { - assert_eq!(usize::from(n), index_vec.len()); + indicies: I, + ) -> (VerifiableSS, SecretShares) + where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + { + let indicies = indicies.into_iter(); + assert_eq!(usize::from(n), indicies.len()); let polynomial = Polynomial::::sample_exact_with_fixed_const_term(t, secret.clone()); let shares = polynomial - .evaluate_many_bigint(index_vec.iter().cloned()) + .evaluate_many_bigint(indicies.map(NonZeroU16::get)) .collect(); let g = Point::::generator(); @@ -286,8 +293,12 @@ mod tests { fn test_secret_sharing_3_out_of_5_at_indices() { let secret = Scalar::random(); let parties = [1, 2, 4, 5, 6]; - let (vss_scheme, secret_shares) = - VerifiableSS::::share_at_indices(3, 5, &secret, &parties); + let (vss_scheme, secret_shares) = VerifiableSS::::share_at_indices( + 3, + 5, + &secret, + parties.iter().map(|&v| NonZeroU16::new(v).unwrap()), + ); let shares_vec = vec![ secret_shares[0].clone(),