From 64432bd00c66cdcd65eb6f93deff4547087e2ae9 Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Mon, 2 Sep 2024 10:48:45 +0200 Subject: [PATCH 1/3] Rename to HSS_COMPRESSED_USED_LEAFS_SIZE --- src/constants.rs | 4 ++-- src/hss/mod.rs | 8 ++++---- src/hss/reference_impl_private_key.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index bacea1a3..e2975ecc 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -39,10 +39,10 @@ pub const fn prng_len(seed_len: usize) -> usize { 23 + seed_len } -pub const LMS_LEAF_IDENTIFIERS_SIZE: usize = 8; +pub const HSS_COMPRESSED_USED_LEAFS_SIZE: usize = 8; pub const REF_IMPL_MAX_ALLOWED_HSS_LEVELS: usize = 8; pub const REF_IMPL_MAX_PRIVATE_KEY_SIZE: usize = - LMS_LEAF_IDENTIFIERS_SIZE + REF_IMPL_MAX_ALLOWED_HSS_LEVELS + MAX_SEED_LEN; + HSS_COMPRESSED_USED_LEAFS_SIZE + REF_IMPL_MAX_ALLOWED_HSS_LEVELS + MAX_SEED_LEN; pub const MAX_HASH_SIZE: usize = 32; pub const MAX_HASH_BLOCK_SIZE: usize = 64; diff --git a/src/hss/mod.rs b/src/hss/mod.rs index f542b9ef..cd7db949 100644 --- a/src/hss/mod.rs +++ b/src/hss/mod.rs @@ -293,7 +293,7 @@ pub fn hss_keygen( mod tests { use crate::util::helper::test_helper::gen_random_seed; use crate::{ - constants::{LMS_LEAF_IDENTIFIERS_SIZE, MAX_HASH_SIZE}, + constants::{HSS_COMPRESSED_USED_LEAFS_SIZE, MAX_HASH_SIZE}, hasher::{ sha256::{Sha256_128, Sha256_192, Sha256_256}, shake256::{Shake256_128, Shake256_192, Shake256_256}, @@ -338,8 +338,8 @@ mod tests { assert_ne!(signing_key.as_slice(), signing_key_const.as_slice()); assert_eq!( - signing_key.as_slice()[LMS_LEAF_IDENTIFIERS_SIZE..], - signing_key_const.as_slice()[LMS_LEAF_IDENTIFIERS_SIZE..] + signing_key.as_slice()[HSS_COMPRESSED_USED_LEAFS_SIZE..], + signing_key_const.as_slice()[HSS_COMPRESSED_USED_LEAFS_SIZE..] ); } @@ -366,7 +366,7 @@ mod tests { for index in 0..keypair_lifetime { assert_eq!( - signing_key.as_slice()[..LMS_LEAF_IDENTIFIERS_SIZE], + signing_key.as_slice()[..HSS_COMPRESSED_USED_LEAFS_SIZE], index.to_be_bytes(), ); assert_eq!( diff --git a/src/hss/reference_impl_private_key.rs b/src/hss/reference_impl_private_key.rs index 6956b8bb..4cdee7c1 100644 --- a/src/hss/reference_impl_private_key.rs +++ b/src/hss/reference_impl_private_key.rs @@ -1,6 +1,6 @@ use crate::{ constants::{ - LmsTreeIdentifier, D_TOPSEED, ILEN, LMS_LEAF_IDENTIFIERS_SIZE, MAX_ALLOWED_HSS_LEVELS, + LmsTreeIdentifier, D_TOPSEED, HSS_COMPRESSED_USED_LEAFS_SIZE, ILEN, MAX_ALLOWED_HSS_LEVELS, MAX_HASH_SIZE, MAX_SEED_LEN, REF_IMPL_MAX_PRIVATE_KEY_SIZE, SEED_CHILD_SEED, SEED_SIGNATURE_RANDOMIZER_SEED, TOPSEED_D, TOPSEED_LEN, TOPSEED_SEED, TOPSEED_WHICH, }, @@ -125,7 +125,7 @@ impl ReferenceImplPrivateKey { let mut index = 0; let compressed_used_leafs_indexes = - read_and_advance(data, LMS_LEAF_IDENTIFIERS_SIZE, &mut index); + read_and_advance(data, HSS_COMPRESSED_USED_LEAFS_SIZE, &mut index); result.compressed_used_leafs_indexes = CompressedUsedLeafsIndexes::from_slice(compressed_used_leafs_indexes); From 963c3b424f125c6c031c327ae488820f717d1b30 Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Mon, 2 Sep 2024 10:53:58 +0200 Subject: [PATCH 2/3] Rename to MAX_NUM_WINTERNITZ_CHAINS --- src/constants.rs | 14 +++++++++----- src/lm_ots/definitions.rs | 8 +++++--- src/lm_ots/keygen.rs | 4 ++-- src/lm_ots/signing.rs | 10 +++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index e2975ecc..faafd458 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -13,7 +13,11 @@ pub type LmsLeafIdentifier = [u8; 4]; type FvcMax = u16; type FvcSum = u16; type FvcCoef = (usize, u16, u64); // (index, shift, mask) -pub type FastVerifyCached = (FvcMax, FvcSum, ArrayVec<[FvcCoef; MAX_HASH_CHAIN_COUNT]>); +pub type FastVerifyCached = ( + FvcMax, + FvcSum, + ArrayVec<[FvcCoef; MAX_NUM_WINTERNITZ_CHAINS]>, +); pub const D_PBLC: [u8; 2] = [0x80, 0x80]; pub const D_MESG: [u8; 2] = [0x81, 0x81]; @@ -49,20 +53,20 @@ pub const MAX_HASH_BLOCK_SIZE: usize = 64; pub const PRNG_MAX_LEN: usize = prng_len(MAX_HASH_SIZE); -pub const MAX_HASH_CHAIN_COUNT: usize = +pub const MAX_NUM_WINTERNITZ_CHAINS: usize = get_hash_chain_count(MIN_WINTERNITZ_PARAMETER, MAX_HASH_SIZE); pub const MAX_LMOTS_SIGNATURE_LENGTH: usize = - lmots_signature_length(MAX_HASH_SIZE, MAX_HASH_CHAIN_COUNT); + lmots_signature_length(MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS); pub const MAX_LMS_PUBLIC_KEY_LENGTH: usize = lms_public_key_length(MAX_HASH_SIZE); pub const MAX_LMS_SIGNATURE_LENGTH: usize = - lms_signature_length(MAX_HASH_SIZE, MAX_HASH_CHAIN_COUNT, MAX_TREE_HEIGHT); + lms_signature_length(MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS, MAX_TREE_HEIGHT); pub const MAX_HSS_PUBLIC_KEY_LENGTH: usize = size_of::() // HSS Level + lms_public_key_length(MAX_HASH_SIZE); // Root LMS PublicKey pub const MAX_HSS_SIGNED_PUBLIC_KEY_LENGTH: usize = - hss_signed_public_key_length(MAX_HASH_SIZE, MAX_HASH_CHAIN_COUNT, MAX_TREE_HEIGHT); + hss_signed_public_key_length(MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS, MAX_TREE_HEIGHT); pub const MAX_HSS_SIGNATURE_LENGTH: usize = get_hss_signature_length(); /// Calculated using the formula from RFC 8554 Appendix B diff --git a/src/lm_ots/definitions.rs b/src/lm_ots/definitions.rs index b6c7989b..001df92a 100644 --- a/src/lm_ots/definitions.rs +++ b/src/lm_ots/definitions.rs @@ -2,7 +2,9 @@ use tinyvec::ArrayVec; use zeroize::{Zeroize, ZeroizeOnDrop}; use crate::{ - constants::{LmsLeafIdentifier, LmsTreeIdentifier, Node, MAX_HASH_CHAIN_COUNT, MAX_HASH_SIZE}, + constants::{ + LmsLeafIdentifier, LmsTreeIdentifier, Node, MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS, + }, hasher::HashChain, util::ArrayVecZeroize, }; @@ -13,7 +15,7 @@ use super::parameters::LmotsParameter; pub struct LmotsPrivateKey { pub lms_tree_identifier: LmsTreeIdentifier, pub lms_leaf_identifier: LmsLeafIdentifier, - pub key: ArrayVecZeroize, // [[0u8; n]; p]; + pub key: ArrayVecZeroize, // [[0u8; n]; p]; #[zeroize(skip)] pub lmots_parameter: LmotsParameter, } @@ -22,7 +24,7 @@ impl LmotsPrivateKey { pub fn new( lms_tree_identifier: LmsTreeIdentifier, lms_leaf_identifier: LmsLeafIdentifier, - key: ArrayVec<[Node; MAX_HASH_CHAIN_COUNT]>, + key: ArrayVec<[Node; MAX_NUM_WINTERNITZ_CHAINS]>, lmots_parameter: LmotsParameter, ) -> Self { LmotsPrivateKey { diff --git a/src/lm_ots/keygen.rs b/src/lm_ots/keygen.rs index c749806a..8062300c 100644 --- a/src/lm_ots/keygen.rs +++ b/src/lm_ots/keygen.rs @@ -1,7 +1,7 @@ use super::definitions::*; use super::parameters::LmotsParameter; use crate::constants::*; -use crate::constants::{D_PBLC, MAX_HASH_CHAIN_COUNT, MAX_HASH_SIZE}; +use crate::constants::{D_PBLC, MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS}; use crate::hasher::HashChain; use crate::Seed; use tinyvec::ArrayVec; @@ -41,7 +41,7 @@ pub fn generate_public_key(private_key: &LmotsPrivateKey) -> Lm let hash_chain_count: usize = 2_usize.pow(lmots_parameter.get_winternitz() as u32) - 1; let key = &private_key.key; - let mut public_key_data: ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_HASH_CHAIN_COUNT]> = + let mut public_key_data: ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_NUM_WINTERNITZ_CHAINS]> = ArrayVec::new(); for i in 0..lmots_parameter.get_hash_chain_count() as usize { diff --git a/src/lm_ots/signing.rs b/src/lm_ots/signing.rs index d730a9e3..69e7ed2e 100644 --- a/src/lm_ots/signing.rs +++ b/src/lm_ots/signing.rs @@ -1,5 +1,5 @@ use crate::{ - constants::{D_MESG, MAX_HASH_CHAIN_COUNT, MAX_HASH_SIZE, MAX_LMOTS_SIGNATURE_LENGTH}, + constants::{D_MESG, MAX_HASH_SIZE, MAX_LMOTS_SIGNATURE_LENGTH, MAX_NUM_WINTERNITZ_CHAINS}, hasher::HashChain, lm_ots::parameters::LmotsAlgorithm, util::{coef::coef, helper::read_and_advance}, @@ -24,7 +24,7 @@ use super::parameters::LmotsParameter; #[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct LmotsSignature { pub signature_randomizer: ArrayVec<[u8; MAX_HASH_SIZE]>, - pub signature_data: ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_HASH_CHAIN_COUNT]>, + pub signature_data: ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_NUM_WINTERNITZ_CHAINS]>, pub lmots_parameter: LmotsParameter, pub hash_iterations: u16, } @@ -113,7 +113,7 @@ impl LmotsSignature { fn calculate_signature( private_key: &LmotsPrivateKey, message_hash_with_checksum: &ArrayVec<[u8; MAX_HASH_SIZE + 2]>, - ) -> ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_HASH_CHAIN_COUNT]> { + ) -> ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_NUM_WINTERNITZ_CHAINS]> { let lmots_parameter = private_key.lmots_parameter; let mut hasher = lmots_parameter.get_hasher(); @@ -338,7 +338,7 @@ mod tests { use tinyvec::ArrayVec; use crate::{ - constants::{MAX_HASH_CHAIN_COUNT, MAX_HASH_SIZE}, + constants::{MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS}, hasher::{ sha256::{Sha256_128, Sha256_192, Sha256_256}, shake256::{Shake256_128, Shake256_192, Shake256_256}, @@ -356,7 +356,7 @@ mod tests { let mut signature_randomizer = ArrayVec::new(); let mut signature_data: ArrayVec< - [ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_HASH_CHAIN_COUNT], + [ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_NUM_WINTERNITZ_CHAINS], > = ArrayVec::new(); for i in 0..lmots_parameter.get_hash_function_output_size() as usize { From 3c52f4514b6c9280ea366d34d47161ab9bfa13ff Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Mon, 2 Sep 2024 10:57:25 +0200 Subject: [PATCH 3/3] Rename to get_num_winternitz_chains --- src/constants.rs | 36 ++++++++++++++++++------------------ src/hss/signing.rs | 8 ++++++-- src/lm_ots/definitions.rs | 2 +- src/lm_ots/keygen.rs | 4 ++-- src/lm_ots/parameters.rs | 16 ++++++++-------- src/lm_ots/signing.rs | 10 +++++----- src/lm_ots/verify.rs | 30 +++++++++++++++++------------- src/lms/signing.rs | 2 +- 8 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index faafd458..1f60c5fe 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -54,7 +54,7 @@ pub const MAX_HASH_BLOCK_SIZE: usize = 64; pub const PRNG_MAX_LEN: usize = prng_len(MAX_HASH_SIZE); pub const MAX_NUM_WINTERNITZ_CHAINS: usize = - get_hash_chain_count(MIN_WINTERNITZ_PARAMETER, MAX_HASH_SIZE); + get_num_winternitz_chains(MIN_WINTERNITZ_PARAMETER, MAX_HASH_SIZE); pub const MAX_LMOTS_SIGNATURE_LENGTH: usize = lmots_signature_length(MAX_HASH_SIZE, MAX_NUM_WINTERNITZ_CHAINS); @@ -73,7 +73,7 @@ pub const MAX_HSS_SIGNATURE_LENGTH: usize = get_hss_signature_length(); /// https://datatracker.ietf.org/doc/html/rfc8554#appendix-B const HASH_CHAIN_COUNTS: [usize; 12] = [136, 200, 265, 68, 101, 133, 35, 51, 67, 18, 26, 34]; -pub const fn get_hash_chain_count(winternitz_parameter: usize, output_size: usize) -> usize { +pub const fn get_num_winternitz_chains(winternitz_parameter: usize, output_size: usize) -> usize { let w_i = match winternitz_parameter { 1 => 0usize, 2 => 1usize, @@ -132,7 +132,7 @@ pub const fn get_hss_signature_length() -> usize { while level > 0 { length += hss_signed_public_key_length( MAX_HASH_SIZE, - get_hash_chain_count(WINTERNITZ_PARAMETERS[level], MAX_HASH_SIZE), + get_num_winternitz_chains(WINTERNITZ_PARAMETERS[level], MAX_HASH_SIZE), TREE_HEIGHTS[level], ); level -= 1; @@ -141,7 +141,7 @@ pub const fn get_hss_signature_length() -> usize { length + lms_signature_length( MAX_HASH_SIZE, - get_hash_chain_count(WINTERNITZ_PARAMETERS[0], MAX_HASH_SIZE), + get_num_winternitz_chains(WINTERNITZ_PARAMETERS[0], MAX_HASH_SIZE), TREE_HEIGHTS[0], ) } @@ -170,21 +170,21 @@ pub mod winternitz_chain { #[cfg(test)] mod tests { - use crate::constants::get_hash_chain_count; + use crate::constants::get_num_winternitz_chains; #[test] - fn test_get_hash_chain_count() { - assert_eq!(get_hash_chain_count(1, 32), 265); - assert_eq!(get_hash_chain_count(2, 32), 133); - assert_eq!(get_hash_chain_count(4, 32), 67); - assert_eq!(get_hash_chain_count(8, 32), 34); - assert_eq!(get_hash_chain_count(1, 24), 200); - assert_eq!(get_hash_chain_count(2, 24), 101); - assert_eq!(get_hash_chain_count(4, 24), 51); - assert_eq!(get_hash_chain_count(8, 24), 26); - assert_eq!(get_hash_chain_count(1, 16), 136); - assert_eq!(get_hash_chain_count(2, 16), 68); - assert_eq!(get_hash_chain_count(4, 16), 35); - assert_eq!(get_hash_chain_count(8, 16), 18); + fn test_get_num_winternitz_chains() { + assert_eq!(get_num_winternitz_chains(1, 32), 265); + assert_eq!(get_num_winternitz_chains(2, 32), 133); + assert_eq!(get_num_winternitz_chains(4, 32), 67); + assert_eq!(get_num_winternitz_chains(8, 32), 34); + assert_eq!(get_num_winternitz_chains(1, 24), 200); + assert_eq!(get_num_winternitz_chains(2, 24), 101); + assert_eq!(get_num_winternitz_chains(4, 24), 51); + assert_eq!(get_num_winternitz_chains(8, 24), 26); + assert_eq!(get_num_winternitz_chains(1, 16), 136); + assert_eq!(get_num_winternitz_chains(2, 16), 68); + assert_eq!(get_num_winternitz_chains(4, 16), 35); + assert_eq!(get_num_winternitz_chains(8, 16), 18); } } diff --git a/src/hss/signing.rs b/src/hss/signing.rs index b973554a..cba89ea8 100644 --- a/src/hss/signing.rs +++ b/src/hss/signing.rs @@ -216,7 +216,9 @@ impl<'a, H: HashChain> InMemoryHssSignedPublicKey<'a, H> { sig.lmots_signature .lmots_parameter .get_hash_function_output_size(), - sig.lmots_signature.lmots_parameter.get_hash_chain_count() as usize, + sig.lmots_signature + .lmots_parameter + .get_num_winternitz_chains() as usize, sig.lms_parameter.get_tree_height() as usize, ); @@ -234,7 +236,9 @@ impl<'a, H: HashChain> InMemoryHssSignedPublicKey<'a, H> { sig.lmots_signature .lmots_parameter .get_hash_function_output_size(), - sig.lmots_signature.lmots_parameter.get_hash_chain_count() as usize, + sig.lmots_signature + .lmots_parameter + .get_num_winternitz_chains() as usize, sig.lms_parameter.get_tree_height() as usize, ); let public_key_size = diff --git a/src/lm_ots/definitions.rs b/src/lm_ots/definitions.rs index 001df92a..7c044e44 100644 --- a/src/lm_ots/definitions.rs +++ b/src/lm_ots/definitions.rs @@ -71,7 +71,7 @@ mod tests { let parameter = $parameter.construct_parameter::<$hash_chain>().unwrap(); assert_eq!(parameter.get_hash_function_output_size(), $n); assert_eq!(parameter.get_winternitz(), $w); - assert_eq!(parameter.get_hash_chain_count(), $p); + assert_eq!(parameter.get_num_winternitz_chains(), $p); assert_eq!(parameter.get_checksum_left_shift(), $ls); assert_eq!(parameter.get_type_id(), $type); } diff --git a/src/lm_ots/keygen.rs b/src/lm_ots/keygen.rs index 8062300c..4469896b 100644 --- a/src/lm_ots/keygen.rs +++ b/src/lm_ots/keygen.rs @@ -16,7 +16,7 @@ pub fn generate_private_key( let mut hasher = lmots_parameter.get_hasher(); - for index in 0..lmots_parameter.get_hash_chain_count() { + for index in 0..lmots_parameter.get_num_winternitz_chains() { hasher.update(&lms_tree_identifier); hasher.update(&lms_leaf_identifier); hasher.update(&index.to_be_bytes()); @@ -44,7 +44,7 @@ pub fn generate_public_key(private_key: &LmotsPrivateKey) -> Lm let mut public_key_data: ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_NUM_WINTERNITZ_CHAINS]> = ArrayVec::new(); - for i in 0..lmots_parameter.get_hash_chain_count() as usize { + for i in 0..lmots_parameter.get_num_winternitz_chains() as usize { let mut hash_chain_data = H::prepare_hash_chain_data( &private_key.lms_tree_identifier, &private_key.lms_leaf_identifier, diff --git a/src/lm_ots/parameters.rs b/src/lm_ots/parameters.rs index 87338eea..7cd99af1 100644 --- a/src/lm_ots/parameters.rs +++ b/src/lm_ots/parameters.rs @@ -2,7 +2,7 @@ use core::marker::PhantomData; use tinyvec::ArrayVec; -use crate::constants::get_hash_chain_count; +use crate::constants::get_num_winternitz_chains; use crate::{ constants::{FastVerifyCached, MAX_HASH_SIZE}, hasher::HashChain, @@ -45,25 +45,25 @@ impl LmotsAlgorithm { LmotsAlgorithm::LmotsW1 => Some(LmotsParameter::new( 1, 1, - get_hash_chain_count(1, H::OUTPUT_SIZE as usize) as u16, + get_num_winternitz_chains(1, H::OUTPUT_SIZE as usize) as u16, 7, )), LmotsAlgorithm::LmotsW2 => Some(LmotsParameter::new( 2, 2, - get_hash_chain_count(2, H::OUTPUT_SIZE as usize) as u16, + get_num_winternitz_chains(2, H::OUTPUT_SIZE as usize) as u16, 6, )), LmotsAlgorithm::LmotsW4 => Some(LmotsParameter::new( 3, 4, - get_hash_chain_count(4, H::OUTPUT_SIZE as usize) as u16, + get_num_winternitz_chains(4, H::OUTPUT_SIZE as usize) as u16, 4, )), LmotsAlgorithm::LmotsW8 => Some(LmotsParameter::new( 4, 8, - get_hash_chain_count(8, H::OUTPUT_SIZE as usize) as u16, + get_num_winternitz_chains(8, H::OUTPUT_SIZE as usize) as u16, 0, )), } @@ -119,7 +119,7 @@ impl LmotsParameter { self.winternitz } - pub fn get_hash_chain_count(&self) -> u16 { + pub fn get_num_winternitz_chains(&self) -> u16 { self.hash_chain_count } @@ -138,7 +138,7 @@ impl LmotsParameter { let sum = max * max_word_size; let mut coef = ArrayVec::new(); - for i in 0..self.get_hash_chain_count() { + for i in 0..self.get_num_winternitz_chains() { coef.push(coef_helper(i, self.get_winternitz())); } @@ -163,7 +163,7 @@ impl LmotsParameter { checksum <<= self.get_checksum_left_shift(); let checksum = [(checksum >> 8 & 0xff) as u8, (checksum & 0xff) as u8]; - for i in *max..self.get_hash_chain_count() { + for i in *max..self.get_num_winternitz_chains() { let (index, shift, mask) = coef[i as usize]; let hash_chain_length = ((checksum[index - 32] as u64 >> shift) & mask) as u16; total_hash_chain_iterations += hash_chain_length; diff --git a/src/lm_ots/signing.rs b/src/lm_ots/signing.rs index 69e7ed2e..2f5e9a90 100644 --- a/src/lm_ots/signing.rs +++ b/src/lm_ots/signing.rs @@ -120,7 +120,7 @@ impl LmotsSignature { let mut signature_data = ArrayVec::new(); - for i in 0..lmots_parameter.get_hash_chain_count() { + for i in 0..lmots_parameter.get_num_winternitz_chains() { let a = coef( message_hash_with_checksum.as_slice(), i, @@ -179,7 +179,7 @@ impl LmotsSignature { let signature_data = LmotsSignature::::calculate_signature(private_key, &message_hash_with_checksum); - let hash_iterations = (0..lmots_parameter.get_hash_chain_count()).fold(0, |sum, i| { + let hash_iterations = (0..lmots_parameter.get_num_winternitz_chains()).fold(0, |sum, i| { sum + coef( message_hash_with_checksum.as_slice(), i, @@ -228,7 +228,7 @@ impl<'a, H: HashChain> InMemoryLmotsSignature<'a, H> { let signature_data = read_and_advance( data, - (H::OUTPUT_SIZE * lmots_parameter.get_hash_chain_count()) as usize, + (H::OUTPUT_SIZE * lmots_parameter.get_num_winternitz_chains()) as usize, &mut index, ); @@ -363,7 +363,7 @@ mod tests { signature_randomizer.push(i as u8); } - for i in 0..lmots_parameter.get_hash_chain_count() as usize { + for i in 0..lmots_parameter.get_num_winternitz_chains() as usize { signature_data.push(ArrayVec::new()); for j in 0..lmots_parameter.get_hash_function_output_size() as usize { signature_data[i].push(j as u8); @@ -381,7 +381,7 @@ mod tests { // check signature len let output_size = lmots_parameter.get_hash_function_output_size() as usize; - let hash_chain_count = lmots_parameter.get_hash_chain_count() as usize; + let hash_chain_count = lmots_parameter.get_num_winternitz_chains() as usize; assert_eq!(binary_rep.len(), 4 + output_size * (hash_chain_count + 1)); let deserialized_signature = InMemoryLmotsSignature::new(binary_rep.as_slice()) diff --git a/src/lm_ots/verify.rs b/src/lm_ots/verify.rs index 0961a74a..fbab8339 100644 --- a/src/lm_ots/verify.rs +++ b/src/lm_ots/verify.rs @@ -9,14 +9,18 @@ use super::{definitions::LmotsPublicKey, signing::InMemoryLmotsSignature}; #[derive(Default)] struct HashChainArray { - pub array_w1: - Option; get_hash_chain_count(1, MAX_HASH_SIZE)]>>, - pub array_w2: - Option; get_hash_chain_count(2, MAX_HASH_SIZE)]>>, - pub array_w4: - Option; get_hash_chain_count(4, MAX_HASH_SIZE)]>>, - pub array_w8: - Option; get_hash_chain_count(8, MAX_HASH_SIZE)]>>, + pub array_w1: Option< + ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(1, MAX_HASH_SIZE)]>, + >, + pub array_w2: Option< + ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(2, MAX_HASH_SIZE)]>, + >, + pub array_w4: Option< + ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(4, MAX_HASH_SIZE)]>, + >, + pub array_w8: Option< + ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(8, MAX_HASH_SIZE)]>, + >, phantom_data: PhantomData, } @@ -25,19 +29,19 @@ impl HashChainArray { let mut hash_chain_array = HashChainArray::::default(); if LmotsAlgorithm::from(lmots_parameter.get_type_id()) == LmotsAlgorithm::LmotsW8 { hash_chain_array.array_w8 = Some(ArrayVec::< - [ArrayVec<[u8; MAX_HASH_SIZE]>; get_hash_chain_count(8, MAX_HASH_SIZE)], + [ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(8, MAX_HASH_SIZE)], >::default()); } else if LmotsAlgorithm::from(lmots_parameter.get_type_id()) == LmotsAlgorithm::LmotsW4 { hash_chain_array.array_w4 = Some(ArrayVec::< - [ArrayVec<[u8; MAX_HASH_SIZE]>; get_hash_chain_count(4, MAX_HASH_SIZE)], + [ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(4, MAX_HASH_SIZE)], >::default()); } else if LmotsAlgorithm::from(lmots_parameter.get_type_id()) == LmotsAlgorithm::LmotsW2 { hash_chain_array.array_w2 = Some(ArrayVec::< - [ArrayVec<[u8; MAX_HASH_SIZE]>; get_hash_chain_count(2, MAX_HASH_SIZE)], + [ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(2, MAX_HASH_SIZE)], >::default()); } else { hash_chain_array.array_w1 = Some(ArrayVec::< - [ArrayVec<[u8; MAX_HASH_SIZE]>; get_hash_chain_count(1, MAX_HASH_SIZE)], + [ArrayVec<[u8; MAX_HASH_SIZE]>; get_num_winternitz_chains(1, MAX_HASH_SIZE)], >::default()); } hash_chain_array @@ -111,7 +115,7 @@ pub fn generate_public_key_candidate( let mut hash_chain_array = HashChainArray::new(&lmots_parameter); let max_w = 2usize.pow(lmots_parameter.get_winternitz() as u32) - 1; - for i in 0..lmots_parameter.get_hash_chain_count() { + for i in 0..lmots_parameter.get_num_winternitz_chains() { let a = coef( message_hash_with_checksum.as_slice(), i, diff --git a/src/lms/signing.rs b/src/lms/signing.rs index 96fa0dfd..3a55e6a9 100644 --- a/src/lms/signing.rs +++ b/src/lms/signing.rs @@ -174,7 +174,7 @@ impl<'a, H: HashChain> InMemoryLmsSignature<'a, H> { .unwrap(); let lmots_signature = lm_ots::signing::InMemoryLmotsSignature::new(read_and_advance( data, - (4 + H::OUTPUT_SIZE * (1 + lmots_parameter.get_hash_chain_count())) as usize, + (4 + H::OUTPUT_SIZE * (1 + lmots_parameter.get_num_winternitz_chains())) as usize, &mut index, )) .unwrap();