Commit graph

23 commits

Author SHA1 Message Date
Michael Rosenberg
f460ae149b
Make scalars always reduced (#519)
* Removed Scalar::{from_bits, from_bytes_clamped}; all constructible scalars are now reduced mod l

* Made Scalar::reduce() not pub; fixed test warning

* Added benches for scalar add/sub/mul

* Docs

* Added EdwardsPoint::mul_base_clamped and gated Scalar::from_bits behind legacy_compatibility

* Added unit test for Mul impl on unreduced Scalars

* Added Montgomery::mul_base_clamped

* Added BasepointTable::mul_base_clamped

* Removed invalid scalar arithmetic test; this functionality is no longer supported

* Made clamp_integer() const

* Updated readme and changelog

* Added BasepointTable::mul_base_clamped to tests

* Added proper deprecation notice to Scalar::from_bits; added legacy_compatibility to Makefile and docsrs flags
2023-03-28 18:12:24 -04:00
Tony Arcieri
b375b46d37
Fixed-based Montgomery scalar multiplication (#503)
* Fixed-based Montgomery scalar multiplication

Adds `MontgomeryPoint::mul_base` as an API for fixed-base scalar
multiplication which allows for potential future optimizations.

As a baseline implementation, it uses the variable base scalar
multiplication implementation.

This follows the existing `EdwardsPoint::mul_base` and
`RistrettoPoint::mul_base` APIs.

* Added Montgomery mul_base bench

* Switched MontgomeryPoint::mul_base to use EdwardsPoint::mul_base

---------

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2023-01-31 03:37:03 -05:00
Michael Rosenberg
3effd73307
Feature-gated more precomputed tables (#500)
Feature-gates `AFFINE_ODD_MULTIPLES_OF_BASEPOINT`

Feature-gated tables out of vector vartime aA + bB procedure
2023-01-20 10:55:32 -07:00
Tony Arcieri
6a51f4fa40
Make basepoint table constants &'static references (#488)
* Make basepoint table constants static references

This ensures they have a fixed address and aren't duplicated across
compilation units.

Since they were already always borrowed, this changes the static values
to be `&'static` addresses to ensure they're always borrowed rather than
potentially copied.

* rustfmt
2022-12-28 03:24:46 -05:00
pinkforest(she/her)
e01bb1bdc6
Fix all clippy warnings replay (#441)
Also fixes CI not running on all branches

Co-authored-by: Anthony Ramine <nox@nox.paris>
2022-12-04 03:40:51 -05:00
Michael Rosenberg
d2bf310330
cargo fmt 2022-10-28 17:00:24 -04:00
Michael Rosenberg
5758b8cce1
Updated to edition 2021 (#413) 2022-10-18 13:45:59 -04:00
Isis Lovecruft
076cf347ba
Fix non-unique benchmark IDs for newer criterion versions. 2021-08-17 00:22:26 +00:00
François Garillot
d130b5f17e
[benchmarks-only] Updates the benchmarks
- removes usages fo the (deprecated) `bench_function_over_inputs`
- introduces a few benchmark groups.
2021-03-26 09:18:18 -07:00
Isis Lovecruft
409ebd94c0
Remove dev-dependency on deprecated rand_os crate.
The functionality we were using is now contained in the `rand_core` crate, which
we already depend upon.  As far as testing code goes, only benchmarks still
depend upon `rand`, as they use `thread_rng`.
2019-10-28 18:06:29 +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
47967b49f0 Use rerandomized inputs for variable-time benchmarks.
This avoids potentially misleading benchmark results where the memory cost of
precomputation becomes "free" as re-running the benchmark loop lifts exactly
the required table entries into the highest-level caches.
2019-02-14 09:38:09 -08:00
Henry de Valence
2c3629b30e Add a separate benchmark for pure-fixed multiscalar mul. 2019-02-14 07:16:20 -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
c6acdfd5e2 Add serial implementation of precomputation. 2019-02-12 12:52:02 -08:00
Henry de Valence
00675b4c56 Add benchmarks for precomputed multiscalar multiplication. 2019-02-12 12:52:02 -08: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
Isis Lovecruft
9a89a217f8
Merge remote-tracking branch 'dalek/multiscalar-trait-without-precomputation_r1' into develop 2018-05-15 20:23:05 +00: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
2eed24109e Move double-base scmul to the EdwardsPoint type 2018-05-15 11:33:38 -07:00
Henry de Valence
e3bf9b0213 Add MultiscalarMul and VartimeMultiscalarMul traits.
These traits have the same interface, but with different names, so that it's
not possible to use them interchangeably.  (Constant-time and variable-time
routines should not be used interchangeably).

This commit changes the external API to use these traits, replacing
```
edwards::multiscalar_mul
edwards::vartime::multiscalar_mul
```
with
```
EdwardsPoint::multiscalar_mul (as an impl)
EdwardsPoint::vartime_multiscalar_mul (as an impl)
```
and similarly for Ristretto.

Refactoring the backend is for a later commit.

Multiscalar multiplication with precomputation is for a later commit.

The `edwards::vartime` module is retained since it's used for
`vartime_double_base_scalar_mul`.

It should be subsumed into the precomputation API in a later commit.
2018-05-15 11:33:38 -07:00
Henry de Valence
1048100cd0 Reduce benchmark runs 2018-04-04 10:16:32 -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