Package org.bouncycastle.math
Class Primes
- java.lang.Object
 - 
- org.bouncycastle.math.Primes
 
 
- 
public abstract class Primes extends java.lang.ObjectUtility methods for generating primes and testing for primality. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPrimes.MROutputUsed to return the output from the Enhanced Miller-Rabin Probabilistic Primality Teststatic classPrimes.STOutputUsed to return the output from the Shawe-Taylor Random_Prime Routine 
- 
Field Summary
Fields Modifier and Type Field Description static intSMALL_FACTOR_LIMIT 
- 
Constructor Summary
Constructors Constructor Description Primes() 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Primes.MROutputenhancedMRProbablePrimeTest(java.math.BigInteger candidate, java.security.SecureRandom random, int iterations)FIPS 186-4 C.3.2 Enhanced Miller-Rabin Probabilistic Primality Test Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases.static Primes.STOutputgenerateSTRandomPrime(Digest hash, int length, byte[] inputSeed)FIPS 186-4 C.6 Shawe-Taylor Random_Prime Routine Construct a provable prime number using a hash function.static booleanhasAnySmallFactors(java.math.BigInteger candidate)A fast check for small divisors, up to some implementation-specific limit.static booleanisMRProbablePrime(java.math.BigInteger candidate, java.security.SecureRandom random, int iterations)FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases.static booleanisMRProbablePrimeToBase(java.math.BigInteger candidate, java.math.BigInteger base)FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test (to a fixed base). 
 - 
 
- 
- 
Field Detail
- 
SMALL_FACTOR_LIMIT
public static final int SMALL_FACTOR_LIMIT
- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
generateSTRandomPrime
public static Primes.STOutput generateSTRandomPrime(Digest hash, int length, byte[] inputSeed)
FIPS 186-4 C.6 Shawe-Taylor Random_Prime Routine Construct a provable prime number using a hash function.- Parameters:
 hash- theDigestinstance to use (as "Hash()"). Cannot be null.length- the length (in bits) of the prime to be generated. Must be at least 2.inputSeed- the seed to be used for the generation of the requested prime. Cannot be null or empty.- Returns:
 - an 
Primes.STOutputinstance containing the requested prime. 
 
- 
enhancedMRProbablePrimeTest
public static Primes.MROutput enhancedMRProbablePrimeTest(java.math.BigInteger candidate, java.security.SecureRandom random, int iterations)
FIPS 186-4 C.3.2 Enhanced Miller-Rabin Probabilistic Primality Test Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases. This is an alternative toisMRProbablePrime(BigInteger, SecureRandom, int)that provides more information about a composite candidate, which may be useful when generating or validating RSA moduli.- Parameters:
 candidate- theBigIntegerinstance to test for primality.random- the source of randomness to use to choose bases.iterations- the number of randomly-chosen bases to perform the test for.- Returns:
 - an 
Primes.MROutputinstance that can be further queried for details. 
 
- 
hasAnySmallFactors
public static boolean hasAnySmallFactors(java.math.BigInteger candidate)
A fast check for small divisors, up to some implementation-specific limit.- Parameters:
 candidate- theBigIntegerinstance to test for division by small factors.- Returns:
 trueif the candidate is found to have any small factors,falseotherwise.
 
- 
isMRProbablePrime
public static boolean isMRProbablePrime(java.math.BigInteger candidate, java.security.SecureRandom random, int iterations)FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases.- Parameters:
 candidate- theBigIntegerinstance to test for primality.random- the source of randomness to use to choose bases.iterations- the number of randomly-chosen bases to perform the test for.- Returns:
 falseif any witness to compositeness is found amongst the chosen bases (socandidateis definitely NOT prime), or elsetrue(indicating primality with some probability dependent on the number of iterations that were performed).
 
- 
isMRProbablePrimeToBase
public static boolean isMRProbablePrimeToBase(java.math.BigInteger candidate, java.math.BigInteger base)FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test (to a fixed base). Run a single iteration of the Miller-Rabin algorithm against the specified base.- Parameters:
 candidate- theBigIntegerinstance to test for primality.base- the base value to use for this iteration.- Returns:
 falseif the specified base is a witness to compositeness (socandidateis definitely NOT prime), or elsetrue.
 
 - 
 
 -