Skip to content
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
5 changes: 0 additions & 5 deletions src/inc_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ pub trait IncomparableEncoding {
randomness: &Self::Randomness,
epoch: u32,
) -> Result<Vec<u8>, Self::Error>;

/// Function to check internal consistency of any given parameters
/// For testing only, and expected to panic if something is wrong.
#[cfg(test)]
fn internal_consistency_check();
}

pub mod target_sum;
33 changes: 12 additions & 21 deletions src/inc_encoding/target_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ impl<MH: MessageHash, const TARGET_SUM: usize> IncomparableEncoding
randomness: &Self::Randomness,
epoch: u32,
) -> Result<Vec<u8>, Self::Error> {
const {
// base and dimension must not be too large
assert!(
MH::BASE <= 1 << 8,
"Target Sum Encoding: Base must be at most 2^8"
);
assert!(
MH::DIMENSION <= 1 << 8,
"Target Sum Encoding: Dimension must be at most 2^8"
);
}

// apply the message hash first to get chunks
let chunks =
MH::apply(parameter, epoch, randomness, message).map_err(TargetSumError::HashError)?;
Expand All @@ -75,22 +87,6 @@ impl<MH: MessageHash, const TARGET_SUM: usize> IncomparableEncoding
})
}
}

#[cfg(test)]
fn internal_consistency_check() {
// base and dimension must not be too large
assert!(
Self::BASE <= 1 << 8,
"Target Sum Encoding: Base must be at most 2^8"
);
assert!(
Self::DIMENSION <= 1 << 8,
"Target Sum Encoding: Dimension must be at most 2^8"
);

// also check internal consistency of message hash
MH::internal_consistency_check();
}
}

#[cfg(test)]
Expand All @@ -105,11 +101,6 @@ mod tests {
const TEST_TARGET_SUM: usize = 115;
type TestTargetSumEncoding = TargetSumEncoding<PoseidonMessageHash445, TEST_TARGET_SUM>;

#[test]
fn test_internal_consistency() {
TestTargetSumEncoding::internal_consistency_check();
}

#[test]
fn test_successful_encoding_fixed_message() {
// keep message fixed and only resample randomness
Expand Down
8 changes: 0 additions & 8 deletions src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,6 @@ pub trait SignatureScheme {
message: &[u8; MESSAGE_LENGTH],
sig: &Self::Signature,
) -> bool;

/// A test-only function to assert that all internal parameters chosen for the
/// signature scheme are valid and compatible.
///
/// ### Panics
/// This function will panic if any of the internal consistency checks fail.
#[cfg(test)]
fn internal_consistency_check();
}

pub mod generalized_xmss;
Expand Down
56 changes: 19 additions & 37 deletions src/signature/generalized_xmss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,25 @@ where
activation_epoch: usize,
num_active_epochs: usize,
) -> (Self::PublicKey, Self::SecretKey) {
const {
// assert BASE and DIMENSION are small enough to make sure that we can fit
// pos_in_chain and chain_index in u8.
assert!(
IE::BASE <= 1 << 8,
"Generalized XMSS: Encoding base too large, must be at most 2^8"
);
assert!(
IE::DIMENSION <= 1 << 8,
"Generalized XMSS: Encoding dimension too large, must be at most 2^8"
);

// LOG_LIFETIME needs to be even, so that we can use the top-bottom tree approach
assert!(
LOG_LIFETIME.is_multiple_of(2),
"Generalized XMSS: LOG_LIFETIME must be multiple of two"
);
}

// checks for `activation_epoch` and `num_active_epochs`
assert!(
activation_epoch + num_active_epochs <= Self::LIFETIME as usize,
Expand Down Expand Up @@ -921,33 +940,6 @@ where
&sig.path,
)
}

#[cfg(test)]
fn internal_consistency_check() {
// we check consistency of all internally used components
// namely, PRF, incomparable encoding, and tweak hash
PRF::internal_consistency_check();
IE::internal_consistency_check();
TH::internal_consistency_check();

// assert BASE and DIMENSION are small enough to make sure that we can fit
// pos_in_chain and chain_index in u8.

assert!(
IE::BASE <= 1 << 8,
"Generalized XMSS: Encoding base too large, must be at most 2^8"
);
assert!(
IE::DIMENSION <= 1 << 8,
"Generalized XMSS: Encoding dimension too large, must be at most 2^8"
);

// LOG_LIFETIME needs to be even, so that we can use the top-bottom tree approach
assert!(
LOG_LIFETIME.is_multiple_of(2),
"Generalized XMSS: LOG_LIFETIME must be multiple of two"
);
}
}

impl<TH: TweakableHash> Encode for GeneralizedXMSSPublicKey<TH> {
Expand Down Expand Up @@ -1061,8 +1053,6 @@ mod tests {
const LOG_LIFETIME: usize = 6;
type Sig = GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;

Sig::internal_consistency_check();

test_signature_scheme_correctness::<Sig>(2, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(19, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(0, 0, Sig::LIFETIME as usize);
Expand All @@ -1083,8 +1073,6 @@ mod tests {
const LOG_LIFETIME: usize = 6;
type Sig = GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;

Sig::internal_consistency_check();

// we sign the same (epoch, message) pair twice (which users of this code should not do)
// and ensure that it produces the same randomness for the signature.
let mut rng = rand::rng();
Expand Down Expand Up @@ -1122,8 +1110,6 @@ mod tests {
const LOG_LIFETIME: usize = 10;
type Sig = GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;

Sig::internal_consistency_check();

test_signature_scheme_correctness::<Sig>(0, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(11, 0, Sig::LIFETIME as usize);
}
Expand All @@ -1139,8 +1125,6 @@ mod tests {
const LOG_LIFETIME: usize = 10;
type Sig = GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;

Sig::internal_consistency_check();

test_signature_scheme_correctness::<Sig>(2, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(19, 0, Sig::LIFETIME as usize);
}
Expand All @@ -1156,8 +1140,6 @@ mod tests {
const LOG_LIFETIME: usize = 6;
type Sig = GeneralizedXMSSSignatureScheme<PRF, IE, TH, LOG_LIFETIME>;

Sig::internal_consistency_check();

test_signature_scheme_correctness::<Sig>(2, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(19, 0, Sig::LIFETIME as usize);
test_signature_scheme_correctness::<Sig>(0, 0, Sig::LIFETIME as usize);
Expand Down
5 changes: 0 additions & 5 deletions src/signature/generalized_xmss/instantiations_aborting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ pub mod lifetime_2_to_the_6 {

use super::SIGAbortingLifetime6Dim64Base8;

#[test]
pub fn test_internal_consistency() {
SIGAbortingLifetime6Dim64Base8::internal_consistency_check();
}

#[test]
pub fn test_correctness() {
test_signature_scheme_correctness::<SIGAbortingLifetime6Dim64Base8>(
Expand Down
58 changes: 2 additions & 56 deletions src/signature/generalized_xmss/instantiations_poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ pub mod lifetime_2_to_the_18 {
pub type SIGTargetSumLifetime18W8Off10 =
GeneralizedXMSSSignatureScheme<PRFw8, IEw8<2805>, THw8, LOG_LIFETIME>;

#[cfg(test)]
#[cfg(all(test, feature = "slow-tests"))]
mod test {
use crate::signature::SignatureScheme;

#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

use super::{
Expand All @@ -145,28 +143,6 @@ pub mod lifetime_2_to_the_18 {
};

#[test]
pub fn test_w1_internal_consistency() {
SIGTargetSumLifetime18W1NoOff::internal_consistency_check();
SIGTargetSumLifetime18W1Off10::internal_consistency_check();
}
#[test]
pub fn test_w2_internal_consistency() {
SIGTargetSumLifetime18W2NoOff::internal_consistency_check();
SIGTargetSumLifetime18W2Off10::internal_consistency_check();
}
#[test]
pub fn test_w4_internal_consistency() {
SIGTargetSumLifetime18W4NoOff::internal_consistency_check();
SIGTargetSumLifetime18W4Off10::internal_consistency_check();
}
#[test]
pub fn test_w8_internal_consistency() {
SIGTargetSumLifetime18W8NoOff::internal_consistency_check();
SIGTargetSumLifetime18W8Off10::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w1_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime18W1NoOff>(
1032,
Expand All @@ -180,7 +156,6 @@ pub mod lifetime_2_to_the_18 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w2_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime18W2NoOff>(
436,
Expand All @@ -194,7 +169,6 @@ pub mod lifetime_2_to_the_18 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w4_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime18W4NoOff>(
21,
Expand All @@ -208,7 +182,6 @@ pub mod lifetime_2_to_the_18 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w8_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime18W8NoOff>(
32,
Expand Down Expand Up @@ -358,11 +331,9 @@ pub mod lifetime_2_to_the_20 {
pub type SIGTargetSumLifetime20W8Off10 =
GeneralizedXMSSSignatureScheme<PRFw8, IEw8<2805>, THw8, LOG_LIFETIME>;

#[cfg(test)]
#[cfg(all(test, feature = "slow-tests"))]
mod test {
use crate::signature::SignatureScheme;

#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

use super::{
Expand All @@ -373,28 +344,6 @@ pub mod lifetime_2_to_the_20 {
};

#[test]
pub fn test_w1_internal_consistency() {
SIGTargetSumLifetime20W1NoOff::internal_consistency_check();
SIGTargetSumLifetime20W1Off10::internal_consistency_check();
}
#[test]
pub fn test_w2_internal_consistency() {
SIGTargetSumLifetime20W2NoOff::internal_consistency_check();
SIGTargetSumLifetime20W2Off10::internal_consistency_check();
}
#[test]
pub fn test_w4_internal_consistency() {
SIGTargetSumLifetime20W4NoOff::internal_consistency_check();
SIGTargetSumLifetime20W4Off10::internal_consistency_check();
}
#[test]
pub fn test_w8_internal_consistency() {
SIGTargetSumLifetime20W8NoOff::internal_consistency_check();
SIGTargetSumLifetime20W8Off10::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w1_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime20W1NoOff>(
1032,
Expand All @@ -408,7 +357,6 @@ pub mod lifetime_2_to_the_20 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w2_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime20W2NoOff>(
436,
Expand All @@ -422,7 +370,6 @@ pub mod lifetime_2_to_the_20 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w4_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime20W4NoOff>(
21,
Expand All @@ -436,7 +383,6 @@ pub mod lifetime_2_to_the_20 {
);
}
#[test]
#[cfg(feature = "slow-tests")]
pub fn test_w8_correctness() {
test_signature_scheme_correctness::<SIGTargetSumLifetime20W8NoOff>(
32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ pub mod lifetime_2_to_the_18 {
#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

#[test]
pub fn test_internal_consistency() {
SIGTopLevelTargetSumLifetime18Dim64Base8::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_correctness() {
Expand Down Expand Up @@ -144,11 +139,6 @@ pub mod lifetime_2_to_the_32 {
#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

#[test]
pub fn test_internal_consistency() {
SIGTopLevelTargetSumLifetime32Dim64Base8::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_correctness() {
Expand Down Expand Up @@ -225,11 +215,6 @@ pub mod lifetime_2_to_the_32 {
#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

#[test]
pub fn test_internal_consistency() {
SIGTopLevelTargetSumLifetime32Dim48Base10::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_correctness() {
Expand Down Expand Up @@ -305,11 +290,6 @@ pub mod lifetime_2_to_the_32 {
#[cfg(feature = "slow-tests")]
use crate::signature::test_templates::test_signature_scheme_correctness;

#[test]
pub fn test_internal_consistency() {
SIGTopLevelTargetSumLifetime32Dim32Base26::internal_consistency_check();
}

#[test]
#[cfg(feature = "slow-tests")]
pub fn test_correctness() {
Expand Down Expand Up @@ -391,11 +371,6 @@ pub mod lifetime_2_to_the_8 {

use super::SIGTopLevelTargetSumLifetime8Dim64Base8;

#[test]
pub fn test_internal_consistency() {
SIGTopLevelTargetSumLifetime8Dim64Base8::internal_consistency_check();
}

#[cfg(feature = "slow-tests")]
#[test]
pub fn test_correctness() {
Expand Down
Loading
Loading