mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Add tests and benchmark for MontgomeryPoint.ct_eq().
This commit is contained in:
parent
d39cb275c5
commit
7e4fd5677c
1 changed files with 32 additions and 0 deletions
|
|
@ -425,6 +425,7 @@ impl<'a, 'b> Mul<&'b MontgomeryPoint> for &'a Scalar {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use constants::ED25519_BASEPOINT_TABLE;
|
||||||
use constants::BASE_COMPRESSED_MONTGOMERY;
|
use constants::BASE_COMPRESSED_MONTGOMERY;
|
||||||
use edwards::Identity;
|
use edwards::Identity;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -481,6 +482,26 @@ mod test {
|
||||||
assert_eq!(p.to_montgomery().compress(), q.compress());
|
assert_eq!(p.to_montgomery().compress(), q.compress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn montgomery_ct_eq_ne() {
|
||||||
|
let mut csprng: OsRng = OsRng::new().unwrap();
|
||||||
|
let s1: Scalar = Scalar::random(&mut csprng);
|
||||||
|
let s2: Scalar = Scalar::random(&mut csprng);
|
||||||
|
let p1: MontgomeryPoint = (&s1 * &ED25519_BASEPOINT_TABLE).to_montgomery();
|
||||||
|
let p2: MontgomeryPoint = (&s2 * &ED25519_BASEPOINT_TABLE).to_montgomery();
|
||||||
|
|
||||||
|
assert_eq!(p1.ct_eq(&p2), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn montgomery_ct_eq_eq() {
|
||||||
|
let mut csprng: OsRng = OsRng::new().unwrap();
|
||||||
|
let s1: Scalar = Scalar::random(&mut csprng);
|
||||||
|
let p1: MontgomeryPoint = (&s1 * &ED25519_BASEPOINT_TABLE).to_montgomery();
|
||||||
|
|
||||||
|
assert_eq!(p1.ct_eq(&p1), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn differential_add_matches_edwards_model() {
|
fn differential_add_matches_edwards_model() {
|
||||||
let mut csprng: OsRng = OsRng::new().unwrap();
|
let mut csprng: OsRng = OsRng::new().unwrap();
|
||||||
|
|
@ -532,6 +553,17 @@ mod bench {
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn montgomery_ct_eq(b: &mut Bencher) {
|
||||||
|
let mut csprng: OsRng = OsRng::new().unwrap();
|
||||||
|
let s1: Scalar = Scalar::random(&mut csprng);
|
||||||
|
let s2: Scalar = Scalar::random(&mut csprng);
|
||||||
|
let p1: MontgomeryPoint = (&s1 * &ED25519_BASEPOINT_TABLE).to_montgomery();
|
||||||
|
let p2: MontgomeryPoint = (&s2 * &ED25519_BASEPOINT_TABLE).to_montgomery();
|
||||||
|
|
||||||
|
b.iter(| | p1.ct_eq(&p2))
|
||||||
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn montgomery_decompress(b: &mut Bencher) {
|
fn montgomery_decompress(b: &mut Bencher) {
|
||||||
b.iter(| | BASE_COMPRESSED_MONTGOMERY.decompress());
|
b.iter(| | BASE_COMPRESSED_MONTGOMERY.decompress());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue