Skip to main content

EdwardsCurve

Struct EdwardsCurve 

Source
pub struct EdwardsCurve<F: FieldOps> {
    pub d1: F,
    pub d2: F,
}
Expand description

An Edwards curve over a field F, covering both odd and even characteristic.

In odd characteristic only d2 is used (the parameter d). In characteristic 2 both d1 and d2 are used.

Fields§

§d1: F

The invariant d1 in the equation

§d2: F

The invariant d2 in the equation

Implementations§

Source§

impl<F: FieldOps + FieldRandom> EdwardsCurve<F>

Source

pub fn new(d: F) -> Self

Construct an odd-characteristic Edwards curve x² + y² = 1 + d·x²·y².

Stores d as d2; d1 is set to zero (unused).

Examples found in repository?
examples/ec_demo.rs (line 54)
41fn main() {
42    let mut rng = rand::rng();
43    // 1. Short Weierstrass over F_19: y^2 = x^3 + 2x + 3
44    let w = WeierstrassCurve::new_short(fp(2), fp(3));
45    show_curve("Weierstrass", &w, &mut rng);
46
47    // 2. Montgomery over F_19: B y^2 = x(x^2 + A x + 1)
48    // Smooth if B != 0 and A != ±2 in odd characteristic.
49    let m = MontgomeryCurve::new(fp(3), fp(1));
50    show_curve("Montgomery", &m, &mut rng);
51
52    // 3. Edwards over F_19: x^2 + y^2 = 1 + d x^2 y^2
53    // Pick d = 2 (nonzero, not 1; also a nonsquare in F_19).
54    let e = EdwardsCurve::new(fp(2));
55    show_curve("Edwards", &e, &mut rng);
56
57    // 4. Jacobi quartic over F_19: y^2 = d x^4 + 2 a x^2 + 1
58    // Need d != 0 and a^2 != d.
59    let jq = JacobiQuarticCurve::new(fp(3), fp(5));
60    show_curve("Jacobi quartic", &jq, &mut rng);
61
62    // 5. Jacobi intersection over F_19:
63    // s^2 + c^2 = 1,  a s^2 + d^2 = 1
64    // Need a != 0, 1.
65    let ji = JacobiIntersectionCurve::new(fp(2));
66    show_curve("Jacobi intersection", &ji, &mut rng);
67}
Source

pub fn new_binary(d1: F, d2: F) -> Self

Construct a binary Edwards curve d₁(x+y) + d₂(x²+y²) = xy + xy(x+y) + x²y².

Source

pub fn d(&self) -> F

Convenience accessor: the parameter d in odd characteristic.

Source

pub fn contains(&self, x: &F, y: &F) -> bool

Check whether the affine point (x, y) lies on the curve.

Source

pub fn random_point(&self, rng: &mut (impl CryptoRng + Rng)) -> EdwardsPoint<F>

Sample a random affine point on this Edwards curve using the provided RNG.

This currently uses a square-root-based construction and is implemented only for odd characteristic. It returns a point P such that self.is_on_curve(&P) holds.

Trait Implementations§

Source§

impl<F: Clone + FieldOps> Clone for EdwardsCurve<F>

Source§

fn clone(&self) -> EdwardsCurve<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: FieldOps + FieldRandom> Curve for EdwardsCurve<F>

Source§

type BaseField = F

Base field of the curve.
Source§

type Point = EdwardsPoint<F>

Native point representation for this curve model.
Source§

fn is_on_curve(&self, point: &Self::Point) -> bool

Return true if point is a valid point on this curve.
Source§

fn random_point(&self, rng: &mut (impl CryptoRng + Rng)) -> Self::Point

Return a random point that is on the curve.
Source§

fn j_invariant(&self) -> F

Return the j_invariant of the curve;
Source§

fn a_invariants(&self) -> Vec<Self::BaseField>

The interpretation depends on the curve model: Read more
Source§

fn identity(&self) -> Self::Point

Return the group identity.
Source§

impl<F: Debug + FieldOps> Debug for EdwardsCurve<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> Display for EdwardsCurve<F>
where F: FieldOps + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: PartialEq + FieldOps> PartialEq for EdwardsCurve<F>

Source§

fn eq(&self, other: &EdwardsCurve<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Eq + FieldOps> Eq for EdwardsCurve<F>

Source§

impl<F: FieldOps> StructuralPartialEq for EdwardsCurve<F>

Auto Trait Implementations§

§

impl<F> Freeze for EdwardsCurve<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for EdwardsCurve<F>
where F: RefUnwindSafe,

§

impl<F> Send for EdwardsCurve<F>
where F: Send,

§

impl<F> Sync for EdwardsCurve<F>
where F: Sync,

§

impl<F> Unpin for EdwardsCurve<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for EdwardsCurve<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for EdwardsCurve<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.