make edwards an optional feature, and separate benches
This commit is contained in:
parent
28f58d7222
commit
3c61f6f043
5 changed files with 59 additions and 39 deletions
|
|
@ -8,7 +8,12 @@ crypto-bigint = { version = "0.6.1" }
|
|||
|
||||
[features]
|
||||
rand = ["crypto-bigint/rand"]
|
||||
edwards = []
|
||||
|
||||
[[bench]]
|
||||
name = "benchmarks"
|
||||
path = "bench/bench.rs"
|
||||
name = "montgomery"
|
||||
path = "bench/montgomery.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "edwards"
|
||||
path = "bench/edwards.rs"
|
||||
|
|
|
|||
48
bench/edwards.rs
Normal file
48
bench/edwards.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#![cfg(feature = "edwards")]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
mod benches {
|
||||
use test::{black_box, Bencher};
|
||||
use crypto_bigint::U448;
|
||||
use diffie_hellman::edwards::{ed448_clamp, ED448_GOLDILOCKS};
|
||||
use diffie_hellman::traits::{Curve, Point};
|
||||
|
||||
#[bench]
|
||||
fn edwards_point_add(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.generator();
|
||||
let q = p.double();
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.add(&q, &p))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn edwards_point_double(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.generator();
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.double())
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn edwards_ladder(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.point(U448::from_u32(123456789));
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.ladder(&ed448_clamp(U448::from_u64(987654321))))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn constant_time_edwards_ladder(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.point(U448::from_u32(123456789));
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.ct_ladder(&ed448_clamp(U448::from_u64(987654321))))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
mod benches {
|
||||
|
|
@ -64,42 +65,5 @@ mod benches {
|
|||
black_box(p.ct_ladder(&clamp_u256(U256::from_u64(987654321))))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn edwards_point_add(b: &mut Bencher) {
|
||||
let p = CURVE_25519.generator();
|
||||
let q = p.double();
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.add(&q, &p))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn edwards_point_double(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.generator();
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.double())
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn edwards_ladder(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.point(U448::from_u32(123456789));
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.ladder(&ed448_clamp(U448::from_u64(987654321))))
|
||||
})
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn constant_time_edwards_ladder(b: &mut Bencher) {
|
||||
let p = ED448_GOLDILOCKS.point(U448::from_u32(123456789));
|
||||
|
||||
b.iter(|| {
|
||||
black_box(p.ct_ladder(&ed448_clamp(U448::from_u64(987654321))))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg(feature = "edwards")]
|
||||
|
||||
use crate::traits::{Curve, Point};
|
||||
use crypto_bigint::{AddMod, ConstZero, Integer, InvMod, MulMod, NonZero, SubMod, U448};
|
||||
use std::ops::Div;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
#[cfg(feature = "edwards")]
|
||||
pub mod edwards;
|
||||
pub mod montgomery;
|
||||
pub mod traits;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue