Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
members = [
"h2s2",
]


[workspace.dependencies]
ark-std = "0.5.0"
ark-ec = "0.5.0"
digest = "0.10.7"
19 changes: 19 additions & 0 deletions h2s2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "h2s2"
version = "0.1.0"
authors = [
"Bryan Cole <bryan.cole@semiotic.ai>",
"Severiano Sisneros <severiano@semiotic.ai>",
"Alexis Asseman <alexis@semiotic.ai>",
"Tomasz Kornuta <tomasz@semiotic.ai>",
]
license = "Apache-2.0"
description = ""
edition = "2021"
keywords = ["holographic", "homomorphic", "signature-scheme"]
catagories = ["cryptography", "cryptography::cryptocurrencies"]

[dependencies]
ark-ec = {workspace = true}
ark-std = { workspace = true}
digest = { workspace = true}
64 changes: 64 additions & 0 deletions h2s2/src/holographic_homomorphic_signature_scheme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use ark_std::UniformRand;
use ark_std::Zero;
use std::error::Error;
use ark_ec::pairing::Pairing;
use ark_ec::AffineRepr;
use ark_std::{marker::PhantomData, rand::Rng};
use digest::Digest;
use std::ops::MulAssign;

pub trait HolographicHomomorphicSignatureScheme<P: Pairing, D: Digest + Send + Sync> {
type Parameters;
type PublicKey;
type SecretKey;
type Signature;
type Message;
type Weight;

/// Generate one G2 element and `n` G1 elements
fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Box<dyn Error>>;

/// Generate hash aggregate (H_a) with `tag` and `n` lanes
fn precompute(tag: &[u8], n: usize) -> Result<P::G1, Box<dyn Error>>;

/// Generate private and public receipt keys using `pp` parameters from `setup`
fn keygen<R: Rng>(
pp: &Self::Parameters,
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey), Box<dyn Error>>;

/// Sign `message` with `tag` at `index`
fn sign(
pp: &Self::Parameters,
sk: &Self::SecretKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
) -> Result<Self::Signature, Box<dyn Error>>;

/// Verify a single `signature` matches `message` with `tag` at `index` using `pp` parameter and `pk` public key
fn verify(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
signature: &Self::Signature,
) -> Result<bool, Box<dyn Error>>;

/// Verify aggregate `signature` matches `message_aggregate` with `tag` and `hash_aggregate` using `pp` parameter and `pk` public key
fn verify_aggregate(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
message_aggregate: &[Self::Message],
hash_aggregate: &P::G1,
signature: &Self::Signature,
) -> Result<bool, Box<dyn Error>>;

/// Aggregate `signatures` with `weights`
fn evaluate(
signatures: &[Self::Signature],
weights: &[Self::Weight],
) -> Result<Self::Signature, Box<dyn Error>>;
}
2 changes: 2 additions & 0 deletions h2s2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod holographic_homomorphic_signature_scheme;
pub mod nc1;
89 changes: 89 additions & 0 deletions h2s2/src/nc1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

use ark_std::UniformRand;
use ark_std::Zero;
use std::error::Error;
use ark_ec::pairing::Pairing;
use ark_ec::AffineRepr;
use ark_std::{marker::PhantomData, rand::Rng};
use digest::Digest;
use std::ops::MulAssign;

use crate::holographic_homomorphic_signature_scheme::HolographicHomomorphicSignatureScheme;

pub struct NC1<P: Pairing, D: Digest> {
_pairing: PhantomData<P>,
_hash: PhantomData<D>,
}


#[derive(Clone)]
pub struct H2S2Parameters<P: Pairing> {
pub g1_generators: Vec<P::G1>,
pub g2_generator: P::G2,
}

impl<P: Pairing, D: Digest + Send + Sync> HolographicHomomorphicSignatureScheme<P, D> for NC1<P, D> {
type Parameters = H2S2Parameters<P>;
type PublicKey = P::G2;
type SecretKey = P::ScalarField;
type Signature = P::G1;
type Message = P::ScalarField;
type Weight = usize;

fn setup<R: Rng>(rng: &mut R, n: usize) -> Result<Self::Parameters, Box<dyn Error>> {
Ok(H2S2Parameters {
g1_generators: vec![P::G1::rand(rng); n],
g2_generator: P::G2::rand(rng),
})
}

fn precompute(tag: &[u8], n: usize) -> Result<P::G1, Box<dyn Error>> {
Ok(P::G1::default())
}

fn keygen<R: Rng>(
pp: &Self::Parameters,
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey), Box<dyn Error>> {
Ok((P::G2::rand(rng), P::ScalarField::rand(rng)))
}

fn sign(
pp: &Self::Parameters,
sk: &Self::SecretKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
) -> Result<Self::Signature, Box<dyn Error>> {
Ok(P::G1::default())
}

fn verify(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
index: &[u8],
message: &[Self::Message],
signature: &Self::Signature,
) -> Result<bool, Box<dyn Error>> {
Ok(true)
}

fn verify_aggregate(
pp: &Self::Parameters,
pk: &Self::PublicKey,
tag: &[u8],
message_aggregate: &[Self::Message],
hash_aggregate: &P::G1,
signature: &Self::Signature,
) -> Result<bool, Box<dyn Error>> {
Ok(true)
}

fn evaluate(
signatures: &[Self::Signature],
weights: &[Self::Weight],
) -> Result<Self::Signature, Box<dyn Error>> {
Ok(P::G1::default())
}
}