Skip to content

Commit

Permalink
feat(repr)!: switch internal representation to Affine
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrusu authored and dirvine committed Nov 7, 2022
1 parent 73de2a5 commit f52d1f0
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 128 deletions.
28 changes: 14 additions & 14 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ mod public_key_benches {
let pk = sk.public_key();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
let sig = sk.sign(&msg);
let sig = sk.sign(msg);
(pk, msg, sig)
};
b.iter_with_setup(rand_factors, |(pk, msg, sig)| pk.verify(&sig, &msg));
b.iter_with_setup(rand_factors, |(pk, msg, sig)| pk.verify(&sig, msg));
});
}

Expand All @@ -435,11 +435,11 @@ mod public_key_benches {
let pk = sk.public_key();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
let hash = hash_g2(&msg);
let sig = sk.sign_g2(&hash);
let hash = hash_g2(msg);
let sig = sk.sign_g2(hash);
(pk, hash, sig)
};
b.iter_with_setup(rand_factors, |(pk, hash, sig)| pk.verify_g2(&sig, &hash));
b.iter_with_setup(rand_factors, |(pk, hash, sig)| pk.verify_g2(&sig, hash));
});
}

Expand Down Expand Up @@ -471,7 +471,7 @@ mod public_key_benches {
rng.fill_bytes(&mut msg);
(pk, msg)
};
b.iter_with_setup(rand_factors, |(pk, msg)| pk.encrypt(&msg));
b.iter_with_setup(rand_factors, |(pk, msg)| pk.encrypt(msg));
});
}

Expand Down Expand Up @@ -499,7 +499,7 @@ mod secret_key_benches {
rng.fill_bytes(&mut msg);
(sk, msg)
};
b.iter_with_setup(rand_factors, |(sk, msg)| sk.sign(&msg));
b.iter_with_setup(rand_factors, |(sk, msg)| sk.sign(msg));
});
}

Expand All @@ -512,10 +512,10 @@ mod secret_key_benches {
let sk = SecretKey::random();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
let hash = hash_g2(&msg);
let hash = hash_g2(msg);
(sk, hash)
};
b.iter_with_setup(rand_factors, |(sk, hash)| sk.sign_g2(&hash));
b.iter_with_setup(rand_factors, |(sk, hash)| sk.sign_g2(hash));
});
}

Expand All @@ -528,10 +528,10 @@ mod secret_key_benches {
let sk = SecretKey::random();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
let hash = hash_g2(&msg);
let hash = hash_g2(msg);
(sk, hash)
};
b.iter_with_setup(rand_factors, |(sk, hash)| sk.sign_g2(&hash));
b.iter_with_setup(rand_factors, |(sk, hash)| sk.sign_g2(hash));
});
}

Expand All @@ -545,7 +545,7 @@ mod secret_key_benches {
let pk = sk.public_key();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
let ct = pk.encrypt(&msg);
let ct = pk.encrypt(msg);
(sk, ct)
};
b.iter_with_setup(rand_factors, |(sk, ct)| sk.decrypt(&ct));
Expand Down Expand Up @@ -576,7 +576,7 @@ mod ciphertext_benches {
let pk = sk.public_key();
let mut msg = [0u8; 1000];
rng.fill_bytes(&mut msg);
pk.encrypt(&msg)
pk.encrypt(msg)
};
b.iter_with_setup(rand_factors, |ct| ct.verify());
});
Expand Down Expand Up @@ -606,7 +606,7 @@ mod lib_benches {
rng.fill_bytes(&mut msg);
msg
};
b.iter_with_setup(rand_factors, |msg| hash_g2(&msg));
b.iter_with_setup(rand_factors, hash_g2);
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/basic_pkc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
let msg = b"let's get pizza";
let signed_msg = bob.create_signed_msg(msg);
let serialized = serialize(&signed_msg).expect("Failed to serialize `SignedMsg`");
let ciphertext = alice.pk.encrypt(&serialized);
let ciphertext = alice.pk.encrypt(serialized);

// Alice receives Bob's encrypted message. She decrypts the message using her secret key. She
// then verifies that the signature of the plaintext is valid using Bob's public key.
Expand Down
8 changes: 4 additions & 4 deletions src/cmp_pairing.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::cmp::Ordering;

use group::{prime::PrimeCurve, GroupEncoding};
use group::prime::PrimeCurveAffine;

/// Compares two curve elements and returns their `Ordering`.
pub fn cmp_projective<G: PrimeCurve>(x: &G, y: &G) -> Ordering {
let xc = x.to_affine().to_bytes();
let yc = y.to_affine().to_bytes();
pub fn cmp_affine<G: PrimeCurveAffine>(x: &G, y: &G) -> Ordering {
let xc = x.to_bytes();
let yc = y.to_bytes();
xc.as_ref().cmp(yc.as_ref())
}
Loading

0 comments on commit f52d1f0

Please sign in to comment.