Add some constants and lay out functions for point arithmetic.

This commit is contained in:
Sean Bowe 2018-09-02 09:16:39 -06:00
parent 88ca4f321f
commit 16d01207ef
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
2 changed files with 20 additions and 4 deletions

View File

@ -9,7 +9,7 @@ use subtle::{Choice, ConditionallyAssignable, ConditionallySelectable, ConstantT
// integers in little-endian order. Elements of Fq are always in
// Montgomery form; i.e., Fq(a) = aR mod q, with R = 2^256.
#[derive(Clone, Copy)]
pub struct Fq([u64; 4]);
pub struct Fq(pub(crate) [u64; 4]);
impl fmt::Debug for Fq {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

View File

@ -7,7 +7,7 @@ extern crate std;
extern crate byteorder;
extern crate subtle;
use core::ops::Neg;
use core::ops::{AddAssign, Neg};
mod fq;
pub use fq::*;
@ -39,9 +39,15 @@ struct Point {
z: Fq,
}
// `d = -(10240/10241)`
const EDWARDS_D: Fq = Fq([
0x2a522455b974f6b0, 0xfc6cc9ef0d9acab3, 0x7a08fb94c27628d1, 0x57f8f6a8fe0e262e
]);
impl Point {
pub fn zero() -> Point {
// (0, 1) is the neutral element of the group.
pub fn identity() -> Point {
// `(0, 1)` is the neutral element of the group;
// the additive identity.
Point {
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!()
}
}