@@ -213,7 +213,8 @@ pub fn encrypt_and_store_seed(
213213
214214 hal. securechip ( ) . init_new_password ( password) ?;
215215
216- let secret = securechip:: stretch_password ( password) ?;
216+ let secret = hal. securechip ( ) . stretch_password ( password) ?;
217+
217218 let iv_rand = hal. random ( ) . random_32_bytes ( ) ;
218219 let iv: & [ u8 ; 16 ] = iv_rand. first_chunk :: < 16 > ( ) . unwrap ( ) ;
219220 let encrypted = bitbox_aes:: encrypt_with_hmac ( iv, & secret, seed) ;
@@ -243,13 +244,16 @@ fn check_retained_seed(seed: &[u8]) -> Result<(), ()> {
243244 Ok ( ( ) )
244245}
245246
246- fn get_and_decrypt_seed ( password : & str ) -> Result < zeroize:: Zeroizing < Vec < u8 > > , Error > {
247+ fn get_and_decrypt_seed (
248+ hal : & mut impl crate :: hal:: Hal ,
249+ password : & str ,
250+ ) -> Result < zeroize:: Zeroizing < Vec < u8 > > , Error > {
247251 let encrypted = bitbox02:: memory:: get_encrypted_seed_and_hmac ( ) . map_err ( |_| Error :: Memory ) ?;
248252 // Our Optiga securechip implementation fails password stretching if the password is
249253 // wrong, so it already returns an error here. The ATECC stretches the password without checking
250254 // if the password is correct, and we determine if it is correct in the seed decryption
251255 // step below.
252- let secret = securechip:: stretch_password ( password) ?;
256+ let secret = hal . securechip ( ) . stretch_password ( password) ?;
253257 let seed = match bitbox_aes:: decrypt_with_hmac ( & secret, & encrypted) {
254258 Ok ( seed) => seed,
255259 Err ( ( ) ) => return Err ( Error :: IncorrectPassword ) ,
@@ -279,7 +283,7 @@ pub fn unlock(
279283 }
280284 bitbox02:: usb_processing:: timeout_reset ( LONG_TIMEOUT ) ;
281285 bitbox02:: memory:: smarteeprom_increment_unlock_attempts ( ) ;
282- let seed = match get_and_decrypt_seed ( password) {
286+ let seed = match get_and_decrypt_seed ( hal , password) {
283287 Ok ( seed) => seed,
284288 err @ Err ( _) => {
285289 if get_remaining_unlock_attempts ( ) == 0 {
0 commit comments