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
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
Henry de Valence
aaa2315703
add failing test case from fuzzer
2017-10-30 22:25:34 +00:00
Isis Lovecruft
6079b0269f
Revert "Revert "Merge remote-tracking branch 'floodyberry/optimized_scalar' into develop""
...
This reverts commit 90b69c13ee .
Signed-off-by: Isis Lovecruft <isis@torproject.org>
2017-10-30 19:27:44 +00:00
Isis Lovecruft
90b69c13ee
Revert "Merge remote-tracking branch 'floodyberry/optimized_scalar' into develop"
...
This reverts commit 804dab8924 , reversing
changes made to 5d15ca77ff .
This is due to a (previously undocumented) contract on the behaviours of
(potentially unreduced mod \ell) "packed" scalars w.r.t. to the manner in which
their bytes are interpreted.
Upon documentation fixes and corresponding fixes being made on top of the
floodyberry/optimized_scalar branch, this revert will again be reverted and then
the additional changes merged (à la
file:///usr/share/doc/git/html/howto/revert-a-faulty-merge.html).
Signed-off-by: Isis Lovecruft <isis@patternsinthevoid.net>
2017-10-16 21:41:52 +00:00
Andrew Moon
7e53499a10
optimized scalar implementations for 32/64 bit
2017-09-24 22:24:35 -05:00
Brian Smith
7ed9eb8617
Replace one multiplication with a squaring in scalar inversion.
...
This brings the code up to date with the 2017-09-04 version of
the source article.
2017-09-04 09:45:13 -10:00
Brian Smith
028140bb33
Reformat addition chain window building code to better show pattern.
...
Make the 2 digit, `_10`, the first argument to more closely match the
Haskell code in the source article. Align the code into columns to
further clarify the patterns.
2017-09-04 09:23:27 -10:00
Brian Smith
91a7c641c2
Use more efficient addition chain for scalar inversion.
...
Use the addition chain from
https://briansmith.org/ecc-inversion-addition-chains-01#curve25519_scalar_inversion .
In my benchmarking, this consistently runs at least 20% faster.
2017-09-03 17:00:42 -10:00
khyperia
6747133519
Optimize scalar inversion by implementing square()
...
This shows an 11% speedup for invert()
2017-08-21 21:35:26 -07: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
Isis Lovecruft
4bcf8bed9d
Move subtle to its own crate.
2017-05-31 21:20:56 +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
Henry de Valence
69c62a8a17
Serde Scalar support
2017-05-15 22:40:09 -07:00
Isis Lovecruft
4a646806b8
Merge branch 'feature/scalarmult-lhs' into develop
2017-05-14 09:35:15 +00:00
Isis Lovecruft
61d07693ec
Merge remote-tracking branch 'hdevalence/feature/operator_scalar_mult_r2' into develop
2017-05-14 09:34:45 +00:00
Isis Lovecruft
ae11d4bc76
Merge remote-tracking branch 'hdevalence/feature/vartime-module' into develop
2017-05-14 09:34:14 +00:00
Isis Lovecruft
944e8e1649
Fix and allow some non-snakecased variables in scalar tests.
2017-05-09 00:05:11 +00:00
Isis Lovecruft
9a9959061d
Merge remote-tracking branch 'hdevalence/feature/clippy-fixes' into develop
2017-05-06 00:16:09 +00:00
Isis Lovecruft
8f4114a211
Merge remote-tracking branch 'hdevalence/feature/streamable-hash-to-scalar' into develop
2017-05-05 23:52:59 +00:00
Henry & Isis
c6dc9d318d
Add a helper function to construct a Scalar from a u64
2017-05-03 19:32:31 -07:00
Henry & Isis
7cbb8dd94e
Merge branch 'feature/streamable-hash-to-scalar' into develop
2017-05-03 19:32:09 -07:00
Henry de Valence
b05c897123
Implement operators for Scalars using multiply_add
2017-05-02 22:29:18 -07:00
Henry de Valence
91e11b6318
Change docstring to match the trait bound
2017-05-02 21:22:04 -07:00
Henry de Valence
6ea1d4dad2
Add an implementation of Scalar inversion
2017-04-28 22:59:56 -07:00
Henry de Valence
653f134bc7
Implement Mul, MulAssign, zero(), one() for UnpackedScalar
2017-04-28 22:57:17 -07:00
Henry de Valence
b5ccb42759
Rename lminus1 to l_minus_1
2017-04-28 22:54:00 -07:00
Henry de Valence
057c84abd5
Add a bits() function for scalars
2017-04-28 22:51:32 -07:00
Henry de Valence
7f4b96150d
Remove explicit lifetimes
2017-04-02 23:36:05 +02:00
Henry de Valence
b3041f2adc
Remove unnecessary if statements
2017-04-02 23:27:38 +02:00
Henry de Valence
eca28fd3e8
Refactor Scalar::hash_from_bytes to allow streaming input to the hash.
2017-03-27 04:49:00 -07:00
Isis Lovecruft
5ebbd5dd86
Remove an XXX comment about using something better than array_ref!().
...
It turns out array_ref!() is probably the best way, or, at least, we're
already using it everywhere.
2017-03-17 21:42:58 +00:00
Isis Lovecruft
d549fdc8f9
Whitespace fixes.
2017-03-17 21:42:40 +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
3882a41d27
Remove test_ prefix from tests in scalar module.
2017-03-14 01:58:39 +00:00
Isis Lovecruft
4afe4ae37f
Move scalar module benchmarks to separate module.
2017-03-14 01:52:42 +00:00