organize benches, refactor
This commit is contained in:
parent
0702313755
commit
28f58d7222
8 changed files with 144 additions and 191 deletions
|
|
@ -1,9 +1,9 @@
|
|||
use crate::traits::{Curve, Point};
|
||||
use crypto_bigint::{AddMod, ConstZero, Integer, InvMod, MulMod, NonZero, SubMod, U512, Zero};
|
||||
use crypto_bigint::{AddMod, ConstZero, Integer, InvMod, MulMod, NonZero, SubMod, U448};
|
||||
use std::ops::Div;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct EdwardsCurve<N>
|
||||
pub struct EdwardsCurve<N>
|
||||
where
|
||||
N: AddMod<Output = N> + SubMod<Output = N> + MulMod<Output = N> + InvMod<Output = N> + Copy,
|
||||
{
|
||||
|
|
@ -14,21 +14,30 @@ where
|
|||
}
|
||||
|
||||
/// The edwards curve Ed448-Goldilocks
|
||||
const ED_MOD: U512 = U512::ONE
|
||||
.shl(448)
|
||||
.sub_mod(&U512::ONE.shl(224), &U512::MAX)
|
||||
.sub_mod(&U512::ONE, &U512::MAX);
|
||||
const ED448_GOLDILOCKS: EdwardsCurve<U512> = EdwardsCurve::new(
|
||||
U512::ZERO.sub_mod(&U512::from_u16(39081), &ED_MOD),
|
||||
ED_MOD,
|
||||
U512::from_be_hex(
|
||||
"0000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa955555555555555555555555555555555555555555555555555555555",
|
||||
pub const ED448_MOD: U448 = U448::ONE
|
||||
.sub_mod(&U448::ONE.shl(224), &U448::MAX)
|
||||
.sub_mod(&U448::ONE, &U448::MAX);
|
||||
pub const ED448_GOLDILOCKS: EdwardsCurve<U448> = EdwardsCurve::new(
|
||||
U448::ZERO.sub_mod(&U448::from_u16(39081), &ED448_MOD),
|
||||
ED448_MOD,
|
||||
U448::from_be_hex(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa955555555555555555555555555555555555555555555555555555555",
|
||||
),
|
||||
U512::from_be_hex(
|
||||
"0000000000000000ae05e9634ad7048db359d6205086c2b0036ed7a035884dd7b7e36d728ad8c4b80d6565833a2a3098bbbcb2bed1cda06bdaeafbcdea9386ed",
|
||||
U448::from_be_hex(
|
||||
"ae05e9634ad7048db359d6205086c2b0036ed7a035884dd7b7e36d728ad8c4b80d6565833a2a3098bbbcb2bed1cda06bdaeafbcdea9386ed",
|
||||
),
|
||||
);
|
||||
|
||||
pub fn ed448_clamp(mut n: U448) -> U448 {
|
||||
n &= U448::from_u8(0b11).not();
|
||||
|
||||
let big = U448::ONE.shl(447);
|
||||
n &= big.not();
|
||||
n |= big;
|
||||
|
||||
n
|
||||
}
|
||||
|
||||
impl<N> EdwardsCurve<N>
|
||||
where
|
||||
N: AddMod<Output = N>
|
||||
|
|
@ -145,7 +154,6 @@ where
|
|||
}
|
||||
|
||||
fn double(&self) -> Self {
|
||||
/*
|
||||
let a = self.x.add_mod(&self.y, &self.curve.p);
|
||||
let b = a.mul_mod(&a, &self.curve.p);
|
||||
let c = self.x.mul_mod(&self.x, &self.curve.p);
|
||||
|
|
@ -164,9 +172,6 @@ where
|
|||
z,
|
||||
curve: self.curve,
|
||||
}
|
||||
*/
|
||||
|
||||
self.add(self, self)
|
||||
}
|
||||
|
||||
fn mul(&self, x: &N) -> Self {
|
||||
|
|
@ -227,11 +232,11 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn double() {
|
||||
let x = U512::from_be_hex(
|
||||
"000000000000000049dcbc5c6c0cce2c1419a17226f929ea255a09cf4e0891c693fda4be70c74cc301b7bdf1515dd8ba21aee1798949e120e2ce42ac48ba7f30",
|
||||
let x = U448::from_be_hex(
|
||||
"49dcbc5c6c0cce2c1419a17226f929ea255a09cf4e0891c693fda4be70c74cc301b7bdf1515dd8ba21aee1798949e120e2ce42ac48ba7f30",
|
||||
);
|
||||
let y = U512::from_be_hex(
|
||||
"0000000000000000d49077e4accde527164b33a5de021b979cb7c02f0457d845c90dc3227b8a5bc1c0d8f97ea1ca9472b5d444285d0d4f5b32e236f86de51839",
|
||||
let y = U448::from_be_hex(
|
||||
"d49077e4accde527164b33a5de021b979cb7c02f0457d845c90dc3227b8a5bc1c0d8f97ea1ca9472b5d444285d0d4f5b32e236f86de51839",
|
||||
);
|
||||
let p = ED448_GOLDILOCKS.generator().double();
|
||||
|
||||
|
|
@ -241,11 +246,11 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn explicit_double() {
|
||||
let x = U512::from_be_hex(
|
||||
"000000000000000049dcbc5c6c0cce2c1419a17226f929ea255a09cf4e0891c693fda4be70c74cc301b7bdf1515dd8ba21aee1798949e120e2ce42ac48ba7f30",
|
||||
let x = U448::from_be_hex(
|
||||
"49dcbc5c6c0cce2c1419a17226f929ea255a09cf4e0891c693fda4be70c74cc301b7bdf1515dd8ba21aee1798949e120e2ce42ac48ba7f30",
|
||||
);
|
||||
let y = U512::from_be_hex(
|
||||
"0000000000000000d49077e4accde527164b33a5de021b979cb7c02f0457d845c90dc3227b8a5bc1c0d8f97ea1ca9472b5d444285d0d4f5b32e236f86de51839",
|
||||
let y = U448::from_be_hex(
|
||||
"d49077e4accde527164b33a5de021b979cb7c02f0457d845c90dc3227b8a5bc1c0d8f97ea1ca9472b5d444285d0d4f5b32e236f86de51839",
|
||||
);
|
||||
let p = ED448_GOLDILOCKS.generator();
|
||||
let p = p.add(&p, &p);
|
||||
|
|
@ -259,8 +264,8 @@ mod test {
|
|||
let p = ED448_GOLDILOCKS.generator();
|
||||
let q = p.neg();
|
||||
|
||||
let x = U512::ZERO;
|
||||
let y = U512::ONE;
|
||||
let x = U448::ZERO;
|
||||
let y = U448::ONE;
|
||||
|
||||
let sum = p.add(&q, &p);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
mod edwards;
|
||||
mod montgomery;
|
||||
mod traits;
|
||||
pub mod edwards;
|
||||
pub mod montgomery;
|
||||
pub mod traits;
|
||||
|
||||
pub use crypto_bigint::{ConstChoice, Encoding, NonZero, U256};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue