Skip to content

Commit

Permalink
WIP: intro two binary lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
aewag committed Sep 2, 2024
1 parent 76dff01 commit 132d5ae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
15 changes: 7 additions & 8 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ pub const fn prng_len(seed_len: usize) -> usize {
pub const HSS_COMPRESSED_USED_LEAFS_SIZE: usize = size_of::<u64>();
pub const REF_IMPL_MAX_ALLOWED_HSS_LEVELS: usize = 8;

pub const REF_IMPL_SSTS_EXT_SIGNING_ENTITY_IDX_SIZE: usize = size_of::<u8>();
pub const REF_IMPL_SSTS_EXT_L0_TOP_DIV_SIZE: usize = size_of::<u8>();
pub const SST_SIGNING_ENTITY_IDX_SIZE: usize = size_of::<u8>();
pub const SST_L0_TOP_DIV_SIZE: usize = size_of::<u8>();
pub const SST_SIZE: usize = SST_SIGNING_ENTITY_IDX_SIZE + SST_L0_TOP_DIV_SIZE;

pub const REF_IMPL_SSTS_EXT_SIZE: usize =
REF_IMPL_SSTS_EXT_SIGNING_ENTITY_IDX_SIZE + REF_IMPL_SSTS_EXT_L0_TOP_DIV_SIZE;
pub const SST_IMPL_MAX_PRIVATE_KEY_SIZE: usize =
SST_SIZE + HSS_COMPRESSED_USED_LEAFS_SIZE + REF_IMPL_MAX_ALLOWED_HSS_LEVELS + MAX_SEED_LEN;

pub const REF_IMPL_MAX_PRIVATE_KEY_SIZE: usize = REF_IMPL_SSTS_EXT_SIZE
+ HSS_COMPRESSED_USED_LEAFS_SIZE
+ REF_IMPL_MAX_ALLOWED_HSS_LEVELS
+ MAX_SEED_LEN;
pub const REF_IMPL_MAX_PRIVATE_KEY_SIZE: usize =
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;
Expand Down
14 changes: 6 additions & 8 deletions src/hss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ mod tests {
use super::parameter::HssParameter;
use crate::util::helper::test_helper::gen_random_seed;
use crate::{
constants::{HSS_COMPRESSED_USED_LEAFS_SIZE, MAX_HASH_SIZE, REF_IMPL_SSTS_EXT_SIZE},
constants::{HSS_COMPRESSED_USED_LEAFS_SIZE, MAX_HASH_SIZE, SST_SIZE},
hasher::{
sha256::{Sha256_128, Sha256_192, Sha256_256},
shake256::{Shake256_128, Shake256_192, Shake256_256},
Expand Down Expand Up @@ -348,12 +348,12 @@ mod tests {
assert_ne!(signing_key.as_slice(), signing_key_const.as_slice());

assert_eq!(
signing_key.as_slice()[..REF_IMPL_SSTS_EXT_SIZE],
signing_key_const.as_slice()[..REF_IMPL_SSTS_EXT_SIZE]
signing_key.as_slice()[..SST_SIZE],
signing_key_const.as_slice()[..SST_SIZE]
);
assert_eq!(
signing_key.as_slice()[REF_IMPL_SSTS_EXT_SIZE + HSS_COMPRESSED_USED_LEAFS_SIZE..],
signing_key_const.as_slice()[REF_IMPL_SSTS_EXT_SIZE + HSS_COMPRESSED_USED_LEAFS_SIZE..]
signing_key.as_slice()[SST_SIZE + HSS_COMPRESSED_USED_LEAFS_SIZE..],
signing_key_const.as_slice()[SST_SIZE + HSS_COMPRESSED_USED_LEAFS_SIZE..]
);
}

Expand Down Expand Up @@ -409,9 +409,7 @@ mod tests {
);
}
assert_eq!(
signing_key.as_slice()[(REF_IMPL_MAX_PRIVATE_KEY_SIZE
- REF_IMPL_SSTS_EXT_SIZE
- H::OUTPUT_SIZE as usize)..],
signing_key.as_slice()[(REF_IMPL_MAX_PRIVATE_KEY_SIZE - H::OUTPUT_SIZE as usize)..],
[0u8; H::OUTPUT_SIZE as usize],
);
}
Expand Down
14 changes: 6 additions & 8 deletions src/hss/reference_impl_private_key.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
constants::{
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, REF_IMPL_SSTS_EXT_SIZE,
SEED_CHILD_SEED, SEED_SIGNATURE_RANDOMIZER_SEED, TOPSEED_D, TOPSEED_LEN, TOPSEED_SEED,
TOPSEED_WHICH,
MAX_HASH_SIZE, MAX_SEED_LEN, REF_IMPL_MAX_PRIVATE_KEY_SIZE, SEED_CHILD_SEED,
SEED_SIGNATURE_RANDOMIZER_SEED, SST_IMPL_MAX_PRIVATE_KEY_SIZE, SST_SIZE, TOPSEED_D,
TOPSEED_LEN, TOPSEED_SEED, TOPSEED_WHICH,
},
hasher::HashChain,
hss::{definitions::HssPrivateKey, seed_derive::SeedDerive},
Expand Down Expand Up @@ -146,9 +146,7 @@ impl<H: HashChain> ReferenceImplPrivateKey<H> {

pub fn from_binary_representation(data: &[u8]) -> Result<Self, ()> {
if data.len() != REF_IMPL_MAX_PRIVATE_KEY_SIZE - MAX_SEED_LEN + H::OUTPUT_SIZE as usize
&& data.len()
!= REF_IMPL_MAX_PRIVATE_KEY_SIZE - MAX_SEED_LEN + H::OUTPUT_SIZE as usize
- REF_IMPL_SSTS_EXT_SIZE
&& data.len() != SST_IMPL_MAX_PRIVATE_KEY_SIZE - MAX_SEED_LEN + H::OUTPUT_SIZE as usize
{
// TODO/Review: why don't we just use REF_IMPL_MAX_PRIVATE_KEY_SIZE? (as in "SigningKey")?
return Err(());
Expand All @@ -157,8 +155,8 @@ impl<H: HashChain> ReferenceImplPrivateKey<H> {
let mut result = Self::default();
let mut index = 0;

if data.len() == REF_IMPL_MAX_PRIVATE_KEY_SIZE - MAX_SEED_LEN + H::OUTPUT_SIZE as usize {
let ssts_ext = read_and_advance(data, REF_IMPL_SSTS_EXT_SIZE, &mut index);
if data.len() == SST_IMPL_MAX_PRIVATE_KEY_SIZE - MAX_SEED_LEN + H::OUTPUT_SIZE as usize {
let ssts_ext = read_and_advance(data, SST_SIZE, &mut index);
result.sst_ext = SstExtension::from_slice(ssts_ext)?;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sst/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl SstExtension {
// "this returns a `Result<_, ()>`" and "use a custom `Error` type instead"
// see "Result<Self, ()>" in "hss/reference_impl_private_key.rs" -> CompressedParameterSet
pub fn from_slice(data: &[u8]) -> Result<Self, ()> {
if data.len() != constants::REF_IMPL_SSTS_EXT_SIZE {
if data.len() != constants::SST_SIZE {
return Err(());
}

Expand Down

0 comments on commit 132d5ae

Please sign in to comment.