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