Top Description Fields Constructors Methods
org.bouncycastle.tls.crypto.impl.jcajce

pack-priv abstract Class Primes

extends Object
Class Inheritance
Imports
java.math.BigInteger, java.security.SecureRandom, org.bouncycastle.util.BigIntegers

Utility methods for generating primes and testing for primality.

Field Summary

Modifier and TypeField and Description
private static final BigInteger
private static final BigInteger

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
public static boolean

Returns:

true if the candidate is found to have any small factors, false otherwise.
hasAnySmallFactors
(BigInteger
the BigInteger instance to test for division by small factors.
candidate
)

A fast check for small divisors, up to some implementation-specific limit.

private static boolean
private static boolean
public static boolean

Returns:

false if any witness to compositeness is found amongst the chosen bases (so candidate is definitely NOT prime), or else true (indicating primality with some probability dependent on the number of iterations that were performed).
isMRProbablePrime
(BigInteger
the BigInteger instance to test for primality.
candidate
,
SecureRandom
the source of randomness to use to choose bases.
random
,
int
the number of randomly-chosen bases to perform the test for.
iterations
)

FIPS 186-4 C.3.1 Miller-Rabin Probabilistic Primality Test Run several iterations of the Miller-Rabin algorithm with randomly-chosen bases.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ONEback to summary
private static final BigInteger ONE
TWOback to summary
private static final BigInteger TWO

Constructor Detail

Primesback to summary
pack-priv Primes()

Method Detail

checkCandidateback to summary
private static void checkCandidate(BigInteger n, String name)
hasAnySmallFactorsback to summary
public static boolean hasAnySmallFactors(BigInteger candidate)

A fast check for small divisors, up to some implementation-specific limit.

Parameters
candidate:BigInteger

the BigInteger instance to test for division by small factors.

Returns:boolean

true if the candidate is found to have any small factors, false otherwise.

implHasAnySmallFactorsback to summary
private static boolean implHasAnySmallFactors(BigInteger x)
implMRProbablePrimeToBaseback to summary
private static boolean implMRProbablePrimeToBase(BigInteger w, BigInteger wSubOne, BigInteger m, int a, BigInteger b)
isMRProbablePrimeback to summary
public static boolean isMRProbablePrime(BigInteger candidate, 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:BigInteger

the BigInteger instance to test for primality.

random:SecureRandom

the source of randomness to use to choose bases.

iterations:int

the number of randomly-chosen bases to perform the test for.

Returns:boolean

false if any witness to compositeness is found amongst the chosen bases (so candidate is definitely NOT prime), or else true (indicating primality with some probability dependent on the number of iterations that were performed).