@@ -319,7 +319,7 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr)
319319 }
320320}
321321
322-
322+ #if defined( WOLFBOOT_SIGN_ECC256 )
323323int wc_ecc_init (ecc_key * key ) {
324324 if (ecc_init_fail )
325325 return -1 ;
@@ -348,7 +348,9 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
348348 * res = 1 ;
349349 return 0 ;
350350}
351+ #endif
351352
353+ #if defined(WOLFBOOT_SIGN_ECC256 )
352354START_TEST (test_verify_signature )
353355{
354356 uint8_t pubkey [32 ];
@@ -382,6 +384,60 @@ START_TEST(test_verify_signature)
382384 ck_assert_int_eq (verify_called , 1 );
383385}
384386END_TEST
387+ #endif
388+
389+ #if defined(WOLFBOOT_SIGN_RSA2048 ) || defined(WOLFBOOT_SIGN_RSA3072 ) || \
390+ defined(WOLFBOOT_SIGN_RSA4096 ) || defined(WOLFBOOT_SIGN_SECONDARY_RSA2048 ) || \
391+ defined(WOLFBOOT_SIGN_SECONDARY_RSA3072 ) || \
392+ defined(WOLFBOOT_SIGN_SECONDARY_RSA4096 )
393+ int wc_InitRsaKey (RsaKey * key , void * heap )
394+ {
395+ (void )key ;
396+ (void )heap ;
397+ return 0 ;
398+ }
399+
400+ int wc_FreeRsaKey (RsaKey * key )
401+ {
402+ (void )key ;
403+ return 0 ;
404+ }
405+
406+ int wc_RsaPublicKeyDecode (const byte * input , word32 * inOutIdx , RsaKey * key ,
407+ word32 inSz )
408+ {
409+ (void )input ;
410+ (void )inOutIdx ;
411+ (void )key ;
412+ (void )inSz ;
413+ return 0 ;
414+ }
415+
416+ int wc_RsaSSL_VerifyInline (byte * in , word32 inLen , byte * * out , RsaKey * key )
417+ {
418+ (void )in ;
419+ (void )inLen ;
420+ (void )out ;
421+ (void )key ;
422+ return 0 ;
423+ }
424+
425+ START_TEST (test_decode_asn1_tag_start_bounds )
426+ {
427+ uint8_t * input = malloc (1 );
428+ int idx = 0 ;
429+ volatile int input_sz = 1 ;
430+ int tag_len = -1 ;
431+
432+ ck_assert_ptr_nonnull (input );
433+ input [0 ] = ASN_SEQUENCE | ASN_CONSTRUCTED ;
434+
435+ ck_assert_int_eq (DecodeAsn1Tag (input , input_sz , & idx , & tag_len ,
436+ ASN_SEQUENCE | ASN_CONSTRUCTED ), -1 );
437+ free (input );
438+ }
439+ END_TEST
440+ #endif
385441
386442
387443START_TEST (test_sha_ops )
@@ -517,6 +573,7 @@ START_TEST(test_headers)
517573 ck_assert_uint_eq (sz , test_img_len - 256 );
518574}
519575
576+ #if defined(WOLFBOOT_SIGN_ECC256 )
520577START_TEST (test_verify_authenticity )
521578{
522579 struct wolfBoot_image test_img ;
@@ -583,6 +640,7 @@ START_TEST(test_verify_authenticity_bad_siglen)
583640 ck_assert_int_eq (ret , -1 );
584641}
585642END_TEST
643+ #endif
586644
587645START_TEST (test_verify_integrity )
588646{
@@ -683,11 +741,35 @@ Suite *wolfboot_suite(void)
683741 /* Suite initialization */
684742 Suite * s = suite_create ("wolfBoot" );
685743
744+ #if defined(WOLFBOOT_SIGN_ECC256 )
686745 TCase * tcase_verify_signature = tcase_create ("verify_signature" );
687746 tcase_set_timeout (tcase_verify_signature , 20 );
688747 tcase_add_test (tcase_verify_signature , test_verify_signature );
689748 suite_add_tcase (s , tcase_verify_signature );
749+ #endif
750+
751+ #if defined(WOLFBOOT_SIGN_RSA2048 ) || defined(WOLFBOOT_SIGN_RSA3072 ) || \
752+ defined(WOLFBOOT_SIGN_RSA4096 ) || defined(WOLFBOOT_SIGN_SECONDARY_RSA2048 ) || \
753+ defined(WOLFBOOT_SIGN_SECONDARY_RSA3072 ) || \
754+ defined(WOLFBOOT_SIGN_SECONDARY_RSA4096 )
755+ TCase * tcase_rsa_asn1 = tcase_create ("rsa_asn1" );
756+ tcase_set_timeout (tcase_rsa_asn1 , 20 );
757+ tcase_add_test (tcase_rsa_asn1 , test_decode_asn1_tag_start_bounds );
758+ suite_add_tcase (s , tcase_rsa_asn1 );
759+ #endif
760+
761+ #if defined(WOLFBOOT_SIGN_ECC256 )
762+ TCase * tcase_verify_authenticity = tcase_create ("verify_authenticity" );
763+ tcase_set_timeout (tcase_verify_authenticity , 20 );
764+ tcase_add_test (tcase_verify_authenticity , test_verify_authenticity );
765+ tcase_add_test (tcase_verify_authenticity , test_verify_authenticity_bad_siglen );
766+ suite_add_tcase (s , tcase_verify_authenticity );
767+ #endif
690768
769+ #if !defined(WOLFBOOT_SIGN_RSA2048 ) && !defined(WOLFBOOT_SIGN_RSA3072 ) && \
770+ !defined(WOLFBOOT_SIGN_RSA4096 ) && !defined(WOLFBOOT_SIGN_SECONDARY_RSA2048 ) && \
771+ !defined(WOLFBOOT_SIGN_SECONDARY_RSA3072 ) && \
772+ !defined(WOLFBOOT_SIGN_SECONDARY_RSA4096 )
691773 TCase * tcase_sha_ops = tcase_create ("sha_ops" );
692774 tcase_set_timeout (tcase_sha_ops , 20 );
693775 tcase_add_test (tcase_sha_ops , test_sha_ops );
@@ -698,12 +780,6 @@ Suite *wolfboot_suite(void)
698780 tcase_add_test (tcase_headers , test_headers );
699781 suite_add_tcase (s , tcase_headers );
700782
701- TCase * tcase_verify_authenticity = tcase_create ("verify_authenticity" );
702- tcase_set_timeout (tcase_verify_authenticity , 20 );
703- tcase_add_test (tcase_verify_authenticity , test_verify_authenticity );
704- tcase_add_test (tcase_verify_authenticity , test_verify_authenticity_bad_siglen );
705- suite_add_tcase (s , tcase_verify_authenticity );
706-
707783 TCase * tcase_verify_integrity = tcase_create ("verify_integrity" );
708784 tcase_set_timeout (tcase_verify_integrity , 20 );
709785 tcase_add_test (tcase_verify_integrity , test_verify_integrity );
@@ -713,6 +789,7 @@ Suite *wolfboot_suite(void)
713789 tcase_set_timeout (tcase_open_image , 20 );
714790 tcase_add_test (tcase_open_image , test_open_image );
715791 suite_add_tcase (s , tcase_open_image );
792+ #endif
716793 return s ;
717794}
718795
0 commit comments