BN_GENERATE_PRIME(3) | Library Functions Manual | BN_GENERATE_PRIME(3) |

`BN_generate_prime_ex`

,
`BN_is_prime_ex`

,
`BN_is_prime_fasttest_ex`

,
`BN_GENCB_call`

,
`BN_GENCB_new`

,
`BN_GENCB_free`

,
`BN_GENCB_set_old`

,
`BN_GENCB_set`

,
`BN_GENCB_get_arg`

,
`BN_generate_prime`

,
`BN_is_prime`

,
`BN_is_prime_fasttest`

—
generate primes and test for primality

```
#include
<openssl/bn.h>
```

`BN_generate_prime_ex`

(`BN_is_prime_ex`

(`BN_is_prime_fasttest_ex`

(`BN_GENCB_call`

(`BN_GENCB_new`

(`BN_GENCB_free`

(`BN_GENCB_set_old`

(`BN_GENCB_set`

(`BN_GENCB_get_arg`

(`BN_generate_prime`

(`BN_is_prime`

(`BN_is_prime_fasttest`

(`BN_generate_prime_ex`

() generates a
pseudo-random prime number of at least bit length
`NULL`

, it will be used to store the
number.
If `NULL`

, it is used as follows:
`BN_GENCB_call`

(`cb`,`0`,`i`) is called after generating the i-th potential prime number.- While the number is being tested for primality,
`BN_GENCB_call`

(`cb`,`1`,`j`) is called as described below. - When a prime has been found,
`BN_GENCB_call`

(`cb`,`2`,`i`) is called.

`NULL`

, the prime will fulfill the condition
p % `NULL`

) in order to suit a given generator.
If `BN_is_prime_ex`

() and
`BN_is_prime_fasttest_ex`

() test if the
number `BN_is_prime_fasttest_ex`

(), when called with
`NULL`

,
`BN_is_prime_ex`

() and
`BN_is_prime_fasttest_ex`

() perform a
Miller-Rabin probabilistic primality test with
`BN_prime_checks`

, a number of iterations is
used that yields a false positive rate of at most 2^-80 for random input.
If `NULL`

,
`NULL`

.
`BN_GENCB_call`

() calls the callback function
held in the `BN_GENCB_new`

() and freed through
a call to `BN_GENCB_free`

().
For "new" style callbacks a `BN_GENCB_set`

(), where
`BN_GENCB_set_old`

() and
`BN_GENCB_call`

(). This will check the type
of the callback and will invoke
`callback`

(`callback`

(`BN_GENCB_set`

() or
`BN_GENCB_set_old`

()) using
`BN_GENCB_get_arg`

().
`BN_generate_prime`

() (deprecated) works in the
same way as `BN_generate_prime_ex`

() but
expects an old style callback function directly in the
`BN_is_prime`

() and
`BN_is_prime_fasttest`

() are deprecated and
can be compared to `BN_is_prime_ex`

() and
`BN_is_prime_fasttest_ex`

() respectively.
`BN_generate_prime_ex`

() returns 1 on success
or 0 on error.
`BN_is_prime_ex`

(),
`BN_is_prime_fasttest_ex`

(),
`BN_is_prime`

(), and
`BN_is_prime_fasttest`

() return 0 if the
number is composite, 1 if it is prime with an error probability of less than
0.25^`BN_generate_prime`

() returns the prime number
on success, `NULL`

otherwise.
`BN_GENCB_new`

() returns a pointer to a
`NULL`

otherwise.
`BN_GENCB_get_arg`

() returns the argument
previously associated with a `BN_generate_prime`

() and
`BN_is_prime`

() first appeared in SSLeay
0.5.1 and had their `BN_generate_prime`

() was added in SSLeay
0.9.1 and OpenBSD 2.6.
`BN_is_prime_fasttest`

() first appeared in
OpenSSL 0.9.5 and has been available since OpenBSD
2.7.
`BN_generate_prime_ex`

(),
`BN_is_prime_ex`

(),
`BN_is_prime_fasttest_ex`

(),
`BN_GENCB_call`

(),
`BN_GENCB_set_old`

(), and
`BN_GENCB_set`

() first appeared in OpenSSL
0.9.8 and have been available since OpenBSD 4.5.
`BN_GENCB_new`

(),
`BN_GENCB_free`

(), and
`BN_GENCB_get_arg`

() first appeared in
OpenSSL 1.1.0 and have been available since OpenBSD
6.3.March 27, 2018 | OpenBSD-current |