2525enum mock_mode {
2626 MOCK_OVERSIZE_PUB ,
2727 MOCK_OVERSIZE_PRIV ,
28+ MOCK_UNSEAL_OK ,
2829 MOCK_UNSEAL_OVERSIZE
2930};
3031
3132static enum mock_mode current_mode ;
3233static int nvread_calls ;
3334static int oversized_pub_read_attempted ;
3435static int oversized_priv_read_attempted ;
36+ static int forcezero_calls ;
37+ static word32 last_forcezero_len ;
3538static uint8_t test_hdr [64 ];
3639static uint8_t test_modulus [256 ];
3740static uint8_t test_exponent_der [] = { 0xAA , 0x01 , 0x00 , 0x01 , 0x7B };
@@ -217,6 +220,12 @@ TPM_RC TPM2_Unseal(Unseal_In* in, Unseal_Out* out)
217220{
218221 (void )in ;
219222
223+ if (current_mode == MOCK_UNSEAL_OK ) {
224+ out -> outData .size = 4 ;
225+ memset (out -> outData .buffer , 0x5A , out -> outData .size );
226+ return 0 ;
227+ }
228+
220229 if (current_mode != MOCK_UNSEAL_OVERSIZE ) {
221230 ck_abort_msg ("Unexpected TPM2_Unseal call in mode %d" , current_mode );
222231 }
@@ -226,6 +235,13 @@ TPM_RC TPM2_Unseal(Unseal_In* in, Unseal_Out* out)
226235 return 0 ;
227236}
228237
238+ void TPM2_ForceZero (void * mem , word32 len )
239+ {
240+ forcezero_calls ++ ;
241+ last_forcezero_len = len ;
242+ memset (mem , 0 , len );
243+ }
244+
229245int keyslot_id_by_sha (const uint8_t * pubkey_hint )
230246{
231247 (void )pubkey_hint ;
@@ -312,6 +328,8 @@ static void setup(void)
312328 nvread_calls = 0 ;
313329 oversized_pub_read_attempted = 0 ;
314330 oversized_priv_read_attempted = 0 ;
331+ forcezero_calls = 0 ;
332+ last_forcezero_len = 0 ;
315333 memset (test_hdr , 0x22 , sizeof (test_hdr ));
316334 memset (test_modulus , 0x33 , sizeof (test_modulus ));
317335}
@@ -332,6 +350,30 @@ START_TEST(test_wolfBoot_read_blob_rejects_oversized_public_area)
332350}
333351END_TEST
334352
353+ START_TEST (test_wolfBoot_unseal_blob_zeroes_unseal_output )
354+ {
355+ uint8_t secret [WOLFBOOT_MAX_SEAL_SZ ];
356+ WOLFTPM2_KEYBLOB blob ;
357+ uint8_t pubkey_hint [WOLFBOOT_SHA_DIGEST_SIZE ] = {0 };
358+ uint8_t policy [sizeof (uint32_t ) + 4 ] = {0 };
359+ int secret_sz ;
360+ int rc ;
361+
362+ memset (& blob , 0 , sizeof (blob ));
363+ memset (secret , 0 , sizeof (secret ));
364+ current_mode = MOCK_UNSEAL_OK ;
365+ secret_sz = (int )sizeof (secret );
366+
367+ rc = wolfBoot_unseal_blob (pubkey_hint , policy , sizeof (policy ), & blob ,
368+ secret , & secret_sz , NULL , 0 );
369+
370+ ck_assert_int_eq (rc , 0 );
371+ ck_assert_int_eq (secret_sz , 4 );
372+ ck_assert_int_eq (forcezero_calls , 1 );
373+ ck_assert_uint_eq (last_forcezero_len , sizeof (Unseal_Out ));
374+ }
375+ END_TEST
376+
335377START_TEST (test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity )
336378{
337379 struct {
@@ -388,6 +430,7 @@ static Suite *tpm_blob_suite(void)
388430 tcase_add_checked_fixture (tc , setup , NULL );
389431 tcase_add_test (tc , test_wolfBoot_read_blob_rejects_oversized_public_area );
390432 tcase_add_test (tc , test_wolfBoot_read_blob_rejects_oversized_private_area );
433+ tcase_add_test (tc , test_wolfBoot_unseal_blob_zeroes_unseal_output );
391434 tcase_add_test (tc , test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity );
392435 suite_add_tcase (s , tc );
393436 return s ;
0 commit comments