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

Stable wNAF API #27

Closed
ebfull opened this issue Jul 31, 2017 · 4 comments
Closed

Stable wNAF API #27

ebfull opened this issue Jul 31, 2017 · 4 comments
Milestone

Comments

@ebfull
Copy link
Collaborator

ebfull commented Jul 31, 2017

Currently you have to opt-in to it because it's a low level API. I want a simple API that you cannot misuse.

@daira
Copy link
Collaborator

daira commented Aug 11, 2017

Is this just a matter of being able to preprocess the exponent into wNAF form (so that it can be reused)? If so then perhaps the API does not need to specify that it is wNAF, so that other things like mbwNAF can be implemented later.

@daira
Copy link
Collaborator

daira commented Aug 11, 2017

Also, consider having separate APIs for constant-time and variable-time (or side-channel resistant and non-side-channel-resistant).

@ebfull
Copy link
Collaborator Author

ebfull commented Aug 13, 2017

There are many use cases for wNAF (MPC, solo paramgen, multiexp perhaps, verification) but various ways of interacting and sharing allocated space for window tables and wNAF-form scalars across threads, and it's a little bit tricky to balance all of these requirements for a nice clean API. In particular, I want it to be impossible to accidentally use the wrong window table sizes in these different contexts.

I know there's a nice API to do it, I just haven't come up with it yet. :)

@ebfull ebfull modified the milestone: 0.12.0 Sep 6, 2017
@ebfull
Copy link
Collaborator Author

ebfull commented Sep 28, 2017

Alright, I have a mockup of something that may work. It's similar to what I originally wrote for bellman a while back.

There's a Wnaf<W, B, S> object that you can instantiate as Wnaf<(), Vec<G>, Vec<i64>> with new(). If you call .base(..) on this, it populates the window table and returns a Wnaf<usize, &'a [G], &'a mut Vec<i64>>, i.e., a distinctly typed Wnaf which immutably borrows the window table and mutably borrows the scalar representation vector space. Similarly, you can call .scalar(..) on it which returns Wnaf<usize, &'a mut Vec<G>, &'a [i64]> which immutably borrows the scalar representation space after conversion and mutably borrows the window table vector space.

Once you have one of these objects with a defined window size, you can call .scalar() or .base() on them as appropriate. (They're defined abstractly over whether the scalar space is mutable or the window table space is.) If you need to toss this around threads, you can also call .shared() which will replace the appropriate mutable representation with an owned vector and an immutable reference to the original Wnaf -- which is always Send and thus threadsafe.

All using the typesystem, no unsafe code:

  • can reuse window tables and scalar representations for multiple exponentiations without unnecessary allocation
  • can reuse window tables and scalar representations for multiple threads
  • window size is defined for you
  • the window size is fixed when you specify the base or the scalar, so you can never mix things up and use the wrong window size.
  • cannot accidentally overwrite a window table before exponentiation

bmerge added a commit that referenced this issue Sep 28, 2017
Introduce a more typesafe wNAF API, and remove the unstable-wnaf feature

Closes #27.
bmerge added a commit that referenced this issue Sep 28, 2017
Introduce a more typesafe wNAF API, and remove the unstable-wnaf feature

Closes #27.
bmerge added a commit that referenced this issue Sep 28, 2017
Introduce a more typesafe wNAF API, and remove the unstable-wnaf feature

Closes #27.
bmerge added a commit that referenced this issue Sep 28, 2017
Introduce a more typesafe wNAF API, and remove the unstable-wnaf feature

Closes #27.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants