diff --git a/src/sst/gen_key.rs b/src/sst/gen_key.rs index 7162baf..68dd273 100644 --- a/src/sst/gen_key.rs +++ b/src/sst/gen_key.rs @@ -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() { @@ -152,47 +155,69 @@ mod tests { } #[test] - fn test_finalize_sst_keygen() { + fn signing_sst_sha256_128() { + signing_sst_core::(); + } + + #[test] + fn signing_sst_sha256_192() { + signing_sst_core::(); + } + + #[test] + fn signing_sst_sha256_256() { + signing_sst_core::(); + } + + fn signing_sst_core() { 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::(); + let seed = gen_random_seed::(); let mut hss_parameters = ArrayVec::new(); hss_parameters.extend_from_slice(&[ HssParameter::construct_default_parameters(), HssParameter::construct_default_parameters(), ]); - let ssts_parameter = SstsParameter::::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::::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::( - &ssts_parameter, - &seed, - Some(aux), - &mut lms_tree_identifier, - ) - .unwrap() - } else { - // TODO Rm dead-end - prepare_sst_keygen::(&ssts_parameter, &seed, None, &mut lms_tree_identifier) - .unwrap() - }; + let (mut signing_key, interm_node) = prepare_sst_keygen::( + &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::( + + let verifying_key = finalize_sst_keygen::( 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()); } }