Skip to main content

Edwards

Struct Edwards 

Source
pub struct Edwards { /* private fields */ }
Expand description

A twisted Edwards curve a x^2 + y^2 = 1 + d x^2 y^2 over the field of a prime p > 3, with a a square and d not, which makes its addition law complete: one formula for every pair of points, doublings and the neutral element (0, 1) included.

Its points are held in extended coordinates, x = X / Z, y = Y / Z, x y = T / Z, the fastest known form of the group, with a formula of its own for a = -1, as on Ed25519.

§Examples

use a::math::ec::{Curve, Edwards};
use a::math::numbers::{ByteOrder, Number};

let n = |x| Number::new_from_u32(x, ByteOrder::BigEndian);
// x^2 + y^2 = 1 + 2 x^2 y^2 over F_13, where 1 is a square and 2 is not.
let curve = Edwards::new(&n(1), &n(2), &n(13)).unwrap();
let o = curve.identity();
assert_eq!(o.coordinates(), Some((n(0), n(1))));

Implementations§

Source§

impl Edwards

Source

pub fn new(a: &Number, d: &Number, p: &Number) -> Result<Edwards, CurveError>

The curve a x^2 + y^2 = 1 + d x^2 y^2 modulo p, in p’s byte order. a and d are reduced modulo p.

§Errors

CurveError::NotPrime when p is not a prime above 3, by is_probable_prime; CurveError::Singular when a, d or a - d is zero modulo p; CurveError::NotComplete when a is not a square or d is.

Source

pub fn a(&self) -> &Number

The coefficient a, below p.

Source

pub fn d(&self) -> &Number

The coefficient d, below p.

Source

pub fn to_montgomery(&self) -> Montgomery

The Montgomery curve this one is birationally equivalent to, with A = 2 (a + d) / (a - d) and B = 4 / (a - d).

Source

pub fn map_to_montgomery<'t>( &self, target: &'t Montgomery, point: &Point<'_, Edwards>, ) -> Point<'t, Montgomery>

The point of target, from to_montgomery, that point of this curve corresponds to: ((1 + y) / (1 - y), (1 + y) / ((1 - y) x)), with the neutral element going to the point at infinity and (0, -1) to (0, 0).

§Panics

Panics if point is not on this curve or target is not the curve from to_montgomery.

Trait Implementations§

Source§

impl Curve for Edwards

Source§

fn discriminant(&self) -> Number

a d (a - d)^4 / 16 modulo p, the discriminant of the curve’s Montgomery form.

Source§

fn j_invariant(&self) -> Number

16 (a^2 + 14 a d + d^2)^3 / (a d (a - d)^4) modulo p.

Source§

fn modulus(&self) -> &Number

The prime of the field.
Source§

fn identity(&self) -> Point<'_, Self>

The neutral element of the curve’s group: the point at infinity, or (0, 1) on an Edwards curve.
Source§

fn point(&self, x: &Number, y: &Number) -> Result<Point<'_, Self>, NotOnCurve>

The point (x, y), reduced modulo p. Read more
Source§

fn lift(&self, coordinate: &Number, odd: bool) -> Option<Point<'_, Self>>

The point with the given coordinate, reduced modulo p, whose other coordinate has the parity odd: x is given and y computed on Weierstrass and Montgomery curves, and the other way round on Edwards curves, or None when there is no such point.
Source§

fn point_from_bytes(&self, bytes: &[u8]) -> Option<Point<'_, Self>>

The point in the bytes of Point::compress or Point::to_bytes, or None when they are not the encoding of a point of this curve.
Source§

fn multi_mul<'c>( &'c self, terms: &[(&Number, &Point<'c, Self>)], ) -> Point<'c, Self>

The sum of k p over the terms: Straus’s method for a few, Pippenger’s for many, much faster than as many products. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.