Commit graph

123 commits

Author SHA1 Message Date
isis agora lovecruft
5038fcf50a
Merge pull request #308 from isislovecruft/fix/pippenger-typo
Fix typo of Pippenger's name.
2020-07-01 01:14:10 +00:00
Rui Morais
6a8e466063 add derive Hash to Scalar, MontgomeryPoint and CompressedEdwardsY 2020-02-25 22:39:19 +00:00
Isis Lovecruft
7e2aed3943
Fix typo of Pippenger's name. 2019-12-10 20:33:53 +00:00
Isis Lovecruft
9ae2e3b482
Change all from_slice() constructors to return Option<T>s.
We due this in lieu of implementing `TryFrom` to allow for API
consumers to use the `?` operator to convert potential `None`s into
their own `Result<T, CustomError>` types for better error handling
with less boilerplate.

Note that this is a breaking API change.
2019-10-28 17:29:15 +00:00
Isis Lovecruft
1d8b3995c9
Add custom error types, currently only used in TryFrom impls. 2019-10-28 17:28:40 +00:00
Isis Lovecruft
db3d26f4b9
Fix typo in TryFrom docstring. 2019-10-28 17:26:23 +00:00
Isis Lovecruft
a7f317a2b8
Impl TryFrom<&[u8]> for all compressed point types.
This reduces copy-pasta in downstream users to check the length of the
slice beforehand.
2019-10-28 17:26:23 +00:00
Henry de Valence
0fc534d989 Use "tuples" instead of "bytes" in the Serde datamodel.
This is a breaking change to the serialization format.  It fixes it so that the
Serde encoding can match the conventional encoding of each type of object, and
so that Serde can be used with no overhead -- when using serde-bincode, the
Serde encoding now matches the manual encoding.
2019-10-23 15:40:50 -07:00
Henry de Valence
29ce0d4fe9 Add length checks to serde-bincode tests.
This ensures that the serde Serialize and Deserialize implementations use
fixed-length Serde tuples, rather than variable-length byte arrays.  This flaw
in data modeling was pointed out by Trevor Perrin.
2019-10-23 15:28:48 -07: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
François Garillot
9785f56c0f
Rust fixes for some clippy warnings
Clippy lints with instances in the project but NOT applied here, since they seem consistently at odds with the projects' style:
- [unreadable literal](https://rust-lang.github.io/rust-clippy/master/#unreadable_literal)
- [cast lossless](https://rust-lang.github.io/rust-clippy/master/#cast_lossless)
- [assign op pattern](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern)
2019-10-05 12:02:08 -07:00
Henry de Valence
b01888a929
Merge pull request #260 from fabric-and-ink/ed-decompress-simplify
Remove unneeded check for negativity in edwards point decompression
2019-08-07 12:57:24 -07:00
Fabian Drinck
26ae185bc9
Apply suggestion by @hdevalence
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-08-07 19:43:10 +02:00
root
ccaf86ea86 curve_models link in comment mismatch 2019-08-06 16:40:47 +08:00
Fabian Drinck
53da2aaaf4 Remove unneeded check for negativity in edwards point decompression
The function `FieldElement::sqrt_ratio_i` always returns a positive root
by definition. Therefore the test for negativity in the edwards point
decompression function always returns false and we only need to flip its
sign if `compressed_sign_bit` is set.
2019-06-07 21:04:12 +02:00
Henry de Valence
389d2bc9e2 Ensure Pippenger works on manually-constructed extremal values.
When using Scalar::from_bits to manually create unreduced Scalars (e.g.,
X/Ed25519 keys with specified bit patterns), it's possible to construct Scalar
values that range up to 2^255-1.  These shouldn't ever end up in a vartime
multiscalar mul call anyways, because it doesn't handle secret data, but it is
technically allowed by the type system and should be handled.  When w=8, these
can generate terminal carries that can't be folded into the last digit, but
this can be handled by folding them into an extra digit instead.
2019-06-05 23:03:07 -07:00
Henry de Valence
6fe93564cd Add a more comprehensive random multiscalar test.
This exercises the constant- and variable- time code at large sizes, to hit
every path of Straus/Pippenger.
2019-06-05 20:54:00 -07:00
Oleg Andreev
df745e98a2 oops - forgot to switch on pippenger 2019-05-21 14:10:56 -07:00
Henry de Valence
23ca520ac2
Merge pull request #226 from ebfull/faster-equality
Check the equality of `EdwardsPoint`s in the projective coordinates
2019-05-21 08:50:32 -07:00
Henry de Valence
a1123e7cd3
Merge pull request #230 from hdevalence/updated-precomputation
Multiscalar multiplication with precomputation.
2019-02-14 12:18:29 -08:00
Henry de Valence
092ff52cb0 Remove constant-time multiscalar precomputation.
This doesn't (yet) give any speedup over the non-precomputed multiscalar
multiplication, and it's not clear that it's a good idea to commit to
supporting it in the future.  Removing it means that it's not committed-to as
part of the public API, but the source is still there in the tree if we want to
revisit it later.
2019-02-13 12:26:31 -08:00
Henry de Valence
96df60895f Fix comment on Montgomery conversion.
Closes #213.
2019-02-12 19:30:18 -08:00
Henry de Valence
27daa5215e Add Ristretto precomputation facade. 2019-02-12 12:52:02 -08:00
Henry de Valence
727ba86292 Rework the vartime precomputation trait to be Option-al 2019-02-12 12:52:02 -08:00
Henry de Valence
c6acdfd5e2 Add serial implementation of precomputation. 2019-02-12 12:52:02 -08:00
Sean Bowe
d71b6650d6
Check the equality of EdwardsPoints in the projective coordinates to avoid expensive compressions. 2019-02-06 17:45:25 -07:00
Henry de Valence
ff0dc4a3db Merge branch 'master' into develop 2019-01-27 23:19:44 -08:00
Henry de Valence
5ddc30061c Implement ConstantTimeEq on compressed points. 2019-01-27 23:13:58 -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
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
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
b0a190bd63 Change externally-exposed API to implement ConditionallySelectable 2018-11-02 14:16:51 -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
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
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
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
Isis Lovecruft
4d527cae4b
Merge branch 'feature/154-defaults' into develop 2018-07-20 19:52:34 +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
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
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
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