Skip to content

Commit

Permalink
Change field type GxAffine to Gx
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinHon committed Jan 6, 2025
1 parent f4470e2 commit 67ee71a
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 127 deletions.
15 changes: 6 additions & 9 deletions src/automorphic_signature/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ use std::ops::{Add, Mul};

/// Represents a message in the automorphic signatures.
#[derive(Clone, Debug)]
pub struct Message<E: Pairing>(
pub(crate) <E as Pairing>::G1Affine,
pub(crate) <E as Pairing>::G2Affine,
);
pub struct Message<E: Pairing>(pub(crate) <E as Pairing>::G1, pub(crate) <E as Pairing>::G2);

impl<E: Pairing> Message<E> {
pub fn new<G: DHGenerators<E>>(grs: &G, m: E::ScalarField) -> Self {
Self(grs.g().mul(m).into(), grs.h().mul(m).into())
Self(grs.g().mul(m), grs.h().mul(m))
}
}

Expand All @@ -27,30 +24,30 @@ impl<E: Pairing> Add for Message<E> {
type Output = Self;

fn add(self, other: Self) -> Self::Output {
Message((self.0 + other.0).into(), (self.1 + other.1).into())
Message(self.0 + other.0, self.1 + other.1)
}
}

impl<E: Pairing> Add for &Message<E> {
type Output = Message<E>;

fn add(self, other: Self) -> Self::Output {
Message((self.0 + other.0).into(), (self.1 + other.1).into())
Message(self.0 + other.0, self.1 + other.1)
}
}

impl<E: Pairing> Mul<E::ScalarField> for Message<E> {
type Output = Self;

fn mul(self, scalar: E::ScalarField) -> Self {
Self(self.0.mul(scalar).into(), self.1.mul(scalar).into())
Self(self.0.mul(scalar), self.1.mul(scalar))
}
}

impl<E: Pairing> Mul<E::ScalarField> for &Message<E> {
type Output = Message<E>;

fn mul(self, scalar: E::ScalarField) -> Self::Output {
Message(self.0.mul(scalar).into(), self.1.mul(scalar).into())
Message(self.0.mul(scalar), self.1.mul(scalar))
}
}
56 changes: 28 additions & 28 deletions src/automorphic_signature/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ use ark_std::{rand::Rng, UniformRand};
/// The public parameters for the automorphic signatures, Scheme 1.
#[derive(Clone, Debug)]
pub struct Params<E: Pairing> {
pub g: <E as Pairing>::G1Affine,
pub h: <E as Pairing>::G2Affine,
pub g: <E as Pairing>::G1,
pub h: <E as Pairing>::G2,

// additional generators
pub f: <E as Pairing>::G1Affine,
pub k: <E as Pairing>::G1Affine,
pub t: <E as Pairing>::G1Affine,
pub f: <E as Pairing>::G1,
pub k: <E as Pairing>::G1,
pub t: <E as Pairing>::G1,
}

impl<E: Pairing> Params<E> {
pub fn rand<R: Rng>(rng: &mut R) -> Self {
Self {
g: <E as Pairing>::G1Affine::rand(rng),
h: <E as Pairing>::G2Affine::rand(rng),
f: <E as Pairing>::G1Affine::rand(rng),
k: <E as Pairing>::G1Affine::rand(rng),
t: <E as Pairing>::G1Affine::rand(rng),
g: <E as Pairing>::G1::rand(rng),
h: <E as Pairing>::G2::rand(rng),
f: <E as Pairing>::G1::rand(rng),
k: <E as Pairing>::G1::rand(rng),
t: <E as Pairing>::G1::rand(rng),
}
}
}

/// The public parameters for the automorphic signatures, Scheme 2.
pub struct ParamsEx<E: Pairing> {
pub g: <E as Pairing>::G1Affine,
pub h: <E as Pairing>::G2Affine,
pub g: <E as Pairing>::G1,
pub h: <E as Pairing>::G2,

// additional generators
pub f: <E as Pairing>::G1Affine,
pub k: <E as Pairing>::G1Affine,
pub l: <E as Pairing>::G1Affine,
pub t: <E as Pairing>::G1Affine,
pub f: <E as Pairing>::G1,
pub k: <E as Pairing>::G1,
pub l: <E as Pairing>::G1,
pub t: <E as Pairing>::G1,
}

impl<E: Pairing> ParamsEx<E> {
pub fn rand<R: Rng>(rng: &mut R) -> Self {
Self {
g: <E as Pairing>::G1Affine::rand(rng),
h: <E as Pairing>::G2Affine::rand(rng),
f: <E as Pairing>::G1Affine::rand(rng),
k: <E as Pairing>::G1Affine::rand(rng),
l: <E as Pairing>::G1Affine::rand(rng),
t: <E as Pairing>::G1Affine::rand(rng),
g: <E as Pairing>::G1::rand(rng),
h: <E as Pairing>::G2::rand(rng),
f: <E as Pairing>::G1::rand(rng),
k: <E as Pairing>::G1::rand(rng),
l: <E as Pairing>::G1::rand(rng),
t: <E as Pairing>::G1::rand(rng),
}
}
}
Expand All @@ -56,26 +56,26 @@ impl<E: Pairing> ParamsEx<E> {
/// for automorphic signature algorithm. The public parameters
/// ([Params] or [ParamsEx]) implement this trait.
pub trait DHGenerators<E: Pairing> {
fn g(&self) -> <E as Pairing>::G1Affine;
fn h(&self) -> <E as Pairing>::G2Affine;
fn g(&self) -> <E as Pairing>::G1;
fn h(&self) -> <E as Pairing>::G2;
}

impl<E: Pairing> DHGenerators<E> for Params<E> {
fn g(&self) -> <E as Pairing>::G1Affine {
fn g(&self) -> <E as Pairing>::G1 {
self.g
}

fn h(&self) -> <E as Pairing>::G2Affine {
fn h(&self) -> <E as Pairing>::G2 {
self.h
}
}

impl<E: Pairing> DHGenerators<E> for ParamsEx<E> {
fn g(&self) -> <E as Pairing>::G1Affine {
fn g(&self) -> <E as Pairing>::G1 {
self.g
}

fn h(&self) -> <E as Pairing>::G2Affine {
fn h(&self) -> <E as Pairing>::G2 {
self.h
}
}
26 changes: 12 additions & 14 deletions src/automorphic_signature/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<E: Pairing> SigningKey<E> {

/// Get the verifying key from the signing key.
pub fn verifying_key<G: DHGenerators<E>>(&self, grs: &G) -> VerifyingKey<E> {
VerifyingKey(grs.g().mul(self.x).into(), grs.h().mul(self.x).into())
VerifyingKey(grs.g().mul(self.x), grs.h().mul(self.x))
}

/// Signing function `Sign` defined in Scheme 1. Signs on a message (M, N) = (G^m, H^m) in DH.
Expand Down Expand Up @@ -69,20 +69,19 @@ impl<E: Pairing> SigningKey<E> {
&self,
rng: &mut R,
pp: &Params<E>,
m: &<E as Pairing>::G1Affine,
m: &<E as Pairing>::G1,
) -> Signature<E> {
let rand_c = E::ScalarField::rand(rng);
let rand_r = E::ScalarField::rand(rng);

let a = {
let exp = E::ScalarField::one() / (self.x + rand_c);
(pp.k + pp.t.mul(rand_r) + m).mul(exp)
}
.into();
let b = pp.f.mul(rand_c).into();
let d = pp.h.mul(rand_c).into();
let r = pp.g.mul(rand_r).into();
let s = pp.h.mul(rand_r).into();
};
let b = pp.f.mul(rand_c);
let d = pp.h.mul(rand_c);
let r = pp.g.mul(rand_r);
let s = pp.h.mul(rand_r);

Signature { a, b, d, r, s }
}
Expand Down Expand Up @@ -176,12 +175,11 @@ impl<E: Pairing> SigningKey<E> {
let a = {
let exp = E::ScalarField::one() / (self.x + rand_c);
(pp.k + pp.l.mul(v) + pp.t.mul(rand_r) + m).mul(exp)
}
.into();
let b = pp.f.mul(rand_c).into();
let d = pp.h.mul(rand_c).into();
let r = pp.g.mul(rand_r).into();
let s = pp.h.mul(rand_r).into();
};
let b = pp.f.mul(rand_c);
let d = pp.h.mul(rand_c);
let r = pp.g.mul(rand_r);
let s = pp.h.mul(rand_r);

SignatureEx { a, b, d, r, s }
}
Expand Down
20 changes: 10 additions & 10 deletions src/automorphic_signature/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use super::VerifyingKey;
/// Signature created by a signing algorithm in scheme 1.
#[derive(Clone, Debug)]
pub struct Signature<E: Pairing> {
pub(crate) a: <E as Pairing>::G1Affine,
pub(crate) b: <E as Pairing>::G1Affine,
pub(crate) d: <E as Pairing>::G2Affine,
pub(crate) r: <E as Pairing>::G1Affine,
pub(crate) s: <E as Pairing>::G2Affine,
pub(crate) a: <E as Pairing>::G1,
pub(crate) b: <E as Pairing>::G1,
pub(crate) d: <E as Pairing>::G2,
pub(crate) r: <E as Pairing>::G1,
pub(crate) s: <E as Pairing>::G2,
}

/// Signature created by the signing algorithm (that signs two messages) in scheme 1.
Expand All @@ -27,9 +27,9 @@ pub struct Signatures<E: Pairing> {
/// Signature created by a signing algorithm in scheme 2.
#[derive(Clone, Debug)]
pub struct SignatureEx<E: Pairing> {
pub(crate) a: <E as Pairing>::G1Affine,
pub(crate) b: <E as Pairing>::G1Affine,
pub(crate) d: <E as Pairing>::G2Affine,
pub(crate) r: <E as Pairing>::G1Affine,
pub(crate) s: <E as Pairing>::G2Affine,
pub(crate) a: <E as Pairing>::G1,
pub(crate) b: <E as Pairing>::G1,
pub(crate) d: <E as Pairing>::G2,
pub(crate) r: <E as Pairing>::G1,
pub(crate) s: <E as Pairing>::G2,
}
2 changes: 1 addition & 1 deletion src/automorphic_signature/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{message::Message, Params, ParamsEx, Signature, SignatureEx, Signatur

/// Verifying key for the automorphic signatures.
#[derive(Clone, Debug)]
pub struct VerifyingKey<E: Pairing>(pub <E as Pairing>::G1Affine, pub <E as Pairing>::G2Affine);
pub struct VerifyingKey<E: Pairing>(pub <E as Pairing>::G1, pub <E as Pairing>::G2);

impl<E: Pairing> VerifyingKey<E> {
/// Verifying function `Ver` defined in Scheme 1. Verifies a signature on a message (M, N) = (G^m, H^m) in DH.
Expand Down
14 changes: 7 additions & 7 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Commitment<E: Pairing> {
pub(crate) c_q: Com<<E as Pairing>::G2>,
pub(crate) pi_pq: Proof<E>,

pub(crate) u: <E as Pairing>::G1Affine,
pub(crate) u: <E as Pairing>::G1,
pub(crate) pi_u: Proof<E>,
}

Expand All @@ -37,8 +37,8 @@ impl<E: Pairing> Commitment<E> {

let pq = Message::<E>::new(&pp.pps, tau);

let m = Variable::with_randomness(mn.0, mu);
let n = Variable::with_randomness(mn.1, nu);
let m = Variable::with_randomness(mn.0.into(), mu);
let n = Variable::with_randomness(mn.1.into(), nu);
// c_m = Com(ck, M, _)
let c_m = pp.cks.u.commit(&m);
// c_n = Com(ck, N, _)
Expand All @@ -47,8 +47,8 @@ impl<E: Pairing> Commitment<E> {
let equation_dh = equations::equation_dh(pp);
let pi_mn = Proof::new(rng, &pp.cks, &equation_dh, &[m], &[n]);

let p = Variable::with_randomness(pq.0, rho);
let q = Variable::with_randomness(pq.1, sigma);
let p = Variable::with_randomness(pq.0.into(), rho);
let q = Variable::with_randomness(pq.1.into(), sigma);
// c_p = Com(ck, P, _)
let c_p = pp.cks.u.commit(&p);
// c_q = Com(ck, Q, _)
Expand All @@ -58,7 +58,7 @@ impl<E: Pairing> Commitment<E> {
let pi_pq = Proof::new(rng, &pp.cks, &equation_pq, &[p], &[q]);

// u = T^t + M
let u = (pp.pps.t.mul(tau) + m.value).into();
let u = pp.pps.t.mul(tau) + m.value;

// pi_u = Prove(ck, E_u, (M, _), (Q, _))
let equation_u = equations::equation_u(pp, &u);
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<E: Pairing> Commitment<E> {
+ pp.cks.v.commit(&Variable::<_>::with_zero_randomness(
pp.pps.h.mul(scalar_t_prime).into(),
));
let u_prime = (self.u + pp.pps.t.mul(scalar_t_prime)).into();
let u_prime = self.u + pp.pps.t.mul(scalar_t_prime);

// c_m' = RdCom(ck, c_m, _)
// c_n' = RdCom(ck, c_n, _)
Expand Down
Loading

0 comments on commit 67ee71a

Please sign in to comment.