[][src]Module zerocaf::edwards

Edwards Point operations and their implementations are shown with the corresponding definitions. Encoding/decoding process implementations are shown, as is support for all kind of interactions which apply each of the processes.

Examples

use zerocaf::edwards::*;
use zerocaf::traits::ops::*;
use zerocaf::traits::Identity;
use zerocaf::field::FieldElement;
use zerocaf::scalar::Scalar;
 
use subtle::Choice;
use core::ops::{Add, Sub, Mul};
 
// You can work in different point coordinates, such as:
// Affine, Projective or Extended.
// 
// It's highly recommended to work using the Extended cooridnates,
// for defined curves such as as the one in Zerocaf,
// as they they allow for the fastest known arithmetic operations.
// Additionally, they formats can be directly compressed from just
// a singluar coordinate.  
 
// In order to produce a point over the Doppio curve, 
// you can do the following: 
 
// From the y-coordinate of a point: 
let y = FieldElement([1799957170131195, 4493955741554471, 4409493758224495, 3389415867291423, 16342693473584]);
// The `Choice` specifies the symbol that we want to get as a result
// for the `x-coordinate`.
let ex_point = EdwardsPoint::new_from_y_coord(&y, Choice::from(0u8)).unwrap();
 
// Create a random point. 
let rngp = EdwardsPoint::new_random_point();
 
let example = EdwardsPoint::from(&ProjectivePoint::identity());
 
// The same examples work for the ProjectivePoint struct. 
 
// You can perform the following operations with an EdwardsPoint
// or a ProjectivePoint: 
 
// Point addition:
let p1 = &ex_point + &rngp;
// Point subtraction (which is a point negation and a sum): 
let p2 = &ex_point - &rngp;
// Point doubling: 
let p3 = &ex_point.double();
// Scalar mul:
let p4 = double_and_add(&ex_point, &Scalar::from(&8u8));
 
// You can also multiply by the cofactor directly: 
assert!(p4 == mul_by_cofactor(&ex_point));
 
// In order to send points for saving space, you can use
// compressed points, whih are repressented as: `CompressedEwdardsY`. 
 
// The only means of obtaining a `CompressedEdwardsY` is: 
// By compressing an `EdwardsPoint`: 
let cp_point = rngp.compress();
// Note that you can get your EdwardsPoint back just by doing:
let decompr_point = &cp_point.decompress().unwrap();
 
// You can also get a compressed point by copying it from a 
// slice of bytes (as if it came from a socket or similar situations).
let cpedw = CompressedEdwardsY::from_slice(&cp_point.to_bytes()); 

Structs

AffinePoint

An AffinePoint represents a point on the Doppio Curve expressed over the Twisted Edwards Affine Coordinates also known as cartesian coordinates: (X, Y).

CompressedEdwardsY

The first 255 bits of a CompressedEdwardsY represent the (y)-coordinate. The high bit of the 32nd byte gives the sign of (x).

EdwardsPoint

An EdwardsPoint represents a point on the Doppio Curve expressed over the Twisted Edwards Extended Coordinates eg. (X, Y, Z, T).

ProjectivePoint

A ProjectivePoint represents a point on the Doppio Curve expressed over the Twisted Edwards Projective Coordinates eg. (X, Y, Z).

Functions

double_and_add

Implementation of the standard algorithm of double_and_add. This is a function implemented for Generic points that have implemented Add, Double, Identity and Clone.

mul_by_cofactor

Multiply by the cofactor: return (8 P).

mul_by_pow_2

Compute ([2^k] * P (mod l)).