Commit graph

804 commits

Author SHA1 Message Date
Henry de Valence
53fcd1060d Change internal API to use ConditionallySelectable 2018-11-02 14:17:43 -07:00
Henry de Valence
b0a190bd63 Change externally-exposed API to implement ConditionallySelectable 2018-11-02 14:16:51 -07:00
Henry de Valence
8f605dce6d Tweak ristretto elligator to match ristretto.group description 2018-11-01 17:41:56 -07:00
Henry de Valence
4e2fc53e5b Refactor sqrt_ratio to return either sqrt(u/v) or sqrt(iu/v)
Also removes the chi function since Ristretto elligator merges it with the square root.
2018-11-01 17:37:18 -07:00
Tony Arcieri
31e8626133 Update to digest 0.8 and sha2 0.8
Vicariously updates to `generic-array` 0.12, however this change also
removes `generic-array` as a direct dependency, as it can be sourced
from the `digest` crate.
2018-10-19 10:44:42 -07:00
Henry de Valence
e6c9243e46 Merge branch 'develop' into serde-compressed 2018-09-26 15:54:06 -07:00
Henry de Valence
18391bfc5f Add Serde support for compressed points; use bincode for tests. 2018-09-26 15:46:37 -07:00
Isis Lovecruft
b8fa5ec3e0
Add constructors for compressed points from slices. 2018-09-26 02:07:15 +00:00
Isis Lovecruft
819a85ef18
Fix a typo in the curve model docs. 2018-09-13 22:44:41 +00:00
Isis Lovecruft
0c8a046340
Cleanup and comment Ristretto decoding to match explicit formulae. 2018-08-20 21:01:01 +00:00
Henry de Valence
3bed3ef787
Merge pull request #176 from hdevalence/more-pre-1.0-cleanups
More pre 1.0 cleanups
2018-07-26 20:27:11 -07:00
Henry de Valence
31090e79eb
Merge pull request #179 from hdevalence/ristretto_from_uniform
Expose a Ristretto::from_uniform_bytes function.
2018-07-26 20:22:27 -07:00
Henry de Valence
259e2cd188 Expose a Ristretto::from_uniform_bytes function.
Why expose this instead of `from_hash`? Because it allows constructing
arbitrary-length chains of orthogonal generators from a XOF.
2018-07-26 19:04:56 -07:00
Henry de Valence
288625418d Migrate to packed_simd from core::simd 2018-07-26 12:40:34 -07:00
Sam Scott
a1e2c83d31 Fix distribution of curve points for hashing to Ristretto points. 2018-07-25 18:52:52 -04:00
Henry de Valence
e4ad0ec60a Remove outdated note about powers-of-two 2018-07-25 12:23:08 -07:00
Henry de Valence
b7dab8d083 Add iterator length checks to multiscalar muls.
This partially re-adds functionality removed in commit

d2ce1ce5dc

We would like to require ExactSizeIterator, but unfortunately we can't
do that, since ExactSizeIterators aren't chainable, for (in my opinion)
silly reasons (chaining two 4-billion-element ExactSizeIterators could
overflow on 32-bit systems).  Instead we inspect the size hints manually
and assert that the lower and upper bounds are all equal.
2018-07-25 11:21:06 -07:00
Henry de Valence
82a5e18c29 Update docs to point to multiscalar traits 2018-07-25 10:54:31 -07:00
Henry de Valence
d62fd8ebe4 Add prelude import to scalar.rs 2018-07-23 10:59:11 -07:00
Tony Arcieri
10e8abf926 Unify alloc and std cargo features
This change provides a common convention for using allocator-dependent
features with:

    #![cfg(feature = "alloc")]

When available, `Vec` is imported consistently as `prelude::Vec`, which
means modules that need access to `Vec` can simply do:

    use prelude::*;

and if an allocator is available, `Vec` will be in the crate prelude.

This allows all `alloc` vs `std` gating to be handled in `lib.rs`,
`build.rs`, and `prelude.rs` so the rest of the codebase doesn't have to
do any gating whatsoever.
2018-07-23 10:50:21 -07:00
Henry de Valence
f675f4cd2b fixup! Allow Options in the VartimeMultiscalarMul trait 2018-07-20 20:33:33 -07:00
Isis Lovecruft
b087551696
Impl Default for Scalar. 2018-07-20 21:36:38 +00:00
Isis Lovecruft
73b3a9617b
Merge remote-tracking branch 'hdevalence/remove-ristretto-notes' into develop 2018-07-20 19:56:55 +00:00
Isis Lovecruft
4d527cae4b
Merge branch 'feature/154-defaults' into develop 2018-07-20 19:52:34 +00:00
Isis Lovecruft
3324e7d0ae
Remove impl Default for ProjectivePoint. 2018-07-20 19:51:51 +00:00
Isis Lovecruft
16f00cac16
Merge branch 'fix/166-scalar-random-nostd' into develop 2018-07-20 19:27:37 +00:00
Henry de Valence
5a58f42155 Point to https://ristretto.group since our notes live there now. 2018-07-20 12:24:28 -07:00
Henry de Valence
6eb876f3cb Fix doctests (missed during merge) 2018-07-20 11:50:42 -07:00
Henry de Valence
bb50700d77
Merge pull request #163 from hdevalence/fallible-multiscalar-mul
Allow Options in the VartimeMultiscalarMul trait
2018-07-20 11:28:19 -07:00
Isis Lovecruft
6f82c30a88
Fix doctests for From<u64> for Scalar. 2018-07-20 04:45:06 +00:00
Isis Lovecruft
4d390fbd94
Merge remote-tracking branch 'hdevalence/scalar-from-impls' into develop 2018-07-20 01:09:44 +00:00
Isis Lovecruft
38aa0ee2b7
Implement Default for remaining point types.
* FIXES https://github.com/dalek-cryptography/curve25519-dalek/issues/154
2018-07-20 00:47:36 +00:00
Isis Lovecruft
9105d0977a
Merge remote-tracking branch 'hdevalence/more-pre-1.0-cleanups' into develop 2018-07-20 00:15:12 +00:00
Isis Lovecruft
e5d3f8f72e
Merge branch 'feature/148-cleanup-for-1.0.0-pre.0_1' into develop 2018-07-20 00:09:21 +00:00
Isis Lovecruft
73a5f4711a
Remove unnecessary extern crate sha2 from test code. 2018-07-20 00:06:31 +00:00
Isis Lovecruft
7b22fe6e87
Change the wording on the Scalar::as_bytes() docstring. 2018-07-20 00:04:25 +00:00
Isis Lovecruft
04f75767f3
Scalar::random should work with nostd.
* FIXES #166.
2018-07-19 23:51:13 +00:00
Isis Lovecruft
133afff5a7
Feature gate some uses on alloc/std which aren't used in nostd.
* FIXES part of #166.
2018-07-19 23:50:58 +00:00
Henry de Valence
1e74cb3e56 Replace Scalar::from_u64 with From impls
Unfortunately, Rust selects `i32` as the type for an integer literal
when the literal has no other type constraints.  This means that someone
cannot write `Scalar::from(1)`, as Rust will choose `i32` as the type for
`1`, and we don't `impl From<i32> for Scalar`.

We could implement `From` conversions for signed integers, but since
`Scalar` operations should be constant-time by default, this would
require us to extract the sign bit of the integer and use it to
conditionally select between the positive and negative of Scalar
constructed from the value bits.  This is more expensive than the
unsigned operation, and I don't think it's what anyone really wants.

Making API consumers specify that their literals are unsigned is
slightly annoying, but better than the above alternative.

It would also be nice to change `Scalar::from_hash` to be
`impl<D: Digest<OutputSize = U64>> From<D> for Scalar`,
but this isn't currently allowed by Rust (since that `impl` "could"
conflict with the `impl From<u8>` if someone decided that `u8` should
`impl Digest`).
2018-07-19 08:39:09 -07:00
Henry de Valence
b4db0afe18 Allow Options in the VartimeMultiscalarMul trait
This changes the primary function for the `VartimeMultiscalarMul` trait
to an `optional_multiscalar_mul` trait that accepts
`Option<Self::Point>` (and returns `None` if any input points are
`None`).

The existing `vartime_multiscalar_mul` is changed to be a wrapper around
this function to avoid code duplication.  This may result in an
extra copy of each input point, but that cost is probably not
significant compared to the cost of the multiscalar multiplication.

The motivation is to allow performing multiscalar multiplications with
inline decompression.  Currently, API consumers have to allocate
temporary buffers for all of their points, decompress into those
buffers, then pass (iterators over) those buffers into the multiscalar
multiplication code, which then creates new buffers for lookup tables.
2018-07-17 08:19:48 -07:00
Henry de Valence
7bbf7495b0 Change VartimeMultiscalarMul docs to use vartime_ 2018-07-16 22:54:45 -07:00
Henry de Valence
dfc9e7c0b7 fixup extendedpoint validity check 2018-07-16 22:28:22 -07:00
Henry de Valence
0c58de0367 it wouldn't be 2018-07-16 22:22:58 -07:00
Henry de Valence
f7f3f79da8 Add missing Ristretto vartime-double-base fn 2018-07-16 22:22:21 -07:00
Henry de Valence
5bb6cd42a2 we won't remove this function 2018-07-16 22:13:40 -07:00
Henry de Valence
bc731f9d79 Remove fixme notes from FieldElement code 2018-07-16 22:11:48 -07:00
Isis Lovecruft
46c98224f5
Remove erroneous and extraneous alloc import from edwards module.
The "alloc" feature doesn't compile otherwise.

 * FIXES #160.
2018-07-17 00:28:04 +00:00
Isis Lovecruft
74a28559c4
Add example code for Scalar.to_bytes() and Scalar.as_bytes(). 2018-07-17 00:22:34 +00:00
Isis Lovecruft
ff16e93102
Add doctest for Scalar::from_hash(). 2018-07-17 00:21:37 +00:00
Isis Lovecruft
61daa9dce6
Add a doctest for Scalar::from_u64(). 2018-07-06 00:12:35 +00:00
Isis Lovecruft
3854eb0fd8
Remove extra line and unneeded XXX comment from Scalar::hash_from_bytes. 2018-07-06 00:10:41 +00:00
Isis Lovecruft
37935674eb
Add doctest for Scalar::random(). 2018-07-06 00:10:21 +00:00
Henry de Valence
5b009a033e Remove extra line in doctest 2018-07-05 13:34:14 -07:00
Henry de Valence
0ab60b93ee Update wording on Scalar::invert to use self 2018-07-05 13:34:02 -07:00
Henry de Valence
b70b32a0c5 Change Scalar example to use the hasher functions 2018-07-05 13:27:09 -07:00
Isis Lovecruft
f43f4f9770
Update year in copyright notices to 2018. 2018-07-05 00:30:27 +00:00
Isis Lovecruft
03154d47ec
Add an example doctest for Scalar.invert(). 2018-07-05 00:30:27 +00:00
Isis Lovecruft
faf8609246
Copy the inversions of 0 warning to the invert() method. 2018-07-05 00:14:55 +00:00
Isis Lovecruft
626e070896
Document Scalar contructors with doctests. 2018-07-04 23:57:04 +00:00
Isis Lovecruft
5b263dabd0
Line wrap some docstrings in scalar.rs. 2018-07-04 21:43:13 +00:00
Isis Lovecruft
f4669c8b4d
Move the Scalar constructor documentation to the module level. 2018-07-04 21:29:36 +00:00
Isis Lovecruft
11aa71fb8d
Merge remote-tracking branch 'ebfull/sequential-montgomery-trick' into develop 2018-07-04 20:24:19 +00:00
Sean Bowe
61d6d89cd8
Fix comment describing Montgomery adjustment factor's value. 2018-07-02 10:41:45 -06:00
Sean Bowe
c4f86b231c
Only test debug assertion in batch_invert when debug assertions are enabled. 2018-07-01 15:07:04 -06:00
Sean Bowe
02af12b81a
Replace batch inversion for FieldElement with sequential variant of Montgomery's trick. 2018-07-01 15:07:04 -06:00
Sean Bowe
6294c02b52
Replace batch inversion implementation for Scalar with sequential variant of Montgomery's trick. 2018-07-01 15:07:04 -06:00
Sean Bowe
611fc40318
Add test that an empty vector field inversion returns one. 2018-06-30 16:29:02 -06:00
Sean Bowe
11b1dc142f
Add test for behavior of Scalar::batch_invert(). 2018-06-30 09:49:54 -06:00
Henry de Valence
16f39c82e5 Remove yolocrypto from avx2_backend 2018-06-18 13:32:04 -07:00
Henry de Valence
d791047aac Rewrite notes and documentation. 2018-06-18 13:22:03 -07:00
Henry de Valence
15f97221ba Suppress extraneous warnings 2018-06-15 13:44:31 -07:00
Henry de Valence
7198719419 Document bounds on FieldElement32x4 functions 2018-06-15 13:36:38 -07:00
Henry de Valence
9f5bd8c4c0 Rename reduce32 to reduce and have it return its result.
This means that all FieldElement32x4 operations return values, vs mutating interior state.
2018-06-14 15:54:36 -07:00
Henry de Valence
bab1ebbeb8 Replace scale_by_curve_constants by a Mul<(u32,u32,u32,u32)> impl 2018-06-14 15:42:20 -07:00
Henry de Valence
6ef9e9dcfb Make publicity a little more consistent 2018-06-14 15:22:16 -07:00
Henry de Valence
97292fef91 Move packing functions to top of the module 2018-06-14 15:21:51 -07:00
Henry de Valence
4dc219910a Move blend_lanes into the blend function 2018-06-14 15:13:53 -07:00
Henry de Valence
64b1b481ba Rewrite diff_sum in terms of shuffle, blend, negate 2018-06-14 14:59:11 -07:00
Henry de Valence
fe51adad31 Don't expose u32x8 unpacking functions 2018-06-14 14:32:13 -07:00
Henry de Valence
c46ec9638c Add documentation 2018-06-14 14:23:24 -07:00
Henry de Valence
eea3eadf5b Replace special-case swap_{AB,CD} methods with general shuffles 2018-06-14 14:23:24 -07:00
Henry de Valence
02296fafb5 Delete unused constant 2018-06-14 14:23:24 -07:00
Henry de Valence
25d9f3f6ca Eliminate vector constants from edwards module 2018-06-14 14:23:24 -07:00
Henry de Valence
cc8728b2a6 Add comment about rustc-constant-info to blend function 2018-06-14 14:23:24 -07:00
Henry de Valence
28f10bc183 Change Lanes::ALL to Lanes::ABCD for consistency 2018-06-14 14:23:24 -07:00
Henry de Valence
794ed5c8e3 Rewrite the doubling horrorshow 2018-06-14 14:23:24 -07:00
Henry de Valence
30a2b01c05 Add more selectors to the Lanes enum 2018-06-14 14:19:46 -07:00
Henry de Valence
64cb999866 Make platform-vector lanes constants private 2018-06-14 14:19:26 -07:00
Henry de Valence
00d8b6ea4f Change negate_D, negate_D_lazy to impl Neg, negate_lazy 2018-06-14 14:17:36 -07:00
Henry de Valence
14ce6d3da6 Add a shuffling abstraction for FieldElement32x4 2018-06-14 14:10:37 -07:00
Henry de Valence
c8dc2a6418 Implement addition for FieldElement32x4 2018-06-14 14:10:32 -07:00
Henry de Valence
bd1e3c5f3e some rustfmt changes 2018-06-14 14:05:52 -07:00
Isis Lovecruft
9a89a217f8
Merge remote-tracking branch 'dalek/multiscalar-trait-without-precomputation_r1' into develop 2018-05-15 20:23:05 +00:00
Henry de Valence
bbb64312f7 Use rand 0.5
Requires `0.5.0-pre.2`, which adds `impl CryptoRng for OsRng`.
2018-05-15 12:30:28 -07:00
Henry de Valence
bab642c5af Add doc comments 2018-05-15 11:33:38 -07:00
Henry de Valence
2eed24109e Move double-base scmul to the EdwardsPoint type 2018-05-15 11:33:38 -07:00
Henry de Valence
149c5004e8 Use multiscalar traits for the backend implementations. 2018-05-15 11:33:38 -07:00
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
Henry de Valence
62bb6b79a1
Merge pull request #134 from Mandragorian/feature-scalar-traits
Implement Product and Sum traits
2018-05-03 13:56:45 -07:00
mandragore
96d2fe4905 Implement Sum trait for RistrettoPoint
Closes #131.
2018-05-03 03:42:37 +03:00
mandragore
aff69a58a4 Implement Sum trait for EdwardsPoint 2018-05-03 03:42:37 +03:00
Henry de Valence
185bbd3da8 Fix build on recent nightlies (was broken due to type inference failure) 2018-05-02 17:30:10 -07:00
mandragore
01fd44ffd2 Remove trailing whitespaces 2018-05-02 23:53:52 +03:00
mandragore
3ab087ea7f Implement Sum trait for Scalar 2018-05-02 23:53:49 +03:00
mandragore
afffe962f9 Implement Product trait for Scalar 2018-05-02 23:53:24 +03:00
Henry de Valence
285e57f2ff
Merge pull request #128 from hdevalence/feature/avx2-docs
Update docs for AVX2 backend
2018-04-08 17:16:05 -07:00
Henry de Valence
67ba201835 Update AVX2 documentation 2018-04-08 16:59:57 -07:00
Henry de Valence
6bb2c02a1f
Merge pull request #127 from hdevalence/feature/generalize-naf
Generalize NAF code to wider window sizes.
2018-04-08 16:39:45 -07:00
Henry de Valence
1464c4101d change LSB to least significant bit 2018-04-08 16:29:54 -07:00
Henry de Valence
9fc5602ce7 Split AVX2 docs into markdown file 2018-04-08 15:15:23 -07:00
Henry de Valence
68bbd1bd03 Document algorithm for NAFs 2018-04-06 12:11:59 -07:00
Henry de Valence
6b768c2a1a Change AVX2 backend to use width-8 tables 2018-04-05 16:20:47 -07:00
Henry de Valence
ff787c2f12 Clarify Ristretto / Decaf relation in user docs 2018-04-05 14:52:00 -07:00
Henry de Valence
c99bd62b25 Add example to RistrettoBasepointTable 2018-04-05 14:52:00 -07:00
Henry de Valence
46048e451b Clarify wording on canonical scalars 2018-04-05 14:52:00 -07:00
Henry de Valence
35e1b07e72 Clarify abstraction layers in Ristretto intro 2018-04-05 14:52:00 -07:00
Henry de Valence
c841998b07 Extract Ristretto notes into a markdown file 2018-04-05 14:52:00 -07:00
Henry de Valence
ef0dae241a Add an explanatory note that's built on stable
When building on stable, the README.md is not included in the documentation,
leaving a bare entry. This adds a warning stub, pointing people to use nightly
rust.
2018-04-05 14:52:00 -07:00
Henry & Isis
62d43752df
Add NafLookupTable8 and use for pre-computed basepoint table generation. 2018-04-05 05:12:13 +00:00
Henry & Isis
753a0292de
Rename OddLookupTable to NafLookupTable5.
An OddLookupTable corresponds to a non-adjacent form of width 5.
2018-04-05 04:48:28 +00:00
Henry de Valence
7e0ddf6b98 Rewrite NAF code to work with more window sizes
Change Scalar::non_adjacent_form() to take a width parameter.

This rewrite also makes it faster, although it's probably a ways off
from optimal. I don't know how much it matters.

TODO: write up description of why this computes the same thing.

Thanks to @oleganza for pointing out an error reading bits across words
in an earlier version of this code.
2018-04-04 21:13:09 -07:00
Henry de Valence
5f136fbd0c Remove some warnings.
Not all of the warnings are removed, since although this code works, it still
needs a significant amount of cleanup, editing, and polish.
2018-04-04 10:25:42 -07:00
Henry de Valence
b0bda0278c Drop the stdsimd crate in favor of core::{simd, arch}.
This change required some work, because the to-be-stabilized SIMD functions
don't allow non-constant `imm8`s.  Previously, the `stdsimd` functions had a
constifying macro that ensured that the immediates were known.  The dalek code
used this to build helper functions which would be inlined into different
places where the immediates were known.  Unfortunately, since constexprs aren't
fully supported in Rust yet, this is done by a hidden compiler attribute, and
there's no way to propagate "constness".

To deal with this, some of the functions are specialized (e.g.,
`square_and_negate_D` instead of taking a mask), and others use an enum.
2018-04-03 17:58:23 -07:00
Isis Lovecruft
3281708965
Define mul variants for MontgomeryPoints.
This results in less changes to the x25519-dalek code to upgrade to
the latest version.
2018-04-02 21:09:41 +00:00
Henry de Valence
4a648df713 Feature-gate multiscalar impls on alloc 2018-03-26 17:58:31 -07:00
Henry de Valence
7ef6a1e6fa Reorganize AVX2 point code 2018-03-26 17:41:05 -07:00
Henry de Valence
e8b053b281 Remove AVX2 addition formulas
Only the readdition formulas are actually used by scalar multiplication, so
there's no reason to implement vectorized addition.
2018-03-26 17:41:05 -07:00
Henry de Valence
c73a0fd0d6 Remove AVX2 fixed-base code.
This was faster than the non-AVX2 code, but the serial code is already so fast that there's no reason not to use it.
2018-03-26 17:41:05 -07: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
c9239f54e9 Merge branch 'fix/warnings' into develop 2018-03-22 12:34:31 -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
f2e44898ee Suppress warnings about square() on UnpackedScalars 2018-03-22 12:17:23 -07:00
Henry de Valence
0ba5c72122 This variable doesn't need to be mut since it's immediately consumed 2018-03-22 12:17:23 -07:00
Henry de Valence
e73b635fe0 Remove unused constants 2018-03-22 12:17:23 -07:00
Henry de Valence
844da9712b Fix AVX2 docs formatting, remove obsolete AVX512 note 2018-03-22 12:13:39 -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
132b1a9d77 Merge branch 'feature/ristretto-uniform-hash' into develop 2018-03-22 11:44:52 -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
b48d568f47 Add debug_assert that Scalar::batch_invert inputs are nonzero 2018-03-22 11:32:00 -07:00
Henry de Valence
0e7d872ad0 Add batch inversion for Scalars 2018-03-22 11:32:00 -07:00
Henry de Valence
792ac0775e Change to the updated subtle API. 2018-03-22 11:13:26 -07:00
Henry de Valence
7f39656b4a Apply the Elligator map twice to ensure a uniform distribution
As noted in the Decaf paper, mapping twice and adding the results ensures a
uniform distribution over the group.  This changes our random point and
hash-to-point functions to do this, matching the Sage script.
2018-03-19 15:37:38 -07:00
Henry de Valence
c20e09f6cc Rename multiscalar_mult->multiscalar_mul to match Mul traits 2018-03-19 14:28:21 -07:00
Henry de Valence
c5fcc6602d Fix build for AVX2 backend.
A missing import of the Borrow trait caused the build to break with the
"yolocrypto" feature enabled; this was't caught by CI because the CI machine
that Travis used didn't have AVX2, so the code was never built.

This commit adds the missing import and changes `std` to `core` so that the
AVX2 backend builds with no_std, but this isn't tested and is, actually,
"yolocrypto".
2018-03-19 11:15:52 -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
3969d80c89 Add links to dalek.rs 2018-02-21 11:11:17 -08:00
Henry de Valence
2b42966bb4 Load resources from our own domain 2018-02-21 11:03:18 -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
b5e664ab16
Add RISTRETTO_BASEPOINT_COMPRESSED constant. 2018-02-02 02:33:51 +00:00
Isis Lovecruft
23bc6ff848
Change README and docs sidebar image to transparent version. 2018-01-31 02:26:28 +00: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
2d5dc5079f Add type to X25519 basepoint doc 2018-01-29 14:39:37 -08:00
Henry de Valence
1d480a8a71 Rename X25519 basepoint to X25519_BASEPOINT_MONTGOMERY 2018-01-29 14:36:45 -08:00
Henry de Valence
ae46ecd445 Rename BASE_CMPRSSD to ED25519_BASEPOINT_COMPRESSED. 2018-01-29 12:38:58 -08:00
Henry de Valence
06994e8139 Tidy docs for public constants in backends 2018-01-29 12:38:58 -08:00
Henry de Valence
739755cb1c Fix up constants docstrings 2018-01-29 12:38:58 -08:00
Henry de Valence
d3a8ee0d7b Remove BASEPOINT_ORDER_MINUS_* constants
These were originally added in 32da4c7d50
to implement Scalar negation in terms of multiply-add.

But we have a full implementation of scalar arithmetic now, so it's not
necessary to keep the constants around.
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
d4d9d86d72 Fix up coffee/ristretto reference 2018-01-26 15:35:51 -08:00
Henry de Valence
12e658401c Reword Ristretto intro 2018-01-26 14:53:31 -08:00
Henry de Valence
52904b5c3e Use math for multiscalar docs 2018-01-26 13:39:11 -08:00
Henry de Valence
4b47087b40 Refactor Ristretto notes into doc and doc-internal sections. 2018-01-26 13:35:30 -08:00
Henry de Valence
576e27982f Tweak module header names 2018-01-26 10:44:48 -08:00
Henry de Valence
fbd84af767 Ristretto API docs fixups 2018-01-25 17:34:57 -08:00
Henry de Valence
d04d3719a5 Add logo to sidebar 2018-01-25 17:34:20 -08:00
Henry de Valence
99921de6f3 Use README.md for the crate docs, and rewrite it. 2018-01-25 16:26:05 -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
Isis Lovecruft
9cb915126e
Merge remote-tracking branch 'dalek/feature/borrow-operators' into develop 2018-01-25 02:00:52 +00:00
Henry de Valence
86fd06db00 s/eps/epsilon/ for clarity 2018-01-24 12:42:57 -08: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
0e9b8e0a6e Refactor multiply implementation to eliminate reduce() call 2018-01-19 18:23:41 -08:00
Henry de Valence
ec50ec96f7 Use parallel carry-ins and carry-outs in FieldElement64::reduce() 2018-01-19 17:50:48 -08:00
Henry de Valence
d8d235fb48 Move pow2k into the backends and use it to implement square() 2018-01-19 17:50:48 -08:00
Henry de Valence
1f821d34a5 Feature-gate batch inversion and compression on alloc 2018-01-19 17:22:28 -08:00
Henry de Valence
b20ccbd685 Implement batched encoding for RistrettoPoints 2018-01-19 17:22:28 -08:00
Henry de Valence
de377290ee Implement batch inversion using a product tree. 2018-01-19 17:22:28 -08:00
Isis Lovecruft
0012e1f12f
Merge remote-tracking branch 'hdevalence/feature/avx2_r7' into develop 2018-01-19 23:46:30 +00:00
Henry de Valence
a0c93cb730 fix inconsistency in variable naming 2018-01-10 06:04:03 -08:00
Henry de Valence
841c026c13 Remove dead code 2018-01-10 05:49:47 -08:00
Henry de Valence
f816083575 Use >> instead of srl intrinsic 2018-01-03 14:04:27 -08:00
Henry de Valence
4cbff3983d Remove fixme notes 2018-01-03 14:01:48 -08:00
Henry de Valence
628af18a1d Suppress some warnings 2018-01-03 13:57:50 -08:00
Henry de Valence
3686562b2f Clear memory from avx2 multiscalar mult 2018-01-03 13:37:12 -08:00