Module: crypto/public_key/prime

Algorithms for probabilistic random prime generation

Source:

Requires

Methods

(inner) 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 BN

Number to test

b Integer

Optional Fermat test base

Source:
Returns:
Type
boolean

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

Probabilistic primality testing

Parameters:
Name Type Description
n BN

Number to test

e BN

Optional RSA exponent to check against the prime

k Integer

Optional number of iterations of Miller-Rabin test

Source:
Returns:
Type
boolean

(async, inner) 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 BN

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, inner) randomProbablePrime(bits, e, k)

Probabilistic random number generator

Parameters:
Name Type Description
bits Integer

Bit length of the prime

e BN

Optional RSA exponent to check against the prime

k Integer

Optional number of iterations of Miller-Rabin test

Source:
Returns:

BN