From b9bee0898aed28bfaf560f85cd63d1534813c257 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 25 Apr 2014 00:37:28 +0000 Subject: Any fixed MR iterations is probably wrong for somebody. Allow the user to specify a probability as well as if n was randomly chosen or not. If the input is random use a better bounds to reduce the number of needed tests. --- src/lib/math/numbertheory/numthry.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/lib/math/numbertheory/numthry.h') diff --git a/src/lib/math/numbertheory/numthry.h b/src/lib/math/numbertheory/numthry.h index cb73356b2..5499ff76f 100644 --- a/src/lib/math/numbertheory/numthry.h +++ b/src/lib/math/numbertheory/numthry.h @@ -126,9 +126,24 @@ size_t BOTAN_DLL low_zero_bits(const BigInt& x); * Check for primality * @param n a positive integer to test for primality * @param rng a random number generator +* @param prob chance of false positive is bounded by 1/2**prob +* @param is_random true if n was randomly chosen by us * @return true if all primality tests passed, otherwise false */ -bool BOTAN_DLL check_prime(const BigInt& n, RandomNumberGenerator& rng); +bool BOTAN_DLL is_prime(const BigInt& n, + RandomNumberGenerator& rng, + size_t prob = 56, + bool is_random = false); + +inline bool quick_check_prime(const BigInt& n, RandomNumberGenerator& rng) + { return is_prime(n, rng, 32); } + +inline bool check_prime(const BigInt& n, RandomNumberGenerator& rng) + { return is_prime(n, rng, 56); } + +inline bool verify_prime(const BigInt& n, RandomNumberGenerator& rng) + { return is_prime(n, rng, 80); } + /** * Randomly generate a prime -- cgit v1.2.3