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::{MerkleTree, Path},
29 nizk::NIZK,
30 prf::PRF,
31 signature::SignatureScheme,
32};
33
34#[cfg(feature = "r1cs")]
35#[cfg(feature = "r1cs")]
36pub use self::{
37 commitment::CommitmentGadget, crh::FixedLengthCRHGadget, merkle_tree::constraints::PathVar,
38 nizk::NIZKVerifierGadget, prf::PRFGadget, signature::SigRandomizePkGadget,
39};
40
41pub type Error = Box<dyn algebra_core::Error>;
42
43#[derive(Debug)]
44pub enum CryptoError {
45 IncorrectInputLength(usize),
46 NotPrimeOrder,
47}
48
49impl core::fmt::Display for CryptoError {
50 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
51 let msg = match self {
52 CryptoError::IncorrectInputLength(len) => format!("input length is wrong: {}", len),
53 CryptoError::NotPrimeOrder => "element is not prime order".to_owned(),
54 };
55 write!(f, "{}", msg)
56 }
57}
58
59impl algebra_core::Error for CryptoError {}