Commit graph

65 commits

Author SHA1 Message Date
Henry de Valence
e3bf9b0213 Add MultiscalarMul and VartimeMultiscalarMul traits.
These traits have the same interface, but with different names, so that it's
not possible to use them interchangeably.  (Constant-time and variable-time
routines should not be used interchangeably).

This commit changes the external API to use these traits, replacing
```
edwards::multiscalar_mul
edwards::vartime::multiscalar_mul
```
with
```
EdwardsPoint::multiscalar_mul (as an impl)
EdwardsPoint::vartime_multiscalar_mul (as an impl)
```
and similarly for Ristretto.

Refactoring the backend is for a later commit.

Multiscalar multiplication with precomputation is for a later commit.

The `edwards::vartime` module is retained since it's used for
`vartime_double_base_scalar_mul`.

It should be subsumed into the precomputation API in a later commit.
2018-05-15 11:33:38 -07:00
Henry de Valence
34c43c20a9 Rework backend selection code.
Each backend can now be selected by an individual feature:

- `u32_backend` for `backend::u32`;
- `u64_backend` for `backend::u64`;
- `avx2_backend` for `backend::avx2`;

The `u64_backend` is selected by default, since most people use X64 and we have
no way to select based on target (see discussion in #126).  However, these
changes mean that it is possible to select the backend explicitly, and if we
had the ability to select target-default features, we could do so easily.
2018-05-14 17:43:54 -07:00
Henry de Valence
9b6c932635 Rename 'precomputed_tables' to the more accurate 'stage2_build' 2018-05-14 15:41:45 -07:00
mandragore
aff69a58a4 Implement Sum trait for EdwardsPoint 2018-05-03 03:42:37 +03:00
Henry de Valence
0c4e7188a0 Pull out vartime double-base scalar mul code 2018-03-26 17:41:05 -07:00
Henry de Valence
2d99892eab Pull out variable-time straus implementation 2018-03-26 17:41:05 -07:00
Henry de Valence
2864a422bc Pull out constant-time straus implementation 2018-03-26 16:04:17 -07:00
Henry de Valence
ac739a3edd Split out constant-time variable-base scalar mul.
The serial (`u32`/`u64`) implementations use a multiple curve models, passing
between extended and projective coordinates when performing addition and
doubling (respectively). But the AVX2 backend doesn't, so in order to write a
single scalar mult implementation, we have to either abstract over the curve
models or have two implementations.

A generic solution is possible but extremely unreadable: the scalar mul
implementation would be parameterized over the point types used by the serial
implementations, with many where clauses describing how the types relate. The
AVX2 types could then be substituted in the appropriate places.

Instead we just duplicate the code into the `avx2` backend.
2018-03-26 16:01:51 -07:00
Henry de Valence
76a8d43a04 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.
2018-03-26 14:34:28 -07:00
Henry de Valence
d6b8389428 Use criterion.rs instead of libtest for benchmarks.
Since Criterion can only benchmark public API, these changes just drop
all internal benchmarks (e.g., benchmarks for field operations). But
those are usually microbenchmarks whose meaning is kind of questionable
anyways, so I don't think this is a big loss.

The `bench` feature disappears, since Criterion works on stable Rust.
2018-03-25 17:14:37 -07:00
Henry de Valence
6f9c229e65 Remove Elligator stubs for now, since this isn't the API we want anyways 2018-03-22 12:17:23 -07:00
Henry de Valence
d67e895619 Merge branch 'feature/rename-to-multiscalar-mul' into develop 2018-03-22 12:08:49 -07:00
Henry de Valence
2e73b2bc20 Use scalar_mul instead of scalar_mult 2018-03-22 11:40:13 -07:00
Henry de Valence
70eee5208a Rename double_scalar_mult_basepoint to double_scalar_mul_basepoint for consistency 2018-03-22 11:39:47 -07:00
Henry de Valence
296cd16463 Rename mult_by_cofactor to mul_by_cofactor for consistency 2018-03-22 11:36:34 -07:00
Henry de Valence
8de3d7576a Rename mult_by_pow_2 to mul_by_pow_2 for consistency 2018-03-22 11:35:42 -07:00
Henry de Valence
792ac0775e Change to the updated subtle API. 2018-03-22 11:13:26 -07:00
Henry de Valence
c20e09f6cc Rename multiscalar_mult->multiscalar_mul to match Mul traits 2018-03-19 14:28:21 -07:00
Isis Lovecruft
de90f16994
Merge branch 'feature/dalek-rs-assets' into develop 2018-03-12 19:50:56 +00:00
Henry de Valence
a271ff907d add link to curve models docs 2018-02-22 15:37:16 -08:00
Henry de Valence
0f185d3e28 Generalize trait bounds on multiscalar multiplication.
This allows iterators returning either &Scalars or Scalars, so that it's
possible to use map() and friends to adjust scalars as they're being fed into
the multiscalar multiplication.
2018-02-20 18:31:23 -08:00
Henry de Valence
4a4ec74100 Add example to edwards::multiscalar_mult 2018-02-20 17:32:50 -08:00
Henry de Valence
6748dddb96 Simplify and optimize Montgomery code.
The `MontgomeryPoint` struct is now a point on the Kummer line of the Montgomery curve.

The `ProjectivePoint` struct is made private, since its only purpose is
internal to the Montgomery ladder.

The Montgomery ladder takes affine input, making it faster, and produces affine output.

The Edwards-Montgomery correspondence is simplified.
2018-02-05 10:40:25 -08:00
Isis Lovecruft
cd112afff5
Whitespace EOL fixes. 2018-01-31 02:19:53 +00:00
Henry de Valence
9698435e38 Add note on point validity and "make illegal states unrepresentable".
Remove references to Montgomery conversions, as a prelude to putting the
Montgomery/Edwards conversion docs in the Montgomery module.
2018-01-30 12:31:53 -08:00
Henry de Valence
ae46ecd445 Rename BASE_CMPRSSD to ED25519_BASEPOINT_COMPRESSED. 2018-01-29 12:38:58 -08:00
Henry de Valence
3b5a8f84a8 Add an is_torsion_free function and document cofactor-related functions. 2018-01-26 16:07:52 -08:00
Henry de Valence
3d2cf74261 Add docs on Edwards points 2018-01-26 15:36:06 -08:00
Henry de Valence
ce45cfec8e This isn't true after renaming the struct 2018-01-25 12:16:11 -08:00
Henry de Valence
3f7923b628 Keep the AVX2 point type named as ExtendedPoint. 2018-01-25 12:00:40 -08:00
Isis Lovecruft
4f37785f0e
Rename ExtendedPoint to EdwardsPoint. 2018-01-25 02:56:38 +00:00
Henry de Valence
52d600db95 Implement public-facing ops traits on all combos of &T/T
The public-facing types with arithmetic operations are:

- `Scalar`s
- `ExtendedPoint`s
- `RistrettoPoint`s

For these types we define operators with all combinations of borrowed and
non-borrowed inputs, to avoid forcing API consumers to write extra ampersands.
Since all of the operations involved with these types are expensive relative to
the cost of an unnecessary copy, this isn't a big deal.

The `MontgomeryPoint` struct isn't included in the above because it's only
useful for scalar multiplication.

This commit is based on work by @UnlawfulMonad.
2018-01-24 11:05:06 -08:00
Henry de Valence
3686562b2f Clear memory from avx2 multiscalar mult 2018-01-03 13:37:12 -08:00
Henry de Valence
caf296a546 Try to make target_feature work on stable 2017-12-15 13:57:01 -08:00
Henry de Valence
34f44dcf5d Merge branch 'develop' into feature/avx2_r8 2017-12-15 11:37:10 -08:00
Henry de Valence
a3f53c9134 Refactor select_precomputed_point into a LookupTable struct.
Originally this was for hygiene, so that we could erase points from
heap-allocated memory in multiscalar_mult, but it ends up providing a cleaner
API for scalar multiplication.

It's kept inside curve_models for now, but it could go somewhere else if that's a better place.
2017-12-07 12:46:57 -08:00
Henry de Valence
98a78d7a58 Clear scalar digits from memory in multiscalar_mult 2017-12-07 12:34:40 -08:00
Henry de Valence
7d2d87441b Connect double_scalar_mult_basepoint to AVX2 backend 2017-12-04 11:05:24 -08:00
Henry de Valence
b5305b4e30 Connect multiscalar_mult to the AVX2 backend 2017-12-04 10:37:37 -08:00
Henry de Valence
97fe2f0bf4 Try to connect the AVX2 backend to the ExtendedPoint frontend 2017-12-04 10:37:37 -08:00
Henry de Valence
841e0d5b64 Fix wrong feature for benchmarks 2017-12-04 10:37:37 -08:00
Henry de Valence
2d6d79dc21 KaTeXify more of edwards.rs 2017-11-30 17:36:56 -08:00
Henry de Valence
10bba1207b KaTeXify and document basepoint tables 2017-11-30 17:11:25 -08:00
Henry de Valence
d32fe9772b Ensure that all Scalars are bounded by 2^255.
This commit defines a Scalar to hold an integer representing an element of
Z/lZ.  Applications like X/Ed25519 that care about the bit-patterns of the
scalars they use can set a specific bit-pattern using the `from_bits`
constructor.  Applications that want to treat scalars as integers mod l can use
the `from_bytes_mod_order` constructor.  Either way, the constructor ensures
that the integer representing each Scalar is bounded by 2^255 so that the high
bit is set.  This means that any Scalar object is always safe to use for scalar
multiplication, while maintaining compatibility with both the Ristretto
use-case and the X/Ed25519 usecase.
2017-11-23 12:29:46 -08:00
Henry de Valence
2d69a8a7dc Eliminate array_ref dependency 2017-11-20 14:53:08 -08:00
Henry de Valence
a9f8789524 hide unimplemented fns from docs 2017-11-17 15:50:04 -08:00
Henry de Valence
9fda4739d0 Hide fns using private types 2017-11-17 15:42:37 -08:00
Henry de Valence
78d9e70071 Move ExtendedPoint->MontgomeryPoint conversion to edwards.rs
Need to find a solution to the internal/external docs problem
2017-11-17 15:13:45 -08:00
Henry de Valence
8337a895d4 Only compress ExtendedPoints 2017-11-17 13:32:22 -08:00
Henry de Valence
8d0808a077 Split internal curve models into a private submodule 2017-11-16 17:34:28 -08:00