Commit graph

2434 commits

Author SHA1 Message Date
Tony Arcieri
59ab400f1b
Bump RustCrypto dependencies (#815)
Updates the following dependencies (which now use `hybrid-array` v0.4
instead of v0.3):

- `blake2` v0.11.0-rc.2
- `digest` v0.11.0-rc.1
- `ed25519` v3.0.0-rc.0
- `sha2` v0.11.0-rc.2
- `sha3` v0.11.0-rc.2
- `signature` v3.0.0-rc.3
2025-09-03 17:12:43 -04:00
daxpedda
44433757a0
Add fixed-array Scalar batch inversion (#789) 2025-08-26 20:54:09 +02:00
Iñigo Querejeta Azurmendi
015707ab4e
Add proper hash_to_curve. (#786)
* Rename hash_to_curve as encode_to_curve

* Implement the inline description of the standard.

* Generalise map_to_field to return an arbitrary number of field elements.

* Implement hash_to_curve as defined in the standard.

* Put elligator behind the "digest" feature.

* Add warning on non-uniformity of `encode_to_curve`.

* Remove the need of Vec for hash_to_field.

* Apply suggestions from code review

* Refactor expand_message_xmd out of hash_to_field

* Add hash-to-curve to benches

* Constraint COUNT to 1 or 2; add note on secure hash function usage

* Correct hash function usage in encode- and hash-to-curve

---------

Co-authored-by: Armando Faz <armfazh@users.noreply.github.com>
Co-authored-by: Michael Rosenberg <mrosenberg@cloudflare.com>
2025-08-26 20:51:39 +02:00
Tony Arcieri
fc8815721c
Scalar::div_by_2 (#805)
* [WIP] Scalar::div_by_2

* debug_assert that carry is 0

* revise tests

* Test multiply by half scalar, double and compress (#804)

* Test `div_by_2` with `proptest` (#806)

---------

Co-authored-by: daxpedda <daxpedda@gmail.com>
2025-08-22 20:45:51 +02:00
yumeiyin
1ad4603e0a
chore: fix some minor issues in sage comments (#788) 2025-08-08 16:13:28 -04:00
Arthur Gautier
246723eefe
workspace: use a global patch.crates-io to avoid duplicates (#793)
When pulling crates via git (to grab non-released yet fixes or
otherwise), the `path = "../"` in each crate crates duplicates unless
you pull the whole tree in your local `[patch.crates-io]`.

This creates issues in downstream packaging (nix, ...) where a crate
version can only appear once.
Those are somewhat difficult to diagnose.

Using a `[patch.crates-io]` in the workspace serves the same purpose but
does not create the duplication in consumers' tree.
2025-07-18 08:26:13 -06:00
Tony Arcieri
c6e32a2c7a
curve: add yanking notes for v4.2.0 (#794)
Yanked due to #785
2025-07-17 21:52:40 -04:00
Arthur Gautier
03df416703
chore(deps): bump signature to 3.0.0-rc.2 (#791)
This also relax the dependency to use future RC versions of signatures
2025-07-16 19:11:24 -06:00
daxpedda
c3f91f7620
ed25519: implement MultipartSigner/Verifier (#764) 2025-07-14 09:41:20 -05:00
Michael Rosenberg
fc8a8a5276
Cut pre.0 prereleases (#784) 2025-07-09 19:04:17 +02:00
Michael Rosenberg
6a515e60a8
Update all READMEs and CHANGELOGs (#783)
* Update changelogs and readmes

* Fix missing/wrong features in readmes

* ed: Remove std entirely

* ed: Fix deprecated warnings in bench

* Document removing std from ed
2025-07-08 21:46:55 -04:00
Michael Rosenberg
e3c2455f63
x: Remove Zeroize impl for secret types (#782) 2025-07-08 21:06:07 +02:00
Aaron Feickert
55e3e00d97
curve: Remove unnecessary CofactorGroup documentation (#683) 2025-07-07 21:42:31 -04:00
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