Skip to content

Commit

Permalink
WIP Rework SST tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aewag committed Sep 8, 2024
1 parent baa5393 commit 837ada2
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions src/sst/gen_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ mod tests {
use crate::util::helper::test_helper::gen_random_seed;
use crate::HssParameter;
use crate::Sha256_128;
use crate::Sha256_192;
use crate::Sha256_256;
use signature::Verifier;

#[test]
fn test_prepare_sst_keygen_se_without_lms_tree_id() {
Expand Down Expand Up @@ -152,47 +155,69 @@ mod tests {
}

#[test]
fn test_finalize_sst_keygen() {
fn signing_sst_sha256_128() {
signing_sst_core::<Sha256_128>();
}

#[test]
fn signing_sst_sha256_192() {
signing_sst_core::<Sha256_192>();
}

#[test]
fn signing_sst_sha256_256() {
signing_sst_core::<Sha256_256>();
}

fn signing_sst_core<H: HashChain>() {
const L0_TOP_DIV: u32 = 4;

let mut message = [
32u8, 48, 2, 1, 48, 58, 20, 57, 9, 83, 99, 255, 0, 34, 2, 1, 0,
];

let mut lms_tree_identifier = LmsTreeIdentifier::default();
let seed = gen_random_seed::<Sha256_128>();
let seed = gen_random_seed::<H>();
let mut hss_parameters = ArrayVec::new();
hss_parameters.extend_from_slice(&[
HssParameter::construct_default_parameters(),
HssParameter::construct_default_parameters(),
]);
let ssts_parameter = SstsParameter::<Sha256_128>::new(hss_parameters, L0_TOP_DIV as u8, 3);
let mut aux_data = [0u8; 4 + 16 + 2usize.pow(L0_TOP_DIV) * 16];
let ssts_parameter = SstsParameter::<H>::new(hss_parameters, L0_TOP_DIV as u8, 3);
let mut aux_data = [0u8; 4 + MAX_HASH_SIZE + 2usize.pow(L0_TOP_DIV) * MAX_HASH_SIZE];
let aux_ref: &mut &mut [u8] = &mut &mut aux_data[..];
let mut aux_option = Some(aux_ref);

let (signing_key, interm_node) = if let Some(aux) = aux_option.as_deref_mut() {
prepare_sst_keygen::<Sha256_128>(
&ssts_parameter,
&seed,
Some(aux),
&mut lms_tree_identifier,
)
.unwrap()
} else {
// TODO Rm dead-end
prepare_sst_keygen::<Sha256_128>(&ssts_parameter, &seed, None, &mut lms_tree_identifier)
.unwrap()
};
let (mut signing_key, interm_node) = prepare_sst_keygen::<H>(
&ssts_parameter,
&seed,
Some(aux_option.as_mut().unwrap()),
&mut lms_tree_identifier,
)
.unwrap();

let mut interm_nodes =
ArrayVec::<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_SSTS_SIGNING_ENTITIES]>::new();
let mut tmp_node = ArrayVec::<[u8; MAX_HASH_SIZE]>::new();
tmp_node.extend_from_slice(&interm_node);
for _ in 0..2usize.pow(L0_TOP_DIV) {
let mut tmp_node = ArrayVec::<[u8; MAX_HASH_SIZE]>::new();
tmp_node.extend_from_slice(&interm_node);
interm_nodes.push(tmp_node);
}
let _verifying_key = finalize_sst_keygen::<Sha256_128>(

let verifying_key = finalize_sst_keygen::<H>(
signing_key.as_slice(),
&interm_nodes,
aux_option,
Some(aux_option.as_mut().unwrap()),
&lms_tree_identifier,
)
.unwrap();

let signature = signing_key
.try_sign_with_aux(&message, aux_option, Some(&lms_tree_identifier))
.unwrap();

assert!(verifying_key.verify(&message, &signature).is_ok());
message[0] = 33;
assert!(verifying_key.verify(&message, &signature).is_err());
}
}

0 comments on commit 837ada2

Please sign in to comment.