• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H03-May-2022-10394

benches/H03-May-2022-330270

docs/H03-May-2022-1,056942

src/H03-May-2022-31,14625,523

vendor/H03-May-2022-858720

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

CHANGELOG.mdH A D01-Jan-19705.6 KiB170110

CODE_OF_CONDUCT.mdH A D01-Jan-1970373 96

CONTRIBUTING.mdH A D01-Jan-1970827 2014

Cargo.tomlH A D01-Jan-19702.2 KiB8673

Cargo.toml.orig-cargoH A D01-Jan-19702.4 KiB6457

LICENSEH A D01-Jan-19703.2 KiB6552

MakefileH A D01-Jan-1970303 95

README.mdH A D01-Jan-19709.5 KiB222171

README.md

1
2# curve25519-dalek-ng
3
4<img
5 width="33%"
6 align="right"
7 src="https://doc.dalek.rs/assets/dalek-logo-clear.png"/>
8
9**A pure-Rust implementation of group operations on Ristretto and Curve25519.**
10
11`curve25519-dalek` is a library providing group operations on the Edwards and
12Montgomery forms of Curve25519, and on the prime-order Ristretto group.
13
14`curve25519-dalek` is not intended to provide implementations of any particular
15crypto protocol.  Rather, implementations of those protocols (such as
16[`x25519-dalek`][x25519-dalek] and [`ed25519-dalek`][ed25519-dalek]) should use
17`curve25519-dalek` as a library.
18
19`curve25519-dalek` is intended to provide a clean and safe _mid-level_ API for use
20implementing a wide range of ECC-based crypto protocols, such as key agreement,
21signatures, anonymous credentials, rangeproofs, and zero-knowledge proof
22systems.
23
24In particular, `curve25519-dalek` implements Ristretto, which constructs a
25prime-order group from a non-prime-order Edwards curve.  This provides the
26speed and safety benefits of Edwards curve arithmetic, without the pitfalls of
27cofactor-related abstraction mismatches.
28
29# Documentation
30
31The semver-stable, public-facing `curve25519-dalek` API is documented
32[here][docs-external].  In addition, the unstable internal implementation
33details are documented [here][docs-internal].
34
35The `curve25519-dalek` documentation requires a custom HTML header to include
36KaTeX for math support. Unfortunately `cargo doc` does not currently support
37this, but docs can be built using
38```sh
39make doc
40make doc-internal
41```
42
43# Use
44
45To import `curve25519-dalek`, add the following to the dependencies section of
46your project's `Cargo.toml`:
47```toml
48curve25519-dalek-ng = "4"
49```
50
51To switch from the previous `curve25519-dalek` crate without changing your code,
52use the following:
53```toml
54curve25519-dalek = { package = "curve25519-dalek-ng", version = "4" }
55```
56
57This crate continues the `curve25519-dalek` series under a different package name.
58Unfortunately, one of the maintainers of the previous crate seized control of the
59`dalek-cryptography` GitHub organization and the `subtle` and `curve25519-dalek`
60crates by silently removing all other co-maintainers.
61
62The `4.x` series has API almost entirely unchanged from the `3.x` series,
63except that the `rand_core` version was updated.
64
65The `3.x` series has API almost entirely unchanged from the `2.x` series,
66except that the `digest` version was updated.
67
68The `2.x` series (unsupported) has API almost entirely unchanged from the
69`1.x` series, except that:
70
71* an error in the data modeling for the (optional) `serde` feature was
72  corrected, so that when the `2.x`-series `serde` implementation is used
73  with `serde-bincode`, the derived serialization matches the usual X/Ed25519
74  formats;
75
76* the `rand` version was updated.
77
78See `CHANGELOG.md` for more details.
79
80# Backends and Features
81
82The `nightly` feature enables features available only when using a Rust nightly
83compiler.  In particular, it is required for rendering documentation and for
84the SIMD backends.
85
86Curve arithmetic is implemented using one of the following backends:
87
88* a `u32` backend using serial formulas and `u64` products;
89* a `u64` backend using serial formulas and `u128` products;
90* an `avx2` backend using [parallel formulas][parallel_doc] and `avx2` instructions (sets speed records);
91* an `ifma` backend using [parallel formulas][parallel_doc] and `ifma` instructions (sets speed records);
92
93By default the `u64` backend is selected.  To select a specific backend, use:
94```sh
95cargo build --no-default-features --features "std u32_backend"
96cargo build --no-default-features --features "std u64_backend"
97# Requires nightly, RUSTFLAGS="-C target_feature=+avx2" to use avx2
98cargo build --no-default-features --features "std simd_backend"
99# Requires nightly, RUSTFLAGS="-C target_feature=+avx512ifma" to use ifma
100cargo build --no-default-features --features "std simd_backend"
101```
102Crates using `curve25519-dalek` can either select a backend on behalf of their
103users, or expose feature flags that control the `curve25519-dalek` backend.
104
105The `std` feature is enabled by default, but it can be disabled for no-`std`
106builds using `--no-default-features`.  Note that this requires explicitly
107selecting an arithmetic backend using one of the `_backend` features.
108If no backend is selected, compilation will fail.
109
110# Safety
111
112The `curve25519-dalek` types are designed to make illegal states
113unrepresentable.  For example, any instance of an `EdwardsPoint` is
114guaranteed to hold a point on the Edwards curve, and any instance of a
115`RistrettoPoint` is guaranteed to hold a valid point in the Ristretto
116group.
117
118All operations are implemented using constant-time logic (no
119secret-dependent branches, no secret-dependent memory accesses),
120unless specifically marked as being variable-time code.
121We believe that our constant-time logic is lowered to constant-time
122assembly, at least on `x86_64` targets.
123
124As an additional guard against possible future compiler optimizations,
125the `subtle` crate places an optimization barrier before every
126conditional move or assignment.  More details can be found in [the
127documentation for the `subtle` crate][subtle_doc].
128
129Some functionality (e.g., multiscalar multiplication or batch
130inversion) requires heap allocation for temporary buffers.  All
131heap-allocated buffers of potentially secret data are explicitly
132zeroed before release.
133
134However, we do not attempt to zero stack data, for two reasons.
135First, it's not possible to do so correctly: we don't have control
136over stack allocations, so there's no way to know how much data to
137wipe.  Second, because `curve25519-dalek` provides a mid-level API,
138the correct place to start zeroing stack data is likely not at the
139entrypoints of `curve25519-dalek` functions, but at the entrypoints of
140functions in other crates.
141
142The implementation is memory-safe, and contains no significant
143`unsafe` code.  The SIMD backend uses `unsafe` internally to call SIMD
144intrinsics.  These are marked `unsafe` only because invoking them on an
145inappropriate CPU would cause `SIGILL`, but the entire backend is only
146compiled with appropriate `target_feature`s, so this cannot occur.
147
148# Performance
149
150Benchmarks are run using [`criterion.rs`][criterion]:
151
152```sh
153cargo bench --no-default-features --features "std u32_backend"
154cargo bench --no-default-features --features "std u64_backend"
155# Uses avx2 or ifma only if compiled for an appropriate target.
156export RUSTFLAGS="-C target_cpu=native"
157cargo bench --no-default-features --features "std simd_backend"
158```
159
160Performance is a secondary goal behind correctness, safety, and
161clarity, but we aim to be competitive with other implementations.
162
163# FFI
164
165Unfortunately, we have no plans to add FFI to `curve25519-dalek` directly.  The
166reason is that we use Rust features to provide an API that maintains safety
167invariants, which are not possible to maintain across an FFI boundary.  For
168instance, as described in the _Safety_ section above, invalid points are
169impossible to construct, and this would not be the case if we exposed point
170operations over FFI.
171
172However, `curve25519-dalek` is designed as a *mid-level* API, aimed at
173implementing other, higher-level primitives.  Instead of providing FFI at the
174mid-level, our suggestion is to implement the higher-level primitive (a
175signature, PAKE, ZKP, etc) in Rust, using `curve25519-dalek` as a dependency,
176and have that crate provide a minimal, byte-buffer-oriented FFI specific to
177that primitive.
178
179# Contributing
180
181Please see [CONTRIBUTING.md][contributing].
182
183# About
184
185**SPOILER ALERT:** *The Twelfth Doctor's first encounter with the Daleks is in
186his second full episode, "Into the Dalek". A beleaguered ship of the "Combined
187Galactic Resistance" has discovered a broken Dalek that has turned "good",
188desiring to kill all other Daleks. The Doctor, Clara and a team of soldiers
189are miniaturized and enter the Dalek, which the Doctor names Rusty. They
190repair the damage, but accidentally restore it to its original nature, causing
191it to go on the rampage and alert the Dalek fleet to the whereabouts of the
192rebel ship. However, the Doctor manages to return Rusty to its previous state
193by linking his mind with the Dalek's: Rusty shares the Doctor's view of the
194universe's beauty, but also his deep hatred of the Daleks. Rusty destroys the
195other Daleks and departs the ship, determined to track down and bring an end
196to the Dalek race.*
197
198`curve25519-dalek` is authored by Isis Agora Lovecruft and Henry de Valence.
199
200Portions of this library were originally a port of [Adam Langley's
201Golang ed25519 library](https://github.com/agl/ed25519), which was in
202turn a port of the reference `ref10` implementation.  Most of this code,
203including the 32-bit field arithmetic, has since been rewritten.
204
205The fast `u32` and `u64` scalar arithmetic was implemented by Andrew Moon, and
206the addition chain for scalar inversion was provided by Brian Smith.  The
207optimised batch inversion was contributed by Sean Bowe and Daira Hopwood.
208
209The `no_std` and `zeroize` support was contributed by Tony Arcieri.
210
211Thanks also to Ashley Hauck, Lucas Salibian, and Manish Goregaokar for their
212contributions.
213
214[ed25519-dalek]: https://github.com/dalek-cryptography/ed25519-dalek
215[x25519-dalek]: https://github.com/dalek-cryptography/x25519-dalek
216[contributing]: https://github.com/zkcrypto/curve25519-dalek-ng/blob/master/CONTRIBUTING.md
217[subtle_doc]: https://docs.rs/subtle_ng/
218[docs-external]: https://docs.rs/curve25519-dalek-ng/
219[docs-internal]: https://doc-internal.dalek.rs/curve25519_dalek/
220[parallel_doc]: https://doc-internal.dalek.rs/curve25519_dalek/backend/vector/avx2/index.html
221[criterion]: https://github.com/japaric/criterion.rs
222