Commit graph

2421 commits

Author SHA1 Message Date
Michael Rosenberg
86832640ed
curve: Undeprecate Scalar::from_bits (#780) 2025-07-07 17:15:06 -04:00
Aaron Feickert
9e4ec01fa2
curve: Use constant-time compressed edwards equality testing (#684) 2025-07-07 23:02:51 +02:00
Aaron Feickert
d54b196d18
curve: Use constant-time compressed equality testing (#669) 2025-07-07 23:01:55 +02:00
Michael Rosenberg
445fd7d59d
curve,x: Clear deprecated functions (#778) 2025-07-07 22:33:05 +02:00
Arthur Gautier
d159f47f53
ed25519-dalek: use SignatureAlgorithmIdenfier instead of the dynamic counterpart (#779)
This allows to use ed25519 to create certificates for example

This partially reverts #712
2025-07-07 13:57:47 -06:00
Arthur Gautier
a99efe2304
curve,ed,x: Bump rand_core to 0.9 (#777)
---------

Co-authored-by: pinkforest <36498018+pinkforest@users.noreply.github.com>
2025-07-07 15:36:11 -04:00
Tony Arcieri
a9aa94736b
Bump digest, ed25519, signature, and sha2 (#676)
Bumps the aforementioned dependencies to their latest (pre)releases.
2025-07-07 11:34:26 -06:00
Steve Fan
0736088c94
ed: Don't implicitly enable zeroize for ed25519-dalek alloc feature (#761) 2025-07-07 18:02:14 +02:00
Tony Arcieri
53df025bb3
Bump edition to 2024 and crate versions to prereleases (#775)
This represents the first breaking change in a new release series,
bumping all crates to the 2024 edition of Rust.

As such, the version numbers of all crates have been incremented to
represent a new prerelease series:

- `curve25519-dalek`: v5.0.0-pre
- `ed25519-dalek`: v3.0.0-pre
- `x25519-dalek`: v3.0.0-pre

Note that this commit isn't intended to cut associated crate releases of
these on crates.io, but is merely bumping the version numbers to denote
there are pending breaking changes.

This commit also includes rustfmt changes which were made as part of the
2024 edition.

Also includes clippy fixes.
2025-07-07 11:52:25 -04:00
Tony Arcieri
37d3ae99d3
x25519: use manual impls instead of zeroize_derive (#776)
The types involved are all simple 1-tuple newtypes where zeroization
only involves calling `zeroize` on the inner type, making all of the
involved impls relatively trivial.

Avoiding custom derive arguably improves auditability as you don't need
to expand a proc macro to see the resulting code. It decreases the
number of required dependencies in order for the `zeroize` feature to
work, where some of those dependencies are incredibly heavy
(particularly `syn`).
2025-07-07 10:14:51 -04:00
Iñigo Querejeta Azurmendi
25a9dbb811
curve: Hash to curve and field as defined in the standard (#377)
* Implementation of `hash_to_field` as defined in the standard
* Implementation of `hash_to_curve` as defined in the standard, by changing the mechanism over which we chose the sign.
* For the point above, had to change the `elligator_encode` to return whether `eps` is a square or not (required for `hash_to_curve`).
* Included test vectors of the draft.
* Included `FieldElement::from_bytes_wide(bytes: &u8; 64])` to reduce integers encoded in 64 bytes.
2025-07-05 22:01:26 +02:00
Tony Arcieri
44bb8cb7c1
ed: vendor merlin dependency (#774)
`merlin` is currently a blocker for upgrading to `rand_core` v0.9 by way
of the `transcript.build_rng().finalize()` function (which we only pass
`ZeroRng` to).

There is an open PR to update `rand_core` in `merlin` and I have pinged
the relevant people to take a look, hopefully: zkcrypto/merlin#11

However, in the event we can't get `merlin` updated, this at least
unblocks the `rand_core` upgrade, and is being opened as a contingency
plan for that case.

The PR has been implemented in a way that it should be easy to switch
back to upstream `merlin` in the event they upgrade `rand_core`.
2025-06-20 16:54:16 -04:00
Tony Arcieri
655992f3c2
curve: fix nightly build (#773)
The latest nightlies have stabilized `stdarch_x86_avx512` so having it
present is now an error
2025-06-15 12:56:10 -04:00
Duy Do
055ca55bcb
Remove confusing docs (#772) 2025-06-15 08:01:41 -06:00
Tony Arcieri
8c53a8f10b
curve: extract AffinePoint type (#769)
* curve: extract `AffinePoint` type

Based on discussions about `elliptic-curve` trait impls in #746, and
observing a similar type in `ed448-goldilocks` which inspired this one
(not to mention in all of the @RustCrypto elliptic curve crates), adds
an `AffinePoint` type with `x` and `y` coordinates.

For now, the type is kept out of the public API, and used as an
implementation detail for point compression. However, it's been written
with the intent of eventually stabilizing and exposing it. It's been
marked `pub` so unused functionality doesn't automatically trigger dead
code lints.

Further work could include refactoring point decompression to first
produce an `AffinePoint` and then convert to extended twisted Edwards
coordinates (i.e. `EdwardsPoint`), which is more or less what the
existing `step_1` and `step_2` functions do (`step_1` technically
produces projective coordinates, but `Z` is always set to `ONE`).

* Update curve25519-dalek/src/edwards.rs
2025-06-08 01:23:59 -04:00
Tony Arcieri
cf7b099585
curve: rename FieldElement*::as_bytes => ::to_bytes (#767)
* curve: rename `FieldElement*::as_bytes` => `::to_bytes`

Methods named `as_*` should perform a zero-cost  borrowing conversion:

https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv

Methods named `to_*` can perform an expensive owned conversion.

Since the `FieldElement*` types are technically part of the public API
(but feature gated), this also preserves the old names with a
deprecation. We can remove them in the next breaking release.

The same change was also made to the backend `Scalar*` types, however
these types are not a part of the public API.
2025-06-06 15:10:29 -06:00
Tony Arcieri
ad4a37df53
CI: bump clippy to Rust 1.87 (#768)
* CI: bump `clippy` to Rust 1.87

Performs a `cargo clippy --fix`

* ed25519: fix warning

* Rename solitary `'b` lifetimes to `'a`
2025-06-06 18:30:32 +02:00
Tony Arcieri
5e0b429b05
Add typos action and correct typos (#766)
* Add `typos` action and correct typos

https://github.com/crate-ci/typos

* Add `name` to `typos` job
2025-06-04 17:40:10 +02:00
root
83ddc4b34b
fix typos (#740) 2025-06-04 10:43:16 -04:00
daxpedda
ea6ffc354e
Implement Debug and Eq for ExpandedSecretKey (#748) 2025-06-04 10:27:23 -04:00
Michael Rosenberg
08d7176d58
ed: Expose hazmat::raw_sign_byupdate() for streamed signing (#765)
* Added raw_sign_byupdate to hazmat; refactored other funcs to use that directly
2025-06-03 09:14:22 -04:00
Rob Ede
6dc7a1c7c5
Verify by digest update + StreamVerifier (#735)
* Replace recompute_R with a separate RCompute

This struct can be use to implement verifiers with incremental updates

* Add raw_sign_byupdate and raw_verify_byupdate

These allow signing/verifying a non-prehashed message
but don't require the whole message to be provided at once.

* Tests for raw_sign_byupdate, raw_verify_byupdate

* Add StreamVerifier

* Make StreamVerifier use RCompute

This allows it to use the same implementation as non-stream signature
verification.

* Guard StreamVerifier behind hazmat feature

* docs: disambiguate unsafety

Co-authored-by: Tony Arcieri <bascule@gmail.com>

* chore: relax F bounds on raw_verify_byupdate

* chore: remove raw_sign_byupdate and raw_verify_byupdate

* chore: address clippy lints within new code

* docs: fixup changelog

* test: invert new chunked test

* chore: revert raw_sign

---------

Co-authored-by: Matt Johnston <matt@ucc.asn.au>
Co-authored-by: Tony Arcieri <bascule@gmail.com>
2025-06-02 18:30:57 -04:00
Andrew Poelstra
dcd39743ea
curve25519-dalek: add batch montgomery conversion (#722) 2025-06-02 16:02:43 -06:00
Tony Arcieri
dd5bd108d6
curve: add EdwardsPoint::compress_batch and inherent ::random (#759)
* curve: add `EdwardsPoint::compress_batch` and `::random`

We've had various requests to implement batch point compression for
`EdwardsPoint`, e.g. #705.

We can leverage `FieldElement::batch_invert` to implement it, which
results in a fairly significant speedup.

The name `EdwardsPoint::compress_batch` has been chosen to match
`RistrettoPoint::double_and_compress_batch`.

For benchmarking, randomized `EdwardsPoint`s have been used. To obtain
these, an inherent `EdwardsPoint::random` has been extracted from the
existing `Group::random` implementation, which uses rejection sampling.
`Group::random` has been updated to call the inherent
`EdwardsPoint::random`. This avoids a `group` dependency just to run the
batch compression benchmarks.

The following benchmark results have been obtained:

edwards benches/EdwardsPoint compression
                        time:   [3.5029 µs 3.5098 µs 3.5171 µs]

edwards benches/Batch EdwardsPoint compression/1
                        time:   [3.6698 µs 3.6758 µs 3.6817 µs]
edwards benches/Batch EdwardsPoint compression/2
                        time:   [3.8410 µs 3.8461 µs 3.8516 µs]
edwards benches/Batch EdwardsPoint compression/4
                        time:   [4.1534 µs 4.1961 µs 4.2558 µs]
edwards benches/Batch EdwardsPoint compression/8
                        time:   [4.8466 µs 4.8533 µs 4.8600 µs]
edwards benches/Batch EdwardsPoint compression/16
                        time:   [6.1216 µs 6.1315 µs 6.1410 µs]

As you can see, it affords a fairly significant speedup, batch
compressing 16 points in less time than the standard point compression
algorithm would take to compress 2 in a row.
2025-05-28 00:09:49 -04:00
Noa Resare
e3b5328202
Fix curve25519-dalek-derive test compilation on CentOS 10 x86_64 (#756)
The test assumed that the 'avx2' target_feature would never be set
and used this fact to verify that unsafe_target_feature would
correctly not even compile test functions maked with that
target_feature. As of CentOS 10 and derivatives, th avx2
target_feature is now set by the system rustc, so let's use a
target_feature less likely to appear in the real world.

Closes #755
2025-05-26 08:24:17 -06:00
Tony Arcieri
67625763c1
curve: remove feature(avx512_target_feature) (#757)
The build is currently broken because it's been stabilized:

    error: the feature `avx512_target_feature` has been stable since 1.89.0-nightly and no longer requires an attribute to enable
2025-05-25 20:21:55 -04:00
Arthur Gautier
8c0cf3a64f
chore(deps): bump cpufeatures from 0.2.12 to 0.2.17 (#750)
This fixes warnings like:
```
warning: unexpected `cfg` condition value: ``
  --> curve25519-dalek/src/backend/mod.rs:58:9
   |
58 |         cpufeatures::new!(cpuid_avx512, "avx512ifma", "avx512vl");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
2025-05-08 14:06:28 -06:00
Arthur Gautier
773a0646ce
fixup ci: unsafe usage on nightly and bump ed25519's MSRV (#753)
* ed25519-dalek: bump MSRV to 1.81

base64ct now requires rustc 1.81

* nightly and stable disagree on usage of unsafe

```
error: unnecessary `unsafe` block
492
   --> curve25519-dalek/src/backend/vector/avx2/field.rs:479:28
493
    |
494
479 |         let c9_19: u32x8 = unsafe {
495
    |                            ^^^^^^ unnecessary `unsafe` block
```

This would only happen on nightly.
2025-05-08 12:37:08 -06:00
Aaron Feickert
fbf1fb5339
Use ZeroizeOnDrop exclusively (#723) 2025-01-19 11:55:45 -05:00
Aaron Feickert
868d614020
Support zeroizing for SubgroupPoint (#682) 2025-01-19 11:54:30 -05:00
camcui
6a0caa1b98
chore: fix spelling issues (#727)
Signed-off-by: camcui <cuishua@sina.cn>
2025-01-18 16:34:18 -07:00
Aaron Feickert
485ffab769
docs: update VartimeRistrettoPrecomputation documentation (#667) 2025-01-11 23:07:09 -05:00
Aaron Feickert
ed83542d7e
curve: add precomputation length to MSM structs (#685) 2025-01-11 22:57:50 -05:00
Bryant Luk
4570d806ee
Fix typo in README.md Malleability definition (#690) 2025-01-03 12:26:16 -05:00
Julius Liu
43a16f03d4
Implement DynSignatureAlgorithmIdentifier trait for ed25519 (#712) 2024-10-07 18:01:13 -06:00
Arthur Gautier
cbf794d883
{curve,ed}25519-dalek: clippy fixes (#710)
Clippy 1.81 brings new lints, this fixes those warnings
2024-09-30 15:09:28 -06:00
Tony Arcieri
d5ef57a3c2
ed: update VerifyingKey::from_bytes with ZIP-215 info (#704)
Removes the previous warning that points are unvalidated: they're
validated using the ZIP-215 rules, which allows unreduced y-coordinates.
Points are ensured valid by performing decompression, which finds a
solution to the curve equation, or returns an error.

Adds references to ZIP-215 and dalek-cryptography/curve25519-dalek#626
which is an issue about potentially adding support for the RFC8032/NIST
validation criteria in the future.
2024-09-19 18:43:32 -04:00
pinkforest(she/her)
b636fb8ee4
Make AVX512IFMA opt-in backend (#695)
* Make AVX512IFMA opt-in backend

* Updated README to have backend info

* Added entry to changelog

---------

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2024-09-08 01:13:36 -04:00
Aaron Feickert
0964f800ab
curve: Support MSM #static scalars <= #static points (#668) 2024-07-30 09:43:13 -04:00
Aaron Feickert
83a57e591f
curve: Impl Default ConstantTImeEq and ConditionallySelectable for SubgroupPoint (#672) 2024-07-30 02:05:52 -04:00
Elichai Turkel
79ab6c29bd
curve: Implement ConditionallySelectable for MontgomeryPoint (#677) 2024-07-30 01:51:44 -04:00
Aaron Feickert
a7a9fffdc9
Minor documentation fixes (#671) 2024-07-30 01:11:26 -04:00
Simon Wülker
35e78b21ef
Enable unexpected cfgs lint (#656)
Previously, the only way to configure this lint was using a build.rs
file, but now it can be done using Cargo.toml as well.
2024-07-25 20:24:39 -06:00
Tony Arcieri
921bd7ced0
curve: use subtle::Choice for constant-time fixes (#665)
Alternative to #659/#661 and #662 which leverages `subtle::Choice` and
`subtle::ConditionallySelectable` as the optimization barriers.

Really the previous masking was there to conditionally add the scalar
field modulus on underflow, so instead of that, we can conditionally
select zero or the modulus using a `Choice` constructed from the
underflow bit.
2024-07-17 12:05:46 -06:00
Tony Arcieri
5b7082bbc8
curve: use subtle::BlackBox optimization barrier (#662)
Replaces the security mitigation added in #659 and #661 for
masking-related timing variability which used an inline `black_box`
using the recently added `subtle::BlackBox` newtype (see
dalek-cryptography/subtle#123)

Internally `BlackBox` uses a volatile read by default (i.e. same
strategy which was used before) or when the `core_hint_black_box`
feature of `subtle` is enabled, it uses `core::hint::black_box`
(whose documentation was recently updated to reflect the nuances of
potential cryptographic use, see rust-lang/rust#126703)

This PR goes ahead and uses `BlackBox` for both `mask` and
`underflow_mask` where previously it was only used on `underflow_mask`.
The general pattern of bitwise masking inside a loop seems worrisome for
the optimizer potentially inserting branches in the future.

Below are godbolt inspections of the generated assembly, which are free
of the `jns` instructions originally spotted in #659/#661:

- 32-bit (read_volatile): https://godbolt.org/z/TKo9fqza4
- 32-bit (hint::black_box): https://godbolt.org/z/caoMxYbET
- 64-bit (read_volatile): https://godbolt.org/z/PM6zKjj1f
- 64-bit (hint::black_box): https://godbolt.org/z/nseaPvdWv
2024-06-24 20:13:54 +02:00
Michael Rosenberg
5312a0311e
curve: Bump version to 4.1.3 (#660)
* Bumped to v4.1.3

* Added recent PRs to changelog
2024-06-18 21:18:51 +02:00
Tony Arcieri
b4f9e4df92
SECURITY: fix timing variability in backend/serial/u32/scalar.rs (#661)
Similar security fix to #659, but for the 32-bit backend. See that PR
for more information about the problem. Relevant compiler outputs (thanks to @tarcieri):

Without fix
https://godbolt.org/z/zvaWxzvqv
Notice the `jns` ("jump if not sign") instruction on line 106.

With fix
https://godbolt.org/z/jc9j7eb8E
2024-06-18 21:02:37 +02:00
Michael Rosenberg
415892acf1
SECURITY: fix timing variability in backend/serial/u64/scalar.rs (#659)
Timing variability of any kind is problematic when working with
potentially secret values such as elliptic curve scalars, and such
issues can potentially leak private keys and other secrets. Such a
problem was recently discovered in `curve25519-dalek`.

The `Scalar52::sub` function contained usage of a mask value inside of a
loop where LLVM saw an opportunity to insert a branch instruction
(`jns` on x86) to conditionally bypass this code section when the mask
value is set to zero, as can be seen in godbolt:

https://godbolt.org/z/PczYj7Pda

A similar problem was recently discovered in the Kyber reference
implementation:

https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/hqbtIGFKIpU/m/cnE3pbueBgAJ

As discussed on that thread, one portable solution, which is also used
in this PR, is to introduce a volatile read as an optimization barrier,
which prevents the compiler from optimizing it away.

The fix can be validated in godbolt here:

https://godbolt.org/z/x8d46Yfah

The problem was discovered and the solution independently verified by
Alexander Wagner <alexander.wagner@aisec.fraunhofer.de> and
Lea Themint <lea.thiemt@tum.de> using their DATA tool:

https://github.com/Fraunhofer-AISEC/DATA

Co-authored-by: Tony Arcieri <bascule@gmail.com>
2024-06-18 19:49:31 +02:00
Isaiah Becker-Mayer
56bf398d0c
Updates license field to valid SPDX format (#647) 2024-06-03 14:30:13 -06:00
pinkforest(she/her)
9252fa5c0d
Mitigate check-cfg until MSRV 1.77 (#652) 2024-05-09 07:24:16 -06:00