mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Also make scalar multiplication with DecafPoints go both ways.
This commit is contained in:
parent
944e8e1649
commit
738049619b
1 changed files with 28 additions and 1 deletions
29
src/curve.rs
29
src/curve.rs
|
|
@ -84,6 +84,8 @@ use core::ops::{Mul, MulAssign};
|
|||
use core::ops::Index;
|
||||
|
||||
use constants;
|
||||
#[cfg(feature = "yolocrypto")]
|
||||
use decaf::DecafPoint;
|
||||
use field::FieldElement;
|
||||
use scalar::Scalar;
|
||||
use subtle::arrays_equal_ct;
|
||||
|
|
@ -829,6 +831,17 @@ impl<'a, 'b> Mul<&'b ExtendedPoint> for &'a Scalar {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "yolocrypto")]
|
||||
impl<'a, 'b> Mul<&'b DecafPoint> for &'a Scalar {
|
||||
type Output = DecafPoint;
|
||||
|
||||
/// Scalar multiplication: compute `self * scalar`.
|
||||
fn mul(self, point: &'b DecafPoint) -> DecafPoint {
|
||||
DecafPoint(self * &point.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Precomputation
|
||||
#[derive(Clone)]
|
||||
pub struct EdwardsBasepointTable(pub [[AffineNielsPoint; 8]; 32]);
|
||||
|
|
@ -1162,6 +1175,8 @@ pub mod vartime {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[cfg(feature = "yolocrypto")]
|
||||
use decaf::DecafPoint;
|
||||
use field::FieldElement;
|
||||
use scalar::Scalar;
|
||||
use subtle::CTAssignable;
|
||||
|
|
@ -1472,7 +1487,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn scalarmult_works_both_ways() {
|
||||
fn scalarmult_extended_point_works_both_ways() {
|
||||
let G: ExtendedPoint = constants::ED25519_BASEPOINT;
|
||||
let s: Scalar = A_SCALAR;
|
||||
|
||||
|
|
@ -1482,6 +1497,18 @@ mod test {
|
|||
assert!(P1.compress_edwards().to_bytes() == P2.compress_edwards().to_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "yolocrypto")]
|
||||
fn scalarmult_decafpoint_works_both_ways() {
|
||||
let P: DecafPoint = DecafPoint(constants::ED25519_BASEPOINT);
|
||||
let s: Scalar = A_SCALAR;
|
||||
|
||||
let P1 = &P * &s;
|
||||
let P2 = &s * &P;
|
||||
|
||||
assert!(P1.compress().as_bytes() == P2.compress().as_bytes());
|
||||
}
|
||||
|
||||
mod vartime {
|
||||
use super::super::*;
|
||||
use super::{A_SCALAR, B_SCALAR, A_TIMES_BASEPOINT, DOUBLE_SCALAR_MULT_RESULT};
|
||||
|
|
|
|||
Loading…
Reference in a new issue