diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bfed51b..a310585 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,13 +13,10 @@ jobs: fail-fast: false matrix: backend_feature: - - --features ristretto255-u64,ristretto255-voprf - - --features ristretto255-u32,ristretto255-voprf + - --features ristretto255-voprf - - - --features curve25519-u64,ristretto255-u64,ristretto255-voprf - - --features curve25519-u32,ristretto255-u32,ristretto255-voprf - - --features curve25519-u64 - - --features curve25519-u32 + - --features curve25519,ristretto255-voprf + - --features curve25519 frontend_feature: - - --features argon2 @@ -61,13 +58,10 @@ jobs: # 32-bit x86 - i686-unknown-linux-gnu backend_feature: - - --features ristretto255-u64,ristretto255-voprf - - --features ristretto255-u32,ristretto255-voprf + - --features ristretto255-voprf - - - curve25519-u64,ristretto255-u64,ristretto255-voprf - - curve25519-u32,ristretto255-u64,ristretto255-voprf - - curve25519-u64 - - curve25519-u32 + - curve25519,ristretto255-voprf + - curve25519 steps: - uses: actions/checkout@v3 - uses: hecrj/setup-rust-action@v1 @@ -135,13 +129,10 @@ jobs: # for any no_std target - thumbv6m-none-eabi backend_feature: - - ristretto255-u64,ristretto255-voprf - - ristretto255-u32,ristretto255-voprf + - ristretto255-voprf - - - curve25519-u64,ristretto255-u64,ristretto255-voprf - - curve25519-u32,ristretto255-u32,ristretto255-voprf - - curve25519-u64 - - curve25519-u32 + - curve25519,ristretto255-voprf + - curve25519 frontend_feature: - argon2 - serde @@ -158,13 +149,10 @@ jobs: fail-fast: false matrix: backend_feature: - - --features ristretto255-u64,ristretto255-voprf - - --features ristretto255-u32,ristretto255-voprf + - --features ristretto255-voprf - - - --features curve25519-u64,ristretto255-u64,ristretto255-voprf - - --features curve25519-u32,ristretto255-u32,ristretto255-voprf - - --features curve25519-u32 - - --features curve25519-u32 + - --features curve25519,ristretto255-voprf + - --features curve25519 steps: - name: Checkout sources uses: actions/checkout@v3 @@ -201,7 +189,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets --features argon2,std,curve25519-u64 -- -D warnings + args: --all-targets --features argon2,std,curve25519 -- -D warnings - name: Run cargo doc uses: actions-rs/cargo@v1 @@ -209,7 +197,7 @@ jobs: RUSTDOCFLAGS: -D warnings with: command: doc - args: --no-deps --document-private-items --features argon2,std,curve25519-u64 + args: --no-deps --document-private-items --features argon2,std,curve25519 format: name: cargo fmt diff --git a/Cargo.toml b/Cargo.toml index 56c1b9c..94e7dae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,8 @@ version = "2.0.0" [features] curve25519 = ["curve25519-dalek"] -curve25519-fiat-u32 = ["curve25519-dalek/fiat_u32_backend", "curve25519"] -curve25519-fiat-u64 = ["curve25519-dalek/fiat_u64_backend", "curve25519"] -curve25519-u32 = ["curve25519-dalek/u32_backend", "curve25519"] -curve25519-u64 = ["curve25519-dalek/u64_backend", "curve25519"] -curve255195519-simd = ["curve25519-dalek/simd_backend", "curve25519"] -default = ["ristretto255-u64", "ristretto255-voprf", "serde"] +default = ["ristretto255-voprf", "serde"] ristretto255 = ["curve25519-dalek", "voprf/ristretto255"] -ristretto255-fiat-u32 = ["curve25519-dalek/fiat_u32_backend", "ristretto255"] -ristretto255-fiat-u64 = ["curve25519-dalek/fiat_u64_backend", "ristretto255"] -ristretto255-simd = ["curve25519-dalek/simd_backend", "ristretto255"] -ristretto255-u32 = ["curve25519-dalek/u32_backend", "ristretto255"] -ristretto255-u64 = ["curve25519-dalek/u64_backend", "ristretto255"] ristretto255-voprf = ["ristretto255", "voprf/ristretto255-ciphersuite"] serde = ["serde_", "generic-array/serde", "voprf/serde"] std = ["getrandom"] @@ -33,7 +23,9 @@ std = ["getrandom"] argon2 = { version = "0.4", default-features = false, features = [ "alloc", ], optional = true } -curve25519-dalek = { version = "=4.0.0-pre.1", default-features = false, optional = true } +curve25519-dalek = { version = "=4.0.0-pre.5", default-features = false, features = [ + "rand_core", +], optional = true } derive-where = { version = "1", features = ["zeroize-on-drop"] } digest = "0.10" displaydoc = { version = "0.2", default-features = false } @@ -46,7 +38,9 @@ serde_ = { version = "1", package = "serde", default-features = false, features "derive", ], optional = true } subtle = { version = "2.3", default-features = false } -voprf = { version = "0.4", default-features = false, features = ["danger"] } +voprf = { version = "=0.5.0-pre.1", default-features = false, features = [ + "danger", +] } zeroize = { version = "1.5", features = ["zeroize_derive"] } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -74,7 +68,8 @@ harness = false name = "opaque" [package.metadata.docs.rs] -features = ["argon2", "std", "curve25519-u64"] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] targets = [] [[example]] diff --git a/benches/opaque.rs b/benches/opaque.rs index 15fd4d4..d18afbc 100644 --- a/benches/opaque.rs +++ b/benches/opaque.rs @@ -12,14 +12,8 @@ use criterion::Criterion; use opaque_ke::*; use rand::rngs::OsRng; -#[cfg(feature = "ristretto255-u64")] -static SUFFIX: &str = "ristretto255-u64"; -#[cfg(feature = "ristretto255-u32")] -static SUFFIX: &str = "ristretto255-u32"; -#[cfg(feature = "ristretto255-fiat-u64")] -static SUFFIX: &str = "ristretto255-fiat-u64"; -#[cfg(feature = "ristretto255-fiat-u32")] -static SUFFIX: &str = "ristretto255-fiat-u32"; +#[cfg(feature = "ristretto255")] +static SUFFIX: &str = "ristretto255"; #[cfg(all(not(feature = "ristretto255")))] static SUFFIX: &str = "p256"; diff --git a/src/key_exchange/group/curve25519.rs b/src/key_exchange/group/curve25519.rs index 8719989..17de8da 100644 --- a/src/key_exchange/group/curve25519.rs +++ b/src/key_exchange/group/curve25519.rs @@ -49,7 +49,7 @@ impl KeGroup for Curve25519 { loop { let scalar = Scalar::random(rng); - if scalar != Scalar::zero() { + if scalar != Scalar::ZERO { break scalar; } } @@ -69,7 +69,7 @@ impl KeGroup for Curve25519 { let scalar = Scalar::from_bytes_mod_order_wide(&uniform_bytes.into()); - if scalar == Scalar::zero() { + if scalar == Scalar::ZERO { Err(InternalError::HashToScalar) } else { Ok(scalar) @@ -77,7 +77,7 @@ impl KeGroup for Curve25519 { } fn is_zero_scalar(scalar: Self::Sk) -> subtle::Choice { - scalar.ct_eq(&Scalar::zero()) + scalar.ct_eq(&Scalar::ZERO) } fn public_key(sk: Self::Sk) -> Self::Pk { @@ -96,8 +96,8 @@ impl KeGroup for Curve25519 { bytes .try_into() .ok() - .and_then(Scalar::from_canonical_bytes) - .filter(|scalar| scalar != &Scalar::zero()) + .and_then(|bytes| Scalar::from_canonical_bytes(bytes).into()) + .filter(|scalar| scalar != &Scalar::ZERO) .ok_or(InternalError::PointError) } } diff --git a/src/key_exchange/group/ristretto255.rs b/src/key_exchange/group/ristretto255.rs index e9665ad..f1aa98a 100644 --- a/src/key_exchange/group/ristretto255.rs +++ b/src/key_exchange/group/ristretto255.rs @@ -66,7 +66,7 @@ impl KeGroup for Ristretto255 { } }; - if scalar != Scalar::zero() { + if scalar != Scalar::ZERO { break scalar; } } @@ -84,7 +84,7 @@ impl KeGroup for Ristretto255 { } fn is_zero_scalar(scalar: Self::Sk) -> subtle::Choice { - scalar.ct_eq(&Scalar::zero()) + scalar.ct_eq(&Scalar::ZERO) } fn public_key(sk: Self::Sk) -> Self::Pk { @@ -103,8 +103,8 @@ impl KeGroup for Ristretto255 { bytes .try_into() .ok() - .and_then(Scalar::from_canonical_bytes) - .filter(|scalar| scalar != &Scalar::zero()) + .and_then(|bytes| Scalar::from_canonical_bytes(bytes).into()) + .filter(|scalar| scalar != &Scalar::ZERO) .ok_or(InternalError::PointError) } } diff --git a/src/lib.rs b/src/lib.rs index 80d1f3a..9738237 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1097,23 +1097,12 @@ //! //! - The `serde` feature, enabled by default, provides convenience functions for serializing and deserializing with [serde](https://serde.rs/). //! -//! - The backend features are re-exported from [curve25519-dalek](https://doc.dalek.rs/curve25519_dalek/index.html#backends-and-features) -//! and allow for selecting the corresponding backend for the curve arithmetic -//! used. The `ristretto255-u64` feature is included as the default. Other -//! features are mapped as `ristretto255-u32`, `ristretto255-fiat-u64` and -//! `ristretto255-fiat-u32`. Any `ristretto255-*` backend feature will enable -//! the `ristretto255` feature, which can be used too, but keep in mind that -//! `curve25519-dalek` will fail to compile without a selected backend. This -//! enables the use of [`Ristretto255`] as a `KeGroup` and `OprfCs`. +//! - The `ristretto255` feature enables using [`Ristretto255`] as a `KeGroup` +//! and `OprfCs`. To select a specific backend see the [curve25519-dalek] +//! documentation. //! -//! - The `curve25519` feature is similar to the `ristretto255` feature and -//! requires to select a backend like `curve25519-u64`, other backends are the -//! same as in `ristretto255-*`. This enables [`Curve25519`] as a `KeGroup`. -//! -//! - The `ristretto255-simd` feature is re-exported from [curve25519-dalek](https://doc.dalek.rs/curve25519_dalek/index.html#backends-and-features) -//! and enables parallel formulas, using either AVX2 or AVX512-IFMA. This will -//! automatically enable the `ristretto255-u64` feature and requires Rust -//! nightly. +//! - The `curve25519` feature enables [`Curve25519`] as a `KeGroup`. To select +//! a specific backend see the [curve25519-dalek] documentation. //! //! - The `p256` feature enables the use of [`p256::NistP256`] as a `KeGroup` //! and a `OprfCs` for `CipherSuite`. @@ -1121,10 +1110,13 @@ //! - The `bench` feature is used only for running performance benchmarks for //! this implementation. //! +//! [curve25519-dalek]: +//! (https://docs.rs/curve25519-dalek/4.0.0-pre.5/curve25519_dalek/index.html#backends) //! [`p256::NistP256`]: https://docs.rs/p256/latest/p256/struct.NistP256.html -#![cfg_attr(not(test), deny(unsafe_code))] #![no_std] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(not(test), deny(unsafe_code))] #![warn(clippy::cargo, missing_docs)] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![allow(type_alias_bounds)] diff --git a/src/tests/full_test.rs b/src/tests/full_test.rs index 363cd55..dfe6cf1 100644 --- a/src/tests/full_test.rs +++ b/src/tests/full_test.rs @@ -122,7 +122,7 @@ static STR_PASSWORD: &str = "password"; static STR_CREDENTIAL_IDENTIFIER: &str = "credential_identifier"; // To regenerate these test vectors, run: -// cargo test --features curve25519-u64 -- --nocapture generate_test_vectors +// cargo test --features curve25519 -- --nocapture generate_test_vectors #[cfg(feature = "ristretto255")] static TEST_VECTOR_RISTRETTO255: &str = r#" {