Add some constants and lay out functions for point arithmetic.
This commit is contained in:
parent
88ca4f321f
commit
16d01207ef
|
@ -9,7 +9,7 @@ use subtle::{Choice, ConditionallyAssignable, ConditionallySelectable, ConstantT
|
||||||
// integers in little-endian order. Elements of Fq are always in
|
// integers in little-endian order. Elements of Fq are always in
|
||||||
// Montgomery form; i.e., Fq(a) = aR mod q, with R = 2^256.
|
// Montgomery form; i.e., Fq(a) = aR mod q, with R = 2^256.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Fq([u64; 4]);
|
pub struct Fq(pub(crate) [u64; 4]);
|
||||||
|
|
||||||
impl fmt::Debug for Fq {
|
impl fmt::Debug for Fq {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -7,7 +7,7 @@ extern crate std;
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate subtle;
|
extern crate subtle;
|
||||||
|
|
||||||
use core::ops::Neg;
|
use core::ops::{AddAssign, Neg};
|
||||||
|
|
||||||
mod fq;
|
mod fq;
|
||||||
pub use fq::*;
|
pub use fq::*;
|
||||||
|
@ -39,9 +39,15 @@ struct Point {
|
||||||
z: Fq,
|
z: Fq,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `d = -(10240/10241)`
|
||||||
|
const EDWARDS_D: Fq = Fq([
|
||||||
|
0x2a522455b974f6b0, 0xfc6cc9ef0d9acab3, 0x7a08fb94c27628d1, 0x57f8f6a8fe0e262e
|
||||||
|
]);
|
||||||
|
|
||||||
impl Point {
|
impl Point {
|
||||||
pub fn zero() -> Point {
|
pub fn identity() -> Point {
|
||||||
// (0, 1) is the neutral element of the group.
|
// `(0, 1)` is the neutral element of the group;
|
||||||
|
// the additive identity.
|
||||||
|
|
||||||
Point {
|
Point {
|
||||||
u: Fq::zero(),
|
u: Fq::zero(),
|
||||||
|
@ -64,3 +70,13 @@ impl<'a> Neg for &'a Point {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'b> AddAssign<&'b Point> for Point {
|
||||||
|
fn add_assign(&mut self, rhs: &'b Point) {
|
||||||
|
// See "Twisted Edwards Curves Revisited"
|
||||||
|
// Hisil, Wong, Carter, and Dawson
|
||||||
|
// 3.1 Unified Addition in E^e
|
||||||
|
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue