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 ,
@@ -112,41 +105,6 @@ int __wrap_secp256k1_anti_exfil_sign(
112
105
return __real_secp256k1_anti_exfil_sign (ctx , sig , msg32 , seckey , host_data32 , recid );
113
106
}
114
107
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
108
/** Reset the SmartEEPROM configuration. */
151
109
static void _smarteeprom_reset (void )
152
110
{
@@ -298,35 +256,10 @@ static void _test_keystore_secp256k1_sign(void** state)
298
256
assert_true (_pubkeys_equal (ctx , & recovered_pubkey , & expected_pubkey ));
299
257
}
300
258
}
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
259
static void _expect_encrypt_and_store_seed (void )
323
260
{
324
261
will_return (__wrap_memory_is_initialized , false);
325
262
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
263
// For the AES IV:
331
264
will_return (__wrap_random_32_bytes , _aes_iv );
332
265
}
@@ -349,15 +282,13 @@ static void _test_keystore_create_and_unlock_twice(void** state)
349
282
_smarteeprom_reset ();
350
283
351
284
will_return (__wrap_memory_is_seeded , true);
352
- _expect_stretch (PASSWORD );
353
285
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
354
286
355
287
// Create new (different) seed.
356
288
_expect_encrypt_and_store_seed ();
357
289
assert_int_equal (keystore_encrypt_and_store_seed (_mock_seed_2 , 32 , PASSWORD ), KEYSTORE_OK );
358
290
359
291
will_return (__wrap_memory_is_seeded , true);
360
- _expect_stretch (PASSWORD );
361
292
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
362
293
}
363
294
@@ -375,7 +306,6 @@ static void _perform_some_unlocks(void)
375
306
for (int i = 0 ; i < 3 ; i ++ ) {
376
307
_reset_reset_called = false;
377
308
will_return (__wrap_memory_is_seeded , true);
378
- _expect_stretch (PASSWORD );
379
309
assert_int_equal (KEYSTORE_OK , keystore_unlock (PASSWORD , & remaining_attempts , NULL ));
380
310
assert_int_equal (remaining_attempts , MAX_UNLOCK_ATTEMPTS );
381
311
assert_false (_reset_reset_called );
@@ -402,7 +332,6 @@ static void _test_keystore_unlock(void** state)
402
332
for (int i = 1 ; i <= MAX_UNLOCK_ATTEMPTS ; i ++ ) {
403
333
_reset_reset_called = false;
404
334
will_return (__wrap_memory_is_seeded , true);
405
- _expect_stretch ("invalid password" );
406
335
assert_int_equal (
407
336
i >= MAX_UNLOCK_ATTEMPTS ? KEYSTORE_ERR_MAX_ATTEMPTS_EXCEEDED
408
337
: KEYSTORE_ERR_INCORRECT_PASSWORD ,
@@ -483,9 +412,6 @@ static void _test_keystore_create_and_store_seed(void** state)
483
412
size_t seed_len = test_sizes [i ];
484
413
// Seed random is xored with host entropy and the salted/hashed user password.
485
414
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
415
_expect_encrypt_and_store_seed ();
490
416
assert_int_equal (
491
417
keystore_create_and_store_seed (PASSWORD , host_entropy , seed_len ), KEYSTORE_OK );
0 commit comments