/// Computes combined public coefficients and key shares
Computes combined public coefficients and key shares
Computes combined public coefficients and key shares
pub fn combine_public_coefficients_and_receiver_shares(
            selected_dealer_indices: &[NodeIndex],
            selected_dealings: Vec<CLibDealing>,
            receiver_key_bytes: &[Option<EphemeralPublicKeyBytes>],
        ) -> (PublicCoefficients, Vec<Option<EncryptedShare>>) {
            // The Lagrange coefficients are factors used when combining:
            let lagrange_coefficients = {
                let reshare_x: Vec<ThresholdSecretKey> = selected_dealer_indices
                    .iter()
                    .copied()
                    .map(x_for_index)
                    .collect();
                PublicCoefficients::lagrange_coefficients_at_zero(&reshare_x)
                    .expect("Cannot fail because all x are distinct.")
            };
            // Initial values:
            let mut public_coefficients = PublicCoefficients::zero();
            let mut receiver_data: Vec<Option<EncryptedShare>> = receiver_key_bytes
                .iter()
                .map(|key_maybe| key_maybe.as_ref().map(|_| EncryptedShare::zero()))
                .collect();
            // Combine:
            for (dealing, factor) in selected_dealings.into_iter().zip(lagrange_coefficients) {
                // Aggregate the public coefficients:
                public_coefficients += dealing.public_coefficients * factor;
                // Aggregate the ciphertexts:
                for (accumulator, next) in receiver_data.iter_mut().zip(&dealing.receiver_data) {
                    if let (Some(accumulated_receiver_data), Some(dealing_receiver_data)) =
                        (accumulator.as_mut(), next.as_ref())
                    {
                        accumulated_receiver_data.add_assign(&{
                            let mut x = *dealing_receiver_data;
                            x.mul_assign(&factor);
                            x
                        })
                    }
                }
            }
            (public_coefficients, receiver_data)
        }
pub fn combine_public_coefficients_and_receiver_shares ( selected_dealer_indices : & [ NodeIndex ] , selected_dealings : Vec < CLibDealing > , receiver_key_bytes : & [ Option < EphemeralPublicKeyBytes > ] , ) -> ( PublicCoefficients , Vec < Option < EncryptedShare > > ) { // The Lagrange coefficients are factors used when combining: let lagrange_coefficients = { let reshare_x : Vec < ThresholdSecretKey > = selected_dealer_indices . iter ( ) . copied ( ) . map ( x_for_index ) . collect ( ) ; PublicCoefficients :: lagrange_coefficients_at_zero ( & reshare_x ) . expect ( " " ) } ; // Initial values: let mut public_coefficients = PublicCoefficients :: zero ( ) ; let mut receiver_data : Vec < Option < EncryptedShare > > = receiver_key_bytes . iter ( ) . map ( | key_maybe | key_maybe . as_ref ( ) . map ( | _ | EncryptedShare :: zero ( ) ) ) . collect ( ) ; // Combine: for ( dealing , factor ) in selected_dealings . into_iter ( ) . zip ( lagrange_coefficients ) { // Aggregate the public coefficients: public_coefficients += dealing . public_coefficients * factor ; // Aggregate the ciphertexts: for ( accumulator , next ) in receiver_data . iter_mut ( ) . zip ( & dealing . receiver_data ) { if let ( Some ( accumulated_receiver_data ) , Some ( dealing_receiver_data ) ) = ( accumulator . as_mut ( ) , next . as_ref ( ) ) { accumulated_receiver_data . add_assign ( & { let mut x = * dealing_receiver_data ; x . mul_assign ( & factor ) ; x } ) } } } ( public_coefficients , receiver_data ) }
Computes combined public coefficients and key shares
Computes combined public coefficients and key shares
selected_dealer_indices
&[NodeIndex]
selected_dealings
Vec<CLibDealing>
receiver_key_bytes
&[Option<EphemeralPublicKeyBytes>]