Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ec/examples/ec_demo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crypto_bigint::{const_prime_monty_params, Uint};
use crypto_bigint::{Uint, const_prime_monty_params};

use ec::curve_edwards::EdwardsCurve;
use ec::curve_jacobi_intersection::JacobiIntersectionCurve;
Expand Down Expand Up @@ -64,4 +64,4 @@ fn main() {
// Need a != 0, 1.
let ji = JacobiIntersectionCurve::new(fp(2));
show_curve("Jacobi intersection", &ji, &mut rng);
}
}
30 changes: 4 additions & 26 deletions ec/src/curve_edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
//! - Binary Edwards curves (characteristic $2$): Bernstein–Lange–Rezaeian Farashahi (2008)
//! - Odd characteristic: <https://hyperelliptic.org/EFD/g1p/auto-edwards.html>

use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
use fp::{ref_field_impl, ref_field_trait_impl};
use core::fmt;
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

use crate::curve_ops::Curve;
use crate::point_edwards::EdwardsPoint;
Expand All @@ -48,7 +48,6 @@ pub struct EdwardsCurve<F: FieldOps> {
pub d2: F,
}


impl<F> fmt::Display for EdwardsCurve<F>
where
F: FieldOps + fmt::Display,
Expand Down Expand Up @@ -82,7 +81,6 @@ where
}
}


ref_field_impl! {
impl<F: FieldOps + FieldRandom> EdwardsCurve<F> {
/// Construct an odd-characteristic Edwards curve `x² + y² = 1 + d·x²·y²`.
Expand Down Expand Up @@ -181,26 +179,7 @@ ref_field_impl! {
}
}




















ref_field_trait_impl!{
ref_field_trait_impl! {
impl<F: FieldOps + FieldRandom> Curve for EdwardsCurve<F> {
type BaseField = F;
type Point = EdwardsPoint<F>;
Expand Down Expand Up @@ -261,7 +240,6 @@ ref_field_trait_impl!{
}
}


// ---------------------------------------------------------------------------
// Constant-time functionalities
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -299,4 +277,4 @@ where
fn ct_ne(&self, other: &Self) -> Choice {
!self.ct_eq(other)
}
}
}
18 changes: 7 additions & 11 deletions ec/src/curve_hessian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
//! - EFD, projective Hessian formulas:
//! <https://www.hyperelliptic.org/EFD/g1p/auto-hessian-standard.html>

use core::fmt;
use fp::field_ops::{FieldOps, FieldRandom};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
use fp::{ref_field_impl, ref_field_trait_impl};
use crate::curve_ops::Curve;
use crate::curve_weierstrass::WeierstrassCurve;
use crate::point_hessian::HessianPoint;
use crate::point_weierstrass::AffinePoint;
use core::fmt;
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

/// A generalized Hessian curve
///
Expand Down Expand Up @@ -82,7 +82,7 @@ where
}
}

ref_field_impl!{
ref_field_impl! {
impl<F: FieldOps + FieldRandom> HessianCurve<F> {
/// Construct a generalized Hessian curve
///
Expand Down Expand Up @@ -176,8 +176,7 @@ ref_field_impl!{
}
}


ref_field_trait_impl!{
ref_field_trait_impl! {
impl<F: FieldOps + FieldRandom> Curve for HessianCurve<F> {
type BaseField = F;
type Point = HessianPoint<F>;
Expand Down Expand Up @@ -220,7 +219,6 @@ ref_field_trait_impl!{
}
}


impl<F> ConditionallySelectable for HessianCurve<F>
where
F: FieldOps + Copy,
Expand Down Expand Up @@ -256,8 +254,7 @@ where
}
}


ref_field_impl!{
ref_field_impl! {
impl<F: FieldOps> HessianCurve<F> {
/// Return the EFD Hessian parameter `delta` for the ordinary Hessian model
///
Expand Down Expand Up @@ -404,4 +401,3 @@ ref_field_impl!{
}
}
}

6 changes: 3 additions & 3 deletions ec/src/curve_jacobi_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
//!

use core::fmt;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use rand::{CryptoRng, Rng};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

use crate::curve_ops::Curve;
use crate::curve_weierstrass::WeierstrassCurve;
Expand Down Expand Up @@ -100,7 +100,7 @@ ref_field_impl! {
}
}

ref_field_impl!{
ref_field_impl! {
impl<F: FieldOps + FieldRandom> JacobiIntersectionCurve<F> {
/// Sample a random affine point on this Jacobi‑intersection curve using the
/// provided RNG.
Expand Down Expand Up @@ -183,4 +183,4 @@ where
fn ct_ne(&self, other: &Self) -> Choice {
!self.ct_eq(other)
}
}
}
13 changes: 4 additions & 9 deletions ec/src/curve_jacobi_quartic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//! `d(a²-d) ≠ 0`.

use core::fmt;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

use crate::curve_ops::Curve;
use crate::point_jacobi_quartic::JacobiQuarticPoint;
Expand Down Expand Up @@ -48,11 +48,7 @@ where
self.a, self.d
)
} else {
write!(
f,
"y^2 = ({})x^4 + 2({})x^2 + 1",
self.d, self.a
)
write!(f, "y^2 = ({})x^4 + 2({})x^2 + 1", self.d, self.a)
}
}
}
Expand Down Expand Up @@ -108,7 +104,7 @@ ref_field_impl! {
}
}

ref_field_impl!{
ref_field_impl! {
impl<F: FieldOps + FieldRandom> JacobiQuarticCurve<F> {
/// Sample a random affine point on this Jacobi quartic using the provided RNG.
///
Expand All @@ -134,7 +130,6 @@ ref_field_impl!{
}
}


ref_field_trait_impl! {
impl<F: FieldOps + FieldRandom> Curve for JacobiQuarticCurve<F> {
type BaseField = F;
Expand Down Expand Up @@ -223,4 +218,4 @@ where
fn ct_ne(&self, other: &Self) -> Choice {
!self.ct_eq(other)
}
}
}
10 changes: 5 additions & 5 deletions ec/src/curve_legendre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
//! - HongFeng Wu and RongQuan Feng,
//! *On the isomorphism classes of Legendre elliptic curves over finite fields*,
//! Sci. China Math. 54(9) (2011), 1885–1890.
use crate::curve_ops::Curve;
use crate::curve_weierstrass::WeierstrassCurve;
use crate::point_legendre::LegendrePoint;
use core::fmt;
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use crate::curve_ops::Curve;
use crate::point_legendre::LegendrePoint;
use crate::curve_weierstrass::WeierstrassCurve;

/// A Legendre elliptic curve over a field `F`.
///
Expand All @@ -73,7 +73,7 @@ pub struct LegendreCurve<F: FieldOps> {
pub lambda: F,
}

ref_field_impl!{
ref_field_impl! {
impl<F: FieldOps + FieldRandom> LegendreCurve<F> {
/// Construct the Legendre curve $y^2 = x(x-1)(x-\lambda).$
pub fn new(lambda: F) -> Self {
Expand Down Expand Up @@ -280,7 +280,7 @@ where
}
}

ref_field_trait_impl!{
ref_field_trait_impl! {
impl<F: FieldOps + FieldRandom> Curve for LegendreCurve<F> {
type BaseField = F;
type Point = LegendrePoint<F>;
Expand Down
21 changes: 10 additions & 11 deletions ec/src/curve_montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
//! scalar multiplication.

use core::fmt;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
use fp::{ref_field_impl, ref_field_trait_impl};
use fp::field_ops::{FieldOps, FieldRandom};
use fp::{ref_field_impl, ref_field_trait_impl};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

use crate::curve_ops::Curve;
use crate::point_montgomery::KummerPoint;
Expand All @@ -55,7 +55,6 @@ pub struct MontgomeryCurve<F: FieldOps> {
pub b: F,
}


impl<F> fmt::Display for MontgomeryCurve<F>
where
F: FieldOps + fmt::Display,
Expand Down Expand Up @@ -93,7 +92,7 @@ where
}
}

ref_field_impl!{
ref_field_impl! {
impl<F> MontgomeryCurve<F> {
// -------------------------------------------------------------------
// Constructor
Expand Down Expand Up @@ -162,7 +161,6 @@ ref_field_impl! {
}
}


// -------------------------------------------------------------------
// Curve predicates
// -------------------------------------------------------------------
Expand Down Expand Up @@ -256,7 +254,6 @@ ref_field_trait_impl! {
}
}


// ---------------------------------------------------------------------------
// Constant-time functionalities
// ---------------------------------------------------------------------------
Expand All @@ -266,9 +263,9 @@ where
F: FieldOps + Copy,
{
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
Self{
a: F::conditional_select(& a.a, &b.a, choice),
b: F::conditional_select(& a.b, &b.b, choice),
Self {
a: F::conditional_select(&a.a, &b.a, choice),
b: F::conditional_select(&a.b, &b.b, choice),
}
}

Expand All @@ -291,5 +288,7 @@ where
self.a.ct_eq(&other.a) & self.b.ct_eq(&other.b)
}

fn ct_ne(&self, other: &Self) -> Choice { !self.ct_eq(other) }
}
fn ct_ne(&self, other: &Self) -> Choice {
!self.ct_eq(other)
}
}
4 changes: 2 additions & 2 deletions ec/src/curve_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//! Each concrete curve type chooses its base field and its native point type
//! through associated types.

use fp::field_ops::FieldOps;
use crate::point_ops::PointOps;
use fp::field_ops::FieldOps;

/// Generic elliptic-curve model.
///
Expand Down Expand Up @@ -48,4 +48,4 @@ pub trait Curve: Sized + Clone + PartialEq + Eq {
fn identity(&self) -> Self::Point {
Self::Point::identity(self)
}
}
}
2 changes: 1 addition & 1 deletion ec/src/curve_twisted_hessian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! The twisted Hessian curve is nonsingular when
//!
//! $$a \neq 0 \quad\text{and}\quad d^3 \neq a.$$
//! $$a \neq 0 \quad\text{and}\quad d^3 \neq a.$$
//!
//! # References
//!
Expand Down
Loading
Loading