This commit is contained in:
Neemek 2025-11-03 18:56:06 +01:00
parent 3c61f6f043
commit 59c2e1e6dd
5 changed files with 8 additions and 10 deletions

View file

@ -4,9 +4,7 @@ extern crate test;
mod benches { mod benches {
use test::{black_box, Bencher}; use test::{black_box, Bencher};
use crypto_bigint::U448;
use diffie_hellman::{Public, Secret, U256}; use diffie_hellman::{Public, Secret, U256};
use diffie_hellman::edwards::{ed448_clamp, ED448_GOLDILOCKS};
use diffie_hellman::montgomery::{clamp_u256, CURVE_25519}; use diffie_hellman::montgomery::{clamp_u256, CURVE_25519};
use diffie_hellman::traits::{Curve, Point}; use diffie_hellman::traits::{Curve, Point};

View file

@ -156,6 +156,7 @@ where
} }
fn double(&self) -> Self { fn double(&self) -> Self {
/*
let a = self.x.add_mod(&self.y, &self.curve.p); let a = self.x.add_mod(&self.y, &self.curve.p);
let b = a.mul_mod(&a, &self.curve.p); let b = a.mul_mod(&a, &self.curve.p);
let c = self.x.mul_mod(&self.x, &self.curve.p); let c = self.x.mul_mod(&self.x, &self.curve.p);
@ -174,6 +175,9 @@ where
z, z,
curve: self.curve, curve: self.curve,
} }
*/
self.add(self, self)
} }
fn mul(&self, x: &N) -> Self { fn mul(&self, x: &N) -> Self {
@ -200,7 +204,7 @@ where
+ ConstZero + ConstZero
+ crypto_bigint::subtle::ConstantTimeEq, + crypto_bigint::subtle::ConstantTimeEq,
{ {
fn get_y(self) -> N { pub fn get_y(self) -> N {
self.y self.y
.mul_mod(&self.z.inv_mod(&self.curve.p).unwrap(), &self.curve.p) .mul_mod(&self.z.inv_mod(&self.curve.p).unwrap(), &self.curve.p)
} }

View file

@ -75,9 +75,6 @@ impl From<U256> for Secret {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
const BIG_VALID_VALUE: U256 = U256::ONE
.shl(251)
.add_mod(&U256::from_u64(1232039487203 * 8), &CURVE_25519.p);
#[test] #[test]
fn public_key_derivation() { fn public_key_derivation() {

View file

@ -1,9 +1,8 @@
use crate::traits::{Curve, Point}; use crate::traits::{Curve, Point};
use crypto_bigint::subtle::{Choice, ConstantTimeEq}; use crypto_bigint::{AddMod, Encoding, NonZero, SubMod, U256};
use crypto_bigint::{AddMod, ConstChoice, Encoding, NonZero, SubMod, U256};
use crypto_bigint::{Integer, InvMod, MulMod}; use crypto_bigint::{Integer, InvMod, MulMod};
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::ops::{Add, Div, Mul}; use std::ops::{Div, Mul};
/// A curve of the form `By^2 = x^3 + Ax^2 + x` /// A curve of the form `By^2 = x^3 + Ax^2 + x`
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]

View file

@ -1,4 +1,4 @@
use crypto_bigint::{AddMod, InvMod, MulMod, SubMod, U256}; use crypto_bigint::{AddMod, InvMod, MulMod, SubMod};
pub trait Curve<T, N> pub trait Curve<T, N>
where where