Class Primes
- Namespace
- Org.BouncyCastle.Math
- Assembly
- BouncyCastle.Cryptography.dll
Utility methods for generating primes and testing for primality.
public static class Primes
- Inheritance
-
Primes
- Inherited Members
Fields
SmallFactorLimit
public static readonly int SmallFactorLimit
Field Value
Methods
EnhancedMRProbablePrimeTest(BigInteger, SecureRandom, int)
FIPS 186-4 C.3.2 Enhanced Miller-Rabin Probabilistic Primality Test.
public static Primes.MROutput EnhancedMRProbablePrimeTest(BigInteger candidate, SecureRandom random, int iterations)
Parameters
candidateBigIntegerThe BigInteger instance to test for primality.
randomSecureRandomThe source of randomness to use to choose bases.
iterationsintThe number of randomly-chosen bases to perform the test for.
Returns
- Primes.MROutput
An Primes.MROutput instance that can be further queried for details.
Remarks
Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases. This is an alternative to IsMRProbablePrime(BigInteger, SecureRandom, int) that provides more information about a composite candidate, which may be useful when generating or validating RSA moduli.
GenerateSTRandomPrime(IDigest, int, byte[])
FIPS 186-4 C.6 Shawe-Taylor Random_Prime Routine.
public static Primes.STOutput GenerateSTRandomPrime(IDigest hash, int length, byte[] inputSeed)
Parameters
hashIDigestThe IDigest instance to use (as "Hash()"). Cannot be null.
lengthintThe length (in bits) of the prime to be generated. Must be at least 2.
inputSeedbyte[]The seed to be used for the generation of the requested prime. Cannot be null or empty.
Returns
- Primes.STOutput
An Primes.STOutput instance containing the requested prime.
Remarks
Construct a provable prime number using a hash function.
HasAnySmallFactors(BigInteger)
A fast check for small divisors, up to some implementation-specific limit.
public static bool HasAnySmallFactors(BigInteger candidate)
Parameters
candidateBigIntegerThe BigInteger instance to test for division by small factors.
Returns
- bool
trueif the candidate is found to have any small factors,falseotherwise.
IsMRProbablePrime(BigInteger, SecureRandom, int)
FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test.
public static bool IsMRProbablePrime(BigInteger candidate, SecureRandom random, int iterations)
Parameters
candidateBigIntegerThe BigInteger instance to test for primality.
randomSecureRandomThe source of randomness to use to choose bases.
iterationsintThe number of randomly-chosen bases to perform the test for.
Returns
- bool
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).
Remarks
Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases.
IsMRProbablePrimeToBase(BigInteger, BigInteger)
FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test (to a fixed base).
public static bool IsMRProbablePrimeToBase(BigInteger candidate, BigInteger baseValue)
Parameters
candidateBigIntegerThe BigInteger instance to test for primality.
baseValueBigIntegerThe base value to use for this iteration.
Returns
- bool
falseifbaseValueis a witness to compositeness (socandidateis definitely NOT prime), or elsetrue.
Remarks
Run a single iteration of the Miller-Rabin algorithm against the specified base.