Commit graph

920 commits

Author SHA1 Message Date
Marek
6c2233bc45
Fix the upper bound in the description of mods (#525) 2023-05-29 15:24:45 -06:00
Koute
4583c472f5
Support SIMD on Rust stable (#520)
* Remove dependency on `packed_simd`

* Support SIMD on stable Rust

* Move `packed_simd.rs` to `vector` module

* Add comment header to `packed_simd.rs`

* Initialize SIMD registers using intrinsics instead of `transmute`

* Use a splat inside of `unpack_pair`

* Update README: the AVX2 backend now works on stable Rust

* Add a CI job to also build the AVX2 SIMD backend on Rust stable

* Added SIMD MSRV test
2023-03-30 02:16:18 -04:00
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
Jordan Rose
a63e14f4de
Use ok_or_else instead of ok_or in serde decoding (#382)
Serde errors are not simple enums; they format a full error string
from their arguments. It's worth not doing that up front.
2023-03-13 21:42:01 -06:00
Michael Rosenberg
3b71630d9f
Fix docsrs build (#505)
* Add docsrs build to CI

* Put cfg flags in both RUSTFLAGS and RUSTDOCFLAGS
2023-02-02 04:06:14 -05: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
Tony Arcieri
79bcbdc89b
Re-export commonly used types from toplevel (#502)
Re-exports the following commonly used types from their respective
modules to the toplevel of the crate, which makes them easier to access:

- `EdwardsPoint`
- `MontgomeryPoint`
- `RistrettoPoint`
- `Scalar`
2023-01-29 13:53:43 -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
bfacbe7ee4
Make from_slice methods fallible; add TryFrom<&[u8]> (#495)
The `from_slice` methods on `CompressedEdwardsY` and
`CompressedRistretto` both previously panicked if the slice was the
wrong length.

This changes them to be fallible, returning `TryFromSliceError` in the
event the slice is the wrong length.

It also adds a `TryFrom<&[u8]>` impl for each of these types which calls
the corresponding `from_slice` method.
2023-01-19 14:08:18 -05:00
Tony Arcieri
8d1bc31805
Rename basepoint-tables to precomputed-tables (#499)
This is the name we adopted for a similar feature in @RustCrypto.

It's a bit less jargony and also leaves the door open in the future to
other types of precomputed tables.
2023-01-19 14:04:22 -05:00
SergeStrashko
fedb1450de
Add Scalar::from_bits_clamped (#498)
As discussed in #497, adds a function which "clamps" a 256-bit input into a
valid scalar by clearing and setting bits, as used by Ed25519 and X25519
2023-01-09 09:34:57 -07:00
Tony Arcieri
83f6b149d3
Add basepoint-tables crate feature (#489)
* Add `basepoint-tables` crate feature

Feature-gates the inclusion of basepoint tables under a
`basepoint-tables` feature, with the goal of reducing code size for e.g.
embedded applications.

* Add `mul_base` method to `EdwardsPoint` and `RistrettoPoint`

Provides fixed-base scalar multiplication which optionally uses
precomputed basepoint tables when the `basepoint-tables` feature is
enabled, providing 4X better performance.

Falls back on variable-base scalar multiplication in the event the
feature is disabled.

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2023-01-08 03:51:51 -05:00
Tony Arcieri
8c2f545d91
Expand const fn support (#494)
Does a pass on adding `const` to methods where it's possible.
2023-01-06 13:29:56 -05: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
Tony Arcieri
0ffcb84625
Don't set html_root_url (#483)
The recommendation to set this has been removed from the Rust API
guidelines:

https://github.com/rust-lang/api-guidelines/pull/230

It used to be used by docs.rs, but docs.rs now unconditionally sets the
`--extern-html-root-url` parameter of rustdoc which overrides it, making
it no longer needed and superfluous.
2022-12-27 05:14:34 -05:00
Tony Arcieri
7d53206366
Weakly activate zeroize?/alloc; MSRV 1.60 (#485)
Previously `alloc` implicitly activated `zeroize` via `zeroize/alloc`.

This commit switches to weak feature activation as added in Rust 1.60,
only activating `zeroize/alloc` if the `zeroize` dependency is
explicitly activated (which it is by default).
2022-12-27 05:12:55 -05:00
Tony Arcieri
39dbaea6f9
Make zeroize an optional dependency (#481)
* Make `zeroize` an optional dependency

The `zeroize` crate provides a defense against memory read oracles which
typically arise from memory unsafety.

Pure Rust programs may not benefit from `zeroize`, and in certain cases
the unsafe code used by `zeroize` may be more concerning.

This commit makes `zeroize` into an optional feature so users may elect
to disable it if they so desire.

* Added zeroize feature flag to README

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2022-12-26 16:19:55 -05:00
pinkforest
39053b1c5d Fix docs release pre.5 2022-12-14 11:28:52 +11:00
Michael Rosenberg
1cedb3727e
Fixed docs build (#475)
Also sets code font size in docs back to normal (no longer small)
2022-12-13 02:29:45 -05:00
Tony Arcieri
274f4a7bec
Change Scalar::from_canonical_bytes to return CtOption (#472)
This is helpful for implementing `ff::PrimeField::from_repr`.
Also changes `Scalar::is_canonical` to return `Choice`.
2022-12-12 17:38:04 -05:00
Tony Arcieri
6f237a0810
Use inherent constants for ZERO, ONE, and MINUS_ONE (#470)
For the field element types `FieldElement` and `Scalar`, use inherent
constants instead of (non-const) functions to return these constant
values.

It's likely the original functions predate support for inherent
constants, but now that they're available, they're a better fit for
these sort of constant values.
2022-12-12 01:04:42 -05:00
Tony Arcieri
fa45d21b76
Use CryptoRngCore trait (#469)
This is a convenience/marker trait for types which impl `CryptoRng` +
`RngCore` which makes the type signatures a little more readable.

It was introduced in `rand_core` v0.6.4 (now pinned as the minimum
version)
2022-12-11 15:11:15 -05:00
Tony Arcieri
cc304c29ff
Use --cfg curve25519_dalek_backend to select backend (#455)
Crate features are intended to be additive, whereas only 1-of-N possible
backends can be selected.

Features can also be activated by transitive dependencies, which leads
to a problem of different dependences selecting conflicting backends.
Using `--cfg` instead moves all backend selection control to the
toplevel executable.

This commit switches to the following RUSTFLAGS to enable backends:

- `--cfg curve25519_dalek_backend="fiat"`: uses `fiat-crypto`
- `--cfg curve25519_dalek_backend="simd"`: uses nightly-only SIMD
2022-12-09 03:42:52 -05:00
Tony Arcieri
1e490bd001
Fix --no-default-features test warnings; consolidate CI jobs (#461)
Previously `cargo test --no-default-features` would succeed but with
warnings. This commit fixes all of those warnings and tests
`--no-default-features` in CI to ensure that in perpetuity.
2022-12-08 23:26:18 -05:00
Michael Rosenberg
0b72bb5dc2
Made Scalar::bits return an iterator rather than an array (#451)
Addresses issue #448 that Scalar::bits may leave unzeroed bits on the stack
2022-12-08 16:37:42 -05:00
Michael Rosenberg
42e93d7faf
Remove mocks (#460)
Gated random() construtors on cfg(test)
2022-12-08 15:36:22 -05:00
Tony Arcieri
1013560fe4
Remove std feature (#459)
All of the existing usages of `std` can be replaced with `alloc`.

They are legacy usages from before when liballoc was stabilized.
2022-12-08 15:05:59 -05:00
pinkforest(she/her)
6b56edf776
Make digest optional (#446)
As proposed in #442 this makes `digest` an
optional feature that is not covered by the
SemVer public API stability guarantees.

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2022-12-08 13:59:28 -05:00
pinkforest(she/her)
47a0c3eacc
Make rand_core optional (#447)
As proposed in #442 this makes `rand_core` an
optional feature that is not covered by the
SemVer public API stability guarantees.

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2022-12-08 13:50:17 -05:00
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
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
03b8668b29
Merge pull request #440 from dalek-cryptography/docs-cleanup 2022-11-26 22:00:45 -05:00
Chris Beck
840a9dc866
Relax Rng trait bounds to allow ?Sized Rngs (#394)
This allows the code to compile if you pass it `&mut dyn RngType`,
since trait objects are unsized.

See here for an example of caller code that is simplified by this
change:

https://github.com/mobilecoinfoundation/mobilecoin/pull/1977#discussion_r872906913
2022-11-26 20:56:04 -05:00
Michael Rosenberg
01672bfc63
Applied @pinkforest's patch to make make doc build on non-x86_64 arches 2022-11-26 13:53:51 -05:00
Michael Rosenberg
791ba170b1 Cleanup: enabled doc_auto_cfg and doc_cfg_hide 2022-11-26 06:34:48 -05:00
pinkforest
289cc52fef Document backend mod as INTERNALS: 2022-11-26 22:20:18 +11:00
Michael Rosenberg
fec474b1ba Shouldn't have removed stdsimd feature 2022-11-26 05:58:29 -05:00
Michael Rosenberg
774e56e2c1 Removed unnecessary unstable features 2022-11-26 05:54:22 -05:00
Michael Rosenberg
a35ca1e9cf Added cfg_attr everywhere possible, and simplified cfg over std/alloc 2022-11-26 05:53:28 -05:00
pinkforest
ad7c755f49 Documentation migrate to docs.rs hosted
This change migrates all the documentation from dalek.rs
to docs.rs hosted and fixed the backend documentation
generation that was broken.
2022-11-26 11:26:25 +11:00
Michael Rosenberg
969940e954
Wibble 2022-11-24 02:37:07 -05:00
Michael Rosenberg
a743ea5348
Fixed doc warnings 2022-11-24 02:37:05 -05:00
Michael Rosenberg
6eafb1ebda
Deprecate EdwardsPoint::hash_from_bytes (#438)
* Deprecated `EdwardsPoint::hash_from_bytes` and renamed to
  `EdwardsPoint::nonspec_map_to_curve`

* Added KAT test vectors for `RistrettoPoint::from_uniform_bytes`
2022-11-24 01:45:03 -05:00
Tony Arcieri
f88cf6836b
Use include_str! for .md inclusion in rustdoc (#434)
Previously a now-removed nightly-only feature was used, but now that
it's stable, `include_str!` can be used for all of these cases.
2022-11-14 00:22:50 -05:00
Tony Arcieri
d05afa02a3
Add alloc feature gates to simd tests that need it (#433) 2022-11-14 00:11:23 -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
pinkforest
62fe24e022 Include README.md into the crate Documentation
As proposed in #426 this commit changes to include README.md into
the crate documentation instead of maintaining a carbon copy in
the code.

This helps to keep the documentation in a single place without
duplicating the documentation in multiple places leading to less
errors and out of date documentation.
2022-11-11 22:36:57 +11:00
Thomas Pornin
d687cc8f82
Fix double-and-compress on Ristretto identity (issue #398). (#399) 2022-11-05 11:35:30 -04:00
Michael Rosenberg
d2bf310330
cargo fmt 2022-10-28 17:00:24 -04:00
Michael Rosenberg
a959787c2e
Added more #[rusfmt::skip] 2022-10-28 16:58:40 -04:00