Introduce ristretto255 crate feature (#35)

This commit is contained in:
daxpedda
2021-12-23 01:50:48 -05:00
committed by GitHub
parent 140f9e063d
commit 6669a0c4e6
9 changed files with 194 additions and 154 deletions
+1 -2
View File
@@ -37,8 +37,7 @@ jobs:
backend_feature: backend_feature:
- ristretto255_u64 - ristretto255_u64
- ristretto255_u32 - ristretto255_u32
# skip doc tests - p256
- p256 --lib
- ristretto255_u64,p256 - ristretto255_u64,p256
frontend_feature: frontend_feature:
- -
+6 -5
View File
@@ -16,11 +16,12 @@ version = "0.3.0"
danger = [] danger = []
default = ["ristretto255_u64", "serde"] default = ["ristretto255_u64", "serde"]
p256 = ["num-bigint", "num-integer", "num-traits", "once_cell", "p256_"] p256 = ["num-bigint", "num-integer", "num-traits", "once_cell", "p256_"]
ristretto255_fiat_u32 = ["curve25519-dalek/fiat_u32_backend"] ristretto255 = []
ristretto255_fiat_u64 = ["curve25519-dalek/fiat_u64_backend"] ristretto255_fiat_u32 = ["curve25519-dalek/fiat_u32_backend", "ristretto255"]
ristretto255_simd = ["curve25519-dalek/simd_backend"] ristretto255_fiat_u64 = ["curve25519-dalek/fiat_u64_backend", "ristretto255"]
ristretto255_u32 = ["curve25519-dalek/u32_backend"] ristretto255_simd = ["curve25519-dalek/simd_backend", "ristretto255"]
ristretto255_u64 = ["curve25519-dalek/u64_backend"] ristretto255_u32 = ["curve25519-dalek/u32_backend", "ristretto255"]
ristretto255_u64 = ["curve25519-dalek/u64_backend", "ristretto255"]
std = [] std = []
[dependencies] [dependencies]
+3 -11
View File
@@ -7,20 +7,12 @@
//! Defines the Group trait to specify the underlying prime order group //! Defines the Group trait to specify the underlying prime order group
#[cfg(any( #[cfg(any(feature = "ristretto255", feature = "p256",))]
feature = "ristretto255_u64",
feature = "ristretto255_u32",
feature = "ristretto255_fiat_u64",
feature = "ristretto255_fiat_u32",
feature = "ristretto255_simd",
feature = "p256",
))]
mod expand; mod expand;
#[cfg(feature = "p256")] #[cfg(feature = "p256")]
mod p256; mod p256;
cfg_ristretto! { #[cfg(feature = "ristretto255")]
mod ristretto; mod ristretto;
}
use core::ops::{Add, Mul, Sub}; use core::ops::{Add, Mul, Sub};
+98 -102
View File
@@ -5,127 +5,123 @@
// License, Version 2.0 found in the LICENSE-APACHE file in the root directory // License, Version 2.0 found in the LICENSE-APACHE file in the root directory
// of this source tree. // of this source tree.
use super::Group;
use crate::errors::InternalError;
use core::convert::TryInto; use core::convert::TryInto;
use core::ops::Add; use core::ops::Add;
use curve25519_dalek::{
constants::RISTRETTO_BASEPOINT_POINT, use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT;
ristretto::{CompressedRistretto, RistrettoPoint}, use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint};
scalar::Scalar, use curve25519_dalek::scalar::Scalar;
traits::Identity, use curve25519_dalek::traits::Identity;
};
use digest::{BlockInput, Digest}; use digest::{BlockInput, Digest};
use generic_array::{ use generic_array::typenum::{U1, U32, U64};
typenum::{U1, U32, U64}, use generic_array::{ArrayLength, GenericArray};
ArrayLength, GenericArray,
};
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
// `cfg` here is only needed because of a bug in Rust's crate feature documentation. See: use super::Group;
// https://github.com/rust-lang/rust/issues/83428 use crate::errors::InternalError;
cfg_ristretto! {
/// The implementation of such a subgroup for Ristretto
impl Group for RistrettoPoint {
const SUITE_ID: usize = 0x0001;
// Implements the `hash_to_ristretto255()` function from // `cfg` here is only needed because of a bug in Rust's crate feature documentation. See: https://github.com/rust-lang/rust/issues/83428
// https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-10.txt #[cfg(feature = "ristretto255")]
fn hash_to_curve<H: BlockInput + Digest, D: ArrayLength<u8> + Add<U1>>( /// The implementation of such a subgroup for Ristretto
msg: &[u8], impl Group for RistrettoPoint {
dst: GenericArray<u8, D>, const SUITE_ID: usize = 0x0001;
) -> Result<Self, InternalError>
where
<D as Add<U1>>::Output: ArrayLength<u8>,
{
let uniform_bytes = super::expand::expand_message_xmd::<H, U64, _, _>(Some(msg), dst)?;
Ok(RistrettoPoint::from_uniform_bytes( // Implements the `hash_to_ristretto255()` function from
uniform_bytes // https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-10.txt
.as_slice() fn hash_to_curve<H: BlockInput + Digest, D: ArrayLength<u8> + Add<U1>>(
.try_into() msg: &[u8],
.map_err(|_| InternalError::HashToCurveError)?, dst: GenericArray<u8, D>,
)) ) -> Result<Self, InternalError>
} where
<D as Add<U1>>::Output: ArrayLength<u8>,
{
let uniform_bytes = super::expand::expand_message_xmd::<H, U64, _, _>(Some(msg), dst)?;
// Implements the `HashToScalar()` function from Ok(RistrettoPoint::from_uniform_bytes(
// https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-07.html#section-4.1 uniform_bytes
fn hash_to_scalar< .as_slice()
'a, .try_into()
H: BlockInput + Digest, .map_err(|_| InternalError::HashToCurveError)?,
D: ArrayLength<u8> + Add<U1>, ))
I: IntoIterator<Item = &'a [u8]>, }
>(
input: I,
dst: GenericArray<u8, D>,
) -> Result<Self::Scalar, InternalError>
where
<D as Add<U1>>::Output: ArrayLength<u8>,
{
let uniform_bytes = super::expand::expand_message_xmd::<H, U64, _, _>(input, dst)?;
Ok(Scalar::from_bytes_mod_order_wide( // Implements the `HashToScalar()` function from
uniform_bytes // https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-07.html#section-4.1
.as_slice() fn hash_to_scalar<
.try_into() 'a,
.map_err(|_| InternalError::HashToCurveError)?, H: BlockInput + Digest,
)) D: ArrayLength<u8> + Add<U1>,
} I: IntoIterator<Item = &'a [u8]>,
>(
input: I,
dst: GenericArray<u8, D>,
) -> Result<Self::Scalar, InternalError>
where
<D as Add<U1>>::Output: ArrayLength<u8>,
{
let uniform_bytes = super::expand::expand_message_xmd::<H, U64, _, _>(input, dst)?;
type Scalar = Scalar; Ok(Scalar::from_bytes_mod_order_wide(
type ScalarLen = U32; uniform_bytes
fn from_scalar_slice_unchecked( .as_slice()
scalar_bits: &GenericArray<u8, Self::ScalarLen>, .try_into()
) -> Result<Self::Scalar, InternalError> { .map_err(|_| InternalError::HashToCurveError)?,
Ok(Scalar::from_bytes_mod_order(*scalar_bits.as_ref())) ))
} }
fn random_nonzero_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar { type Scalar = Scalar;
loop { type ScalarLen = U32;
let scalar = { fn from_scalar_slice_unchecked(
let mut scalar_bytes = [0u8; 64]; scalar_bits: &GenericArray<u8, Self::ScalarLen>,
rng.fill_bytes(&mut scalar_bytes); ) -> Result<Self::Scalar, InternalError> {
Scalar::from_bytes_mod_order_wide(&scalar_bytes) Ok(Scalar::from_bytes_mod_order(*scalar_bits.as_ref()))
}; }
if scalar != Scalar::zero() { fn random_nonzero_scalar<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Scalar {
break scalar; loop {
} let scalar = {
let mut scalar_bytes = [0u8; 64];
rng.fill_bytes(&mut scalar_bytes);
Scalar::from_bytes_mod_order_wide(&scalar_bytes)
};
if scalar != Scalar::zero() {
break scalar;
} }
} }
}
fn scalar_as_bytes(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> { fn scalar_as_bytes(scalar: Self::Scalar) -> GenericArray<u8, Self::ScalarLen> {
scalar.to_bytes().into() scalar.to_bytes().into()
} }
fn scalar_invert(scalar: &Self::Scalar) -> Self::Scalar { fn scalar_invert(scalar: &Self::Scalar) -> Self::Scalar {
scalar.invert() scalar.invert()
} }
// The byte length necessary to represent group elements // The byte length necessary to represent group elements
type ElemLen = U32; type ElemLen = U32;
fn from_element_slice_unchecked( fn from_element_slice_unchecked(
element_bits: &GenericArray<u8, Self::ElemLen>, element_bits: &GenericArray<u8, Self::ElemLen>,
) -> Result<Self, InternalError> { ) -> Result<Self, InternalError> {
CompressedRistretto::from_slice(element_bits) CompressedRistretto::from_slice(element_bits)
.decompress() .decompress()
.ok_or(InternalError::PointError) .ok_or(InternalError::PointError)
} }
// serialization of a group element // serialization of a group element
fn to_arr(&self) -> GenericArray<u8, Self::ElemLen> { fn to_arr(&self) -> GenericArray<u8, Self::ElemLen> {
self.compress().to_bytes().into() self.compress().to_bytes().into()
} }
fn base_point() -> Self { fn base_point() -> Self {
RISTRETTO_BASEPOINT_POINT RISTRETTO_BASEPOINT_POINT
} }
fn identity() -> Self { fn identity() -> Self {
<Self as Identity>::identity() <Self as Identity>::identity()
} }
fn scalar_zero() -> Self::Scalar { fn scalar_zero() -> Self::Scalar {
Self::Scalar::zero() Self::Scalar::zero()
}
} }
} }
+3 -2
View File
@@ -15,12 +15,13 @@ use crate::group::Group;
#[test] #[test]
fn test_group_properties() -> Result<(), InternalError> { fn test_group_properties() -> Result<(), InternalError> {
cfg_ristretto! { { #[cfg(feature = "ristretto255")]
{
use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::ristretto::RistrettoPoint;
test_identity_element_error::<RistrettoPoint>()?; test_identity_element_error::<RistrettoPoint>()?;
test_zero_scalar_error::<RistrettoPoint>()?; test_zero_scalar_error::<RistrettoPoint>()?;
} } }
#[cfg(feature = "p256")] #[cfg(feature = "p256")]
{ {
+70 -2
View File
@@ -23,7 +23,7 @@
//! //!
//! We will use the following choices in this example: //! We will use the following choices in this example:
//! //!
//! ``` //! ```ignore
//! type Group = curve25519_dalek::ristretto::RistrettoPoint; //! type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! type Hash = sha2::Sha512; //! type Hash = sha2::Sha512;
//! ``` //! ```
@@ -51,8 +51,14 @@
//! must be persisted on the server and used for online client evaluations. //! must be persisted on the server and used for online client evaluations.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! use rand::rngs::OsRng; //! use rand::rngs::OsRng;
//! use rand::RngCore; //! use rand::RngCore;
//! use voprf::NonVerifiableServer; //! use voprf::NonVerifiableServer;
@@ -71,8 +77,14 @@
//! step of the VOPRF protocol. //! step of the VOPRF protocol.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! use rand::rngs::OsRng; //! use rand::rngs::OsRng;
//! use rand::RngCore; //! use rand::RngCore;
//! use voprf::NonVerifiableClient; //! use voprf::NonVerifiableClient;
@@ -92,8 +104,14 @@
//! [EvaluationElement] to be sent to the client. //! [EvaluationElement] to be sent to the client.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::NonVerifiableClient; //! # use voprf::NonVerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -118,8 +136,14 @@
//! [NonVerifiableClient::finalize] to produce an output for the protocol. //! [NonVerifiableClient::finalize] to produce an output for the protocol.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::NonVerifiableClient; //! # use voprf::NonVerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -163,8 +187,14 @@
//! must be persisted on the server and used for online client evaluations. //! must be persisted on the server and used for online client evaluations.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! use rand::rngs::OsRng; //! use rand::rngs::OsRng;
//! use rand::RngCore; //! use rand::RngCore;
//! use voprf::VerifiableServer; //! use voprf::VerifiableServer;
@@ -190,8 +220,14 @@
//! of the VOPRF protocol. //! of the VOPRF protocol.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! use rand::rngs::OsRng; //! use rand::rngs::OsRng;
//! use rand::RngCore; //! use rand::RngCore;
//! use voprf::VerifiableClient; //! use voprf::VerifiableClient;
@@ -211,8 +247,14 @@
//! a proof. //! a proof.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::VerifiableClient; //! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -238,8 +280,14 @@
//! output for the protocol. //! output for the protocol.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::VerifiableClient; //! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -288,8 +336,14 @@
//! messages: //! messages:
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::VerifiableClient; //! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -311,8 +365,14 @@
//! proof: //! proof:
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::VerifiableClient; //! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -342,8 +402,14 @@
//! outputs if the proof verifies correctly. //! outputs if the proof verifies correctly.
//! //!
//! ``` //! ```
//! # #[cfg(feature = "ristretto255")]
//! # type Group = curve25519_dalek::ristretto::RistrettoPoint; //! # type Group = curve25519_dalek::ristretto::RistrettoPoint;
//! # #[cfg(feature = "ristretto255")]
//! # type Hash = sha2::Sha512; //! # type Hash = sha2::Sha512;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Group = p256_::ProjectivePoint;
//! # #[cfg(all(feature = "p256", not(feature = "ristretto255")))]
//! # type Hash = sha2::Sha256;
//! # use voprf::VerifiableClient; //! # use voprf::VerifiableClient;
//! # use rand::{rngs::OsRng, RngCore}; //! # use rand::{rngs::OsRng, RngCore};
//! # //! #
@@ -411,7 +477,9 @@
//! and allow for selecting the corresponding backend for the curve arithmetic //! and allow for selecting the corresponding backend for the curve arithmetic
//! used. The `ristretto255_u64` feature is included as the default. Other //! used. The `ristretto255_u64` feature is included as the default. Other
//! features are mapped as `ristretto255_u32`, `ristretto255_fiat_u64` and //! features are mapped as `ristretto255_u32`, `ristretto255_fiat_u64` and
//! `ristretto255_fiat_u32`. //! `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.
//! //!
//! - The `ristretto255_simd` feature is re-exported from [curve25519-dalek](https://doc.dalek.rs/curve25519_dalek/index.html#backends-and-features) //! - 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 //! and enables parallel formulas, using either AVX2 or AVX512-IFMA. This will
+3 -2
View File
@@ -87,7 +87,8 @@ fn test_vectors() -> Result<(), InternalError> {
let rfc = json::parse(rfc_to_json(super::voprf_vectors::VECTORS).as_str()) let rfc = json::parse(rfc_to_json(super::voprf_vectors::VECTORS).as_str())
.expect("Could not parse json"); .expect("Could not parse json");
cfg_ristretto! { { #[cfg(feature = "ristretto255")]
{
use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::ristretto::RistrettoPoint;
use sha2::Sha512; use sha2::Sha512;
@@ -112,7 +113,7 @@ fn test_vectors() -> Result<(), InternalError> {
test_verifiable_blind::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?; test_verifiable_blind::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?;
test_verifiable_evaluate::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?; test_verifiable_evaluate::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?;
test_verifiable_finalize::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?; test_verifiable_finalize::<RistrettoPoint, Sha512>(&ristretto_verifiable_tvs)?;
} } }
#[cfg(feature = "p256")] #[cfg(feature = "p256")]
{ {
+7 -26
View File
@@ -121,29 +121,6 @@ macro_rules! chain {
}; };
} }
macro_rules! cfg_ristretto {
($tree:tt) => {
#[cfg(any(
feature = "ristretto255_u64",
feature = "ristretto255_u32",
feature = "ristretto255_fiat_u64",
feature = "ristretto255_fiat_u32",
feature = "ristretto255_simd",
))]
$tree
};
($($item:item)+) => {
$(#[cfg(any(
feature = "ristretto255_u64",
feature = "ristretto255_u32",
feature = "ristretto255_fiat_u64",
feature = "ristretto255_fiat_u32",
feature = "ristretto255_simd",
))]
$item)+
};
}
#[cfg(test)] #[cfg(test)]
mod unit_tests { mod unit_tests {
use generic_array::typenum::{U1, U2}; use generic_array::typenum::{U1, U2};
@@ -172,9 +149,13 @@ mod unit_tests {
macro_rules! test_deserialize { macro_rules! test_deserialize {
($item:ident, $bytes:ident) => { ($item:ident, $bytes:ident) => {
cfg_ristretto! { { #[cfg(feature = "ristretto255")]
let _ = $item::<curve25519_dalek::ristretto::RistrettoPoint, sha2::Sha512>::deserialize(&$bytes[..]); {
} } let _ =
$item::<curve25519_dalek::ristretto::RistrettoPoint, sha2::Sha512>::deserialize(
&$bytes[..],
);
}
#[cfg(feature = "p256")] #[cfg(feature = "p256")]
{ {
let _ = $item::<p256_::ProjectivePoint, sha2::Sha256>::deserialize(&$bytes[..]); let _ = $item::<p256_::ProjectivePoint, sha2::Sha256>::deserialize(&$bytes[..]);
+3 -2
View File
@@ -1196,7 +1196,8 @@ mod tests {
#[test] #[test]
fn test_functionality() -> Result<(), InternalError> { fn test_functionality() -> Result<(), InternalError> {
cfg_ristretto! { { #[cfg(feature = "ristretto255")]
{
use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::ristretto::RistrettoPoint;
use sha2::Sha512; use sha2::Sha512;
@@ -1211,7 +1212,7 @@ mod tests {
zeroize_base_server::<RistrettoPoint, Sha512>(); zeroize_base_server::<RistrettoPoint, Sha512>();
zeroize_verifiable_client::<RistrettoPoint, Sha512>(); zeroize_verifiable_client::<RistrettoPoint, Sha512>();
zeroize_verifiable_server::<RistrettoPoint, Sha512>(); zeroize_verifiable_server::<RistrettoPoint, Sha512>();
} } }
#[cfg(feature = "p256")] #[cfg(feature = "p256")]
{ {