From c707ac75c77ffa3cabb15dddfa0c164025b52900 Mon Sep 17 00:00:00 2001 From: UneBaguette <28904802+UneBaguette@users.noreply.github.com> Date: Sat, 27 Jun 2026 16:20:21 +0200 Subject: [PATCH] chore: fix no-default-features test failures and doctest support, rename to voprf-vexahub - Add doctest feature with P256CipherSuite for doc examples - Remove CipherSuite bound from Group impl in elliptic_curve.rs - Update CI to use --lib --tests for no-default-features runs - Rename crate to voprf-vexahub --- .gitea/workflows/ci.yml | 6 +- Cargo.toml | 5 +- src/group/elliptic_curve.rs | 12 ++-- src/lib.rs | 116 ++++++++++++++++++++---------------- 4 files changed, 77 insertions(+), 62 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 79b042a..caf0ba4 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -53,11 +53,11 @@ jobs: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 - uses: dtolnay/rust-toolchain@${{ matrix.toolchain }} - name: Run cargo test - run: cargo test --no-default-features ${{ matrix.backend_feature }} + run: cargo test --no-default-features --lib --tests ${{ matrix.backend_feature }} - name: Run cargo test with alloc - run: cargo test --no-default-features ${{ matrix.frontend_feature }} ${{ matrix.backend_feature }} --features alloc + run: cargo test --no-default-features --lib --tests ${{ matrix.frontend_feature }} ${{ matrix.backend_feature }} --features alloc - name: Run cargo test with std - run: cargo test --no-default-features ${{ matrix.frontend_feature }} ${{ matrix.backend_feature }} --features std + run: cargo test --no-default-features --lib --tests ${{ matrix.frontend_feature }} ${{ matrix.backend_feature }} --features std - name: Run cargo test with all features run: cargo test --all-features diff --git a/Cargo.toml b/Cargo.toml index 41f6751..0e48c82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ description = "An implementation of a verifiable oblivious pseudorandom function edition = "2024" keywords = ["oprf"] license = "MIT" -name = "voprf" +name = "voprf-vexahub" readme = "README.md" repository = "https://github.com/facebook/voprf/" rust-version = "1.87" @@ -14,6 +14,7 @@ version = "0.6.0-rc.0" [features] alloc = [] danger = [] +doctest = ["dep:p256", "dep:sha2"] default = ["ristretto255-ciphersuite", "dep:serde"] ristretto255 = ["dep:curve25519-dalek"] ristretto255-ciphersuite = ["ristretto255", "dep:sha2"] @@ -35,6 +36,7 @@ serde = { version = "1", default-features = false, features = [ "derive", ], optional = true } sha2 = { version = "0.11", default-features = false, optional = true } +p256 = { version = "0.14.0-rc", default-features = false, features = ["hash2curve", "oprf"], optional = true } subtle = { version = "2.6", default-features = false } zeroize = { version = "1.5", default-features = false } @@ -62,3 +64,4 @@ sha2 = "0.11" all-features = true rustdoc-args = ["--cfg", "docsrs"] targets = [] +features = ["doctest"] diff --git a/src/group/elliptic_curve.rs b/src/group/elliptic_curve.rs index 1f04cdb..544e9af 100644 --- a/src/group/elliptic_curve.rs +++ b/src/group/elliptic_curve.rs @@ -16,20 +16,20 @@ use elliptic_curve::{ AffinePoint, Field, FieldBytes, FieldBytesSize, Group as _, ProjectivePoint, PublicKey, Scalar, SecretKey, }; -use hash2curve::{ExpandMsgXmd, GroupDigest, hash_to_scalar}; +use hash2curve::{ExpandMsgXmd, GroupDigest, hash_to_scalar, MapToCurve}; use hybrid_array::typenum::{IsGreaterOrEqual, Prod, Sum, True, U2}; use hybrid_array::{Array, ArraySize}; use rand_core::TryCryptoRng; use super::Group; -use crate::{CipherSuite, Error, InternalError, Result}; +use crate::{Error, InternalError, Result}; type ElemLen = as ModulusSize>::CompressedPointSize; type ScalarLen = FieldBytesSize; impl Group for C where - C: GroupDigest + CipherSuite + hash2curve::MapToCurve, + C: GroupDigest + MapToCurve, C::SecurityLevel: Mul, C::SecurityLevel: ArraySize, >::Output: ArraySize, @@ -38,7 +38,7 @@ where ScalarLen: ArraySize, ScalarLen: hybrid_array::typenum::NonZero, Scalar: elliptic_curve::ops::Reduce>>, - Scalar: elliptic_curve::ops::Reduce::Length>>, + Scalar: elliptic_curve::ops::Reduce::Length>>, AffinePoint: FromSec1Point + ToSec1Point, // `VoprfClientLen`, `PoprfClientLen`, `VoprfServerLen`, `PoprfServerLen` ScalarLen: Add>, @@ -58,7 +58,7 @@ where type SecurityLevel = C::SecurityLevel; - type OkmLen = ::Length; + type OkmLen = ::Length; // Implements the `hash_to_curve()` function from // https://www.rfc-editor.org/rfc/rfc9380.html#section-3 @@ -74,7 +74,7 @@ where C::SecurityLevel: Mul, H::OutputSize: IsGreaterOrEqual, Output = True>, { - hash_to_scalar::, ::Length>(input, dst) + hash_to_scalar::, ::Length>(input, dst) .map_err(|_| InternalError::Input) } diff --git a/src/lib.rs b/src/lib.rs index 6c19802..3ab7ca1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,7 @@ //! We will use the following choice in this example: //! //! ```ignore -//! type CipherSuite = voprf::Ristretto255; +//! type CipherSuite = voprf_vexahub::Ristretto255; //! ``` //! //! ## Modes of Operation @@ -51,12 +51,12 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; //! use rand::rngs::SysRng; //! use rand::Rng; -//! use voprf::OprfServer; +//! use voprf_vexahub::OprfServer; //! //! let mut server_rng = SysRng; //! let server = OprfServer::::new(&mut server_rng); @@ -71,12 +71,12 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; //! use rand::rngs::SysRng; //! use rand::Rng; -//! use voprf::OprfClient; +//! use voprf_vexahub::OprfClient; //! //! let mut client_rng = SysRng; //! let client_blind_result = OprfClient::::blind(b"input", &mut client_rng) @@ -92,10 +92,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::OprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::OprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -103,7 +103,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::OprfServer; +//! # use voprf_vexahub::OprfServer; //! # let mut server_rng = SysRng; //! # let server = OprfServer::::new(&mut server_rng).unwrap(); //! let server_evaluate_result = server.blind_evaluate(&client_blind_result.message); @@ -117,10 +117,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::OprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::OprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -128,7 +128,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::OprfServer; +//! # use voprf_vexahub::OprfServer; //! # let mut server_rng = SysRng; //! # let server = OprfServer::::new(&mut server_rng).unwrap(); //! # let message = server.blind_evaluate(&client_blind_result.message); @@ -150,10 +150,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::OprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::OprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -161,7 +161,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::OprfServer; +//! # use voprf_vexahub::OprfServer; //! # let mut server_rng = SysRng; //! # let server = OprfServer::::new(&mut server_rng).unwrap(); //! # let message = server.blind_evaluate(&client_blind_result.message); @@ -197,12 +197,12 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; //! use rand::rngs::SysRng; //! use rand::Rng; -//! use voprf::VoprfServer; +//! use voprf_vexahub::VoprfServer; //! //! let mut server_rng = SysRng; //! let server = VoprfServer::::new(&mut server_rng).unwrap(); @@ -224,12 +224,12 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; //! use rand::rngs::SysRng; //! use rand::Rng; -//! use voprf::VoprfClient; +//! use voprf_vexahub::VoprfClient; //! //! let mut client_rng = SysRng; //! let client_blind_result = VoprfClient::::blind(b"input", &mut client_rng) @@ -246,10 +246,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::{VoprfServerEvaluateResult, VoprfClient}; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::{VoprfServerEvaluateResult, VoprfClient}; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -257,7 +257,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! # let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! let VoprfServerEvaluateResult { message, proof } = @@ -273,10 +273,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::VoprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::VoprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -284,7 +284,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! # let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! # let server_evaluate_result = server.blind_evaluate( @@ -314,10 +314,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::VoprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::VoprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -325,7 +325,7 @@ //! # b"input", //! # &mut client_rng, //! # ).expect("Unable to construct client"); -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! # let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! # let server_evaluate_result = server.blind_evaluate( @@ -368,10 +368,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::VoprfClient; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::VoprfClient; //! # use rand::{rngs::SysRng, Rng}; //! # //! let mut client_rng = SysRng; @@ -392,10 +392,10 @@ //! //! ``` //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::{VoprfServerBatchEvaluateFinishResult, VoprfClient}; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::{VoprfServerBatchEvaluateFinishResult, VoprfClient}; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -409,7 +409,7 @@ //! # client_states.push(client_blind_result.state); //! # client_messages.push(client_blind_result.message); //! # } -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! let prepared_evaluation_elements = server.batch_blind_evaluate_prepare(client_messages.iter()); @@ -426,10 +426,10 @@ //! ``` //! # #[cfg(feature = "alloc")] { //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::{VoprfServerBatchEvaluateResult, VoprfClient}; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::{VoprfServerBatchEvaluateResult, VoprfClient}; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -443,7 +443,7 @@ //! # client_states.push(client_blind_result.state); //! # client_messages.push(client_blind_result.message); //! # } -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! let VoprfServerBatchEvaluateResult { messages, proof } = server @@ -460,10 +460,10 @@ //! ``` //! # #[cfg(feature = "alloc")] { //! # #[cfg(feature = "ristretto255")] -//! # type CipherSuite = voprf::Ristretto255; +//! # type CipherSuite = voprf_vexahub::Ristretto255; //! # #[cfg(not(feature = "ristretto255"))] -//! # type CipherSuite = p256::NistP256; -//! # use voprf::{VoprfServerBatchEvaluateResult, VoprfClient}; +//! # type CipherSuite = voprf_vexahub::P256CipherSuite; +//! # use voprf_vexahub::{VoprfServerBatchEvaluateResult, VoprfClient}; //! # use rand::{rngs::SysRng, Rng}; //! # //! # let mut client_rng = SysRng; @@ -477,7 +477,7 @@ //! # client_states.push(client_blind_result.state); //! # client_messages.push(client_blind_result.message); //! # } -//! # use voprf::VoprfServer; +//! # use voprf_vexahub::VoprfServer; //! # let mut server_rng = SysRng; //! # let server = VoprfServer::::new(&mut server_rng).unwrap(); //! # let VoprfServerBatchEvaluateResult { messages, proof } = server @@ -566,6 +566,18 @@ mod voprf; #[cfg(test)] mod tests; +#[cfg(feature = "doctest")] +#[derive(Debug)] +#[doc(hidden)] +pub struct P256CipherSuite; + +#[cfg(feature = "doctest")] +impl CipherSuite for P256CipherSuite { + const ID: &'static [u8] = b"P256-SHA256"; + type Group = p256::NistP256; + type Hash = sha2::Sha256; +} + // Exports pub use crate::ciphersuite::CipherSuite;