Skip to content

Commit

Permalink
Rename to MAX_NUM_WINTERNITZ_CHAINS
Browse files Browse the repository at this point in the history
  • Loading branch information
aewag committed Sep 2, 2024
1 parent 64432bd commit 963c3b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
14 changes: 9 additions & 5 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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::<u32>() // 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
Expand Down
8 changes: 5 additions & 3 deletions src/lm_ots/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -13,7 +15,7 @@ use super::parameters::LmotsParameter;
pub struct LmotsPrivateKey<H: HashChain> {
pub lms_tree_identifier: LmsTreeIdentifier,
pub lms_leaf_identifier: LmsLeafIdentifier,
pub key: ArrayVecZeroize<Node, MAX_HASH_CHAIN_COUNT>, // [[0u8; n]; p];
pub key: ArrayVecZeroize<Node, MAX_NUM_WINTERNITZ_CHAINS>, // [[0u8; n]; p];
#[zeroize(skip)]
pub lmots_parameter: LmotsParameter<H>,
}
Expand All @@ -22,7 +24,7 @@ impl<H: HashChain> LmotsPrivateKey<H> {
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<H>,
) -> Self {
LmotsPrivateKey {
Expand Down
4 changes: 2 additions & 2 deletions src/lm_ots/keygen.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,7 +41,7 @@ pub fn generate_public_key<H: HashChain>(private_key: &LmotsPrivateKey<H>) -> 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 {
Expand Down
10 changes: 5 additions & 5 deletions src/lm_ots/signing.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -24,7 +24,7 @@ use super::parameters::LmotsParameter;
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct LmotsSignature<H: HashChain> {
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<H>,
pub hash_iterations: u16,
}
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<H: HashChain> LmotsSignature<H> {
fn calculate_signature(
private_key: &LmotsPrivateKey<H>,
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();
Expand Down Expand Up @@ -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},
Expand All @@ -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 {
Expand Down

0 comments on commit 963c3b4

Please sign in to comment.