work a bit on code coverage
This commit is contained in:
		
							parent
							
								
									d32e7a3dd0
								
							
						
					
					
						commit
						c4501e1eb5
					
				
							
								
								
									
										43
									
								
								demo/demo.c
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								demo/demo.c
									
									
									
									
									
								
							@ -165,6 +165,26 @@ int main(void)
 | 
				
			|||||||
   printf("MP_PREC: %d\n", MP_PREC);
 | 
					   printf("MP_PREC: %d\n", MP_PREC);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if LTM_DEMO_TEST_VS_MTEST == 0
 | 
					#if LTM_DEMO_TEST_VS_MTEST == 0
 | 
				
			||||||
 | 
					   // trivial stuff
 | 
				
			||||||
 | 
					   mp_set_int(&a, 5);
 | 
				
			||||||
 | 
					   mp_neg(&a, &b);
 | 
				
			||||||
 | 
					   if (mp_cmp(&a, &b) != MP_GT) {
 | 
				
			||||||
 | 
					      return EXIT_FAILURE;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					   if (mp_cmp(&b, &a) != MP_LT) {
 | 
				
			||||||
 | 
					      return EXIT_FAILURE;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					   mp_neg(&a, &a);
 | 
				
			||||||
 | 
					   if (mp_cmp(&b, &a) != MP_EQ) {
 | 
				
			||||||
 | 
					      return EXIT_FAILURE;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					   mp_abs(&a, &b);
 | 
				
			||||||
 | 
					   if (mp_isneg(&b) != MP_NO) {
 | 
				
			||||||
 | 
					      return EXIT_FAILURE;
 | 
				
			||||||
 | 
					   }
 | 
				
			||||||
 | 
					   mp_add_d(&a, 1, &b);
 | 
				
			||||||
 | 
					   mp_add_d(&a, 6, &b);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   // test montgomery
 | 
					   // test montgomery
 | 
				
			||||||
   printf("Testing: montgomery...\n");
 | 
					   printf("Testing: montgomery...\n");
 | 
				
			||||||
   for (i = 1; i < 10; i++) {
 | 
					   for (i = 1; i < 10; i++) {
 | 
				
			||||||
@ -279,7 +299,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      if (mp_cmp_mag (&b, &c) != MP_EQ) {
 | 
					      if (mp_cmp_mag (&b, &c) != MP_EQ) {
 | 
				
			||||||
         printf ("mp_sqrt() bad result!\n");
 | 
					         printf ("mp_sqrt() bad result!\n");
 | 
				
			||||||
	 return 1;
 | 
					         return EXIT_FAILURE;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -334,10 +354,9 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
   for (ix = 10; ix < 128; ix++) {
 | 
					   for (ix = 10; ix < 128; ix++) {
 | 
				
			||||||
      printf ("Testing (not safe-prime): %9d bits    \r", ix);
 | 
					      printf ("Testing (not safe-prime): %9d bits    \r", ix);
 | 
				
			||||||
      fflush (stdout);
 | 
					      fflush (stdout);
 | 
				
			||||||
      err =
 | 
					      err = mp_prime_random_ex (&a, 8, ix,
 | 
				
			||||||
	 mp_prime_random_ex(&a, 8, ix,
 | 
					                                (rand () & 1) ? 0 : LTM_PRIME_2MSB_ON, myrng,
 | 
				
			||||||
			    (rand() & 1) ? 0 : LTM_PRIME_2MSB_ON,
 | 
					                                NULL);
 | 
				
			||||||
				myrng, NULL);
 | 
					 | 
				
			||||||
      if (err != MP_OKAY) {
 | 
					      if (err != MP_OKAY) {
 | 
				
			||||||
         printf ("failed with err code %d\n", err);
 | 
					         printf ("failed with err code %d\n", err);
 | 
				
			||||||
         return EXIT_FAILURE;
 | 
					         return EXIT_FAILURE;
 | 
				
			||||||
@ -352,9 +371,8 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
   for (ix = 16; ix < 128; ix++) {
 | 
					   for (ix = 16; ix < 128; ix++) {
 | 
				
			||||||
      printf ("Testing (    safe-prime): %9d bits    \r", ix);
 | 
					      printf ("Testing (    safe-prime): %9d bits    \r", ix);
 | 
				
			||||||
      fflush (stdout);
 | 
					      fflush (stdout);
 | 
				
			||||||
      err =
 | 
					      err = mp_prime_random_ex (
 | 
				
			||||||
	 mp_prime_random_ex(&a, 8, ix,
 | 
					            &a, 8, ix, ((rand () & 1) ? 0 : LTM_PRIME_2MSB_ON) | LTM_PRIME_SAFE,
 | 
				
			||||||
			    ((rand() & 1) ? 0 : LTM_PRIME_2MSB_ON) | LTM_PRIME_SAFE,
 | 
					 | 
				
			||||||
            myrng, NULL);
 | 
					            myrng, NULL);
 | 
				
			||||||
      if (err != MP_OKAY) {
 | 
					      if (err != MP_OKAY) {
 | 
				
			||||||
         printf ("failed with err code %d\n", err);
 | 
					         printf ("failed with err code %d\n", err);
 | 
				
			||||||
@ -414,7 +432,6 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
      mp_2expt (&a, cnt);
 | 
					      mp_2expt (&a, cnt);
 | 
				
			||||||
      mp_sub_d (&a, 2, &a); /* a = 2**cnt - 2 */
 | 
					      mp_sub_d (&a, 2, &a); /* a = 2**cnt - 2 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
      printf ("\r %4d bits", cnt);
 | 
					      printf ("\r %4d bits", cnt);
 | 
				
			||||||
      printf ("(%d)", mp_reduce_is_2k (&a));
 | 
					      printf ("(%d)", mp_reduce_is_2k (&a));
 | 
				
			||||||
      mp_reduce_2k_setup (&a, &tmp);
 | 
					      mp_reduce_2k_setup (&a, &tmp);
 | 
				
			||||||
@ -430,7 +447,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
         mp_reduce_2k (&b, &a, 2);
 | 
					         mp_reduce_2k (&b, &a, 2);
 | 
				
			||||||
         if (mp_cmp (&c, &b)) {
 | 
					         if (mp_cmp (&c, &b)) {
 | 
				
			||||||
            printf ("FAILED\n");
 | 
					            printf ("FAILED\n");
 | 
				
			||||||
	    exit(0);
 | 
					            return EXIT_FAILURE;
 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
@ -482,12 +499,12 @@ printf("compare no compare!\n"); return EXIT_FAILURE; }
 | 
				
			|||||||
         mp_copy (&b, &c);
 | 
					         mp_copy (&b, &c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         mp_mod (&b, &a, &b);
 | 
					         mp_mod (&b, &a, &b);
 | 
				
			||||||
	 mp_dr_reduce(&c, &a, (((mp_digit) 1) << DIGIT_BIT) - a.dp[0]);
 | 
					         mp_dr_setup(&a, &mp),
 | 
				
			||||||
 | 
					         mp_dr_reduce (&c, &a, mp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         if (mp_cmp (&b, &c) != MP_EQ) {
 | 
					         if (mp_cmp (&b, &c) != MP_EQ) {
 | 
				
			||||||
            printf ("Failed on trial %u\n", rr);
 | 
					            printf ("Failed on trial %u\n", rr);
 | 
				
			||||||
	    exit(-1);
 | 
					            return EXIT_FAILURE;
 | 
				
			||||||
 | 
					 | 
				
			||||||
         }
 | 
					         }
 | 
				
			||||||
      } while (++rr < 500);
 | 
					      } while (++rr < 500);
 | 
				
			||||||
      printf (" passed");
 | 
					      printf (" passed");
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
#include <tommath.h>
 | 
					#include <tommath.h>
 | 
				
			||||||
#include <time.h>
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ulong64 _tt;
 | 
					ulong64 _tt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user