Skip to content

Commit

Permalink
Remove clones
Browse files Browse the repository at this point in the history
  • Loading branch information
claucece committed Aug 20, 2024
1 parent 02ad5f0 commit ba97df1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 49 deletions.
4 changes: 2 additions & 2 deletions acl/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ impl<A: ACLConfig> SigSign<A> {
pub fn sign(
pub_key: sw::Affine<A>,
tag_key: sw::Affine<A>,
chall_m: SigChall<A>,
resp_m: SigResp<A>,
chall_m: &SigChall<A>,
resp_m: &SigResp<A>,
message: &str,
) -> SigSign<A> {
let rho = resp_m.r + chall_m.t1;
Expand Down
4 changes: 2 additions & 2 deletions acl/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<A: ACLConfig> SigResp<A> {
/// respond. This function creates the third signature message.
/// # Arguments
/// * `inter` - the intermediate values to use.
pub fn respond(keys: KeyPair<A>, comm_m: SigComm<A>, chall_m: SigChall<A>) -> SigResp<A> {
pub fn respond(keys: &KeyPair<A>, comm_m: &SigComm<A>, chall_m: &SigChall<A>) -> SigResp<A> {
let c = chall_m.e - comm_m.c;
let r = comm_m.u - c * keys.signing_key();

Expand Down Expand Up @@ -225,7 +225,7 @@ impl<A: ACLConfig> SigVerifProof<A> {
transcript.append_message(b"c1", &compressed_bytes[..]);
}

pub fn verify(proof: SigProof<A>, tag_key: sw::Affine<A>, sig_m: &SigSign<A>) -> bool {
pub fn verify(proof: &SigProof<A>, tag_key: sw::Affine<A>, sig_m: &SigSign<A>) -> bool {
// Equality proof of zeta = b_gamma
let rhs1 = (tag_key.mul(proof.pi1.a1)).into_affine();
let rhs2 = (A::GENERATOR.mul(proof.pi1.a1)).into_affine();
Expand Down
12 changes: 6 additions & 6 deletions boomerang/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ impl<B: BoomerangConfig> IssuanceC<B> {
let sig = SigSign::sign(
s_key_pair.s_key_pair.verifying_key,
s_key_pair.s_key_pair.tag_key,
c_m.m3.unwrap().e,
s_m.m4.unwrap().s,
&c_m.m3.unwrap().e,
&s_m.m4.unwrap().s,
"message",
);

Expand Down Expand Up @@ -430,8 +430,8 @@ impl<B: BoomerangConfig> CollectionC<B> {
let sig = SigSign::sign(
s_key_pair.s_key_pair.verifying_key,
s_key_pair.s_key_pair.tag_key,
c_m.m4.unwrap().e,
s_m.m5.unwrap().s,
&c_m.m4.unwrap().e,
&s_m.m5.unwrap().s,
"message",
);

Expand Down Expand Up @@ -761,8 +761,8 @@ impl<B: BoomerangConfig> SpendVerifyC<B> {
let sig = SigSign::sign(
s_key_pair.s_key_pair.verifying_key,
s_key_pair.s_key_pair.tag_key,
c_m.m4.unwrap().e,
s_m.m5.unwrap().s,
&c_m.m4.unwrap().e,
&s_m.m5.unwrap().s,
"message",
);

Expand Down
23 changes: 10 additions & 13 deletions boomerang/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ impl<B: BoomerangConfig> IssuanceS<B> {
s_m: IssuanceS<B>,
key_pair: &ServerKeyPair<B>,
) -> IssuanceS<B> {
let sig_resp = SigResp::respond(
key_pair.s_key_pair.clone(),
s_m.m2.sig_commit,
c_m.m3.unwrap().e,
);
let sig_resp =
SigResp::respond(&key_pair.s_key_pair, &s_m.m2.sig_commit, &c_m.m3.unwrap().e);
let m4 = IssuanceM4 { s: sig_resp };

Self {
Expand Down Expand Up @@ -267,7 +264,7 @@ impl<B: BoomerangConfig> CollectionS<B> {
}

let check2 =
SigVerifProof::verify(c_m.m2.s_proof, key_pair.s_key_pair.tag_key, &c_m.m2.sig);
SigVerifProof::verify(&c_m.m2.s_proof, key_pair.s_key_pair.tag_key, &c_m.m2.sig);
if !check2 {
panic!("Boomerang collection: invalid proof sig");
}
Expand Down Expand Up @@ -355,9 +352,9 @@ impl<B: BoomerangConfig> CollectionS<B> {
key_pair: &ServerKeyPair<B>,
) -> CollectionS<B> {
let sig_resp = SigResp::respond(
key_pair.s_key_pair.clone(),
s_m.m3.clone().unwrap().sig_commit,
c_m.m4.unwrap().e,
&key_pair.s_key_pair,
&s_m.m3.clone().unwrap().sig_commit,
&c_m.m4.unwrap().e,
);
let m5 = CollectionM5 { s: sig_resp };

Expand Down Expand Up @@ -530,7 +527,7 @@ impl<B: BoomerangConfig> SpendVerifyS<B> {
}

let check2 =
SigVerifProof::verify(c_m.m2.s_proof, key_pair.s_key_pair.tag_key, &c_m.m2.sig);
SigVerifProof::verify(&c_m.m2.s_proof, key_pair.s_key_pair.tag_key, &c_m.m2.sig);
if !check2 {
panic!("Boomerang spend-verify: invalid proof sig");
}
Expand Down Expand Up @@ -717,9 +714,9 @@ impl<B: BoomerangConfig> SpendVerifyS<B> {
key_pair: &ServerKeyPair<B>,
) -> SpendVerifyS<B> {
let sig_resp = SigResp::respond(
key_pair.s_key_pair.clone(),
s_m.m3.clone().unwrap().sig_commit,
c_m.m4.unwrap().e,
&key_pair.s_key_pair,
&s_m.m3.as_ref().unwrap().sig_commit,
&c_m.m4.unwrap().e,
);
let m5 = SpendVerifyM5 { s: sig_resp };

Expand Down
26 changes: 10 additions & 16 deletions macros/src/bench_tacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ macro_rules! bench_tacl_respond_time {
// Now we can just benchmark how long it takes to create a new multi proof.
c.bench_function(concat!($curve_name, " acl respond time"), |b| {
b.iter(|| {
ACLSR::respond(kp.clone(), m1.clone(), m2.clone());
ACLSR::respond(&kp, &m1, &m2);
});
});
}
Expand All @@ -100,18 +100,12 @@ macro_rules! bench_tacl_sign_time {
let kp = ACLKP::generate(&mut OsRng);
let m1 = ACLSC::commit(&kp, &mut OsRng, com.comm);
let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");
let m3 = ACLSR::respond(kp.clone(), m1.clone(), m2.clone());
let m3 = ACLSR::respond(&kp, &m1, &m2);

// Now we can just benchmark how long it takes to create a new multi proof.
c.bench_function(concat!($curve_name, " acl sign time"), |b| {
b.iter(|| {
ACLSG::sign(
kp.verifying_key,
kp.tag_key,
m2.clone(),
m3.clone(),
"message",
);
ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
});
});
}
Expand All @@ -136,8 +130,8 @@ macro_rules! bench_tacl_verify_time {
let kp = ACLKP::generate(&mut OsRng);
let m1 = ACLSC::commit(&kp, &mut OsRng, com.comm);
let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");
let m3 = ACLSR::respond(kp.clone(), m1.clone(), m2.clone());
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2.clone(), m3, "message");
let m3 = ACLSR::respond(&kp, &m1, &m2);
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");

// Now we can just benchmark how long it takes to create a new multi proof.
c.bench_function(concat!($curve_name, " acl verify time"), |b| {
Expand Down Expand Up @@ -167,8 +161,8 @@ macro_rules! bench_tacl_sign_proof_time {
let kp = ACLKP::generate(&mut OsRng);
let m1 = ACLSC::commit(&kp, &mut OsRng, com.comm);
let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");
let m3 = ACLSR::respond(kp.clone(), m1.clone(), m2.clone());
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2.clone(), m3, "message");
let m3 = ACLSR::respond(&kp, &m1, &m2);
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
ACLSV::verify(kp.verifying_key, kp.tag_key, &m4, "message");

// Now we can just benchmark how long it takes to create a new multi proof.
Expand Down Expand Up @@ -199,14 +193,14 @@ macro_rules! bench_tacl_sign_verify_time {
let kp = ACLKP::generate(&mut OsRng);
let m1 = ACLSC::commit(&kp, &mut OsRng, com.comm);
let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");
let m3 = ACLSR::respond(kp.clone(), m1.clone(), m2.clone());
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2.clone(), m3, "message");
let m3 = ACLSR::respond(&kp, &m1, &m2);
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
ACLSV::verify(kp.verifying_key, kp.tag_key, &m4, "message");
let proof = ACLSP::prove(&mut OsRng, kp.tag_key, &m4, &vals, &gens.generators, com.r);

// Now we can just benchmark how long it takes to create a new multi proof.
c.bench_function(concat!($curve_name, " acl proof verify time"), |b| {
b.iter(|| ACLSPV::verify(proof.clone(), kp.tag_key, &m4));
b.iter(|| ACLSPV::verify(&proof, kp.tag_key, &m4));
});
}
};
Expand Down
20 changes: 10 additions & 10 deletions macros/src/test_acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ macro_rules! __test_acl {
let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");

// Test the third message of the signature scheme.
let m3 = ACLSR::respond(kp.clone(), m1.clone(), m2);
let m3 = ACLSR::respond(&kp, &m1, &m2);
}

#[test]
Expand Down Expand Up @@ -143,9 +143,9 @@ macro_rules! __test_acl {

let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");

let m3 = ACLSR::respond(kp.clone(), m1, m2.clone());
let m3 = ACLSR::respond(&kp, &m1, &m2);

let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2, m3, "message");
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
assert!(m4.sigma.zeta.is_on_curve());
assert!(m4.sigma.zeta1.is_on_curve());
}
Expand Down Expand Up @@ -179,9 +179,9 @@ macro_rules! __test_acl {

let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");

let m3 = ACLSR::respond(kp.clone(), m1, m2.clone());
let m3 = ACLSR::respond(&kp, &m1, &m2);

let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2, m3, "message");
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
assert!(m4.sigma.zeta.is_on_curve());
assert!(m4.sigma.zeta1.is_on_curve());

Expand Down Expand Up @@ -218,9 +218,9 @@ macro_rules! __test_acl {

let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");

let m3 = ACLSR::respond(kp.clone(), m1, m2.clone());
let m3 = ACLSR::respond(&kp, &m1, &m2);

let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2, m3, "message");
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
assert!(m4.sigma.zeta.is_on_curve());
assert!(m4.sigma.zeta1.is_on_curve());

Expand Down Expand Up @@ -264,9 +264,9 @@ macro_rules! __test_acl {

let m2 = ACLCH::challenge(kp.tag_key, kp.verifying_key, &mut OsRng, m1, "message");

let m3 = ACLSR::respond(kp.clone(), m1, m2.clone());
let m3 = ACLSR::respond(&kp, &m1, &m2);

let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, m2, m3, "message");
let m4 = ACLSG::sign(kp.verifying_key, kp.tag_key, &m2, &m3, "message");
assert!(m4.sigma.zeta.is_on_curve());
assert!(m4.sigma.zeta1.is_on_curve());

Expand All @@ -280,7 +280,7 @@ macro_rules! __test_acl {
assert!(proof.pi1.t2.is_on_curve());
assert!(proof.pi2.t3.is_on_curve());

let check = ACLSPV::verify(proof, kp.tag_key, &m4);
let check = ACLSPV::verify(&proof, kp.tag_key, &m4);
assert!(check == true);
}
};
Expand Down

0 comments on commit ba97df1

Please sign in to comment.