@@ -29,9 +29,11 @@ static unsigned long ulabs(long x)
2929static int test_trivial_stuff (void )
3030{
3131 mp_int a , b , c , d ;
32- if (mp_init_multi (& a , & b , & c , & d , NULL )!= MP_OKAY ) {
32+ mp_err e ;
33+ if ((e = mp_init_multi (& a , & b , & c , & d , NULL )) != MP_OKAY ) {
3334 return EXIT_FAILURE ;
3435 }
36+ (void )mp_error_to_string (e );
3537
3638 /* a: 0->5 */
3739 mp_set_int (& a , 5uL );
@@ -87,13 +89,48 @@ static int test_trivial_stuff(void)
8789 mp_set_int (& c , 7uL );
8890 mp_exptmod (& a , & b , & c , & d );
8991
92+ if (mp_iseven (& a ) == mp_isodd (& a )) {
93+ goto LBL_ERR ;
94+ }
95+
9096 mp_clear_multi (& a , & b , & c , & d , NULL );
9197 return EXIT_SUCCESS ;
9298LBL_ERR :
9399 mp_clear_multi (& a , & b , & c , & d , NULL );
94100 return EXIT_FAILURE ;
95101}
96102
103+ static int test_mp_fread_fwrite (void )
104+ {
105+ mp_int a , b ;
106+ mp_err e ;
107+ FILE * tmp = NULL ;
108+ if ((e = mp_init_multi (& a , & b , NULL )) != MP_OKAY ) {
109+ return EXIT_FAILURE ;
110+ }
111+
112+ mp_set_int (& a , 123456uL );
113+ tmp = tmpfile ();
114+ if ((e = mp_fwrite (& a , 64 , tmp )) != MP_OKAY ) {
115+ goto LBL_ERR ;
116+ }
117+ rewind (tmp );
118+ if ((e = mp_fread (& b , 64 , tmp )) != MP_OKAY ) {
119+ goto LBL_ERR ;
120+ }
121+ if (mp_get_int (& b ) != 123456uL ) {
122+ goto LBL_ERR ;
123+ }
124+ fclose (tmp );
125+
126+ mp_clear_multi (& a , & b , NULL );
127+ return EXIT_SUCCESS ;
128+ LBL_ERR :
129+ if (tmp != NULL ) fclose (tmp );
130+ mp_clear_multi (& a , & b , NULL );
131+ return EXIT_FAILURE ;
132+ }
133+
97134static mp_err very_random_source (void * out , size_t size )
98135{
99136 memset (out , 0xff , size );
@@ -841,7 +878,7 @@ static int test_mp_prime_is_prime(void)
841878{
842879 int ix ;
843880 mp_err err ;
844- mp_bool cnt ;
881+ mp_bool cnt , fu ;
845882
846883 mp_int a , b ;
847884 if (mp_init_multi (& a , & b , NULL )!= MP_OKAY ) {
@@ -902,6 +939,10 @@ static int test_mp_prime_is_prime(void)
902939 if (cnt == MP_NO ) {
903940 printf ("\nsub is not prime!\n" );
904941 }
942+ mp_prime_frobenius_underwood (& b , & fu );
943+ if (fu == MP_NO ) {
944+ printf ("\nfrobenius-underwood says sub is not prime!\n" );
945+ }
905946 if ((err != MP_OKAY ) || (cnt == MP_NO )) {
906947 printf ("prime tested was: " );
907948 mp_fwrite (& a ,16 ,stdout );
@@ -1823,7 +1864,7 @@ static int test_s_mp_balance_mul(void)
18231864 goto LTM_ERR ;
18241865 }
18251866
1826- if ((e = mp_mul (& a , & b , & c )) != MP_OKAY ) {
1867+ if ((e = s_mp_balance_mul (& a , & b , & c )) != MP_OKAY ) {
18271868 goto LTM_ERR ;
18281869 }
18291870
@@ -1855,6 +1896,7 @@ int unit_tests(int argc, char **argv)
18551896 T (mp_decr ),
18561897 T (mp_div_3 ),
18571898 T (mp_dr_reduce ),
1899+ T (mp_fread_fwrite ),
18581900 T (mp_get_int ),
18591901 T (mp_get_long ),
18601902 T (mp_get_long_long ),
0 commit comments