35
35
36
36
#define PASSWORD ("password")
37
37
38
- int __real_securechip_kdf (securechip_slot_t slot , const uint8_t * msg , size_t len , uint8_t * kdf_out );
39
- int __wrap_securechip_kdf (securechip_slot_t slot , const uint8_t * msg , size_t len , uint8_t * kdf_out )
40
- {
41
- check_expected (slot );
42
- return __real_securechip_kdf (slot , msg , len , kdf_out );
43
- }
44
-
45
38
static uint8_t _salt_root [KEYSTORE_MAX_SEED_LENGTH ] = {
46
39
0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 ,
47
40
0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x22 , 0x22 , 0x22 , 0x22 , 0x22 , 0x22 , 0x22 , 0x22 ,
@@ -64,8 +57,6 @@ static uint8_t _mock_bip39_seed[64] = {
64
57
0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x33 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 , 0x44 ,
65
58
};
66
59
67
- const uint8_t _aes_iv [32 ] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
68
-
69
60
static const uint32_t _keypath [] = {
70
61
44 + BIP32_INITIAL_HARDENED_CHILD ,
71
62
0 + BIP32_INITIAL_HARDENED_CHILD ,
@@ -112,41 +103,6 @@ int __wrap_secp256k1_anti_exfil_sign(
112
103
return __real_secp256k1_anti_exfil_sign (ctx , sig , msg32 , seckey , host_data32 , recid );
113
104
}
114
105
115
- bool __real_salt_hash_data (
116
- const uint8_t * data ,
117
- size_t data_len ,
118
- const char * purpose ,
119
- uint8_t * hash_out );
120
- bool __wrap_salt_hash_data (
121
- const uint8_t * data ,
122
- size_t data_len ,
123
- const char * purpose ,
124
- uint8_t * hash_out )
125
- {
126
- check_expected (data );
127
- check_expected (data_len );
128
- check_expected (purpose );
129
- return __real_salt_hash_data (data , data_len , purpose , hash_out );
130
- }
131
-
132
- bool __real_cipher_aes_hmac_encrypt (
133
- const unsigned char * in ,
134
- int in_len ,
135
- uint8_t * out ,
136
- int * out_len ,
137
- const uint8_t * secret );
138
-
139
- bool __wrap_cipher_aes_hmac_encrypt (
140
- const unsigned char * in ,
141
- int in_len ,
142
- uint8_t * out ,
143
- int * out_len ,
144
- const uint8_t * secret )
145
- {
146
- check_expected (secret );
147
- return __real_cipher_aes_hmac_encrypt (in , in_len , out , out_len , secret );
148
- }
149
-
150
106
/** Reset the SmartEEPROM configuration. */
151
107
static void _smarteeprom_reset (void )
152
108
{
@@ -298,37 +254,9 @@ static void _test_keystore_secp256k1_sign(void** state)
298
254
assert_true (_pubkeys_equal (ctx , & recovered_pubkey , & expected_pubkey ));
299
255
}
300
256
}
301
-
302
- static void _expect_stretch (const char * password )
303
- {
304
- expect_memory (__wrap_salt_hash_data , data , password , strlen (password ));
305
- expect_value (__wrap_salt_hash_data , data_len , strlen (password ));
306
- expect_string (__wrap_salt_hash_data , purpose , "keystore_seed_access_in" );
307
-
308
- // KDF 1
309
- expect_value (__wrap_securechip_kdf , slot , SECURECHIP_SLOT_ROLLKEY );
310
-
311
- // KDF 2
312
- expect_value (__wrap_securechip_kdf , slot , SECURECHIP_SLOT_KDF );
313
-
314
- // KDF 3
315
- expect_value (__wrap_securechip_kdf , slot , SECURECHIP_SLOT_KDF );
316
-
317
- expect_memory (__wrap_salt_hash_data , data , password , strlen (password ));
318
- expect_value (__wrap_salt_hash_data , data_len , strlen (password ));
319
- expect_string (__wrap_salt_hash_data , purpose , "keystore_seed_access_out" );
320
- }
321
-
322
257
static void _expect_encrypt_and_store_seed (void )
323
258
{
324
259
will_return (__wrap_memory_is_initialized , false);
325
-
326
- _expect_stretch (PASSWORD ); // first stretch to encrypt
327
- _expect_stretch (PASSWORD ); // second stretch to verify
328
-
329
- expect_memory (__wrap_cipher_aes_hmac_encrypt , secret , _expected_secret , 32 );
330
- // For the AES IV:
331
- will_return (__wrap_random_32_bytes , _aes_iv );
332
260
}
333
261
334
262
static void _test_keystore_encrypt_and_store_seed (void * * state )
@@ -349,15 +277,13 @@ static void _test_keystore_create_and_unlock_twice(void** state)
349
277
_smarteeprom_reset ();
350
278
351
279
will_return (__wrap_memory_is_seeded , true);
352
- _expect_stretch (PASSWORD );
353
280
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
354
281
355
282
// Create new (different) seed.
356
283
_expect_encrypt_and_store_seed ();
357
284
assert_int_equal (keystore_encrypt_and_store_seed (_mock_seed_2 , 32 , PASSWORD ), KEYSTORE_OK );
358
285
359
286
will_return (__wrap_memory_is_seeded , true);
360
- _expect_stretch (PASSWORD );
361
287
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
362
288
}
363
289
@@ -375,7 +301,6 @@ static void _perform_some_unlocks(void)
375
301
for (int i = 0 ; i < 3 ; i ++ ) {
376
302
_reset_reset_called = false;
377
303
will_return (__wrap_memory_is_seeded , true);
378
- _expect_stretch (PASSWORD );
379
304
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
380
305
assert_int_equal (remaining_attempts , MAX_UNLOCK_ATTEMPTS );
381
306
assert_false (_reset_reset_called );
@@ -402,7 +327,6 @@ static void _test_keystore_unlock(void** state)
402
327
for (int i = 1 ; i <= MAX_UNLOCK_ATTEMPTS ; i ++ ) {
403
328
_reset_reset_called = false;
404
329
will_return (__wrap_memory_is_seeded , true);
405
- _expect_stretch ("invalid password" );
406
330
assert_int_equal (
407
331
i >= MAX_UNLOCK_ATTEMPTS ? KEYSTORE_ERR_MAX_ATTEMPTS_EXCEEDED
408
332
: KEYSTORE_ERR_INCORRECT_PASSWORD ,
@@ -483,9 +407,6 @@ static void _test_keystore_create_and_store_seed(void** state)
483
407
size_t seed_len = test_sizes [i ];
484
408
// Seed random is xored with host entropy and the salted/hashed user password.
485
409
will_return (__wrap_random_32_bytes , seed_random );
486
- expect_memory (__wrap_salt_hash_data , data , PASSWORD , strlen (PASSWORD ));
487
- expect_value (__wrap_salt_hash_data , data_len , strlen (PASSWORD ));
488
- expect_string (__wrap_salt_hash_data , purpose , "keystore_seed_generation" );
489
410
_expect_encrypt_and_store_seed ();
490
411
assert_int_equal (
491
412
keystore_create_and_store_seed (PASSWORD , host_entropy , seed_len ), KEYSTORE_OK );
0 commit comments