Commit graph

739 commits

Author SHA1 Message Date
Henry de Valence
fa42708257 Change naming scheme for multiplication accumulators. 2019-01-18 14:19:30 -08:00
Henry de Valence
a84f9eafe4 Allow non_snake_case in the IFMA field and edwards modules. 2019-01-18 14:19:30 -08:00
Henry de Valence
06766bfdea Delay shuffles that cross the "Great Wall of Intel". 2019-01-18 14:19:30 -08:00
Henry de Valence
33aa544cf4 Add IFMA constants file. 2019-01-18 14:19:30 -08:00
Henry de Valence
f825426ff4 Add impl Default, Identity for ExtendedPoint, CachedPoint. 2019-01-18 14:19:30 -08:00
Henry de Valence
da62569355 Add lookup table support. 2019-01-18 14:19:30 -08:00
Henry de Valence
6cec313f16 Add impl of Sub and Neg for Edwards points. 2019-01-18 14:19:30 -08:00
Henry de Valence
6faaef21df Add mul_by_pow_2 for IFMA 2019-01-18 14:19:30 -08:00
Henry de Valence
8e38ff2859 Add Edwards doubling implementation. 2019-01-18 14:19:30 -08:00
Henry de Valence
c4617b28a9 Add squaring implementation. 2019-01-18 14:19:30 -08:00
Henry de Valence
a62571b003 Reduce field elements during conversion to vector form.
The IFMA types have tighter bounds than the u64 types.
2019-01-18 14:19:30 -08:00
Henry de Valence
3f21bb3b58 Add skeleton of parallel Edwards formulas. 2019-01-18 14:19:30 -08:00
Henry de Valence
5880fced2b Add skeleton of shuffle and blend functions. 2019-01-18 14:19:30 -08:00
Henry de Valence
d90bb779ca Delay all computations using x[0], y[0]
Since computation of the 0 term in reduction requires a multiplication with a
4-cycle latency, this ensures that the rest of the computation can start before
the 0 term is finished
2019-01-18 14:19:30 -08:00
Henry de Valence
c925c76342 Change the strategy for reducing the high half of the product. 2019-01-18 14:19:30 -08:00
Henry de Valence
607b839032 Change size of limbs in the reduction test. 2019-01-18 14:19:30 -08:00
Henry de Valence
14163131f9 Lift the reduction state of the field elements into the type system.
This splits the `FieldElement51x4` type into two types:

- `F51x4Reduced` (with reduced limbs)
- `F51x4Unreduced` (with unreduced limbs)

The reduction is implemented as a `From` impl to convert one type to the other.

The output of a multiplication is now a `F51x4Unreduced`.  The reason is that
the inputs to IFMA operations must be at most 52 bits, so it's not possible to
perform an addition of (51+epsilon)-bit values and still be small enough to be
used as an input to multiplication.  So, it doesn't make sense to perform a
reduction at the end of a multiplication, because the reduced values will be
fed into an addition or subtraction, which then needs to be re-reduced.
2019-01-18 14:19:30 -08:00
Henry de Valence
ff49673214 Add impl Mul<(u32, u32, u32, u32)> for FieldElement51x4. 2019-01-18 14:19:30 -08:00
Henry de Valence
70199d6094 Add impl Mul<FieldElement51x4> for FieldElement51x4. 2019-01-18 14:19:30 -08:00
Henry de Valence
aa73d7b1bc Add a FieldElement51x4 type. 2019-01-18 14:19:30 -08:00
Henry de Valence
3233e2eac6 Fix: cfg_target_feature is stable since 1.27. 2019-01-18 14:19:20 -08:00
Henry de Valence
be77af1cd8 Remove unnecessary feature gate.
The vector backend doesn't generate constants in build.rs, so this isn't necessary.
2019-01-18 14:18:55 -08:00
Henry de Valence
47a164da4d Replace avx2_backend with simd_backend (autoselects AVX2/IFMA) 2019-01-18 01:52:17 -08:00
Henry de Valence
9ed2128a10 Add stub code for IFMA intrinsics in Rust. 2019-01-18 01:52:17 -08:00
Henry de Valence
0a97f5fe8c Don't compile the serial scalar_mul when using the vector one. 2019-01-18 01:52:07 -08:00
Henry de Valence
f1d2b5182b Restructure source tree into serial and vector backends.
This begins to attempt to restructure the source tree so that the common parts
are common and the different parts are different.

The backend is now split into two parts:
- serial (containing the implementation using serial formulas and mixed-model arithmetic).
- vector (containing the implementation using parallel formulas and single-model arithmetic).

The serial scalar_mul tree is now under backend::serial::scalar_mul.
The avx2 scalar_mul tree is now under backend::avx2::scalar_mul.
2019-01-18 01:49:40 -08:00
Henry de Valence
94cb3e7842 Rename field types based on radix.
`FieldElement32` -> `FieldElement2625`
`FieldElement64` -> `FieldElement51`
`Scalar32` -> `Scalar29`
`Scalar64` -> `Scalar52`

This naming is more accurate and would let us add an ADX backend later.
2019-01-17 22:21:55 -08:00
Henry de Valence
e6f27ca996 Fix Ristretto variable naming in decoding function
The code swaps u_1 and u_2 relative to the formulas (probably when doing the change for a=-1)
2019-01-13 18:01:00 -08:00
Артём Павлов [Artyom Pavlov]
d6ca36fa0b replace rand with rand_core+rand_os 2019-01-05 14:27:24 +03:00
Jeff Burdges
20fd561482 Support passing both borrowed and owned Rngs 2018-12-26 17:09:20 +01:00
DebugSteven
39145da396 implement default for MontgomeryPoint using zero byte array 2018-11-14 23:16:50 -05:00
DebugSteven
2adc985f63 default & identity trait for MontgomeryPoint 2018-11-14 14:43:11 -05:00
isis agora lovecruft
5d0bdf2f21
Merge pull request #205 from dalek-cryptography/fix-subtle-traits
Change to subtle::ConditionallySelectable
2018-11-05 23:50:35 +00:00
isis agora lovecruft
0a1dc053d1
Merge pull request #203 from dalek-cryptography/sqrt_i
Refactor square root computations and Elligator
2018-11-05 23:16:59 +00:00
Henry de Valence
a116fd9679 test subtle 2.0 2018-11-05 12:06:23 -08:00
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