@@ -3879,6 +3879,9 @@ int test_wc_ecc_ecies_ctx_devid_steps(void)
38793879typedef struct EciesFindSeen {
38803880 int invoked ;
38813881 int devId ;
3882+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
3883+ int error ;
3884+ #endif
38823885} EciesFindSeen ;
38833886
38843887static int eciesFindArmed = 0 ;
@@ -3906,6 +3909,12 @@ static int myEciesFindCryptoCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
39063909 return WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
39073910 }
39083911 seen -> devId = devIdArg ;
3912+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
3913+ if (seen -> error != 0 ) {
3914+ seen -> invoked = 1 ;
3915+ return seen -> error ;
3916+ }
3917+ #endif
39093918 eciesFindArmed = 0 ;
39103919 ret = myEciesApiCryptoCb (devIdArg , info , & seen -> invoked );
39113920 eciesFindArmed = 1 ;
@@ -4018,6 +4027,42 @@ int test_wc_ecc_ecies_find_cb(void)
40184027 ExpectIntEQ (XMEMCMP (plain , msg , sizeof (msg )), 0 );
40194028 }
40204029
4030+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS ) && \
4031+ (defined(HAVE_AES_CBC ) || defined(WOLFSSL_AES_COUNTER ) || \
4032+ !defined(WOLFSSL_ECIES_GEN_IV ))
4033+ /* The finder can route a NULL context, too. Exercise both device
4034+ * errors and a successful round trip through that route. */
4035+ eciesFindArmed = 1 ;
4036+ wc_CryptoCb_SetDeviceFindCb (myEciesFindCb );
4037+ seen .error = WC_NO_ERR_TRACE (WC_HW_E );
4038+ seen .invoked = 0 ;
4039+ outSz = (word32 )sizeof (out );
4040+ ExpectIntEQ (wc_ecc_encrypt (& cliKey , & srvKey , msg , sizeof (msg ), out ,
4041+ & outSz , NULL ), WC_NO_ERR_TRACE (WC_HW_E ));
4042+ ExpectIntEQ (seen .invoked , 1 );
4043+
4044+ seen .error = 0 ;
4045+ seen .invoked = 0 ;
4046+ ExpectIntEQ (wc_ecc_encrypt (& cliKey , & srvKey , msg , sizeof (msg ), out ,
4047+ & outSz , NULL ), 0 );
4048+ ExpectIntEQ (seen .invoked , 1 );
4049+
4050+ seen .error = WC_NO_ERR_TRACE (WC_HW_E );
4051+ seen .invoked = 0 ;
4052+ plainSz = (word32 )sizeof (plain );
4053+ ExpectIntEQ (wc_ecc_decrypt (& srvKey , & cliKey , out , outSz , plain ,
4054+ & plainSz , NULL ), WC_NO_ERR_TRACE (WC_HW_E ));
4055+ ExpectIntEQ (seen .invoked , 1 );
4056+
4057+ seen .error = 0 ;
4058+ seen .invoked = 0 ;
4059+ ExpectIntEQ (wc_ecc_decrypt (& srvKey , & cliKey , out , outSz , plain ,
4060+ & plainSz , NULL ), 0 );
4061+ ExpectIntEQ (seen .invoked , 1 );
4062+ ExpectIntEQ (plainSz , sizeof (msg ));
4063+ ExpectBufEQ (plain , msg , sizeof (msg ));
4064+ #endif
4065+
40214066 wc_CryptoCb_SetDeviceFindCb (NULL );
40224067 eciesFindArmed = 0 ;
40234068 wc_ecc_ctx_free (srvCtx );
@@ -4903,6 +4948,8 @@ int test_wc_ecc_mulmod_negative(void)
49034948 WC_NO_ERR_TRACE (ECC_OUT_OF_RANGE_E ));
49044949 ExpectIntEQ (wc_ecc_mulmod (& wide , & base .pubkey , r , curve .pubkey .x ,
49054950 curve .pubkey .y , 1 ), WC_NO_ERR_TRACE (ECC_OUT_OF_RANGE_E ));
4951+ ExpectIntEQ (wc_ecc_mulmod_ex (& wide , & base .pubkey , r , curve .pubkey .x ,
4952+ curve .pubkey .y , 1 , NULL ), WC_NO_ERR_TRACE (ECC_OUT_OF_RANGE_E ));
49064953 ExpectIntEQ (wc_ecc_mulmod_ex2 (& wide , & base .pubkey , r , curve .pubkey .x ,
49074954 curve .pubkey .y , & order , NULL , 1 , NULL ),
49084955 WC_NO_ERR_TRACE (ECC_OUT_OF_RANGE_E ));
@@ -4916,12 +4963,30 @@ int test_wc_ecc_mulmod_negative(void)
49164963 ExpectIntEQ (ecc_mul2add (& base .pubkey , NULL , & base .pubkey , & five , r ,
49174964 curve .pubkey .x , curve .pubkey .y , NULL ),
49184965 WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
4966+ ExpectIntEQ (ecc_mul2add (NULL , & five , & base .pubkey , & five , r ,
4967+ curve .pubkey .x , curve .pubkey .y , NULL ),
4968+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
4969+ ExpectIntEQ (ecc_mul2add (& base .pubkey , & five , NULL , & five , r ,
4970+ curve .pubkey .x , curve .pubkey .y , NULL ),
4971+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
4972+ ExpectIntEQ (ecc_mul2add (& base .pubkey , & five , & base .pubkey , NULL , r ,
4973+ curve .pubkey .x , curve .pubkey .y , NULL ),
4974+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
4975+ ExpectIntEQ (ecc_mul2add (& base .pubkey , & five , & base .pubkey , & five , NULL ,
4976+ curve .pubkey .x , curve .pubkey .y , NULL ),
4977+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
4978+ ExpectIntEQ (ecc_mul2add (& base .pubkey , & five , & base .pubkey , & five , r ,
4979+ curve .pubkey .x , NULL , NULL ), WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
49194980 ExpectIntEQ (ecc_mul2add (& base .pubkey , & five , & base .pubkey , & five , r ,
49204981 curve .pubkey .x , curve .pubkey .y , NULL ), 0 );
49214982#endif
49224983 /* Positive scalars are still accepted. */
49234984 ExpectIntEQ (wc_ecc_mulmod (& five , & base .pubkey , r , curve .pubkey .x ,
49244985 curve .pubkey .y , 1 ), 0 );
4986+ ExpectIntEQ (wc_ecc_mulmod_ex (& five , & base .pubkey , r , curve .pubkey .x ,
4987+ curve .pubkey .y , 1 , NULL ), 0 );
4988+ ExpectIntEQ (wc_ecc_mulmod_ex2 (& five , & base .pubkey , r , curve .pubkey .x ,
4989+ curve .pubkey .y , & order , NULL , 1 , NULL ), 0 );
49254990
49264991 wc_ecc_del_point (r );
49274992 mp_free (& wide );
@@ -6105,23 +6170,6 @@ int test_wc_EccDecisionCoverage4(void)
61056170 }
61066171 ExpectIntEQ (ret , 0 );
61076172
6108- /* ---- ecc_mul2add argument guard: the uncovered-condition report 8446 ----
6109- * NOT closeable by any current variant, API or white-box: both bodies
6110- * of ecc_mul2add() (the argument-checked "normal" one at line ~8417 and
6111- * the Shamir/fixed-point-cache one at line ~13909 that supersedes it
6112- * when FP_ECC is also on) live inside an outer #ifdef ECC_SHAMIR /
6113- * #endif block (lines 8349-8701 and 13616-14035). Every one of this
6114- * module's 6 variants has ECC_SHAMIR either ON-with-FP_ECC-ON (base:
6115- * sp_default/sp_ecc/sp_ecc_nonblock/fastmath/small_stack, which
6116- * exercises the unchecked Shamir body under the name ecc_mul2add) or
6117- * turns BOTH ECC_SHAMIR and FP_ECC OFF together (no_fp_shamir, per its
6118- * config_base's philosophy of flipping the FALSE side of both feature
6119- * guards at once -- see the module registry's ecc notes), which compiles
6120- * *neither* body, making ecc_mul2add an undefined symbol there (link
6121- * failure, confirmed empirically). Reaching this decision needs a new,
6122- * not-yet-scaffolded variant: ECC_SHAMIR on + FP_ECC off. Classified as
6123- * a needs-variant residual; see RESIDUALS.md. */
6124-
61256173 /* ---- wc_ecc_ctx_set_kdf_salt: the uncovered-condition report 14607 ----
61266174 * if (ctx == NULL || (salt == NULL && sz != 0))
61276175 * ctx==NULL already the common BAD_FUNC_ARG idiom shown elsewhere; add
@@ -6143,12 +6191,26 @@ int test_wc_EccDecisionCoverage4(void)
61436191#if defined(WOLFSSL_CUSTOM_CURVES )
61446192 {
61456193 ecc_key ccKey2 ;
6194+ ecc_set_type customDp ;
6195+
61466196 XMEMSET (& ccKey2 , 0 , sizeof (ccKey2 ));
61476197 ExpectIntEQ (wc_ecc_init (& ccKey2 ), 0 );
61486198 ExpectIntEQ (wc_ecc_set_custom_curve (NULL , key .dp ),
61496199 WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
61506200 ExpectIntEQ (wc_ecc_set_custom_curve (& ccKey2 , NULL ),
61516201 WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
6202+ ExpectNotNull (key .dp );
6203+ if (EXPECT_SUCCESS ()) {
6204+ XMEMCPY (& customDp , key .dp , sizeof (customDp ));
6205+ customDp .size = 0 ;
6206+ ExpectIntEQ (wc_ecc_set_custom_curve (& ccKey2 , & customDp ),
6207+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
6208+ customDp .size = MAX_ECC_BYTES + 1 ;
6209+ ExpectIntEQ (wc_ecc_set_custom_curve (& ccKey2 , & customDp ),
6210+ WC_NO_ERR_TRACE (ECC_BAD_ARG_E ));
6211+ customDp .size = key .dp -> size ;
6212+ ExpectIntEQ (wc_ecc_set_custom_curve (& ccKey2 , & customDp ), 0 );
6213+ }
61526214 wc_ecc_free (& ccKey2 );
61536215 }
61546216#endif
0 commit comments