From 76a8d43a04b0ed0b523d3c3b94fae9cd9432acc4 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 20 Mar 2018 12:10:39 -0700 Subject: [PATCH] Create a new `scalar_mul` module hierarchy. This should contain generic implementations of scalar multiplication algorithms that can be used with multiple backends. The goal is to move the existing scalar multiplication code into this submodule, then call it from the user-facing API. This can also contain code for things we can't do now, like multiscalar multiplication with precomputation. --- build.rs | 4 +++- src/backend/avx2/edwards.rs | 2 +- src/curve_models/mod.rs | 2 -- src/edwards.rs | 2 +- src/lib.rs | 8 ++++++++ src/scalar_mul/mod.rs | 11 +++++++++++ src/{curve_models => scalar_mul}/window.rs | 0 7 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/scalar_mul/mod.rs rename src/{curve_models => scalar_mul}/window.rs (100%) diff --git a/build.rs b/build.rs index 1c8be62..5eb523b 100644 --- a/build.rs +++ b/build.rs @@ -54,6 +54,8 @@ mod field; mod curve_models; #[path="src/backend/mod.rs"] mod backend; +#[path="src/scalar_mul/mod.rs"] +mod scalar_mul; use edwards::EdwardsBasepointTable; @@ -77,9 +79,9 @@ use backend::u32::field::FieldElement32; use edwards::EdwardsBasepointTable; -use curve_models::window::LookupTable; use curve_models::AffineNielsPoint; +use scalar_mul::window::LookupTable; /// Table containing precomputed multiples of the Ed25519 basepoint \\\\(B = (x, 4/5)\\\\). pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN; diff --git a/src/backend/avx2/edwards.rs b/src/backend/avx2/edwards.rs index 7f564d7..74b0797 100644 --- a/src/backend/avx2/edwards.rs +++ b/src/backend/avx2/edwards.rs @@ -24,7 +24,7 @@ use subtle::Choice; use edwards; use scalar::Scalar; -use curve_models::window::LookupTable; +use scalar_mul::window::LookupTable; use traits::Identity; diff --git a/src/curve_models/mod.rs b/src/curve_models/mod.rs index 59426fa..a88c37d 100644 --- a/src/curve_models/mod.rs +++ b/src/curve_models/mod.rs @@ -135,8 +135,6 @@ use field::FieldElement; use edwards::EdwardsPoint; use traits::ValidityCheck; -pub mod window; - // ------------------------------------------------------------------------ // Internal point representations // ------------------------------------------------------------------------ diff --git a/src/edwards.rs b/src/edwards.rs index bcc4db6..439d6e6 100644 --- a/src/edwards.rs +++ b/src/edwards.rs @@ -117,7 +117,7 @@ use curve_models::CompletedPoint; use curve_models::AffineNielsPoint; use curve_models::ProjectiveNielsPoint; -use curve_models::window::LookupTable; +use scalar_mul::window::LookupTable; use traits::{Identity, IsIdentity}; use traits::ValidityCheck; diff --git a/src/lib.rs b/src/lib.rs index bb788c4..ffe0009 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,14 +67,19 @@ pub(crate) mod macros; // Scalar arithmetic mod l = 2^252 + ..., the order of the Ristretto group pub mod scalar; + // Point operations on the Montgomery form of Curve25519 pub mod montgomery; + // Point operations on the Edwards form of Curve25519 pub mod edwards; + // Group operations on the Ristretto group pub mod ristretto; + // Useful constants, like the Ed25519 basepoint pub mod constants; + // External (and internal) traits. pub mod traits; @@ -90,3 +95,6 @@ pub(crate) mod backend; // Internal curve models which are not part of the public API. pub(crate) mod curve_models; + +// Implementations of scalar mul algorithms live here +pub(crate) mod scalar_mul; diff --git a/src/scalar_mul/mod.rs b/src/scalar_mul/mod.rs new file mode 100644 index 0000000..bc3ef90 --- /dev/null +++ b/src/scalar_mul/mod.rs @@ -0,0 +1,11 @@ +// -*- mode: rust; -*- +// +// This file is part of curve25519-dalek. +// Copyright (c) 2016-2018 Isis Lovecruft, Henry de Valence +// See LICENSE for licensing information. +// +// Authors: +// - Isis Agora Lovecruft +// - Henry de Valence + +pub mod window; diff --git a/src/curve_models/window.rs b/src/scalar_mul/window.rs similarity index 100% rename from src/curve_models/window.rs rename to src/scalar_mul/window.rs