Skip to content

Commit c27799b

Browse files
committed
WIP hss/def from_with_sst
1 parent 837ada2 commit c27799b

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/hss/definitions.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tinyvec::ArrayVec;
44

55
use crate::{
66
constants::{
7-
LmsTreeIdentifier, MAX_ALLOWED_HSS_LEVELS, MAX_HASH_SIZE, MAX_HSS_PUBLIC_KEY_LENGTH,
7+
LmsTreeIdentifier, Node, MAX_ALLOWED_HSS_LEVELS, MAX_HSS_PUBLIC_KEY_LENGTH,
88
MAX_SSTS_SIGNING_ENTITIES,
99
},
1010
hasher::HashChain,
@@ -218,7 +218,7 @@ impl<H: HashChain> HssPublicKey<H> {
218218
pub fn from_with_sst(
219219
private_key: &ReferenceImplPrivateKey<H>,
220220
aux_data: Option<&mut &mut [u8]>,
221-
intermed_nodes: &ArrayVec<[ArrayVec<[u8; MAX_HASH_SIZE]>; MAX_SSTS_SIGNING_ENTITIES]>,
221+
intermed_nodes: &ArrayVec<[Node; MAX_SSTS_SIGNING_ENTITIES]>,
222222
tree_identifier: &LmsTreeIdentifier,
223223
) -> Result<Self, ()> {
224224
let sst_extension = private_key.sst_option.as_ref().ok_or(())?;
@@ -229,27 +229,26 @@ impl<H: HashChain> HssPublicKey<H> {
229229
let top_lms_parameter = parameters[0].get_lms_parameter();
230230

231231
let is_aux_data_used = aux_data.as_ref().map_or(false, |d| hss_is_aux_data_used(d));
232-
233232
let mut opt_expanded_aux_data = HssPrivateKey::get_expanded_aux_data(
234233
aux_data,
235234
private_key,
236235
top_lms_parameter,
237236
is_aux_data_used,
238237
);
239-
if opt_expanded_aux_data.as_mut().is_none() {
240-
return Err(());
241-
};
242238

243239
let mut current_seed = private_key.generate_root_seed_and_lms_tree_identifier();
244240
current_seed
245241
.lms_tree_identifier
246242
.copy_from_slice(tree_identifier);
247243

248244
// Move intermed_nodes, i.e. other subtree root nodes, into aux_data
245+
(intermed_nodes.len() == 2usize.pow(sst_extension.l0_top_div().into()))
246+
.then_some(())
247+
.ok_or(())?;
249248
for (se_node, se_idx) in intermed_nodes.iter().zip(1..=intermed_nodes.len() as u8) {
250249
let si_sst_ext = SstExtension::new(se_idx, sst_extension.l0_top_div())?;
251250
let node_idx = get_sst_root_node_idx(top_lms_parameter, &si_sst_ext) as usize;
252-
hss_save_aux_data::<H>(opt_expanded_aux_data.as_mut().unwrap(), node_idx, se_node);
251+
hss_save_aux_data::<H>(opt_expanded_aux_data.as_mut().ok_or(())?, node_idx, se_node);
253252
}
254253

255254
// Calculate public key with the help of the aux_data containing other subtree root nodes
@@ -263,7 +262,7 @@ impl<H: HashChain> HssPublicKey<H> {
263262

264263
// Finalize aux_data by updating the HMAC
265264
hss_finalize_aux_data::<H>(
266-
opt_expanded_aux_data.as_mut().unwrap(),
265+
opt_expanded_aux_data.as_mut().ok_or(())?,
267266
private_key.seed.as_slice(),
268267
);
269268

0 commit comments

Comments
 (0)