# Module: crypto/public_key/prime

Algorithms for probabilistic random prime generation

Source:
  - crypto/public_key/prime.js, line 18

### 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:
  - crypto/public_key/prime.js, line 95

##### 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:
  - crypto/public_key/prime.js, line 70

##### 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:
  - crypto/public_key/prime.js, line 232

##### 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:
  - crypto/public_key/prime.js, line 33

##### Returns:

BigInteger