Skip to content

Commit

Permalink
Fully guard alloc tests with feature flags, make KATs no-alloc (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjade273 committed Apr 15, 2024
1 parent f4799f5 commit e210572
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/slh-dsa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
- run: cargo check --all-features
# - run: cargo test --no-default-features TODO
- run: cargo test --no-default-features TODO
- run: cargo test
- run: cargo test --all-features
3 changes: 2 additions & 1 deletion slh-dsa/src/fors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ mod tests {
use rand::{thread_rng, Rng, RngCore};

use super::*;
use hex_literal::hex;

#[test]
#[cfg(feature = "alloc")]
#[allow(clippy::too_many_lines)] // KAT is long
fn fors_sign_kat() {
use hex_literal::hex;

let sk_seed = SkSeed(Array([1; 16]));
let pk_seed = PkSeed(Array([2; 16]));
let adrs = ForsTree::new(3, 5);
Expand Down
5 changes: 3 additions & 2 deletions slh-dsa/src/hypertree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ pub trait HypertreeParams: XmssParams + Sized {
mod tests {
use super::*;
use crate::{hashes::Shake128f, util::macros::test_parameter_sets, PkSeed};
use hex_literal::hex;
use hybrid_array::Array;
use rand::{thread_rng, Rng};
use sha3::{digest::ExtendableOutput, Shake256};

fn test_ht_sign_verify<HTMode: HypertreeParams>() {
let mut rng = thread_rng();
Expand Down Expand Up @@ -207,6 +205,9 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
fn test_ht_sign_kat() {
use hex_literal::hex;
use sha3::{digest::ExtendableOutput, Shake256};

let sk_seed = SkSeed(Array([1; 16]));
let pk_seed = PkSeed(Array([2; 16]));
let m = Array([3; 16]);
Expand Down
1 change: 1 addition & 0 deletions slh-dsa/src/signature_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ mod tests {
assert_eq!(sig, sig2);
}

#[cfg(feature = "alloc")]
test_parameter_sets!(test_serialize_deserialize_vec);

#[test]
Expand Down
4 changes: 2 additions & 2 deletions slh-dsa/tests/known_answer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ where
let sk = SigningKey::<P>::new(&mut seed_rng);
let pk = sk.verifying_key();

writeln!(resp, "pk = {}", hex::encode_upper(&pk.to_vec())).unwrap();
writeln!(resp, "sk = {}", hex::encode_upper(&sk.to_vec())).unwrap();
writeln!(resp, "pk = {}", hex::encode_upper(&pk.to_bytes())).unwrap();
writeln!(resp, "sk = {}", hex::encode_upper(&sk.to_bytes())).unwrap();

let sig = sk.sign_with_rng(&mut rng, msg).to_bytes();
writeln!(resp, "smlen = {}", sig.as_slice().len() + msg.len()).unwrap();
Expand Down

0 comments on commit e210572

Please sign in to comment.