@@ -182,7 +182,6 @@ static keystore_error_t _get_and_decrypt_seed(
182
182
const char * password ,
183
183
uint8_t * decrypted_seed_out ,
184
184
size_t * decrypted_seed_len_out ,
185
- bool * password_correct_out ,
186
185
int * securechip_result_out )
187
186
{
188
187
uint8_t encrypted_seed_and_hmac [96 ];
@@ -202,17 +201,18 @@ static keystore_error_t _get_and_decrypt_seed(
202
201
}
203
202
size_t decrypted_len = encrypted_len - 48 ;
204
203
uint8_t decrypted [decrypted_len ];
205
- * password_correct_out = cipher_aes_hmac_decrypt (
204
+ bool password_correct = cipher_aes_hmac_decrypt (
206
205
encrypted_seed_and_hmac , encrypted_len , decrypted , & decrypted_len , secret );
207
- if (* password_correct_out ) {
208
- if (!_validate_seed_length (decrypted_len )) {
209
- util_zero (decrypted , sizeof (decrypted ));
210
- return KEYSTORE_ERR_SEED_SIZE ;
211
- }
212
- * decrypted_seed_len_out = decrypted_len ;
213
- memcpy (decrypted_seed_out , decrypted , decrypted_len );
206
+ if (!password_correct ) {
207
+ return KEYSTORE_ERR_INCORRECT_PASSWORD ;
214
208
}
215
- util_zero (decrypted , sizeof (decrypted ));
209
+ if (!_validate_seed_length (decrypted_len )) {
210
+ util_zero (decrypted , sizeof (decrypted ));
211
+ return KEYSTORE_ERR_SEED_SIZE ;
212
+ }
213
+ * decrypted_seed_len_out = decrypted_len ;
214
+ memcpy (decrypted_seed_out , decrypted , decrypted_len );
215
+
216
216
return KEYSTORE_OK ;
217
217
}
218
218
@@ -224,12 +224,7 @@ static bool _verify_seed(
224
224
uint8_t decrypted_seed [KEYSTORE_MAX_SEED_LENGTH ] = {0 };
225
225
size_t seed_len ;
226
226
UTIL_CLEANUP_32 (decrypted_seed );
227
- bool password_correct = false;
228
- if (_get_and_decrypt_seed (password , decrypted_seed , & seed_len , & password_correct , NULL ) !=
229
- KEYSTORE_OK ) {
230
- return false;
231
- }
232
- if (!password_correct ) {
227
+ if (_get_and_decrypt_seed (password , decrypted_seed , & seed_len , NULL ) != KEYSTORE_OK ) {
233
228
return false;
234
229
}
235
230
if (expected_seed_len != seed_len ) {
@@ -351,13 +346,12 @@ keystore_error_t keystore_unlock(
351
346
uint8_t seed [KEYSTORE_MAX_SEED_LENGTH ] = {0 };
352
347
UTIL_CLEANUP_32 (seed );
353
348
size_t seed_len ;
354
- bool password_correct = false;
355
349
keystore_error_t result =
356
- _get_and_decrypt_seed (password , seed , & seed_len , & password_correct , securechip_result_out );
357
- if (result != KEYSTORE_OK ) {
350
+ _get_and_decrypt_seed (password , seed , & seed_len , securechip_result_out );
351
+ if (result != KEYSTORE_OK && result != KEYSTORE_ERR_INCORRECT_PASSWORD ) {
358
352
return result ;
359
353
}
360
- if (password_correct ) {
354
+ if (result == KEYSTORE_OK ) {
361
355
if (_is_unlocked_device ) {
362
356
// Already unlocked. Fail if the seed changed under our feet (should never happen).
363
357
if (seed_len != _seed_length || !MEMEQ (_retained_seed , seed , _seed_length )) {
@@ -380,7 +374,7 @@ keystore_error_t keystore_unlock(
380
374
}
381
375
382
376
* remaining_attempts_out = MAX_UNLOCK_ATTEMPTS - failed_attempts ;
383
- return password_correct ? KEYSTORE_OK : KEYSTORE_ERR_INCORRECT_PASSWORD ;
377
+ return result ;
384
378
}
385
379
386
380
bool keystore_unlock_bip39 (const char * mnemonic_passphrase )
0 commit comments