@@ -22,7 +22,7 @@ use crate::{
2222 utils:: init:: { init, zeroed, Init } ,
2323} ;
2424
25- type KeySetKey = [ u8 ; SYMM_KEY_LEN_BYTES ] ;
25+ pub type KeySetKey = [ u8 ; SYMM_KEY_LEN_BYTES ] ;
2626
2727#[ derive( Debug , Default , FromTLV , ToTLV ) ]
2828#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -46,27 +46,36 @@ impl KeySet {
4646 } )
4747 }
4848
49- pub fn new ( epoch_key : & [ u8 ] , compressed_id : & [ u8 ] ) -> Result < Self , Error > {
49+ pub fn new ( epoch_key : & KeySetKey , compressed_fabric_id : & u64 ) -> Result < Self , Error > {
5050 let mut ks = KeySet :: default ( ) ;
51- KeySet :: op_key_from_ipk ( epoch_key, compressed_id , & mut ks. op_key ) ?;
51+ Self :: op_key_from_ipk ( epoch_key, compressed_fabric_id , & mut ks. op_key ) ?;
5252 ks. epoch_key . copy_from_slice ( epoch_key) ;
5353 Ok ( ks)
5454 }
5555
56- fn op_key_from_ipk ( ipk : & [ u8 ] , compressed_id : & [ u8 ] , opkey : & mut [ u8 ] ) -> Result < ( ) , Error > {
56+ fn op_key_from_ipk (
57+ ipk : & KeySetKey ,
58+ compressed_fabric_id : & u64 ,
59+ opkey : & mut KeySetKey ,
60+ ) -> Result < ( ) , Error > {
5761 const GRP_KEY_INFO : [ u8 ; 13 ] = [
5862 0x47 , 0x72 , 0x6f , 0x75 , 0x70 , 0x4b , 0x65 , 0x79 , 0x20 , 0x76 , 0x31 , 0x2e , 0x30 ,
5963 ] ;
6064
61- crypto:: hkdf_sha256 ( compressed_id, ipk, & GRP_KEY_INFO , opkey)
62- . map_err ( |_| ErrorCode :: InvalidData . into ( ) )
65+ crypto:: hkdf_sha256 (
66+ & compressed_fabric_id. to_be_bytes ( ) ,
67+ ipk,
68+ & GRP_KEY_INFO ,
69+ opkey,
70+ )
71+ . map_err ( |_| ErrorCode :: InvalidData . into ( ) )
6372 }
6473
65- pub fn op_key ( & self ) -> & [ u8 ] {
74+ pub fn op_key ( & self ) -> & KeySetKey {
6675 & self . op_key
6776 }
6877
69- pub fn epoch_key ( & self ) -> & [ u8 ] {
78+ pub fn epoch_key ( & self ) -> & KeySetKey {
7079 & self . epoch_key
7180 }
7281}
0 commit comments