Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix simd_backend + --no-default-features #433

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn impl_sum() {
// Test that sum works for non-empty iterators
let BASE = constants::ED25519_BASEPOINT_POINT;
Expand Down Expand Up @@ -1487,6 +1488,7 @@ mod test {
}

// A single iteration of a consistency check for MSM.
#[cfg(feature = "alloc")]
fn multiscalar_consistency_iter(n: usize) {
use core::iter;
let mut rng = rand::thread_rng();
Expand Down Expand Up @@ -1521,6 +1523,7 @@ mod test {
// parameters.

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_consistency_n_100() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -1529,6 +1532,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_consistency_n_250() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -1537,6 +1541,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_consistency_n_500() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -1545,6 +1550,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_consistency_n_1000() {
let iters = 50;
for _ in 0..iters {
Expand All @@ -1553,6 +1559,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::thread_rng();

Expand Down Expand Up @@ -1609,6 +1616,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_mul_vs_ed25519py() {
let A = A_TIMES_BASEPOINT.decompress().unwrap();
let result = EdwardsPoint::vartime_multiscalar_mul(
Expand All @@ -1619,6 +1627,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn multiscalar_mul_vartime_vs_consttime() {
let A = A_TIMES_BASEPOINT.decompress().unwrap();
let result_vartime = EdwardsPoint::vartime_multiscalar_mul(
Expand Down Expand Up @@ -1663,6 +1672,7 @@ mod test {
// https://github.com/signalapp/libsignal-protocol-c/ //
////////////////////////////////////////////////////////////

#[cfg(feature = "alloc")]
fn test_vectors() -> Vec<Vec<&'static str>> {
vec![
vec![
Expand Down Expand Up @@ -1709,6 +1719,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn elligator_signal_test_vectors() {
for vector in test_vectors().iter() {
let input = hex::decode(vector[0]).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn batch_invert_a_matches_nonbatched() {
let a = FieldElement::from_bytes(&A_BYTES);
let ap58 = FieldElement::from_bytes(&AP58_BYTES);
Expand Down Expand Up @@ -495,6 +496,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn batch_invert_empty() {
FieldElement::batch_invert(&mut []);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
// External dependencies:
//------------------------------------------------------------------------

#[cfg(all(feature = "alloc", not(feature = "std")))]
#[cfg(feature = "alloc")]
rozbb marked this conversation as resolved.
Show resolved Hide resolved
#[allow(unused_imports)]
#[macro_use]
extern crate alloc;

Expand Down
4 changes: 2 additions & 2 deletions src/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ mod test {
];

#[test]
#[cfg(feature = "std")] // Vec
#[cfg(feature = "alloc")] // Vec
fn montgomery_elligator_correct() {
let bytes: std::vec::Vec<u8> = (0u8..32u8).collect();
let bytes: alloc::vec::Vec<u8> = (0u8..32u8).collect();
let bits_in: [u8; 32] = (&bytes[..]).try_into().expect("Range invariant broken");

let fe = FieldElement::from_bytes(&bits_in);
Expand Down
3 changes: 3 additions & 0 deletions src/ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn impl_sum() {
// Test that sum works for non-empty iterators
let BASE = constants::RISTRETTO_BASEPOINT_POINT;
Expand Down Expand Up @@ -1500,6 +1501,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn double_and_compress_1024_random_points() {
let mut rng = OsRng;

Expand All @@ -1516,6 +1518,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn vartime_precomputed_vs_nonprecomputed_multiscalar() {
let mut rng = rand::thread_rng();

Expand Down
7 changes: 6 additions & 1 deletion src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ mod test {

#[allow(non_snake_case)]
#[test]
#[cfg(feature = "alloc")]
fn impl_product() {
// Test that product works for non-empty iterators
let X_Y_vector = vec![X, Y];
Expand Down Expand Up @@ -1538,6 +1539,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn impl_sum() {
// Test that sum works for non-empty iterators
let two = Scalar::from(2u64);
Expand Down Expand Up @@ -1705,7 +1707,7 @@ mod test {
assert_eq!(X, bincode::deserialize(X.as_bytes()).unwrap(),);
}

#[cfg(debug_assertions)]
#[cfg(all(debug_assertions, feature = "alloc"))]
#[test]
#[should_panic]
fn batch_invert_with_a_zero_input_panics() {
Expand All @@ -1716,11 +1718,13 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn batch_invert_empty() {
assert_eq!(Scalar::one(), Scalar::batch_invert(&mut []));
}

#[test]
#[cfg(feature = "alloc")]
fn batch_invert_consistency() {
let mut x = Scalar::from(1u64);
let mut v1: Vec<_> = (0..16)
Expand Down Expand Up @@ -1783,6 +1787,7 @@ mod test {
}

#[test]
#[cfg(feature = "alloc")]
fn test_read_le_u64_into() {
let cases: &[(&[u8], &[u64])] = &[
(
Expand Down
9 changes: 9 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub trait MultiscalarMul {
/// iterators returning either `Scalar`s or `&Scalar`s.
///
/// ```
/// # #[cfg(feature = "alloc")]
/// # {
/// use curve25519_dalek::constants;
/// use curve25519_dalek::traits::MultiscalarMul;
/// use curve25519_dalek::ristretto::RistrettoPoint;
Expand All @@ -110,6 +112,7 @@ pub trait MultiscalarMul {
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
///
/// assert_eq!(A1.compress(), (-A2).compress());
/// # }
/// ```
fn multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Point
where
Expand All @@ -136,6 +139,8 @@ pub trait VartimeMultiscalarMul {
/// inlining point decompression into the multiscalar call,
/// avoiding the need for temporary buffers.
/// ```
/// #[cfg(feature = "alloc")]
/// # {
/// use curve25519_dalek::constants;
/// use curve25519_dalek::traits::VartimeMultiscalarMul;
/// use curve25519_dalek::ristretto::RistrettoPoint;
Expand Down Expand Up @@ -175,6 +180,7 @@ pub trait VartimeMultiscalarMul {
/// );
///
/// assert_eq!(A3, Some(A1+A1));
/// # }
/// ```
fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<Self::Point>
where
Expand All @@ -199,6 +205,8 @@ pub trait VartimeMultiscalarMul {
/// iterators returning either `Scalar`s or `&Scalar`s.
///
/// ```
/// #[cfg(feature = "alloc")]
/// # {
/// use curve25519_dalek::constants;
/// use curve25519_dalek::traits::VartimeMultiscalarMul;
/// use curve25519_dalek::ristretto::RistrettoPoint;
Expand All @@ -225,6 +233,7 @@ pub trait VartimeMultiscalarMul {
/// // Note: minus_abc.into_iter(): Iterator<Item=Scalar>
///
/// assert_eq!(A1.compress(), (-A2).compress());
/// # }
/// ```
fn vartime_multiscalar_mul<I, J>(scalars: I, points: J) -> Self::Point
where
Expand Down