2016-12-08 05:12:00 +00:00
|
|
|
|
2018-03-09 23:59:20 +00:00
|
|
|
# curve25519-dalek [](https://crates.io/crates/curve25519-dalek) [](https://doc.dalek.rs) [](https://travis-ci.org/dalek-cryptography/curve25519-dalek)
|
2016-12-08 05:12:00 +00:00
|
|
|
|
2018-01-19 23:01:47 +00:00
|
|
|
<img
|
2018-01-25 21:40:30 +00:00
|
|
|
width="33%"
|
2018-01-19 23:01:47 +00:00
|
|
|
align="right"
|
2018-02-21 19:03:18 +00:00
|
|
|
src="https://doc.dalek.rs/assets/dalek-logo-clear.png"/>
|
2018-01-19 23:01:47 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
**A pure-Rust implementation of group operations on Ristretto and Curve25519.**
|
2016-12-08 05:12:00 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
`curve25519-dalek` is a library providing group operations on the Edwards and
|
|
|
|
|
Montgomery forms of Curve25519, and on the prime-order Ristretto group.
|
2016-12-08 05:12:00 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
`curve25519-dalek` is not intended to provide implementations of any particular
|
|
|
|
|
crypto protocol. Rather, implementations of those protocols (such as
|
|
|
|
|
[`x25519-dalek`][x25519-dalek] and [`ed25519-dalek`][ed25519-dalek]) should use
|
|
|
|
|
`curve25519-dalek` as a library.
|
2016-12-08 05:12:00 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
`curve25519-dalek` is intended to provide a clean and safe _mid-level_ API for use
|
|
|
|
|
implementing a wide range of ECC-based crypto protocols, such as key agreement,
|
|
|
|
|
signatures, anonymous credentials, rangeproofs, and zero-knowledge proof
|
|
|
|
|
systems.
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-26 01:34:06 +00:00
|
|
|
In particular, `curve25519-dalek` implements Ristretto, which constructs a
|
|
|
|
|
prime-order group from a non-prime-order Edwards curve. This provides the
|
|
|
|
|
speed and safety benefits of Edwards curve arithmetic, without the pitfalls of
|
|
|
|
|
cofactor-related abstraction mismatches.
|
|
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
## WARNING
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
We do not yet consider this code to be production-ready. We intend to
|
|
|
|
|
stabilize a production-ready version `1.0` soon.
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
# Documentation
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
The semver-stable, public-facing `curve25519-dalek` API is documented
|
|
|
|
|
[here][docs-external]. In addition, the unstable internal implementation
|
|
|
|
|
details are documented [here][docs-internal].
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
The `curve25519-dalek` documentation requires a custom HTML header to include
|
|
|
|
|
KaTeX for math support. Unfortunately `cargo doc` does not currently support
|
|
|
|
|
this, but docs can be built using
|
|
|
|
|
```sh
|
|
|
|
|
make doc
|
|
|
|
|
make doc-internal
|
|
|
|
|
```
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
# Use
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
To import `curve25519-dalek`, add the following to the dependencies section of
|
|
|
|
|
your project's `Cargo.toml`:
|
2017-12-02 03:19:19 +00:00
|
|
|
```toml
|
2018-05-15 20:34:30 +00:00
|
|
|
curve25519-dalek = "^0.17"
|
2017-12-02 03:19:19 +00:00
|
|
|
```
|
2018-01-25 21:40:30 +00:00
|
|
|
Then import the crate as:
|
|
|
|
|
```rust,no_run
|
|
|
|
|
extern crate curve25519_dalek;
|
|
|
|
|
```
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
# Backends and Features
|
2017-12-02 03:19:19 +00:00
|
|
|
|
2018-05-15 00:35:34 +00:00
|
|
|
The `yolocrypto` feature enables experimental features. The name `yolocrypto`
|
|
|
|
|
is meant to indicate that it is not considered production-ready, and we do not
|
|
|
|
|
consider `yolocrypto` features to be covered by semver guarantees.
|
|
|
|
|
|
|
|
|
|
The `std` feature is enabled by default, but it can be disabled.
|
|
|
|
|
|
|
|
|
|
The `nightly` feature enables nightly-only features. **It is recommended for security**.
|
|
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
Curve arithmetic is implemented using one of the following backends:
|
2016-12-08 22:18:57 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
* a `u32` backend using `u64` products;
|
2018-05-15 00:35:34 +00:00
|
|
|
* a `u64` backend using `u128` products;
|
2018-01-25 22:31:56 +00:00
|
|
|
* an experimental AVX2 backend, available using the `yolocrypto` feature when
|
|
|
|
|
compiling for a target with `target_feature=+avx2`.
|
2017-12-02 03:19:19 +00:00
|
|
|
|
2018-05-15 00:35:34 +00:00
|
|
|
By default the `u64` backend is selected. To select a specific backend, use:
|
|
|
|
|
```sh
|
|
|
|
|
cargo build --no-default-features --features "std u32_backend"
|
|
|
|
|
cargo build --no-default-features --features "std u64_backend"
|
|
|
|
|
cargo build --no-default-features --features "std avx2_backend yolocrypto"
|
|
|
|
|
```
|
|
|
|
|
|
2018-03-26 00:10:30 +00:00
|
|
|
Benchmarks are run using [`criterion.rs`][criterion]:
|
2017-12-02 03:19:19 +00:00
|
|
|
|
|
|
|
|
```sh
|
2018-05-15 00:35:34 +00:00
|
|
|
# You must set RUSTFLAGS to enable AVX2 support.
|
|
|
|
|
export RUSTFLAGS="-C target_cpu=native"
|
|
|
|
|
cargo bench --no-default-features --features "std u32_backend"
|
|
|
|
|
cargo bench --no-default-features --features "std u64_backend"
|
|
|
|
|
cargo bench --no-default-features --features "std avx2_backend yolocrypto"
|
2017-12-02 03:19:19 +00:00
|
|
|
```
|
2017-03-14 08:53:26 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
# Contributing
|
2016-12-08 05:12:00 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
Please see [CONTRIBUTING.md][contributing].
|
2017-08-01 03:03:11 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
Patches and pull requests should be make against the `develop`
|
|
|
|
|
branch, **not** `master`.
|
2017-11-16 00:47:01 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
# About
|
2017-11-16 00:47:01 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
**SPOILER ALERT:** *The Twelfth Doctor's first encounter with the Daleks is in
|
|
|
|
|
his second full episode, "Into the Dalek". A beleaguered ship of the "Combined
|
|
|
|
|
Galactic Resistance" has discovered a broken Dalek that has turned "good",
|
|
|
|
|
desiring to kill all other Daleks. The Doctor, Clara and a team of soldiers
|
|
|
|
|
are miniaturized and enter the Dalek, which the Doctor names Rusty. They
|
|
|
|
|
repair the damage, but accidentally restore it to its original nature, causing
|
|
|
|
|
it to go on the rampage and alert the Dalek fleet to the whereabouts of the
|
|
|
|
|
rebel ship. However, the Doctor manages to return Rusty to its previous state
|
|
|
|
|
by linking his mind with the Dalek's: Rusty shares the Doctor's view of the
|
|
|
|
|
universe's beauty, but also his deep hatred of the Daleks. Rusty destroys the
|
|
|
|
|
other Daleks and departs the ship, determined to track down and bring an end
|
|
|
|
|
to the Dalek race.*
|
2017-11-16 00:47:01 +00:00
|
|
|
|
2018-01-25 21:40:30 +00:00
|
|
|
`curve25519-dalek` is authored by Isis Agora Lovecruft and Henry de Valence.
|
|
|
|
|
|
|
|
|
|
Portions of this library were originally a port of [Adam Langley's
|
|
|
|
|
Golang ed25519 library](https://github.com/agl/ed25519), which was in
|
|
|
|
|
turn a port of the reference `ref10` implementation.
|
|
|
|
|
|
|
|
|
|
The fast `u32` and `u64` scalar arithmetic was implemented by Andrew Moon, and
|
2018-01-26 02:00:17 +00:00
|
|
|
the addition chain for scalar inversion was provided by Brian Smith.
|
|
|
|
|
|
|
|
|
|
The `no_std` support was contributed by Tony Arcieri.
|
|
|
|
|
|
|
|
|
|
Thanks also to Ashley Hauck, Lucas Salibian, and Manish Goregaokar for their
|
|
|
|
|
contributions.
|
2018-01-25 21:40:30 +00:00
|
|
|
|
|
|
|
|
[ed25519-dalek]: https://github.com/dalek-cryptography/ed25519-dalek
|
|
|
|
|
[x25519-dalek]: https://github.com/dalek-cryptography/x25519-dalek
|
|
|
|
|
[contributing]: https://github.com/dalek-cryptography/curve25519-dalek/blob/master/CONTRIBUTING.md
|
2018-02-21 19:11:17 +00:00
|
|
|
[docs-external]: https://doc.dalek.rs/curve25519_dalek/
|
|
|
|
|
[docs-internal]: https://doc-internal.dalek.rs/curve25519_dalek/
|
2018-03-26 00:10:30 +00:00
|
|
|
[criterion]: https://github.com/japaric/criterion.rs
|