pub fn verify_zk_proofs(
    epoch: Epoch,
    receiver_fs_public_keys: &BTreeMap<NodeIndex, FsEncryptionPublicKey>,
    public_coefficients: &PublicCoefficientsBytes,
    ciphertexts: &FsEncryptionCiphertext,
    chunking_proof: &ZKProofDec,
    sharing_proof: &ZKProofShare,
    associated_data: &[u8],
) -> Result<(), CspDkgVerifyDealingError> {
    // Conversions
    let public_keys: Result<Vec<miracl::ECP>, CspDkgVerifyDealingError> = receiver_fs_public_keys
        .values()
        .zip(0..)
        .map(|(public_key, receiver_index)| {
            miracl_g1_from_bytes(public_key.as_bytes()).map_err(|parse_error| {
                let error = MalformedPublicKeyError {
                    algorithm: ALGORITHM_ID,
                    key_bytes: Some(public_key.as_bytes()[..].to_vec()),
                    internal_error: format!("{:?}", parse_error),
                };
                CspDkgVerifyDealingError::MalformedFsPublicKeyError {
                    receiver_index,
                    error,
                }
            })
        })
        .collect();
    let public_keys = public_keys?;

    let ciphertext = ciphertext_into_miracl(ciphertexts).map_err(|error| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: error.to_string(),
        })
    })?;

    let tau = Tau::from(epoch);
    crypto::verify_ciphertext_integrity(&ciphertext, &tau.0[..], associated_data, &SYS_PARAMS)
        .map_err(|_| {
            CspDkgVerifyDealingError::InvalidDealingError(InvalidArgumentError {
                message: "Ciphertext integrity check failed".to_string(),
            })
        })?;

    let chunking_proof = chunking_proof_into_miracl(chunking_proof).map_err(|_| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: "Could not parse proof of correct encryption".to_string(),
        })
    })?;

    // Verify proof
    crypto::verify_chunking(
        &crypto::ChunkingInstance {
            g1_gen: miracl::ECP::generator(),
            public_keys: public_keys.clone(),
            ciphertext_chunks: ciphertext.cc.clone(),
            randomizers_r: ciphertext.rr.clone(),
        },
        &chunking_proof,
    )
    .map_err(|_| {
        let error = InvalidArgumentError {
            message: "Invalid chunking proof".to_string(),
        };
        CspDkgVerifyDealingError::InvalidDealingError(error)
    })?;

    // More conversions
    let miracl_public_coefficients =
        public_coefficients_to_miracl(public_coefficients).map_err(|_| {
            CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
                message: "Could not parse public coefficients".to_string(),
            })
        })?;
    let combined_r = util::ecp_from_big_endian_chunks(&ciphertext.rr);
    let combined_ciphertexts: Vec<miracl::ECP> = ciphertext
        .cc
        .iter()
        .map(util::ecp_from_big_endian_chunks)
        .collect();
    let sharing_proof = sharing_proof_into_miracl(sharing_proof).map_err(|_| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: "Could not parse proof of correct sharing".to_string(),
        })
    })?;

    crypto::verify_sharing(
        &crypto::SharingInstance {
            g1_gen: miracl::ECP::generator(),
            g2_gen: miracl::ECP2::generator(),
            public_keys,
            public_coefficients: miracl_public_coefficients,
            combined_randomizer: combined_r,
            combined_ciphertexts,
        },
        &sharing_proof,
    )
    .map_err(|_| {
        let error = InvalidArgumentError {
            message: "Invalid sharing proof".to_string(),
        };
        CspDkgVerifyDealingError::InvalidDealingError(error)
    })
}
/// Verifies zero-knowledge proofs associated to forward-secure encryptions.
///
/// # Errors
/// * `CspDkgVerifyDealingError::MalformedFsPublicKeyError` if any of
///   `receiver_fs_public_keys` is malformed or invalid.
/// * `CspDkgVerifyDealingError::MalformedDealingError` if `ciphertexts` is
///   malformed or invalid.
/// * `CspDkgVerifyDealingError::InvalidDealingError` if the integrity of
///   `ciphertexts` doesn't verify.
/// * `CspDkgVerifyDealingError::MalformedDealingError` if `chunking_proof` is
///   malformed or invalid.
/// * `CspDkgVerifyDealingError::InvalidDealingError` if `chunking_proof`
///   doesn't verify.
/// * `CspDkgVerifyDealingError::MalformedDealingError` if `public_coefficients`
///   is malformed or invalid.
/// * `CspDkgVerifyDealingError::MalformedDealingError` if `sharing_proof` is
///   malformed or invalid.
/// * `CspDkgVerifyDealingError::InvalidDealingError` if `sharing_proof` doesn't
///   verify.
Verifies zero-knowledge proofs associated to forward-secure encryptions.
Verifies zero - knowledge proofs associated to forward - secure encryptions .
pub fn verify_zk_proofs(
    epoch: Epoch,
    receiver_fs_public_keys: &BTreeMap<NodeIndex, FsEncryptionPublicKey>,
    public_coefficients: &PublicCoefficientsBytes,
    ciphertexts: &FsEncryptionCiphertext,
    chunking_proof: &ZKProofDec,
    sharing_proof: &ZKProofShare,
    associated_data: &[u8],
) -> Result<(), CspDkgVerifyDealingError> {
    // Conversions
    let public_keys: Result<Vec<miracl::ECP>, CspDkgVerifyDealingError> = receiver_fs_public_keys
        .values()
        .zip(0..)
        .map(|(public_key, receiver_index)| {
            miracl_g1_from_bytes(public_key.as_bytes()).map_err(|parse_error| {
                let error = MalformedPublicKeyError {
                    algorithm: ALGORITHM_ID,
                    key_bytes: Some(public_key.as_bytes()[..].to_vec()),
                    internal_error: format!("{:?}", parse_error),
                };
                CspDkgVerifyDealingError::MalformedFsPublicKeyError {
                    receiver_index,
                    error,
                }
            })
        })
        .collect();
    let public_keys = public_keys?;
    let ciphertext = ciphertext_into_miracl(ciphertexts).map_err(|error| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: error.to_string(),
        })
    })?;
    let tau = Tau::from(epoch);
    crypto::verify_ciphertext_integrity(&ciphertext, &tau.0[..], associated_data, &SYS_PARAMS)
        .map_err(|_| {
            CspDkgVerifyDealingError::InvalidDealingError(InvalidArgumentError {
                message: "Ciphertext integrity check failed".to_string(),
            })
        })?;
    let chunking_proof = chunking_proof_into_miracl(chunking_proof).map_err(|_| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: "Could not parse proof of correct encryption".to_string(),
        })
    })?;
    // Verify proof
    crypto::verify_chunking(
        &crypto::ChunkingInstance {
            g1_gen: miracl::ECP::generator(),
            public_keys: public_keys.clone(),
            ciphertext_chunks: ciphertext.cc.clone(),
            randomizers_r: ciphertext.rr.clone(),
        },
        &chunking_proof,
    )
    .map_err(|_| {
        let error = InvalidArgumentError {
            message: "Invalid chunking proof".to_string(),
        };
        CspDkgVerifyDealingError::InvalidDealingError(error)
    })?;
    // More conversions
    let miracl_public_coefficients =
        public_coefficients_to_miracl(public_coefficients).map_err(|_| {
            CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
                message: "Could not parse public coefficients".to_string(),
            })
        })?;
    let combined_r = util::ecp_from_big_endian_chunks(&ciphertext.rr);
    let combined_ciphertexts: Vec<miracl::ECP> = ciphertext
        .cc
        .iter()
        .map(util::ecp_from_big_endian_chunks)
        .collect();
    let sharing_proof = sharing_proof_into_miracl(sharing_proof).map_err(|_| {
        CspDkgVerifyDealingError::MalformedDealingError(InvalidArgumentError {
            message: "Could not parse proof of correct sharing".to_string(),
        })
    })?;
    crypto::verify_sharing(
        &crypto::SharingInstance {
            g1_gen: miracl::ECP::generator(),
            g2_gen: miracl::ECP2::generator(),
            public_keys,
            public_coefficients: miracl_public_coefficients,
            combined_randomizer: combined_r,
            combined_ciphertexts,
        },
        &sharing_proof,
    )
    .map_err(|_| {
        let error = InvalidArgumentError {
            message: "Invalid sharing proof".to_string(),
        };
        CspDkgVerifyDealingError::InvalidDealingError(error)
    })
}
pub fn verify_zk_proofs ( epoch : Epoch , receiver_fs_public_keys : & BTreeMap < NodeIndex , FsEncryptionPublicKey > , public_coefficients : & PublicCoefficientsBytes , ciphertexts : & FsEncryptionCiphertext , chunking_proof : & ZKProofDec , sharing_proof : & ZKProofShare , associated_data : & [ u8 ] , ) -> Result < ( ) , CspDkgVerifyDealingError > { // Conversions let public_keys : Result < Vec < miracl :: ECP > , CspDkgVerifyDealingError > = receiver_fs_public_keys . values ( ) . zip ( 0 .. ) . map ( | ( public_key , receiver_index ) | { miracl_g1_from_bytes ( public_key . as_bytes ( ) ) . map_err ( | parse_error | { let error = MalformedPublicKeyError { algorithm : ALGORITHM_ID , key_bytes : Some ( public_key . as_bytes ( ) [ .. ] . to_vec ( ) ) , internal_error : format ! ( " " parse_error ) , } ; CspDkgVerifyDealingError :: MalformedFsPublicKeyError { receiver_index , error , } } ) } ) . collect ( ) ; let public_keys = public_keys ? ; let ciphertext = ciphertext_into_miracl ( ciphertexts ) . map_err ( | error | { CspDkgVerifyDealingError :: MalformedDealingError ( InvalidArgumentError { message : error . to_string ( ) , } ) } ) ? ; let tau = Tau :: from ( epoch ) ; crypto :: verify_ciphertext_integrity ( & ciphertext , & tau . 0 [ .. ] , associated_data , & SYS_PARAMS ) . map_err ( | _ | { CspDkgVerifyDealingError :: InvalidDealingError ( InvalidArgumentError { message : " " . to_string ( ) , } ) } ) ? ; let chunking_proof = chunking_proof_into_miracl ( chunking_proof ) . map_err ( | _ | { CspDkgVerifyDealingError :: MalformedDealingError ( InvalidArgumentError { message : " " . to_string ( ) , } ) } ) ? ; // Verify proof crypto :: verify_chunking ( & crypto :: ChunkingInstance { g1_gen : miracl :: ECP :: generator ( ) , public_keys : public_keys . clone ( ) , ciphertext_chunks : ciphertext . cc . clone ( ) , randomizers_r : ciphertext . rr . clone ( ) , } , & chunking_proof , ) . map_err ( | _ | { let error = InvalidArgumentError { message : " " . to_string ( ) , } ; CspDkgVerifyDealingError :: InvalidDealingError ( error ) } ) ? ; // More conversions let miracl_public_coefficients = public_coefficients_to_miracl ( public_coefficients ) . map_err ( | _ | { CspDkgVerifyDealingError :: MalformedDealingError ( InvalidArgumentError { message : " " . to_string ( ) , } ) } ) ? ; let combined_r = util :: ecp_from_big_endian_chunks ( & ciphertext . rr ) ; let combined_ciphertexts : Vec < miracl :: ECP > = ciphertext . cc . iter ( ) . map ( util :: ecp_from_big_endian_chunks ) . collect ( ) ; let sharing_proof = sharing_proof_into_miracl ( sharing_proof ) . map_err ( | _ | { CspDkgVerifyDealingError :: MalformedDealingError ( InvalidArgumentError { message : " " . to_string ( ) , } ) } ) ? ; crypto :: verify_sharing ( & crypto :: SharingInstance { g1_gen : miracl :: ECP :: generator ( ) , g2_gen : miracl :: ECP2 :: generator ( ) , public_keys , public_coefficients : miracl_public_coefficients , combined_randomizer : combined_r , combined_ciphertexts , } , & sharing_proof , ) . map_err ( | _ | { let error = InvalidArgumentError { message : " " . to_string ( ) , } ; CspDkgVerifyDealingError :: InvalidDealingError ( error ) } ) }
Verifies zero-knowledge proofs associated to forward-secure encryptions.
Verifies zero - knowledge proofs associated to forward - secure encryptions .
epoch
Epoch
receiver_fs_public_keys
&BTreeMap<NodeIndex, FsEncryptionPublicKey>
public_coefficients
&PublicCoefficientsBytes
ciphertexts
&FsEncryptionCiphertext
chunking_proof
&ZKProofDec
sharing_proof
&ZKProofShare
associated_data
&[u8]
epoch
Epoch
receiver_fs_public_keys
&BTreeMap<NodeIndex, FsEncryptionPublicKey>
public_coefficients
&PublicCoefficientsBytes
ciphertexts
&FsEncryptionCiphertext
chunking_proof
&ZKProofDec
sharing_proof
&ZKProofShare
associated_data
&[u8]
errors
`CspDkgVerifyDealingError::MalformedFsPublicKeyError` if any of
`receiver_fs_public_keys` is malformed or invalid.
`CspDkgVerifyDealingError::MalformedDealingError` if `ciphertexts` is
malformed or invalid.
`CspDkgVerifyDealingError::InvalidDealingError` if the integrity of
`ciphertexts` doesn't verify.
`CspDkgVerifyDealingError::MalformedDealingError` if `chunking_proof` is
malformed or invalid.
`CspDkgVerifyDealingError::InvalidDealingError` if `chunking_proof`
doesn't verify.
`CspDkgVerifyDealingError::MalformedDealingError` if `public_coefficients`
is malformed or invalid.
`CspDkgVerifyDealingError::MalformedDealingError` if `sharing_proof` is
malformed or invalid.
`CspDkgVerifyDealingError::InvalidDealingError` if `sharing_proof` doesn't
verify.
` CspDkgVerifyDealingError :: MalformedFsPublicKeyError ` if any of ` receiver_fs_public_keys ` is malformed or invalid . ` CspDkgVerifyDealingError :: MalformedDealingError ` if ` ciphertexts ` is malformed or invalid . ` CspDkgVerifyDealingError :: InvalidDealingError ` if the integrity of ` ciphertexts ` doesn ' t verify . ` CspDkgVerifyDealingError :: MalformedDealingError ` if ` chunking_proof ` is malformed or invalid . ` CspDkgVerifyDealingError :: InvalidDealingError ` if ` chunking_proof ` doesn ' t verify . ` CspDkgVerifyDealingError :: MalformedDealingError ` if ` public_coefficients ` is malformed or invalid . ` CspDkgVerifyDealingError :: MalformedDealingError ` if ` sharing_proof ` is malformed or invalid . ` CspDkgVerifyDealingError :: InvalidDealingError ` if ` sharing_proof ` doesn ' t verify .