@@ -4,7 +4,7 @@ use tinyvec::ArrayVec;
4
4
5
5
use crate :: {
6
6
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 ,
8
8
MAX_SSTS_SIGNING_ENTITIES ,
9
9
} ,
10
10
hasher:: HashChain ,
@@ -218,7 +218,7 @@ impl<H: HashChain> HssPublicKey<H> {
218
218
pub fn from_with_sst (
219
219
private_key : & ReferenceImplPrivateKey < H > ,
220
220
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 ] > ,
222
222
tree_identifier : & LmsTreeIdentifier ,
223
223
) -> Result < Self , ( ) > {
224
224
let sst_extension = private_key. sst_option . as_ref ( ) . ok_or ( ( ) ) ?;
@@ -229,27 +229,26 @@ impl<H: HashChain> HssPublicKey<H> {
229
229
let top_lms_parameter = parameters[ 0 ] . get_lms_parameter ( ) ;
230
230
231
231
let is_aux_data_used = aux_data. as_ref ( ) . map_or ( false , |d| hss_is_aux_data_used ( d) ) ;
232
-
233
232
let mut opt_expanded_aux_data = HssPrivateKey :: get_expanded_aux_data (
234
233
aux_data,
235
234
private_key,
236
235
top_lms_parameter,
237
236
is_aux_data_used,
238
237
) ;
239
- if opt_expanded_aux_data. as_mut ( ) . is_none ( ) {
240
- return Err ( ( ) ) ;
241
- } ;
242
238
243
239
let mut current_seed = private_key. generate_root_seed_and_lms_tree_identifier ( ) ;
244
240
current_seed
245
241
. lms_tree_identifier
246
242
. copy_from_slice ( tree_identifier) ;
247
243
248
244
// 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 ( ( ) ) ?;
249
248
for ( se_node, se_idx) in intermed_nodes. iter ( ) . zip ( 1 ..=intermed_nodes. len ( ) as u8 ) {
250
249
let si_sst_ext = SstExtension :: new ( se_idx, sst_extension. l0_top_div ( ) ) ?;
251
250
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) ;
253
252
}
254
253
255
254
// Calculate public key with the help of the aux_data containing other subtree root nodes
@@ -263,7 +262,7 @@ impl<H: HashChain> HssPublicKey<H> {
263
262
264
263
// Finalize aux_data by updating the HMAC
265
264
hss_finalize_aux_data :: < H > (
266
- opt_expanded_aux_data. as_mut ( ) . unwrap ( ) ,
265
+ opt_expanded_aux_data. as_mut ( ) . ok_or ( ( ) ) ? ,
267
266
private_key. seed . as_slice ( ) ,
268
267
) ;
269
268
0 commit comments