Commit graph

110 commits

Author SHA1 Message Date
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
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
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
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
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
1464c4101d change LSB to least significant bit 2018-04-08 16:29:54 -07:00
Henry de Valence
68bbd1bd03 Document algorithm for NAFs 2018-04-06 12:11:59 -07: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
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
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
d67e895619 Merge branch 'feature/rename-to-multiscalar-mul' into develop 2018-03-22 12:08:49 -07:00
Henry de Valence
2e73b2bc20 Use scalar_mul instead of scalar_mult 2018-03-22 11:40:13 -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
Isis Lovecruft
cd112afff5
Whitespace EOL fixes. 2018-01-31 02:19:53 +00: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
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
786e4b65a8 Add reference to from_bytes_mod_order_wide ctor 2017-11-30 16:48:29 -08:00
Henry de Valence
bb9c171487 fix typo in internal Scalar docs 2017-11-30 16:46:46 -08:00
Henry de Valence
1caed9a4fc Remove Scalar::multiply_add 2017-11-30 16:44:51 -08:00
Henry de Valence
9e892dd5f3 Rename reduce_wide to from_bytes_mod_order_wide and keep it with the other constructors 2017-11-30 16:44:10 -08:00
Henry de Valence
a6b4467d23 KaTeXify Scalar docs 2017-11-30 16:43:21 -08:00
Henry de Valence
beda5df2f1 Remove "scalar multiplication" since that's more of a scalar*point thing than just a scalar thing 2017-11-29 13:04:04 -08:00
Isis Lovecruft
88200f9fc9
Fix Scalar.to_bytes() after merging PR#88. 2017-11-26 04:16:12 +00:00
Isis Lovecruft
220c6c1d13
Merge remote-tracking branch 'hdevalence/feature/refactor-scalar-api' into develop 2017-11-26 04:15:04 +00:00
Isis Lovecruft
227acc117b
Whitespace fix. 2017-11-26 03:26:47 +00:00
Isis Lovecruft
7a0c0e9d0d
Change Debug for Scalar output to be valid Rust code. 2017-11-26 03:26:29 +00:00
Isis Lovecruft
87f93a5df2
Add to_bytes() convenience method for Scalar. 2017-11-26 03:23:31 +00:00
Henry de Valence
f165b63ee9 Encode scalars canonically using Serde. 2017-11-23 12:29:46 -08:00
Henry de Valence
c1f6302879 Add a Scalar::from_bytes_canonical method 2017-11-23 12:29:46 -08:00
Henry de Valence
9855260bfd Add a method to test if a Scalar is canonical 2017-11-23 12:29:46 -08:00
Henry de Valence
34639725d4 clean up reduction test 2017-11-23 12:29:46 -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
d88f92276a Add Scalar::reduce method 2017-11-21 11:28:25 -08:00
Henry de Valence
df182b79d0 Rename Scalar::reduce to Scalar::reduce_wide
This opens the `Scalar::reduce` name for reduction mod l.
2017-11-21 11:06:54 -08:00
Henry de Valence
033a90890c Remove Scalar::{add, sub, mul} methods 2017-11-21 10:43:49 -08:00
Henry de Valence
e94c6f0a96 Make more Scalar methods pub(crate) 2017-11-20 16:45:30 -08:00
Henry de Valence
2d69a8a7dc Eliminate array_ref dependency 2017-11-20 14:53:08 -08:00
Henry de Valence
504a557b33 Hide UnpackedScalars 2017-11-17 15:51:29 -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
Isis Lovecruft
c59af2c6b8
Merge branch 'optimzed_scalar_r1' into develop 2017-11-15 22:02:36 +00:00
Isis Lovecruft
583a45ddc2
Add test that scalar Montgomery reduction matches reduction. 2017-10-31 01:18:52 +00:00
Isis Lovecruft
e2cbec81fc
Add test that UnpackedScalar::{to,from}_bytes() roundtrips. 2017-10-31 01:02:20 +00:00
Henry de Valence
a7835a1246 UPPERCASE_GLOBALS and add documentation 2017-10-30 17:33:23 -07:00