fn generate_shares<R: RngCore + CryptoRng>(
    secret: &Secret,
    numshares: u32,
    threshold: u32,
    mut rng: R,
) -> Result<Vec<Share>, &'static str> {
    if threshold < 1 {
        return Err("Threshold cannot be 0");
    }

    if numshares < 1 {
        return Err("Number of shares cannot be 0");
    }

    if threshold > numshares {
        return Err("Threshold cannot exceed numshares");
    }

    let numcoeffs = threshold - 1;

    let mut coefficients: Vec<Scalar> = Vec::with_capacity(threshold as usize);

    let mut shares: Vec<Share> = Vec::with_capacity(numshares as usize);

    let mut commitment: ShareCommitment = ShareCommitment(Vec::with_capacity(threshold as usize));

    for _ in 0..numcoeffs {
        let mut bytes = [0; 64];
        rng.fill_bytes(&mut bytes);
        coefficients.push(Scalar::from_bytes_wide(&bytes));
    }

    // Verifiable secret sharing, to make sure that participants can ensure their secret is consistent
    // with every other participant's.
    commitment
        .0
        .push(Commitment(SpendAuth::basepoint() * secret.0));

    for c in &coefficients {
        commitment.0.push(Commitment(SpendAuth::basepoint() * c));
    }

    // Evaluate the polynomial with `secret` as the constant term
    // and `coeffs` as the other coefficients at the point x=share_index,
    // using Horner's method.
    for index in 1..numshares + 1 {
        let scalar_index = Scalar::from(index as u64);
        let mut value = Scalar::zero();

        // Polynomial evaluation, for this index
        for i in (0..numcoeffs).rev() {
            value += &coefficients[i as usize];
            value *= scalar_index;
        }
        value += secret.0;

        shares.push(Share {
            receiver_index: index,
            value: Secret(value),
            commitment: commitment.clone(),
        });
    }

    Ok(shares)
}
/// Creates secret shares for a given secret.
///
/// This function accepts a secret from which shares are generated. While in
/// FROST this secret should always be generated randomly, we allow this secret
/// to be specified for this internal function for testability.
///
/// Internally, [`generate_shares`] performs verifiable secret sharing, which
/// generates shares via Shamir Secret Sharing, and then generates public
/// commitments to those shares.
///
/// More specifically, [`generate_shares`]:
/// - Randomly samples of coefficents [a, b, c], this represents a secret
/// polynomial f
/// - For each participant i, their secret share is f(i)
/// - The commitment to the secret polynomial f is [g^a, g^b, g^c]
Creates secret shares for a given secret.
This function accepts a secret from which shares are generated. While in
FROST this secret should always be generated randomly, we allow this secret
to be specified for this internal function for testability.

Internally, [`generate_shares`] performs verifiable secret sharing, which
generates shares via Shamir Secret Sharing, and then generates public
commitments to those shares.

More specifically, [`generate_shares`]:
Randomly samples of coefficents [a, b, c], this represents a secret
polynomial f
For each participant i, their secret share is f(i)
The commitment to the secret polynomial f is [g^a, g^b, g^c]
Creates secret shares for a given secret . This function accepts a secret from which shares are generated . While in FROST this secret should always be generated randomly we allow this secret to be specified for this internal function for testability . Internally [ ` generate_shares ` ] performs verifiable secret sharing which generates shares via Shamir Secret Sharing and then generates public commitments to those shares . More specifically [ ` generate_shares ` ] : Randomly samples of coefficents [ a b c ] this represents a secret polynomial f For each participant i their secret share is f ( i ) The commitment to the secret polynomial f is [ g^a g^b g^c ]
fn generate_shares<R: RngCore + CryptoRng>(
    secret: &Secret,
    numshares: u32,
    threshold: u32,
    mut rng: R,
) -> Result<Vec<Share>, &'static str> {
    if threshold < 1 {
        return Err("Threshold cannot be 0");
    }
    if numshares < 1 {
        return Err("Number of shares cannot be 0");
    }
    if threshold > numshares {
        return Err("Threshold cannot exceed numshares");
    }
    let numcoeffs = threshold - 1;
    let mut coefficients: Vec<Scalar> = Vec::with_capacity(threshold as usize);
    let mut shares: Vec<Share> = Vec::with_capacity(numshares as usize);
    let mut commitment: ShareCommitment = ShareCommitment(Vec::with_capacity(threshold as usize));
    for _ in 0..numcoeffs {
        let mut bytes = [0; 64];
        rng.fill_bytes(&mut bytes);
        coefficients.push(Scalar::from_bytes_wide(&bytes));
    }
    // Verifiable secret sharing, to make sure that participants can ensure their secret is consistent
    // with every other participant's.
    commitment
        .0
        .push(Commitment(SpendAuth::basepoint() * secret.0));
    for c in &coefficients {
        commitment.0.push(Commitment(SpendAuth::basepoint() * c));
    }
    // Evaluate the polynomial with `secret` as the constant term
    // and `coeffs` as the other coefficients at the point x=share_index,
    // using Horner's method.
    for index in 1..numshares + 1 {
        let scalar_index = Scalar::from(index as u64);
        let mut value = Scalar::zero();
        // Polynomial evaluation, for this index
        for i in (0..numcoeffs).rev() {
            value += &coefficients[i as usize];
            value *= scalar_index;
        }
        value += secret.0;
        shares.push(Share {
            receiver_index: index,
            value: Secret(value),
            commitment: commitment.clone(),
        });
    }
    Ok(shares)
}
fn generate_shares < R : RngCore + CryptoRng > ( secret : & Secret , numshares : u32 , threshold : u32 , mut rng : R , ) -> Result < Vec < Share > , & ' static str > { if threshold < 1 { return Err ( " " ) ; } if numshares < 1 { return Err ( " " ) ; } if threshold > numshares { return Err ( " " ) ; } let numcoeffs = threshold - 1 ; let mut coefficients : Vec < Scalar > = Vec :: with_capacity ( threshold as usize ) ; let mut shares : Vec < Share > = Vec :: with_capacity ( numshares as usize ) ; let mut commitment : ShareCommitment = ShareCommitment ( Vec :: with_capacity ( threshold as usize ) ) ; for _ in 0 .. numcoeffs { let mut bytes = [ 0 ; 64 ] ; rng . fill_bytes ( & mut bytes ) ; coefficients . push ( Scalar :: from_bytes_wide ( & bytes ) ) ; } // Verifiable secret sharing, to make sure that participants can ensure their secret is consistent // with every other participant's. commitment . 0 . push ( Commitment ( SpendAuth :: basepoint ( ) * secret . 0 ) ) ; for c in & coefficients { commitment . 0 . push ( Commitment ( SpendAuth :: basepoint ( ) * c ) ) ; } // Evaluate the polynomial with `secret` as the constant term // and `coeffs` as the other coefficients at the point x=share_index, // using Horner's method. for index in 1 .. numshares + 1 { let scalar_index = Scalar :: from ( index as u64 ) ; let mut value = Scalar :: zero ( ) ; // Polynomial evaluation, for this index for i in ( 0 .. numcoeffs ) . rev ( ) { value += & coefficients [ i as usize ] ; value *= scalar_index ; } value += secret . 0 ; shares . push ( Share { receiver_index : index , value : Secret ( value ) , commitment : commitment . clone ( ) , } ) ; } Ok ( shares ) }
Creates secret shares for a given secret.
Creates secret shares for a given secret .
secret
&Secret
numshares
u32
threshold
u32
rng
R