Skip to content
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

Multiscalar multiplication with precomputation #125

Closed
hdevalence opened this issue Apr 5, 2018 · 7 comments
Closed

Multiscalar multiplication with precomputation #125

hdevalence opened this issue Apr 5, 2018 · 7 comments

Comments

@hdevalence
Copy link
Contributor

The current multiscalar API looks like:

pub fn multiscalar_mul<I, J>(scalars: I, points: J) -> RistrettoPoint
where
    I: IntoIterator,
    I::Item: Borrow<Scalar>,
    J: IntoIterator,
    J::Item: Borrow<RistrettoPoint>, 

This takes an iterator of scalars and an iterator of points, and computes Q = c_1 P_1 + \cdots + c_n P_n. This is super-flexible and very useful (it makes it easy to combine statements), but it doesn't allow precomputation.

To do that, we could create a struct (not sure about naming, let's say MultiscalarPrecomputation for now) that looks like:

struct MultiscalarPrecomputation {
    /// Takes points B_1, ..., B_m
    pub fn new<I>(points: I) -> Self
    where
        I: IntoIterator,
        I::Item: Borrow<Scalar>,
    { ... }

    /// Computes (a_1*A_1 + ... + a_n *A_n) + (b_1*B_1 + ... + b_m * B_n)
    pub fn multiscalar_mul<I,J,K>(
        dynamic_scalars: I, 
        dynamic_points: J,
        static_scalars: K,
    ) -> RistrettoPoint
    where
        I: IntoIterator,
        I::Item: Borrow<Scalar>,
        J: IntoIterator,
        J::Item: Borrow<RistrettoPoint>,
        K: IntoIterator,
        K::Item: Borrow<Scalar>,
    { ... }
}

This API would let us cover every combination of static/dynamic points, and because the precomputation is opaque, it means that we can pick what kind of static data we want to use depending on the backend implementation. This would supersede #79.

@hdevalence
Copy link
Contributor Author

I think that a basic version of this would be easy to implement using the existing scalar mul code, but I'm not sure if it's worth doing before 1.0.

@hdevalence
Copy link
Contributor Author

Some work-in-progress on this is in the https://github.com/dalek-cryptography/curve25519-dalek/tree/feature/multiscalar-traits branch.

This has an additional upshot: by eliminating the bare functions and the vartime modules, we would have the option (if we wanted) to expose a flat API namespace.

@hdevalence
Copy link
Contributor Author

Work-in-progress traits for constant-time and variable-time multiscalar multiplication here: 8f659c3

@isislovecruft does this look generally okay? One thing I'm wondering about is how we would like to expose this API.

For the multiscalar multiplication without precomputation (also WIP in that branch), the trait is implemented externally on EdwardsPoint / RistrettoPoint and also internally in various backend code for each algorithm's implementation. This means that we have the flexibility to select an algorithm or a backend transparently.

For multiscalar multiplication with precomputation, should we take the same strategy, exposing structs like VartimeRistrettoPrecomputation that implement the precomputation traits, and keep the flexibility to select the algorithm?

@hdevalence
Copy link
Contributor Author

Since this is a new API, not a change to an existing one, we can add it after 1.0.

@hdevalence hdevalence added this to the 1.1 milestone Jun 21, 2018
@hdevalence
Copy link
Contributor Author

One reason to do this before 1.0 would be that we could get rid of the vartime_double_scalar_mul_basepoint and replace it with an instance of this API, whereas if we waited we would be stuck with it.

@hdevalence
Copy link
Contributor Author

@hdevalence
Copy link
Contributor Author

Closed by #230 and released in 1.1.0.

pinkforest pushed a commit to pinkforest/curve25519-dalek that referenced this issue Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant