You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

5 years ago
5 years ago
  1. #![cfg_attr(not(feature = "std"), no_std)]
  2. #[macro_use]
  3. extern crate bench_utils;
  4. #[macro_use]
  5. extern crate derivative;
  6. #[macro_use]
  7. extern crate alloc;
  8. #[cfg(not(feature = "std"))]
  9. pub(crate) use alloc::{borrow::ToOwned, boxed::Box, vec::Vec};
  10. #[cfg(feature = "std")]
  11. pub(crate) use std::{borrow::ToOwned, boxed::Box, vec::Vec};
  12. pub mod commitment;
  13. pub mod crh;
  14. pub mod merkle_tree;
  15. pub mod nizk;
  16. pub mod prf;
  17. pub mod signature;
  18. pub use self::{
  19. commitment::CommitmentScheme,
  20. crh::FixedLengthCRH,
  21. merkle_tree::{MerkleHashTree, MerkleTreePath},
  22. nizk::NIZK,
  23. prf::PRF,
  24. signature::SignatureScheme,
  25. };
  26. #[cfg(feature = "r1cs")]
  27. pub use self::{
  28. commitment::CommitmentGadget, crh::FixedLengthCRHGadget,
  29. merkle_tree::constraints::MerkleTreePathGadget, nizk::NIZKVerifierGadget, prf::PRFGadget,
  30. signature::SigRandomizePkGadget,
  31. };
  32. pub type Error = Box<dyn algebra_core::Error>;
  33. #[derive(Debug)]
  34. pub enum CryptoError {
  35. IncorrectInputLength(usize),
  36. NotPrimeOrder,
  37. }
  38. impl core::fmt::Display for CryptoError {
  39. fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
  40. let msg = match self {
  41. CryptoError::IncorrectInputLength(len) => format!("input length is wrong: {}", len),
  42. CryptoError::NotPrimeOrder => "element is not prime order".to_owned(),
  43. };
  44. write!(f, "{}", msg)
  45. }
  46. }
  47. impl algebra_core::Error for CryptoError {}