Commit graph

2354 commits

Author SHA1 Message Date
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
Hiroki Kobayashi
1efe6a93b1
Fix a minor typo in signing.rs (#649)
an -> a
2024-04-13 19:37:33 -06:00
Boyd Kane
cc3421a22f
Indicate that the rand_core feature is required (#641) 2024-03-16 07:43:25 -06:00
pinkforest(she/her)
858c4ca8ae
Address new nightly clippy unnecessary qualifications (#639) 2024-03-07 16:58:20 -07:00
pinkforest(she/her)
31ccb67050
Remove platforms in favor using CARGO_CFG_TARGET_POINTER_WIDTH (#636) 2024-03-01 07:35:23 -07:00
pinkforest(she/her)
19c7f4a5d5
Fix new nightly redundant import lint warns (#638) 2024-02-29 18:56:52 -07:00
Flori
a62e4a5c57
Fix minor spelling mistakes (#629) 2024-02-14 12:01:05 -07:00
Jack Lloyd
17eab3d6c1
ed: Make it possible to convert between VerifyingKey and EdwardsPoint (#624)
Adds VerifyingKey::to_edwards and a From conversion

See #623
2024-02-12 14:36:43 -05:00
Tony Arcieri
50401ab430
curve: mark ValidityCheck trait as allow(dead_code) (#625)
Recent nightlies have started emitting a dead code lint
2024-02-12 11:56:06 -05:00
Michael Rosenberg
4ac84dd066
curve,ed,x: Bump patch version to reflect fix to nightly SIMD build (#621) 2024-02-06 20:09:18 -05:00
Jimmy Chen
ff1c309b23
Fix nightly build (#619)
* Fix nightly build

* Add nightly feature constraint so AVX-512 requires either x86 or x86_64

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

* fmt

---------

Co-authored-by: Michael Rosenberg <micro@fastmail.com>
Co-authored-by: Tony Arcieri <bascule@gmail.com>
Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2024-02-06 15:09:29 -05:00
Ford
ba737a3790
Update README.md (#613) 2024-01-21 08:27:47 -07:00
Pioua
0b45e00ad5
chore: typo fix (#608) 2023-12-13 08:10:05 -07:00
Wiktor Kwapisiewicz
ba7a073487
doc: Fix markdown PR reference (#605) 2023-11-22 06:21:20 -07:00
Bram Westerbaan
a2ff6ba9e4
{Signing,Verifying}KeyVisitor: visit_borrowed_bytes -> visit_bytes (#602) 2023-11-17 02:44:28 -05:00
Michael Rosenberg
f08bbb7f57
ed: Prep to release v2.1.0 (#600) 2023-11-14 15:35:42 -05:00
Michael Rosenberg
04f811ad21
ed: Add back SigningKey::to_scalar_bytes (#599)
* Brought back SigningKey::to_scalar_bytes; added regression test

* Updated SigningKey::to_scalar docs and tests
2023-11-14 13:23:48 -05:00
Tony Arcieri
ac51ef6ecf
ed25519: loosen signature crate dependency again (#598)
Like #582, there is a new release of `signature` (v2.2.0) which contains
no breaking changes from ed25519-dalek's perspective. The main notable
one is it bumps MSRV to 1.60, which so also happens to also be
ed25519-dalek's MSRV.

This commit loosens the version requirement to allow `>=2.0, <2.3` to
allow the `signature` 2.2 series.
2023-11-14 00:09:16 -05:00