elastic_elgamal/proofs/
mod.rsuse merlin::Transcript;
use core::fmt;
use crate::{
alloc::vec,
group::{Group, RandomBytesProvider},
};
mod commitment;
mod log_equality;
mod mul;
mod possession;
mod range;
mod ring;
pub use self::{
commitment::CommitmentEquivalenceProof,
log_equality::LogEqualityProof,
mul::SumOfSquaresProof,
possession::ProofOfPossession,
range::{PreparedRange, RangeDecomposition, RangeProof},
ring::{RingProof, RingProofBuilder},
};
pub(crate) trait TranscriptForGroup {
fn start_proof(&mut self, proof_label: &'static [u8]);
fn append_element_bytes(&mut self, label: &'static [u8], element_bytes: &[u8]);
fn append_element<G: Group>(&mut self, label: &'static [u8], element: &G::Element);
fn challenge_scalar<G: Group>(&mut self, label: &'static [u8]) -> G::Scalar;
}
impl TranscriptForGroup for Transcript {
fn start_proof(&mut self, proof_label: &'static [u8]) {
self.append_message(b"dom-sep", proof_label);
}
fn append_element_bytes(&mut self, label: &'static [u8], element_bytes: &[u8]) {
self.append_message(label, element_bytes);
}
fn append_element<G: Group>(&mut self, label: &'static [u8], element: &G::Element) {
let mut output = vec![0_u8; G::ELEMENT_SIZE];
G::serialize_element(element, &mut output);
self.append_element_bytes(label, &output);
}
fn challenge_scalar<G: Group>(&mut self, label: &'static [u8]) -> G::Scalar {
G::scalar_from_random_bytes(RandomBytesProvider::new(self, label))
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum VerificationError {
ChallengeMismatch,
LenMismatch {
collection: &'static str,
expected: usize,
actual: usize,
},
}
impl VerificationError {
pub(crate) fn check_lengths(
collection: &'static str,
expected: usize,
actual: usize,
) -> Result<(), Self> {
if expected == actual {
Ok(())
} else {
Err(Self::LenMismatch {
collection,
expected,
actual,
})
}
}
}
impl fmt::Display for VerificationError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ChallengeMismatch => formatter.write_str(
"restored challenge scalar does not match the one provided in the proof",
),
Self::LenMismatch {
collection,
expected,
actual,
} => write!(
formatter,
"number of {collection} ({actual}) differs from expected ({expected})",
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for VerificationError {}