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
impl Edwards
Sourcepub fn new(a: &Number, d: &Number, p: &Number) -> Result<Edwards, CurveError>
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.
Sourcepub fn to_montgomery(&self) -> Montgomery
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).
Sourcepub fn map_to_montgomery<'t>(
&self,
target: &'t Montgomery,
point: &Point<'_, Edwards>,
) -> Point<'t, Montgomery>
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
impl Curve for Edwards
Source§fn discriminant(&self) -> Number
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
fn j_invariant(&self) -> Number
16 (a^2 + 14 a d + d^2)^3 / (a d (a - d)^4) modulo p.
Source§fn identity(&self) -> Point<'_, Self>
fn identity(&self) -> Point<'_, Self>
(0, 1) on an Edwards
curve.Source§fn lift(&self, coordinate: &Number, odd: bool) -> Option<Point<'_, Self>>
fn lift(&self, coordinate: &Number, odd: bool) -> Option<Point<'_, Self>>
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>>
fn point_from_bytes(&self, bytes: &[u8]) -> Option<Point<'_, Self>>
Point::compress or Point::to_bytes, or None when they
are not the encoding of a point of this curve.