@@ -63,27 +63,6 @@ static bool _validate_seed_length(size_t seed_len)
6363 return seed_len == 16 || seed_len == 24 || seed_len == 32 ;
6464}
6565
66- USE_RESULT static keystore_error_t _stretch_retained_seed_encryption_key (
67- const uint8_t * encryption_key ,
68- const char * purpose_in ,
69- const char * purpose_out ,
70- uint8_t * out )
71- {
72- uint8_t salted_hashed [32 ] = {0 };
73- UTIL_CLEANUP_32 (salted_hashed );
74- if (!salt_hash_data (encryption_key , 32 , purpose_in , salted_hashed )) {
75- return KEYSTORE_ERR_SALT ;
76- }
77- if (securechip_kdf (salted_hashed , 32 , out )) {
78- return KEYSTORE_ERR_SECURECHIP ;
79- }
80- if (!salt_hash_data (encryption_key , 32 , purpose_out , salted_hashed )) {
81- return KEYSTORE_ERR_SALT ;
82- }
83- rust_hmac_sha256 (salted_hashed , sizeof (salted_hashed ), out , 32 , out );
84- return KEYSTORE_OK ;
85- }
86-
8766bool keystore_copy_seed (uint8_t * seed_out , size_t * length_out )
8867{
8968 if (!_is_unlocked_device ) {
@@ -92,11 +71,15 @@ bool keystore_copy_seed(uint8_t* seed_out, size_t* length_out)
9271
9372 uint8_t retained_seed_encryption_key [32 ] = {0 };
9473 UTIL_CLEANUP_32 (retained_seed_encryption_key );
95- if (_stretch_retained_seed_encryption_key (
96- _unstretched_retained_seed_encryption_key ,
74+ if (!rust_keystore_stretch_retained_seed_encryption_key (
75+ rust_util_bytes (
76+ _unstretched_retained_seed_encryption_key ,
77+ sizeof (_unstretched_retained_seed_encryption_key )),
9778 "keystore_retained_seed_access_in" ,
9879 "keystore_retained_seed_access_out" ,
99- retained_seed_encryption_key ) != KEYSTORE_OK ) {
80+ rust_util_bytes_mut (
81+ retained_seed_encryption_key ,
82+ sizeof (retained_seed_encryption_key )))) {
10083 return false;
10184 }
10285 size_t len = _retained_seed_encrypted_len - 48 ;
@@ -122,11 +105,15 @@ bool keystore_copy_bip39_seed(uint8_t* bip39_seed_out)
122105
123106 uint8_t retained_bip39_seed_encryption_key [32 ] = {0 };
124107 UTIL_CLEANUP_32 (retained_bip39_seed_encryption_key );
125- if (_stretch_retained_seed_encryption_key (
126- _unstretched_retained_bip39_seed_encryption_key ,
108+ if (!rust_keystore_stretch_retained_seed_encryption_key (
109+ rust_util_bytes (
110+ _unstretched_retained_bip39_seed_encryption_key ,
111+ sizeof (_unstretched_retained_bip39_seed_encryption_key )),
127112 "keystore_retained_bip39_seed_access_in" ,
128113 "keystore_retained_bip39_seed_access_out" ,
129- retained_bip39_seed_encryption_key ) != KEYSTORE_OK ) {
114+ rust_util_bytes_mut (
115+ retained_bip39_seed_encryption_key ,
116+ sizeof (retained_bip39_seed_encryption_key )))) {
130117 return false;
131118 }
132119 size_t len = _retained_bip39_seed_encrypted_len - 48 ;
@@ -266,13 +253,15 @@ USE_RESULT static keystore_error_t _retain_seed(const uint8_t* seed, size_t seed
266253#endif
267254 uint8_t retained_seed_encryption_key [32 ] = {0 };
268255 UTIL_CLEANUP_32 (retained_seed_encryption_key );
269- keystore_error_t result = _stretch_retained_seed_encryption_key (
270- _unstretched_retained_seed_encryption_key ,
256+ bool stretched = rust_keystore_stretch_retained_seed_encryption_key (
257+ rust_util_bytes (
258+ _unstretched_retained_seed_encryption_key ,
259+ sizeof (_unstretched_retained_seed_encryption_key )),
271260 "keystore_retained_seed_access_in" ,
272261 "keystore_retained_seed_access_out" ,
273- retained_seed_encryption_key );
274- if (result != KEYSTORE_OK ) {
275- return result ;
262+ rust_util_bytes_mut ( retained_seed_encryption_key , sizeof ( retained_seed_encryption_key )) );
263+ if (! stretched ) {
264+ return KEYSTORE_ERR_STRETCH_RETAINED_SEED_KEY ;
276265 }
277266 size_t len = seed_len + 64 ;
278267 if (!cipher_aes_hmac_encrypt (
@@ -299,11 +288,15 @@ USE_RESULT static bool _retain_bip39_seed(const uint8_t* bip39_seed)
299288#endif
300289 uint8_t retained_bip39_seed_encryption_key [32 ] = {0 };
301290 UTIL_CLEANUP_32 (retained_bip39_seed_encryption_key );
302- if (_stretch_retained_seed_encryption_key (
303- _unstretched_retained_bip39_seed_encryption_key ,
291+ if (!rust_keystore_stretch_retained_seed_encryption_key (
292+ rust_util_bytes (
293+ _unstretched_retained_bip39_seed_encryption_key ,
294+ sizeof (_unstretched_retained_bip39_seed_encryption_key )),
304295 "keystore_retained_bip39_seed_access_in" ,
305296 "keystore_retained_bip39_seed_access_out" ,
306- retained_bip39_seed_encryption_key ) != KEYSTORE_OK ) {
297+ rust_util_bytes_mut (
298+ retained_bip39_seed_encryption_key ,
299+ sizeof (retained_bip39_seed_encryption_key )))) {
307300 return false;
308301 }
309302 size_t len = sizeof (_retained_bip39_seed_encrypted );
0 commit comments