@@ -1846,6 +1846,33 @@ static mp_err s_fill_with_ones(mp_int *a, int size)
18461846 return err ;
18471847}
18481848
1849+ static int test_s_mp_sqr (void )
1850+ {
1851+ mp_int a , b , c ;
1852+ int i ;
1853+
1854+ DOR (mp_init_multi (& a , & b , & c , NULL ));
1855+
1856+ /* s_mp_mul() has a hardcoded branch to s_mul_comba if s_mul_comba is available,
1857+ so test another 10 just in case. */
1858+ for (i = 1 ; i < MP_MAX_COMBA + 10 ; i ++ ) {
1859+ DO (s_fill_with_ones (& a , i ));
1860+ DO (s_mp_sqr (& a , & b ));
1861+ DO (s_mp_mul (& a , & a , & c , 2 * i + 1 ));
1862+ EXPECT (mp_cmp (& b , & c ) == MP_EQ );
1863+ DO (mp_rand (& a , i ));
1864+ DO (s_mp_sqr (& a , & b ));
1865+ DO (s_mp_mul (& a , & a , & c , 2 * i + 1 ));
1866+ EXPECT (mp_cmp (& b , & c ) == MP_EQ );
1867+ }
1868+
1869+ mp_clear_multi (& a , & b , & c , NULL );
1870+ return EXIT_SUCCESS ;
1871+ LBL_ERR :
1872+ mp_clear_multi (& a , & b , & c , NULL );
1873+ return EXIT_FAILURE ;
1874+ }
1875+
18491876static int test_s_mp_sqr_comba (void )
18501877{
18511878 mp_int a , r1 , r2 ;
@@ -2373,6 +2400,7 @@ static int unit_tests(int argc, char **argv)
23732400 T1 (mp_xor , MP_XOR ),
23742401 T3 (s_mp_div_recursive , ONLY_PUBLIC_API , S_MP_DIV_RECURSIVE , S_MP_DIV_SCHOOL ),
23752402 T3 (s_mp_div_small , ONLY_PUBLIC_API , S_MP_DIV_SMALL , S_MP_DIV_SCHOOL ),
2403+ T2 (s_mp_sqr , ONLY_PUBLIC_API , S_MP_SQR ),
23762404 /* s_mp_mul_comba not (yet) testable because s_mp_mul branches to s_mp_mul_comba automatically */
23772405 T2 (s_mp_sqr_comba , ONLY_PUBLIC_API , S_MP_SQR_COMBA ),
23782406 T2 (s_mp_mul_balance , ONLY_PUBLIC_API , S_MP_MUL_BALANCE ),
0 commit comments