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