arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/crypto-primitives/src/lib.rs
crypto-primitives/src/lib.rsRaw
 1#[macro_use]
 2extern crate bench_utils;
 3
 4#[macro_use]
 5extern crate derivative;
 6
 7pub mod commitment;
 8pub mod crh;
 9pub mod mht;
10pub mod nizk;
11pub mod prf;
12pub mod signature;
13
14pub use self::{
15    commitment::CommitmentScheme,
16    crh::FixedLengthCRH,
17    mht::{HashMembershipProof, MerkleHashTree},
18    nizk::NIZK,
19    prf::PRF,
20    signature::SignatureScheme,
21};
22
23#[cfg(feature = "r1cs")]
24pub use self::{
25    commitment::CommitmentGadget,
26    crh::FixedLengthCRHGadget,
27    mht::constraints::{MerklePath, MerklePathVerifierGadget},
28    nizk::NIZKVerifierGadget,
29    prf::PRFGadget,
30    signature::SigRandomizePkGadget,
31};
32
33
34pub type Error  = Box<dyn std::error::Error>;
35
36#[derive(Debug)]
37pub enum CryptoError {
38    IncorrectInputLength(usize),
39    NotPrimeOrder,
40}
41
42impl std::fmt::Display for CryptoError {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        let msg = match self {
45            CryptoError::IncorrectInputLength(len) => format!("input length is wrong: {}", len),
46            CryptoError::NotPrimeOrder => "element is not prime order".to_owned(),
47        };
48        write!(f, "{}", msg)
49    }
50}
51
52impl std::error::Error for CryptoError {
53    #[inline]
54    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55        None
56    }
57}