Module: crypto/public_key/prime

Algorithms for probabilistic random prime generation

Source:

Methods

(static) fermat(n, b) → {boolean}

Tests whether n is probably prime or not using Fermat's test with b = 2. Fails if b^(n-1) mod n != 1.

Parameters:
Name Type Description
n BigInteger

Number to test

b BigInteger

Optional Fermat test base

Source:
Returns:
Type
boolean

(async, static) isProbablePrime(n, e, k) → {boolean}

Probabilistic primality testing

Parameters:
Name Type Description
n BigInteger

Number to test

e BigInteger

Optional RSA exponent to check against the prime

k Integer

Optional number of iterations of Miller-Rabin test

Source:
Returns:
Type
boolean

(async, static) millerRabin(n, k, rand) → {boolean}

Tests whether n is probably prime or not using the Miller-Rabin test. See HAC Remark 4.28.

Parameters:
Name Type Description
n BigInteger

Number to test

k Integer

Optional number of iterations of Miller-Rabin test

rand function

Optional function to generate potential witnesses

Source:
Returns:
Type
boolean

(async, static) randomProbablePrime(bits, e, k)

Generate a probably prime random number

Parameters:
Name Type Description
bits Integer

Bit length of the prime

e BigInteger

Optional RSA exponent to check against the prime

k Integer

Optional number of iterations of Miller-Rabin test

Source:
Returns:

BigInteger