Skip to content

Reuse Edwards windowed scalar multiplication for Decaf #1303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ed448-goldilocks/src/curve/scalar_mul.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub(crate) mod double_and_add;
// pub(crate) mod double_base;
pub(crate) mod variable_base;
pub(crate) mod window;

pub(crate) use double_and_add::double_and_add;
pub(crate) use variable_base::variable_base;
19 changes: 0 additions & 19 deletions ed448-goldilocks/src/curve/scalar_mul/double_and_add.rs

This file was deleted.

22 changes: 19 additions & 3 deletions ed448-goldilocks/src/curve/scalar_mul/variable_base.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#![allow(non_snake_case)]

use super::window::wnaf::LookupTable;
use crate::EdwardsScalar;
use crate::Scalar;
use crate::curve::twedwards::{extended::ExtendedPoint, extensible::ExtensiblePoint};
use crate::field::CurveWithScalar;
use subtle::{Choice, ConditionallyNegatable};

pub fn variable_base(point: &ExtendedPoint, s: &EdwardsScalar) -> ExtendedPoint {
pub fn variable_base<C: CurveWithScalar>(point: &ExtendedPoint, s: &Scalar<C>) -> ExtendedPoint {
let mut result = ExtensiblePoint::IDENTITY;

// Recode Scalar
Expand Down Expand Up @@ -37,12 +38,27 @@ pub fn variable_base(point: &ExtendedPoint, s: &EdwardsScalar) -> ExtendedPoint
#[cfg(test)]
mod test {
use super::*;
use crate::EdwardsScalar;
use crate::TWISTED_EDWARDS_BASE_POINT;
use crate::curve::scalar_mul::double_and_add;
use elliptic_curve::bigint::U448;
use subtle::ConditionallySelectable;

#[test]
fn test_scalar_mul() {
/// Traditional double and add algorithm
fn double_and_add(point: &ExtendedPoint, s_bits: [bool; 448]) -> ExtendedPoint {
let mut result = ExtendedPoint::IDENTITY;

// NB, we reverse here, so we are going from MSB to LSB
// XXX: Would be great if subtle had a From<u32> for Choice. But maybe that is not it's purpose?
for bit in s_bits.into_iter().rev() {
result = result.double();
result.conditional_assign(&result.add(point), Choice::from(u8::from(bit)));
}

result
}

// XXX: In the future use known multiples from Sage in bytes form?
let twisted_point = TWISTED_EDWARDS_BASE_POINT;
let scalar = EdwardsScalar::new(U448::from_be_hex(
Expand Down
6 changes: 3 additions & 3 deletions ed448-goldilocks/src/decaf/ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{DecafAffinePoint, DecafScalar, curve::scalar_mul::double_and_add};
use crate::curve::scalar_mul::variable_base;
use crate::{DecafAffinePoint, DecafScalar};
use core::{
borrow::Borrow,
iter::Sum,
Expand All @@ -13,8 +14,7 @@ impl Mul<&DecafScalar> for &DecafPoint {
type Output = DecafPoint;

fn mul(self, scalar: &DecafScalar) -> DecafPoint {
// XXX: We can do better than double and add
DecafPoint(double_and_add(&self.0, scalar.bits()))
DecafPoint(variable_base(&self.0, scalar))
}
}

Expand Down