From e1feb653be748a93b93b4936d3cfa4fb613909ea Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 13 Jan 2017 13:19:08 -0500 Subject: [PATCH] Add constant value of 1/2 (mod p) --- src/constants.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/constants.rs b/src/constants.rs index 71417d8..97e7fe7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -32,6 +32,9 @@ pub const d2: FieldElement = FieldElement([ pub const SQRT_M1: FieldElement = FieldElement([ -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482, ]); +/// Precomputed value of 1/2 (mod p). +pub const HALF: FieldElement = FieldElement([ + 10, 0, 0, 0, 0, 0, 0, 0, 0, -16777216, ]); /// In Montgomery form y² = x³+Ax²+x, Curve25519 has A=486662. pub const A: FieldElement = FieldElement([ @@ -1480,6 +1483,13 @@ mod test { use curve::PreComputedPoint; use constants; + #[test] + fn test_half() { + let one = FieldElement([1,0,0,0,0,0,0,0,0,0]); + let two = FieldElement([2,0,0,0,0,0,0,0,0,0]); + assert_eq!(one, &two * &constants::HALF); + } + #[test] /// Test that SQRT_M1 is a square root of -1 fn test_sqrt_minus_one() {