-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97bc7ca
commit 880fdf0
Showing
17 changed files
with
1,128 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "tommath_private.h" | ||
#ifdef BN_MP_NEXT_SMALL_PRIME_C | ||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */ | ||
/* SPDX-License-Identifier: Unlicense */ | ||
|
||
/* | ||
* Mimics behaviour of Pari/GP's nextprime(n) | ||
* If n is prime set *result to n else set *result to first prime > n | ||
* and 0 in case of error | ||
*/ | ||
mp_err mp_next_small_prime(mp_sieve_prime n, mp_sieve_prime *result, mp_sieve *sieve) | ||
{ | ||
mp_sieve_prime ret = 0; | ||
int e = MP_OKAY; | ||
|
||
if (n < 2) { | ||
*result = 2; | ||
return e; | ||
} | ||
|
||
for (; ret == 0 && n != 0; n++) { | ||
if (n > MP_SIEVE_BIGGEST_PRIME) { | ||
return MP_SIEVE_MAX_REACHED; | ||
} | ||
/* just call mp_is_small_prime(), it does all of the heavy work */ | ||
if ((e = mp_is_small_prime(n, &ret, sieve)) != MP_OKAY) { | ||
*result = 0; | ||
return e; | ||
} | ||
} | ||
*result = n - 1; | ||
return e; | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "tommath_private.h" | ||
#ifdef BN_MP_PREC_SMALL_PRIME_C | ||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */ | ||
/* SPDX-License-Identifier: Unlicense */ | ||
|
||
/* | ||
* Mimics behaviour of Pari/GP's precprime(n) | ||
* If n is prime set *result to n else set *result to first prime < n | ||
* and 0 in case of error | ||
*/ | ||
mp_err mp_prec_small_prime(mp_sieve_prime n, mp_sieve_prime *result, mp_sieve *sieve) | ||
{ | ||
mp_sieve_prime ret = 0; | ||
int e = MP_OKAY; | ||
|
||
if (n == 2) { | ||
*result = 2; | ||
return e; | ||
} | ||
|
||
if (n < 2) { | ||
*result = 0; | ||
return e; | ||
} | ||
|
||
for (; ret == 0; n--) { | ||
if ((e = mp_is_small_prime(n, &ret, sieve)) != MP_OKAY) { | ||
*result = 0; | ||
return e; | ||
} | ||
} | ||
*result = n + 1; | ||
|
||
return e; | ||
} | ||
#endif | ||
|
Oops, something went wrong.