From 5ab061c93e737711a13afc1f1233ad1f9d823701 Mon Sep 17 00:00:00 2001 From: pinkforest <36498018+pinkforest@users.noreply.github.com> Date: Tue, 13 Dec 2022 11:54:55 +1100 Subject: [PATCH 1/2] Make batch_deterministic win --- src/batch.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/batch.rs b/src/batch.rs index 63bb895..4a3727c 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -24,10 +24,10 @@ pub use curve25519_dalek::digest::Digest; use merlin::Transcript; -#[cfg(all(feature = "batch", not(feature = "batch_deterministic")))] +#[cfg(not(feature = "batch_deterministic"))] use rand::thread_rng; use rand::Rng; -#[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] +#[cfg(feature = "batch_deterministic")] use rand_core; use sha2::Sha512; @@ -75,10 +75,10 @@ impl BatchTranscript for Transcript { /// An implementation of `rand_core::RngCore` which does nothing, to provide /// purely deterministic transcript-based nonces, rather than synthetically /// random nonces. -#[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] +#[cfg(feature = "batch_deterministic")] struct ZeroRng {} -#[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] +#[cfg(feature = "batch_deterministic")] impl rand_core::RngCore for ZeroRng { fn next_u32(&mut self) -> u32 { rand_core::impls::next_u32_via_fill(self) @@ -104,10 +104,10 @@ impl rand_core::RngCore for ZeroRng { } } -#[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] +#[cfg(feature = "batch_deterministic")] impl rand_core::CryptoRng for ZeroRng {} -#[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] +#[cfg(feature = "batch_deterministic")] fn zero_rng() -> ZeroRng { ZeroRng {} } @@ -261,9 +261,9 @@ pub fn verify_batch( transcript.append_message_lengths(&message_lengths); transcript.append_scalars(&scalars); - #[cfg(all(feature = "batch", not(feature = "batch_deterministic")))] + #[cfg(not(feature = "batch_deterministic"))] let mut prng = transcript.build_rng().finalize(&mut thread_rng()); - #[cfg(all(not(feature = "batch"), feature = "batch_deterministic"))] + #[cfg(feature = "batch_deterministic")] let mut prng = transcript.build_rng().finalize(&mut zero_rng()); // Select a random 128-bit scalar for each signature. From df07b552e07c2aca9543eb2b9f71989c21dce412 Mon Sep 17 00:00:00 2001 From: pinkforest <36498018+pinkforest@users.noreply.github.com> Date: Tue, 13 Dec 2022 12:02:34 +1100 Subject: [PATCH 2/2] Add compile error --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ee3a8dd..f6a145f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,6 +232,9 @@ mod signature; pub use curve25519_dalek::digest::Digest; +#[cfg(all(feature = "batch", feature = "batch_deterministic"))] +compile_error!("Features batch and batch_deterministic are mutually exclusive."); + #[cfg(any(feature = "batch", feature = "batch_deterministic"))] pub use crate::batch::*; pub use crate::constants::*;