Commit graph

89 commits

Author SHA1 Message Date
pinkforest(she/her)
2190332b67
Add target u32/u64 backend override (#454)
As suggested in #453 it is sometimes feasible to
select the backend bits via an override.

This change provides `cfg(curve25519_dalek_bits)`
to override the bits used in serial or fiat target backend.
2022-12-08 11:52:42 -05:00
Tony Arcieri
081f632d91
Implement simplified backend selection (#428)
As proposed in #414, this commit changes the backend selection approach,
introspecting `target_pointer_width` to select `u32_backend` vs
`u64_backend` (or `fiat_u32_backend`/`fiat_u64_backend` if the
`fiat_backend` feature is enabled).

This helps eliminate the use of non-additive features, and also the
rather confusing errors that happen if multiple backends are selected
(i.e. thousands of lines of rustc errors).

The selection logic checks if `target_pointer_width = "64"` and uses the
64-bit backend, or falls back to the 32-bit backend otherwise. This
means the crate will always have a valid backend regardless of the
pointer width, although there may be odd edge cases for exotic platforms
which would optimally use the 64-bit backend but have a non-"64" target
pointer width for whatever reason. We can handle those cases as they
come up.
2022-11-13 12:17:42 -05:00
Michael Rosenberg
5758b8cce1
Updated to edition 2021 (#413) 2022-10-18 13:45:59 -04:00
isis agora lovecruft
cecc821f40
Merge pull request #342 from huitseeker/fiat4_with_u32
Serial backends w/formally-verified field arithmetic for 32 & 64 bits
2021-04-13 23:23:41 +00:00
Isis Lovecruft
1491f0db36
Update copyright years. 2021-03-25 04:10:55 +00:00
François Garillot
abd1922456
Add a fiat_u32 backend based on fiat-crypto as well.
Renames fiat backend directory to fiat_u64 and does the additional plumbing required to make fiat_{u32, u64}_backend equal alternatives.
Adds a few comments.
2021-01-11 15:45:24 -08:00
François Garillot
d684e13f09
Add a fiat_u64_backend option to curve25519-dalek
This uses https://github.com/calibra/rust-curve25519-fiat/ to implement a new 64bit serial backend for dalek.

Co-authored-by: Zoe Parakevopoulou <zoopar@fb.com>
2021-01-11 09:30:07 -08:00
Henry de Valence
620d17ef40
Merge pull request #293 from dalek-cryptography/remove-build-rs
Remove build.rs constants generation.
2019-10-23 14:44:46 -07:00
Henry de Valence
574217694e Remove build.rs.
This was more useful at the time when we were determining, e.g., optimal lookup
table sizes and could regenerate them more easily, but it came at a massive
complexity cost.  It also meant that we were unable to implement backend
autoselection.  This commit removes the `build.rs` entirely.  In the future, a
different `build.rs` could be added that auto-selects a backend, but it seems
like the current default-u64 setup has been working fine.
2019-10-23 14:20:38 -07:00
Isis Lovecruft
7c5ba69491
Update copyright year. 2019-10-23 19:43:56 +00: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
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
Isis Lovecruft
f43f4f9770
Update year in copyright notices to 2018. 2018-07-05 00:30:27 +00: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
e73b635fe0 Remove unused constants 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
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
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
cd112afff5
Whitespace EOL fixes. 2018-01-31 02:19:53 +00: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
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
576e27982f Tweak module header names 2018-01-26 10:44:48 -08:00
Henry de Valence
2e9a3cba35 Remove reference to field elts since they're private 2017-11-29 13:03:01 -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
8d0808a077 Split internal curve models into a private submodule 2017-11-16 17:34:28 -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
8952c7f476 initial work on rewriting 32bit arithmetic 2017-11-16 12:13:13 -08:00
Henry de Valence
e7387650f6 Remove warnings from build.rs 2017-11-16 12:13:13 -08:00
Henry de Valence
108a690941 First attempt at generating basepoint tables at compile time 2017-11-16 12:13:13 -08:00
Henry de Valence
8f68b7a3ed Remove MSQRT_M1 constant 2017-10-31 14:10:33 -07:00
Henry de Valence
a7835a1246 UPPERCASE_GLOBALS and add documentation 2017-10-30 17:33:23 -07:00
Henry de Valence
089efbbbbe Prune constants that are no longer used anywhere 2017-10-30 16:53:39 -07:00
Henry de Valence
8c3ae7f010 Remove 'yolocrypto' from Ristretto 2017-10-30 16:34:36 -07:00
Henry de Valence
b6bfc79cd1 Fix up Elligator tests to match ristretto.sage 2017-10-30 16:34:36 -07:00
Henry de Valence
58a55117be Rename Decaf to Ristretto 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
Henry de Valence
c29103d109 Rename _BASEPOINT to _BASEPOINT_POINT.
Having _BASEPOINT_TABLE and _BASEPOINT_POINT means that it's not possible to
use the slow, generic scalar mult in place of the fast, precomputed scalar
mults.
2017-08-14 00:20:18 -07:00
Henry de Valence
8ad02e2f57 Move curve.rs to edwards.rs 2017-08-02 22:35:12 -07: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
52e51bdb16 Add constants for 1/sqrt(a-d) and 1/(a-d) 2017-05-20 21:39:58 -07:00