jf_crhf/lib.rs
1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6
7//! Trait definition for Collision-resistant hash function (CRHF).
8#![no_std]
9
10use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
11use ark_std::{borrow::Borrow, fmt::Debug, hash::Hash};
12
13/// A trait for CRHF
14/// (based on ark-primitives' definition, but self-declared for minimal
15/// dependency and easier future upgradability.)
16pub trait CRHF {
17 /// Input to the CRHF, allowed to be dynamically sized
18 type Input: ?Sized;
19 /// Output of the CRHF
20 type Output: Clone + PartialEq + Eq + Hash + Debug + CanonicalSerialize + CanonicalDeserialize;
21 /// Error type
22 type Error: ark_std::error::Error;
23
24 /// evaluate inputs and return hash output
25 fn evaluate<T: Borrow<Self::Input>>(input: T) -> Result<Self::Output, Self::Error>;
26}