|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.utils.NumberTheory
Some useful number theoretic utility methods.
Field Summary | |
static BigInteger |
ONE
BigInteger constant 1 |
static BigInteger |
TWO
BigInteger constant 2 |
static BigInteger |
ZERO
BigInteger constant 0 |
Method Summary | |
static int[] |
extGcd(int a,
int b)
Extended Euclidean algorithm for computing the greatest common divisor of two integers. |
static int |
gcd(int a,
int b)
Euclidean algorithm for computing the greatest common divisor of two integers. |
static BigInteger |
getStrongPrime(int x,
Random random)
Returns a random strong prime. |
static boolean |
hasSmallFactors(BigInteger b)
Test the given BigInteger b for small prime factors. |
static boolean |
isProbablePrime(BigInteger b)
Perform a probabilistic primality test to determine if b is prime. |
static boolean |
millerRabin(BigInteger n)
Perform the Miller-Rabin probabilistic primality test to determine if b is prime. |
static BigInteger |
nextPrime(BigInteger b)
Return the smallest prime greater than or equal to b. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final BigInteger ZERO
public static final BigInteger ONE
public static final BigInteger TWO
Method Detail |
public static int gcd(int a, int b)
public static int[] extGcd(int a, int b)
public static BigInteger nextPrime(BigInteger b)
public static BigInteger getStrongPrime(int x, Random random)
This method implements an algorithm published in RSA LABORATORIES' CryptoBytes, Volume 3, Number 1 - Spring 1997, page 9.
x
- the strength of the prime numberrandom
- the random number generator to usepublic static boolean isProbablePrime(BigInteger b)
This method can be used as drop-in replacement for the BigInteger.isProbablePrime() method offering much better performance. This is achieved by first filtering out number divisable by small primes and then using the Miller-Rabin test with tighter bounds.
This method only works for positive numbers.
hasSmallFactors(java.math.BigInteger)
,
millerRabin(java.math.BigInteger)
public static boolean millerRabin(BigInteger n)
This is basically the same algorithm as BigInteger.isProbablePrime() but uses tighter bounds for 2-80 based on the length of the number to achieve significantly better average performance.
As implemented here the algorithm was adapted from the Handbook of Applied Cryptography by Menezes, van Oorscho, and Vanstone. This method should only be used to test large positive numbers.
public static boolean hasSmallFactors(BigInteger b)
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |