mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Merge branch 'fix/warnings' into develop
This commit is contained in:
commit
c9239f54e9
8 changed files with 5 additions and 89 deletions
|
|
@ -46,22 +46,11 @@ pub(crate) const SQRT_M1: FieldElement32 = FieldElement32([
|
|||
33281959, 41962654, 31548777, 326685, 11406482,
|
||||
]);
|
||||
|
||||
/// In Montgomery form y² = x³+Ax²+x, Curve25519 has A=486662.
|
||||
pub(crate) const MONTGOMERY_A: FieldElement32 = FieldElement32([
|
||||
486662, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
]);
|
||||
|
||||
/// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.)
|
||||
pub(crate) const APLUS2_OVER_FOUR: FieldElement32 = FieldElement32([
|
||||
121666, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
]);
|
||||
|
||||
/// `SQRT_MINUS_APLUS2` is sqrt(-486664)
|
||||
pub(crate) const SQRT_MINUS_APLUS2: FieldElement32 = FieldElement32([
|
||||
54885894, 25242303, 55597453, 9067496, 51808079,
|
||||
33312638, 25456129, 14121551, 54921728, 3972023,
|
||||
]);
|
||||
|
||||
/// `L` is the order of base point, i.e. 2^252 +
|
||||
/// 27742317777372353535851937790883648493
|
||||
pub(crate) const L: Scalar32 = Scalar32([ 0x1cf5d3ed, 0x009318d2, 0x1de73596, 0x1df3bd45,
|
||||
|
|
|
|||
|
|
@ -341,6 +341,7 @@ impl Scalar32 {
|
|||
|
||||
/// Compute `a^2` (mod l).
|
||||
#[inline(never)]
|
||||
#[allow(dead_code)] // XXX we don't expose square() via the Scalar API
|
||||
pub fn square(&self) -> Scalar32 {
|
||||
let aa = Scalar32::montgomery_reduce(&Scalar32::square_internal(self));
|
||||
Scalar32::montgomery_reduce(&Scalar32::mul_internal(&aa, &constants::RR))
|
||||
|
|
|
|||
|
|
@ -33,15 +33,9 @@ pub(crate) const INVSQRT_A_MINUS_D: FieldElement64 = FieldElement64([
|
|||
/// Precomputed value of one of the square roots of -1 (mod p)
|
||||
pub(crate) const SQRT_M1: FieldElement64 = FieldElement64([1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133]);
|
||||
|
||||
/// In Montgomery form y² = x³+Ax²+x, Curve25519 has A=486662.
|
||||
pub(crate) const MONTGOMERY_A: FieldElement64 = FieldElement64([486662, 0, 0, 0, 0]);
|
||||
|
||||
/// `APLUS2_OVER_FOUR` is (A+2)/4. (This is used internally within the Montgomery ladder.)
|
||||
pub(crate) const APLUS2_OVER_FOUR: FieldElement64 = FieldElement64([121666, 0, 0, 0, 0]);
|
||||
|
||||
/// `SQRT_MINUS_APLUS2` is sqrt(-486664)
|
||||
pub(crate) const SQRT_MINUS_APLUS2: FieldElement64 = FieldElement64([1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600]);
|
||||
|
||||
/// `L` is the order of base point, i.e. 2^252 + 27742317777372353535851937790883648493
|
||||
pub(crate) const L: Scalar64 = Scalar64([ 0x0002631a5cf5d3ed, 0x000dea2f79cd6581, 0x000000000014def9, 0x0000000000000000, 0x0000100000000000 ]);
|
||||
|
||||
|
|
|
|||
|
|
@ -270,6 +270,7 @@ impl Scalar64 {
|
|||
|
||||
/// Compute `a^2` (mod l)
|
||||
#[inline(never)]
|
||||
#[allow(dead_code)] // XXX we don't expose square() via the Scalar API
|
||||
pub fn square(&self) -> Scalar64 {
|
||||
let aa = Scalar64::montgomery_reduce(&Scalar64::square_internal(self));
|
||||
Scalar64::montgomery_reduce(&Scalar64::mul_internal(&aa, &constants::RR))
|
||||
|
|
|
|||
|
|
@ -129,30 +129,6 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
/// Test that the constant for sqrt(-486664) really is a square
|
||||
/// root of -486664.
|
||||
#[test]
|
||||
#[cfg(feature="radix_51")]
|
||||
fn sqrt_minus_aplus2() {
|
||||
use backend::u64::field::FieldElement64;
|
||||
let minus_aplus2 = -&FieldElement64([486664,0,0,0,0]);
|
||||
let sqrt = constants::SQRT_MINUS_APLUS2;
|
||||
let sq = &sqrt * &sqrt;
|
||||
assert_eq!(sq, minus_aplus2);
|
||||
}
|
||||
|
||||
/// Test that the constant for sqrt(-486664) really is a square
|
||||
/// root of -486664.
|
||||
#[test]
|
||||
#[cfg(not(feature="radix_51"))]
|
||||
fn sqrt_minus_aplus2() {
|
||||
use backend::u32::field::FieldElement32;
|
||||
let minus_aplus2 = -&FieldElement32([486664,0,0,0,0,0,0,0,0,0]);
|
||||
let sqrt = constants::SQRT_MINUS_APLUS2;
|
||||
let sq = &sqrt * &sqrt;
|
||||
assert_eq!(sq, minus_aplus2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Test that SQRT_M1 is a square root of -1
|
||||
fn test_sqrt_minus_one() {
|
||||
|
|
|
|||
|
|
@ -824,31 +824,6 @@ impl EdwardsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Elligator2 (uniform encoding/decoding of curve points)
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// XXX should this be in another module, with types and `From` impls, like `CompressedEdwardsY`?
|
||||
|
||||
impl EdwardsPoint {
|
||||
/// Use Elligator2 to try to convert `self` to a uniformly random
|
||||
/// string.
|
||||
///
|
||||
/// Returns `Some<[u8;32]>` if `self` is in the image of the
|
||||
/// Elligator2 map. For a random point on the curve, this happens
|
||||
/// with probability 1/2. Otherwise, returns `None`.
|
||||
fn to_uniform_representative(&self) -> Option<[u8; 32]> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
/// Use Elligator2 to convert a uniformly random string to a curve
|
||||
/// point.
|
||||
#[allow(unused_variables)] // REMOVE WHEN IMPLEMENTED
|
||||
fn from_uniform_representative(bytes: &[u8; 32]) -> EdwardsPoint {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Debug traits
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -50,13 +50,12 @@
|
|||
|
||||
use core::ops::{Mul, MulAssign};
|
||||
|
||||
use constants;
|
||||
use constants::APLUS2_OVER_FOUR;
|
||||
use field::FieldElement;
|
||||
use edwards::{EdwardsPoint, CompressedEdwardsY};
|
||||
use scalar::Scalar;
|
||||
|
||||
use traits::{Identity, ValidityCheck};
|
||||
use traits::Identity;
|
||||
|
||||
use subtle::ConditionallyAssignable;
|
||||
use subtle::ConditionallySwappable;
|
||||
|
|
@ -277,8 +276,7 @@ impl Mul<MontgomeryPoint> for Scalar {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use constants::X25519_BASEPOINT;
|
||||
use traits::Identity;
|
||||
use constants;
|
||||
use super::*;
|
||||
|
||||
use rand::OsRng;
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ impl Scalar {
|
|||
|
||||
// Wrap the tree storage in a ClearOnDrop to wipe it when we
|
||||
// pass out of scope.
|
||||
let mut tree_vec = vec![one; 2*n];
|
||||
let tree_vec = vec![one; 2*n];
|
||||
let mut tree = ClearOnDrop::new(tree_vec);
|
||||
|
||||
for i in 0..inputs.len() {
|
||||
|
|
@ -715,24 +715,6 @@ mod test {
|
|||
0xe8, 0xef, 0x7a, 0xc3, 0x1f, 0x35, 0xbb, 0x05,
|
||||
],
|
||||
};
|
||||
/// z = 5033871415930814945849241457262266927579821285980625165479289807629491019013
|
||||
pub static Z: Scalar = Scalar{
|
||||
bytes: [
|
||||
0x05, 0x9d, 0x3e, 0x0b, 0x09, 0x26, 0x50, 0x3d,
|
||||
0xa3, 0x84, 0xa1, 0x3c, 0x92, 0x7a, 0xc2, 0x06,
|
||||
0x41, 0x98, 0xcf, 0x34, 0x3a, 0x24, 0xd5, 0xb7,
|
||||
0xeb, 0x33, 0x6a, 0x2d, 0xfc, 0x11, 0x21, 0x0b,
|
||||
],
|
||||
};
|
||||
/// w = 3486911242272497535104403593250518247409663771668155364040899665266216860804
|
||||
static W: Scalar = Scalar{
|
||||
bytes: [
|
||||
0x84, 0xfc, 0xbc, 0x4f, 0x78, 0x12, 0xa0, 0x06,
|
||||
0xd7, 0x91, 0xd9, 0x7a, 0x3a, 0x27, 0xdd, 0x1e,
|
||||
0x21, 0x43, 0x45, 0xf7, 0xb1, 0xb9, 0x56, 0x7a,
|
||||
0x81, 0x30, 0x73, 0x44, 0x96, 0x85, 0xb5, 0x07,
|
||||
],
|
||||
};
|
||||
|
||||
/// x*y = 5690045403673944803228348699031245560686958845067437804563560795922180092780
|
||||
static X_TIMES_Y: Scalar = Scalar{
|
||||
|
|
|
|||
Loading…
Reference in a new issue