exchanged direct call to Miller-Rabin in mp_prime_next_prime with mp_prime_is_prime
This commit is contained in:
		
							parent
							
								
									06c8f3ec4e
								
							
						
					
					
						commit
						9b448bdc08
					
				| @ -35,7 +35,6 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) | ||||
| 
 | ||||
|    /* valid value of t? */ | ||||
|    if (t > PRIME_SIZE) { | ||||
|       puts("t > PRIME_SIZE"); | ||||
|       return MP_VAL; | ||||
|    } | ||||
| 
 | ||||
| @ -54,7 +53,6 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) | ||||
| 
 | ||||
|    /* N must be odd */ | ||||
|    if (mp_iseven(a) == MP_YES) { | ||||
|       *result = 0; | ||||
|       return MP_OKAY; | ||||
|    } | ||||
|    /* N is not a perfect square: floor(sqrt(N))^2 != N */ | ||||
| @ -62,14 +60,13 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) | ||||
|       return err; | ||||
|    } | ||||
|    if (res != 0) { | ||||
|       *result = 0; | ||||
|       return MP_OKAY; | ||||
|    } | ||||
| 
 | ||||
|    /* is the input equal to one of the primes in the table? */ | ||||
|    for (ix = 0; ix < PRIME_SIZE; ix++) { | ||||
|       if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) { | ||||
|          *result = 1; | ||||
|          *result = MP_YES; | ||||
|          return MP_OKAY; | ||||
|       } | ||||
|    } | ||||
| @ -126,14 +123,14 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result) | ||||
|    } | ||||
| //#endif
 | ||||
| // commented out for testing purposes
 | ||||
| //#ifdef LTM_USE_FROBENIUS_UNDERWOOD_TEST
 | ||||
| #ifdef LTM_USE_FROBENIUS_UNDERWOOD_TEST | ||||
|    if ((err = mp_prime_frobenius_underwood(a, &res)) != MP_OKAY) { | ||||
|       goto LBL_B; | ||||
|    } | ||||
|    if (res == MP_NO) { | ||||
|       goto LBL_B; | ||||
|    } | ||||
| //#endif
 | ||||
| #endif | ||||
| #endif | ||||
| 
 | ||||
|    /*
 | ||||
|  | ||||
| @ -24,11 +24,6 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style) | ||||
|    mp_digit res_tab[PRIME_SIZE], step, kstep; | ||||
|    mp_int   b; | ||||
| 
 | ||||
|    /* ensure t is valid */ | ||||
|    if ((t <= 0) || (t > PRIME_SIZE)) { | ||||
|       return MP_VAL; | ||||
|    } | ||||
| 
 | ||||
|    /* force positive */ | ||||
|    a->sign = MP_ZPOS; | ||||
| 
 | ||||
| @ -141,17 +136,9 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style) | ||||
|          continue; | ||||
|       } | ||||
| 
 | ||||
|       /* is this prime? */ | ||||
|       for (x = 0; x < t; x++) { | ||||
|          mp_set(&b, ltm_prime_tab[x]); | ||||
|          if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) { | ||||
|       if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) { | ||||
|          goto LBL_ERR; | ||||
|       } | ||||
|          if (res == MP_NO) { | ||||
|             break; | ||||
|          } | ||||
|       } | ||||
| 
 | ||||
|       if (res == MP_YES) { | ||||
|          break; | ||||
|       } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user