From d0ea313e9927e2a23682b83a4275d4e3b2eb3bdb Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 25 Oct 2019 15:38:50 -0700 Subject: [PATCH 1/5] Remove broken impl Zeroize for FieldElement2625x4. This implementation is broken because the packed_simd types don't implement `Zeroize`. --- src/backend/vector/avx2/field.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/backend/vector/avx2/field.rs b/src/backend/vector/avx2/field.rs index d1a84a0..edd1fa6 100644 --- a/src/backend/vector/avx2/field.rs +++ b/src/backend/vector/avx2/field.rs @@ -41,7 +41,6 @@ const D_LANES64: u8 = 0b11_00_00_00; use core::ops::{Add, Mul, Neg}; use packed_simd::{i32x8, u32x8, u64x4, IntoBits}; -use zeroize::Zeroize; use backend::vector::avx2::constants::{P_TIMES_16_HI, P_TIMES_16_LO, P_TIMES_2_HI, P_TIMES_2_LO}; use backend::serial::u64::field::FieldElement51; @@ -874,12 +873,6 @@ impl<'a, 'b> Mul<&'b FieldElement2625x4> for &'a FieldElement2625x4 { } } -impl Zeroize for FieldElement2625x4 { - fn zeroize(&mut self) { - self.0.zeroize(); - } -} - #[cfg(test)] mod test { use super::*; From be4cbe2af31dfa1018edd9c2812815191db41fbf Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 25 Oct 2019 15:58:41 -0700 Subject: [PATCH 2/5] Update README.md with 2.x changes. --- README.md | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f7a9207..5035df2 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ make doc-internal To import `curve25519-dalek`, add the following to the dependencies section of your project's `Cargo.toml`: ```toml -curve25519-dalek = "1" +curve25519-dalek = "2" ``` Then import the crate as: ```rust,no_run @@ -59,17 +59,19 @@ compiler. **It is recommended for security**. Curve arithmetic is implemented using one of the following backends: -* a `u32` backend using `u64` products; -* a `u64` backend using `u128` products; -* an `avx2` backend using [parallel formulas][parallel_doc], available - when compiling for a target with `target_feature=+avx2`. +* a `u32` backend using serial formulas and `u64` products; +* a `u64` backend using serial formulas and `u128` products; +* an `avx2` backend using [parallel formulas][parallel_doc] and `avx2` instructions (sets speed records); +* an `ifma` backend using [parallel formulas][parallel_doc] and `ifma` instructions (sets speed records); 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" -# Requires RUSTFLAGS="-C target_feature=+avx2" -cargo build --no-default-features --features "std avx2_backend" +# Requires nightly, RUSTFLAGS="-C target_feature=+avx2" to use avx2 +cargo build --no-default-features --features "std simd_backend" +# Requires nightly, RUSTFLAGS="-C target_feature=+avx512ifma" to use ifma +cargo build --no-default-features --features "std simd_backend" ``` Crates using `curve25519-dalek` can either select a backend on behalf of their users, or expose feature flags that control the `curve25519-dalek` backend. @@ -79,13 +81,6 @@ builds using `--no-default-features`. Note that this requires explicitly selecting an arithmetic backend using one of the `_backend` features. If no backend is selected, compilation will fail. -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. -This is designed to make it easier to test intended new features -without having to stabilise them first. Use `yolocrypto` at your own, -obvious, risk. - # Safety The `curve25519-dalek` types are designed to make illegal states @@ -120,23 +115,21 @@ entrypoints of `curve25519-dalek` functions, but at the entrypoints of functions in other crates. The implementation is memory-safe, and contains no significant -`unsafe` code. The AVX2 backend uses `unsafe` internally to call AVX2 -intrinsics. These are marked `unsafe` because invoking them on a -non-AVX2 target would cause `SIGILL`, but the entire backend is only -compiled for `target_feature=+avx2`. Some types implement an `unsafe -trait` to mark them as zeroable (for heap allocations), but this does -not affect memory safety. +`unsafe` code. The SIMD backend uses `unsafe` internally to call SIMD +intrinsics. These are marked `unsafe` because invoking them on an +inappropriate CPU would cause `SIGILL`, but the entire backend is only +compiled with appropriate `target_feature`s. # Performance Benchmarks are run using [`criterion.rs`][criterion]: ```sh -# 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" +# Uses avx2 or ifma only if compiled for an appropriate target. +export RUSTFLAGS="-C target_cpu=native" +cargo bench --no-default-features --features "std simd_backend" ``` Performance is a secondary goal behind correctness, safety, and @@ -191,7 +184,7 @@ The fast `u32` and `u64` scalar arithmetic was implemented by Andrew Moon, and the addition chain for scalar inversion was provided by Brian Smith. The optimised batch inversion was contributed by Sean Bowe and Daira Hopwood. -The `no_std` support was contributed by Tony Arcieri. +The `no_std` and `zeroize` support was contributed by Tony Arcieri. Thanks also to Ashley Hauck, Lucas Salibian, and Manish Goregaokar for their contributions. From 8e6b646e64ed73e35176faee51782a207b14db98 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 25 Oct 2019 15:59:19 -0700 Subject: [PATCH 3/5] Remove extern crate instructions. This is no longer required in Rust 2018, which is the default. --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 5035df2..2eb08c0 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,6 @@ your project's `Cargo.toml`: ```toml curve25519-dalek = "2" ``` -Then import the crate as: -```rust,no_run -extern crate curve25519_dalek; -``` # Backends and Features From 1bd18de291731ccc02e25b7925810599003f1ef9 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 25 Oct 2019 16:03:31 -0700 Subject: [PATCH 4/5] Add note on 2.x breaking changes. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 2eb08c0..df534c7 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,18 @@ your project's `Cargo.toml`: curve25519-dalek = "2" ``` +The `2.x` series has API almost entirely unchanged from the `1.x` series, +except that: + +* an error in the data modeling for the (optional) `serde` feature was + corrected, so that when the `2.x`-series `serde` implementation is used + with `serde-bincode`, the derived serialization matches the usual X/Ed25519 + formats; + +* the `rand` version was updated. + +See `CHANGELOG.md` for more details. + # Backends and Features The `nightly` feature enables features available only when using a Rust nightly From 6b71cd863ace5909972b9c66d9f92480e404db5c Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 25 Oct 2019 16:07:19 -0700 Subject: [PATCH 5/5] Update CHANGELOG and bump version --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59cd0a2..a2c2fbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Entries are listed in reverse chronological order. +## 2.0.0-alpha.1 + +* Update `README.md` for `2.x` series. +* Fix a `Zeroize`-related build issue in the AVX2 backend. + ## 2.0.0-alpha.0 * Fix a data modeling error in the `serde` feature pointed out by Trevor Perrin diff --git a/Cargo.toml b/Cargo.toml index 10c47a2..719a1e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "curve25519-dalek" -version = "2.0.0-alpha.0" +version = "2.0.0-alpha.1" authors = ["Isis Lovecruft ", "Henry de Valence "] readme = "README.md"