Commit graph

95 commits

Author SHA1 Message Date
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
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
Henry de Valence
a116fd9679 test subtle 2.0 2018-11-05 12:06:23 -08: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
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
bc731f9d79 Remove fixme notes from FieldElement code 2018-07-16 22:11:48 -07:00
Isis Lovecruft
f43f4f9770
Update year in copyright notices to 2018. 2018-07-05 00:30:27 +00:00
Sean Bowe
02af12b81a
Replace batch inversion for FieldElement with sequential variant of Montgomery's trick. 2018-07-01 15:07:04 -06: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
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
792ac0775e Change to the updated subtle API. 2018-03-22 11:13:26 -07: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
de377290ee Implement batch inversion using a product tree. 2018-01-19 17:22:28 -08:00
Henry de Valence
c0633ae2d7 KaTeXify some backend documentation 2017-12-01 11:46:36 -08:00
Henry de Valence
e196f8347c Move 32/64-bit code into submodules in a backend module.
See the doc comment in `backend/mod.rs` for motivation on naming.
2017-11-16 16:07:55 -08:00
Henry de Valence
207af566b9 Replace signed constants with unsigned constants 2017-11-16 12:13:13 -08:00
Henry de Valence
b6bfc79cd1 Fix up Elligator tests to match ristretto.sage 2017-10-30 16:34:36 -07:00
Henry de Valence
f4135da5c9 Remove is_negative_decaf since ristretto uses the low bit 2017-10-30 16:34:36 -07:00
Henry de Valence
fafdae7a60 Prototype of Ristretto encoding 2017-10-30 16:34:36 -07:00
Isis Lovecruft
acd3826fe2 Implement Montgomery arithmetic and laddering.
* ADDs part of https://github.com/isislovecruft/curve25519-dalek/issues/47
2017-09-14 02:09:14 +00:00
Isis Lovecruft
17290db44c
Update copyright/license headers in source files. 2017-08-15 05:09:20 +00:00
Isis Lovecruft
f2883028dc
Use subtle version 0.2.0.
* CLOSES PR#66 https://github.com/isislovecruft/curve25519-dalek/pull/66
2017-08-01 02:22:43 +00:00
Henry de Valence
f72de04003 Remove unneeded imports to suppress warnings 2017-07-30 16:29:37 -07:00
Henry de Valence
77103986a3 Split field arithmetic into per-implementation files
Split the field arithmetic implementations into `FieldElement`,
`FieldElement32`, and `FieldElement64`.  `FieldElement` is a type alias for one
of `FieldElement32` or `FieldElement64`, depending on feature selection.
`field.rs` contains tests and code which is generic with respect to the
implementation (e.g., inversions), while `field_32bit.rs` and `field_64bit.rs`
contain the implementation-specific code.

The implementation is not completely hidden, since `FieldElement32` and
`FieldElement64` are tuple structs whose elements are public; `pub(crate)`
doesn't seem to work for tuple structs.

Similarly, the constants file is split over multiple files, depending on the
implementation.
2017-07-30 16:25:42 -07:00
Henry de Valence
513ce26942 avoid 128-bit multiplications 2017-07-20 21:33:15 -07:00
Isis Lovecruft
4bcf8bed9d
Move subtle to its own crate. 2017-05-31 21:20:56 +00:00
Isis Lovecruft
16904432be
Remove an unnecessary explicit return in FieldElement.to_bytes(). 2017-05-28 22:45:13 +00:00
Isis Lovecruft
674a00df5b
Some rustfmt fixes. I disagreed with all the other ones. 2017-05-28 22:42:09 +00:00
Isis Lovecruft
0c38718346
Rename subtle::arrays_equal_ct() to subtle::arrays_equal().
It's already obvious that it's constant-time because it's in the subtle
module.
2017-05-26 22:35:45 +00:00
Isis Lovecruft
9a9959061d
Merge remote-tracking branch 'hdevalence/feature/clippy-fixes' into develop 2017-05-06 00:16:09 +00:00
Henry de Valence
cb656bafa7 Delete bytes_equal_less_than
This function is unused and untested.  It's also incorrect, since the loop
32..0 iterates over an empty range.  Remove it for now; if we need it later, it
still lives in the history.
2017-04-25 15:08:59 -07:00
Henry de Valence
57c96616b9 Remove unused import 2017-04-25 14:50:59 -07:00
Henry de Valence
e00cd114d7 Have radix 25.5 reduce() consume its argument 2017-04-02 23:46:01 +02:00
Henry de Valence
162dfc8331 Remove clones on Copy types 2017-04-02 23:45:34 +02:00
Henry de Valence
3705346afa Remove unnecessary returns 2017-04-02 23:39:45 +02:00
Henry de Valence
7f4b96150d Remove explicit lifetimes 2017-04-02 23:36:05 +02:00
Henry de Valence
c8e7e22ddf Remove unnecessary returns 2017-04-02 23:28:01 +02:00
Henry de Valence
73e172484c Add tick marks around code items in docs 2017-04-02 23:12:18 +02:00
Isis Lovecruft
d549fdc8f9
Whitespace fixes. 2017-03-17 21:42:40 +00:00
Henry de Valence
2f5b9e198c Remove warnings from load3/load4 and load8 functions 2017-03-14 01:05:31 -07:00
Isis Lovecruft
6991b4264b
Merge remote-tracking branch 'hdevalence/feature/64bit-multiplication_r3' into develop 2017-03-14 04:23:11 +00:00
Isis Lovecruft
f6930997d2
Make #[feature(test)] depend on #[cfg(all(test, feature = "bench"))].
* FIXES Issue #38:
   https://github.com/isislovecruft/curve25519-dalek/pull/38
2017-03-14 01:59:08 +00:00
Isis Lovecruft
cb3b3144be
Remove prefix from field tests. 2017-03-14 01:11:54 +00:00
Isis Lovecruft
904911e2b8
Move field module benchmarks to separate module. 2017-03-14 01:11:03 +00:00
Henry de Valence
cf9f9aa402 Enable radix_51 on nightly 2017-03-13 17:04:37 -07:00
Henry de Valence
45cc82d258 Move multiply() into the Mul impl 2017-03-13 16:38:05 -07:00
Henry de Valence
f11c97e75c Remove obsolete test code 2017-03-13 16:38:05 -07:00
Henry de Valence
d2a51197d7 Add a carry-reduction during subtraction. 2017-03-13 16:38:05 -07:00