Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add signature scheme abstraction #134

Merged
merged 4 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [\#126](https://github.com/Manta-Network/manta-rs/pull/126) Add ECLAIR v0 scaffolding and deprecate old compiler patterns
- [\#128](https://github.com/Manta-Network/manta-rs/pull/128) Add more parameter loading utilities
- [\#130](https://github.com/Manta-Network/manta-rs/pull/130) Add the sage script and the hardcoded tests for the security of mds matrix
- [\#134](https://github.com/Manta-Network/manta-rs/pull/134) Add signature scheme API and Schnorr signature implementaion

### Changed
- [\#132](https://github.com/Manta-Network/manta-rs/pull/132) Simplify algebra APIs and removing ECC-specific design
Expand Down
63 changes: 56 additions & 7 deletions manta-crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

//! Hash Functions

/// Unary Hash Function
pub trait UnaryHashFunction<COM = ()> {
/// Hash Function
pub trait HashFunction<COM = ()> {
/// Input Type
type Input: ?Sized;

Expand All @@ -28,9 +28,9 @@ pub trait UnaryHashFunction<COM = ()> {
fn hash(&self, input: &Self::Input, compiler: &mut COM) -> Self::Output;
}

impl<H, COM> UnaryHashFunction<COM> for &H
impl<H, COM> HashFunction<COM> for &H
where
H: UnaryHashFunction<COM>,
H: HashFunction<COM>,
{
type Input = H::Input;
type Output = H::Output;
Expand Down Expand Up @@ -76,7 +76,7 @@ pub mod array {
#[cfg(feature = "serde")]
use manta_util::serde::{Deserialize, Serialize};

/// Converts `hasher` from an [`ArrayHashFunction`] into a [`UnaryHashFunction`].
/// Converts `hasher` from an [`ArrayHashFunction`] into a [`HashFunction`].
#[inline]
pub fn as_unary<H, COM>(hasher: H) -> AsUnary<H, COM>
where
Expand Down Expand Up @@ -108,7 +108,7 @@ pub mod array {
where
H: ArrayHashFunction<1, COM>,
{
/// Builds a new [`UnaryHashFunction`] implementation out of an [`ArrayHashFunction`]
/// Builds a new [`HashFunction`] implementation out of an [`ArrayHashFunction`]
/// implementation `hasher`.
#[inline]
pub fn new(hasher: H) -> Self {
Expand All @@ -119,7 +119,7 @@ pub mod array {
}
}

impl<H, COM> UnaryHashFunction<COM> for AsUnary<H, COM>
impl<H, COM> HashFunction<COM> for AsUnary<H, COM>
where
H: ArrayHashFunction<1, COM>,
{
Expand All @@ -132,3 +132,52 @@ pub mod array {
}
}
}

/// Security Assumptions
///
/// The following outlines some standard security assumptions for hash functions. These security
/// properties can be attached to general types that don't exactly conform to the hash function
/// `trait`s to describe the same cryptographic assumptions or guarantees given by the type.
pub mod security {
/// Preimage Resistance
///
/// For a hash function `H` and an output `y`, it should be infeasible to find a preimage `x`
/// such that the following function returns `true`:
///
/// ```text
/// fn is_preimage(x: H::Input, y: H::Output) -> bool {
/// H(x) == h
/// }
/// ```
pub trait PreimageResistance {}

/// Second Preimage Resistance
///
/// For a hash function `H` and an input `x_1`, it should be infeasible to find a another input
/// `x_2` such that the following function returns `true`:
///
/// ```text
/// fn is_collision(x_1: H::Input, x_2: H::Input) -> bool {
/// (x_1 != x_2) && (H(x_1) == H(x_2))
/// }
/// ```
pub trait SecondPreimageResistance {}

/// Collision Resistance
///
/// For a hash function `H` it should be infeasible to find two inputs `x_1` and `x_2` such that
/// the following function returns `true`:
///
/// ```text
/// fn is_collision(x_1: H::Input, x_2: H::Input) -> bool {
/// (x_1 != x_2) && (H(x_1) == H(x_2))
/// }
/// ```
///
/// # Strength
///
/// Note this is a stronger assumption than [`SecondPreimageResistance`] since we are not
/// requiring that the attacker find a second preimage of a given input `x_1`, they only need to
/// find any collision for any input to break this assumption.
pub trait CollisionResistance: SecondPreimageResistance {}
}
1 change: 1 addition & 0 deletions manta-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ pub mod key;
pub mod merkle_tree;
pub mod password;
pub mod rand;
pub mod signature;
Loading