@@ -230,8 +230,20 @@ int wolfTPM2_PolicyRefMake(TPM_ALG_ID pcrAlg, byte* digest, word32* digestSz,
230230
231231int TPM2_GetHashDigestSize (TPMI_ALG_HASH hashAlg )
232232{
233- (void )hashAlg ;
234- return 32 ;
233+ switch (hashAlg ) {
234+ case TPM_ALG_SHA1 :
235+ return 20 ;
236+ case TPM_ALG_SHA256 :
237+ return 32 ;
238+ case TPM_ALG_SHA384 :
239+ return 48 ;
240+ case TPM_ALG_SHA512 :
241+ return 64 ;
242+ case TPM_ALG_SM3_256 :
243+ return 32 ;
244+ default :
245+ return 0 ;
246+ }
235247}
236248
237249int wolfTPM2_GetKeyTemplate_KeySeal (TPMT_PUBLIC * publicTemplate ,
@@ -568,6 +580,25 @@ START_TEST(test_wolfBoot_seal_auth_rejects_oversized_auth)
568580}
569581END_TEST
570582
583+ START_TEST (test_wolfBoot_seal_auth_rejects_negative_auth_size )
584+ {
585+ uint8_t auth [8 ] = {0 };
586+ uint8_t pubkey_hint [WOLFBOOT_SHA_DIGEST_SIZE ] = {0 };
587+ uint8_t policy [sizeof (uint32_t ) + 4 ] = {0 };
588+ uint8_t secret [8 ] = {0 };
589+ int rc ;
590+
591+ rc = wolfBoot_seal_auth (pubkey_hint , policy , sizeof (policy ), 0 ,
592+ secret , sizeof (secret ), auth , -1 );
593+
594+ ck_assert_int_eq (rc , BAD_FUNC_ARG );
595+ ck_assert_int_eq (unexpected_nvcreate_calls , 0 );
596+ ck_assert_int_eq (unexpected_nvwrite_calls , 0 );
597+ ck_assert_int_eq (unexpected_nvopen_calls , 0 );
598+ ck_assert_int_eq (unexpected_nvdelete_calls , 0 );
599+ }
600+ END_TEST
601+
571602START_TEST (test_wolfBoot_unseal_blob_zeroes_unseal_output )
572603{
573604 uint8_t secret [WOLFBOOT_MAX_SEAL_SZ ];
@@ -615,6 +646,28 @@ START_TEST(test_wolfBoot_unseal_blob_rejects_oversized_auth)
615646}
616647END_TEST
617648
649+ START_TEST (test_wolfBoot_unseal_blob_rejects_negative_auth_size )
650+ {
651+ WOLFTPM2_KEYBLOB blob ;
652+ uint8_t auth [8 ] = {0 };
653+ uint8_t secret [WOLFBOOT_MAX_SEAL_SZ ];
654+ uint8_t pubkey_hint [WOLFBOOT_SHA_DIGEST_SIZE ] = {0 };
655+ uint8_t policy [sizeof (uint32_t ) + 4 ] = {0 };
656+ int secret_sz ;
657+ int rc ;
658+
659+ memset (& blob , 0 , sizeof (blob ));
660+ memset (secret , 0 , sizeof (secret ));
661+ secret_sz = (int )sizeof (secret );
662+ current_mode = MOCK_OVERSIZE_PUB ;
663+
664+ rc = wolfBoot_unseal_blob (pubkey_hint , policy , sizeof (policy ), & blob ,
665+ secret , & secret_sz , auth , -1 );
666+
667+ ck_assert_int_eq (rc , BAD_FUNC_ARG );
668+ }
669+ END_TEST
670+
618671START_TEST (test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity )
619672{
620673 struct {
@@ -675,10 +728,12 @@ static Suite *tpm_blob_suite(void)
675728 tcase_add_test (tc , test_wolfBoot_read_blob_rejects_oversized_auth );
676729 tcase_add_test (tc , test_wolfBoot_delete_blob_rejects_oversized_auth );
677730 tcase_add_test (tc , test_wolfBoot_seal_auth_rejects_oversized_auth );
731+ tcase_add_test (tc , test_wolfBoot_seal_auth_rejects_negative_auth_size );
678732 tcase_add_test (tc , test_wolfBoot_read_blob_rejects_oversized_public_area );
679733 tcase_add_test (tc , test_wolfBoot_read_blob_rejects_oversized_private_area );
680734 tcase_add_test (tc , test_wolfBoot_unseal_blob_zeroes_unseal_output );
681735 tcase_add_test (tc , test_wolfBoot_unseal_blob_rejects_oversized_auth );
736+ tcase_add_test (tc , test_wolfBoot_unseal_blob_rejects_negative_auth_size );
682737 tcase_add_test (tc , test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity );
683738 suite_add_tcase (s , tc );
684739 return s ;
0 commit comments