Commit graph

43 commits

Author SHA1 Message Date
d58065f735 Aeneas-compat: decompress step_2 negate-then-conditional-assign
Same documented rewrite as FieldElement::sqrt_ratio_i: semantically
identical and still constant-time, but avoids subtle's
ConditionallyNegatable blanket impl, which the verification toolchain
cannot translate. Unblocks extracting decompress for the phase-2 full
point-level lift.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 01:41:54 +02:00
76b3804d6b Aeneas-compat: index-based LE word load in non_adjacent_form
Pure refactor, semantics identical: the read_le_u64_into call (whose
chunks/zip iterators are opaque to the extraction) becomes an explicit
nested index loop, the same shape as the proven from_bytes_wide unpack.
With this the entire vartime_double_base::mul extraction closure is
self-contained: zero external axioms, zero sorries.
2026-07-04 11:39:12 +02:00
32b32bc56f Aeneas-compat: make vartime_double_base::mul extraction-clean
Pure refactors (cargo check green under both feature sets), semantics of
mul unchanged:
- dsm_top_index / dsm_loop / dsm_step_p / dsm_step_b helpers: the main
  double-and-add loop becomes a strictly-decreasing while with a
  single-assignment body and parameter-rooted borrows (the original
  loop/break shape with match-updates fails Aeneas' loop fixed point);
- the starting-index scan always returns 255: leading zero NAF digits
  double the identity (a no-op), so the result is unchanged - only the
  variable-time skip is dropped (constant-time behavior improves);
- the downward break-scan (which failed Aeneas' symbolic join) is gone.

With these, Charon+Aeneas extract the complete path - non_adjacent_form,
NafLookupTable5::from/select, the affine basepoint table, the 256-step
dsm_loop, and mul - with zero errors and zero sorries. This opens the
double-scalar-multiplication verification campaign (the EdDSA verify
equation's core).
2026-07-04 11:10:34 +02:00
f313da8b8e Aeneas-compat: factor from_bytes_wide through named, closure-free helpers
Pure refactor, semantics identical (cargo check green):
- from_bytes_wide_parts(bytes) -> (Scalar52, Scalar52): the byte-unpack
  loops + the 52-bit lo/hi split, as a named prefix
- split_words_lo / split_words_hi: the two split halves, built with
  Scalar52([...]) struct literals instead of per-index mutation
- from_bytes_wide: parts -> montgomery_mul(lo, R) ->
  montgomery_mul(hi, RR) -> add

Why: the verification side measured that (a) a WP walk whose motives
contain a montgomery_mul call replays its whole body at every kernel
step, and (b) straight-line chains of IndexMut closure back-functions
make kernel defeq exponential in chain depth. Named prefix functions fix
(a); struct-literal construction eliminates the closures and fixes (b).
With this shape the full from_bytes_wide certificate kernel-checks in
77 seconds (was: aborted after 30+ minutes).
2026-07-04 10:23:25 +02:00
e83630b637 Aeneas-compat: mask the bare shift in Scalar52::from_bytes_wide
hi[4] = words[7] >> 20  is the only shift in the function whose result is
stored without a trailing mask/or; at the pinned Aeneas (bf13c42e) a bare
`x >> c` as a full RHS extracts ill-typed (wrapping_shr applied to an i32
with an emitted-but-unsubstituted U32 cast). Masking is a semantic no-op:
words[7] >> 20 < 2^44 < 2^52.  Semantics unchanged; needed to bring
from_bytes_wide (the hash-to-scalar reduction) into verification scope.
2026-07-03 22:40:02 +02:00
54ef3c9293 patch: remove ConditionallyNegatable for Aeneas/Charon transpilation
Upstream: risc0/curve25519-dalek v4.1.3
Required for: formal verification via Aeneas bf13c42e + Charon 9dd7f23c
2026-06-30 17:30:36 +02:00
Victor Graf
385adda1fa
add support for RISC Zero cryptographic accelerators 2025-09-26 17:00:25 -07: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
pinkforest(she/her)
9252fa5c0d
Mitigate check-cfg until MSRV 1.77 (#652) 2024-05-09 07:24:16 -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
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
Pioua
0b45e00ad5
chore: typo fix (#608) 2023-12-13 08:10:05 -07:00
Michael Rosenberg
81d0756bdc
Made unnecessarily pub contents of field.rs pub(crate) 2023-10-29 22:06:47 -04:00
Michael Rosenberg
cd9378e6fd
Removed unnecessary 'pub use' 2023-10-29 21:53:08 -04:00
Michael Rosenberg
0cd099a9fb
curve: Bump version to 4.1.1 (#584) 2023-09-20 17:42:22 -05:00
Luke Parker
76a8b2a081
Add PrimeFieldBits support to Scalar (#579)
Co-authored-by: Michael Rosenberg <micro@fastmail.com>
Co-authored-by: pinkforest(she/her) <36498018+pinkforest@users.noreply.github.com>
2023-09-19 23:21:43 -04:00
pinkforest(she/her)
533b53a0ec
Deprecate BASEPOINT_ORDER from pub API consts (#581)
* Mark constants::BASEPOINT_ORDER_PRIVATE deprecated from pub API

* Move all BASEPOINT_ORDER use private internally

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

* Fix CHANGELOG for 4.1.1

---------

Co-authored-by: Tony Arcieri <bascule@gmail.com>
2023-09-17 23:59:05 -04:00
Luke Parker
c157a1ed6d
Add group to documented features (#578) 2023-09-12 07:41:15 -06:00
Michael Rosenberg
e94a5fe5ab
curve: README typos 2023-09-06 00:53:30 -04:00
pinkforest(she/her)
9db51a6bf7
curve: Release 4.1.0 (#574)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2023-09-06 00:51:15 -04:00
Tony Arcieri
1ec4a36a80
curve: update repository in Cargo.toml (#575)
Point to the subdirectory which contains the crate
2023-09-06 00:08:06 -04:00
David Cook
a3a08b01ab
Adapt to new types introduced in fiat-crypto 0.2 (#566) 2023-09-05 10:07:49 -06:00
pinkforest(she/her)
5c5a32057c
curve: Fix no_std for fiat backend and add test for it (#572) 2023-09-04 13:49:58 -06:00
Rob Ede
c8d1d400f1
curve,ed: chore: update dev deps (#569) 2023-08-28 09:46:38 -04:00
Tony Arcieri
60dd3100c0
curve: add doc(hidden) to serial backend modules (#568)
We have a lot of backend types leaking via the public API, including
e.g. `FieldElement51`:

https://docs.rs/curve25519-dalek/latest/curve25519_dalek/backend/serial/u64/field/struct.FieldElement51.html

At the very least, these types shouldn't be visible in the rustdoc.

This PR hides them from the docs, but ideally we would hide them
completely from the public API (which might technically be considered a
breaking change, but IMO leaking them at all is a bug).
2023-08-28 02:38:11 -04:00
Tony Arcieri
c058cd9057
curve: Expand lints (#530)
Adds a lints section to the top of lib.rs with the following:

    #![warn(
        clippy::unwrap_used,
        missing_docs,
        rust_2018_idioms,
        unused_lifetimes,
        unused_qualifications
    )]

`warn` is used instead of `deny` to prevent the lints from firing during
local development, however we already configure `-D warnings` in CI so
if any lint fails on checked-in code, it will cause a CI failure.

This commit also fixes or explicitly allows any current violations of
these lints. The main ones were:

- `clippy::unwrap_used`: replaces usages of `unwrap` with `expect`
- `rust_2018_idioms`: no implicit lifetimes, which were present on
  usages of `core::fmt::Formatter`
2023-08-28 02:32:31 -04:00
Michael Rosenberg
8e0cef5b72
curve: Add arbitrary integer multiplication with MontgomeryPoint::mul_bits_be (#555)
There is occasionally [a need](https://github.com/dalek-cryptography/curve25519-dalek/pull/519#issuecomment-1637770888) to multiply a non-prime-order Montgomery point by an integer. There's currently no way to do this, since our only methods are multiplication by `Scalar` (doesn't make sense in the non-prime-order case), and `MontgomeryPoint::mul_base_clamped` clamps the integer before multiplying.

This defines `MontgomeryPoint::mul_bits_be`, which takes a big-endian representation of an integer and multiplies the point by that integer. Its usage is not recommended by default, but it is also not so unsafe as to be gated behind a `hazmat` feature.
2023-08-28 01:58:41 -04:00
pinkforest(she/her)
4373695c50
curve: implement ff and group traits (#562)
Originally authored by @str4d as #473
2023-08-27 14:41:06 -06:00
Rob Ede
b93ace8c7f
Address Clippy lints (#543) 2023-08-27 12:47:12 -06:00
moiseev-signal
bf2c4eea23
curve: Mark scalar::clamp_integer as must_use (#558) 2023-08-12 01:44:09 -04:00
Michael Rosenberg
42b55fd117
ed: Bump ed25519-dalek to 2.0.0 (#559)
* Made clippy happy
2023-08-11 11:38:43 -04:00
Michael Rosenberg
e44d4b5903
curve,ed,x: Bump curve version to 4.0.0 (#550) 2023-07-22 12:52:24 -04:00
Michael Rosenberg
0d1bc975d5
Fixed CI badges in workspaces 2023-07-22 12:22:31 -04:00
Michael Rosenberg
98a0a6f2ef
Moved code of conduct 2023-06-29 23:35:29 -04:00
pinkforest
6e422d96d7
Re-organize Cargo manifests to workspace 2023-06-28 09:38:06 +00:00
pinkforest
2cc52c216e
Move CI & assets into workspace
Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2023-06-28 08:59:51 +00:00
pinkforest
40cf5aff99
Workspace curve25519 under curve25519-dalek 2023-06-27 04:00:12 +00:00