@@ -256,6 +256,66 @@ static const byte wb_spc_zdigest[32] = {
256256 #define WB_SPC_HAVE_CHECK_KEY
257257#endif
258258
259+ #if (defined(WOLFSSL_SP_X86_64_ASM ) || !defined(WOLFSSL_SP_ASM )) && \
260+ !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
261+ static int wb_spc_range_failed ;
262+ #define WB_SPC_RANGE_FAILED wb_spc_range_failed
263+
264+ static void wb_spc_check_point_range (int bits , const ecc_point * g ,
265+ const mp_int * prime , mp_int * other ,
266+ int (* is_point )(const mp_int * , const mp_int * ))
267+ {
268+ int xRet ;
269+ int yRet ;
270+ const int rangeErr = WC_NO_ERR_TRACE (ECC_OUT_OF_RANGE_E );
271+
272+ /* Raw import screens out wide ordinates before this SP entry point. */
273+ if (mp_2expt (other , bits ) != MP_OKAY || mp_count_bits (prime ) != bits ) {
274+ printf (" [wb][FAIL] P-%d point range test setup\n" , bits );
275+ wb_spc_range_failed = 1 ;
276+ return ;
277+ }
278+
279+ xRet = is_point (other , g -> y );
280+ yRet = is_point (g -> x , other );
281+ if (xRet != rangeErr || yRet != rangeErr ) {
282+ printf (" [wb][FAIL] P-%d wide point range (X: %d, Y: %d)\n" ,
283+ bits , xRet , yRet );
284+ wb_spc_range_failed = 1 ;
285+ }
286+
287+ xRet = is_point (prime , g -> y );
288+ yRet = is_point (g -> x , prime );
289+ if (xRet != rangeErr || yRet != rangeErr ) {
290+ printf (" [wb][FAIL] P-%d field prime range (X: %d, Y: %d)\n" ,
291+ bits , xRet , yRet );
292+ wb_spc_range_failed = 1 ;
293+ }
294+
295+ #ifdef WOLFSSL_SP_INT_NEGATIVE
296+ if (mp_set (other , 1 ) != MP_OKAY ) {
297+ printf (" [wb][FAIL] P-%d signed point range test setup\n" , bits );
298+ wb_spc_range_failed = 1 ;
299+ return ;
300+ }
301+ mp_setneg (other );
302+ xRet = is_point (other , g -> y );
303+ yRet = is_point (g -> x , other );
304+ if (xRet != rangeErr || yRet != rangeErr ) {
305+ printf (" [wb][FAIL] P-%d signed point range (X: %d, Y: %d)\n" ,
306+ bits , xRet , yRet );
307+ wb_spc_range_failed = 1 ;
308+ }
309+ #endif
310+ }
311+
312+ #define WB_SPC_POINT_RANGE (BITS ) \
313+ wb_spc_check_point_range(BITS, &key.pubkey, &modv, &bigv, \
314+ sp_ecc_is_point_##BITS);
315+ #else
316+ #define WB_SPC_POINT_RANGE (BITS )
317+ #endif
318+
259319#define WB_SPC_DEFINE_CURVE (BITS , SZ , CURVE_ID , AMOK ) \
260320static void wb_spc_ecc_##BITS(void) \
261321{ \
@@ -344,6 +404,7 @@ static void wb_spc_ecc_##BITS(void) \
344404 /* A real point, so the on-curve test passes and everything \
345405 * behind it runs for the first time. */ \
346406 (void )sp_ecc_is_point_ ##BITS (key.pubkey.x, key.pubkey.y); \
407+ WB_SPC_POINT_RANGE(BITS) \
347408 } \
348409 \
349410 WB_SPC_CHECK_KEY_BODY(BITS) \
@@ -572,6 +633,10 @@ static void wb_spc_ecc_all(void)
572633}
573634#endif
574635
636+ #ifndef WB_SPC_RANGE_FAILED
637+ #define WB_SPC_RANGE_FAILED 0
638+ #endif
639+
575640/* ======================================================================= *
576641 * RSA / DH / ModExp: argument-range guards and the two data-dependent
577642 * shapes inside sp_DhExp_<n>.
0 commit comments