1BN_generate_prime(3)                OpenSSL               BN_generate_prime(3)
2
3
4

NAME

6       BN_generate_prime_ex, BN_is_prime_ex, BN_is_prime_fasttest_ex,
7       BN_GENCB_call, BN_GENCB_set_old, BN_GENCB_set, BN_generate_prime,
8       BN_is_prime, BN_is_prime_fasttest - generate primes and test for
9       primality
10

SYNOPSIS

12        #include <openssl/bn.h>
13
14        int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add,
15            const BIGNUM *rem, BN_GENCB *cb);
16
17        int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb);
18
19        int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx,
20            int do_trial_division, BN_GENCB *cb);
21
22        int BN_GENCB_call(BN_GENCB *cb, int a, int b);
23
24        #define BN_GENCB_set_old(gencb, callback, cb_arg) ...
25
26        #define BN_GENCB_set(gencb, callback, cb_arg) ...
27
28       Deprecated:
29
30        BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add,
31            BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
32
33        int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int, int,
34            void *), BN_CTX *ctx, void *cb_arg);
35
36        int BN_is_prime_fasttest(const BIGNUM *a, int checks,
37            void (*callback)(int, int, void *), BN_CTX *ctx, void *cb_arg,
38            int do_trial_division);
39

DESCRIPTION

41       BN_generate_prime_ex() generates a pseudo-random prime number of bit
42       length bits.  If ret is not NULL, it will be used to store the number.
43
44       If cb is not NULL, it is used as follows:
45
46       ·   BN_GENCB_call(cb, 0, i) is called after generating the i-th
47           potential prime number.
48
49       ·   While the number is being tested for primality, BN_GENCB_call(cb,
50           1, j) is called as described below.
51
52       ·   When a prime has been found, BN_GENCB_call(cb, 2, i) is called.
53
54       The prime may have to fulfill additional requirements for use in
55       Diffie-Hellman key exchange:
56
57       If add is not NULL, the prime will fulfill the condition p % add == rem
58       (p % add == 1 if rem == NULL) in order to suit a given generator.
59
60       If safe is true, it will be a safe prime (i.e. a prime p so that
61       (p-1)/2 is also prime).
62
63       The PRNG must be seeded prior to calling BN_generate_prime_ex().  The
64       prime number generation has a negligible error probability.
65
66       BN_is_prime_ex() and BN_is_prime_fasttest_ex() test if the number p is
67       prime.  The following tests are performed until one of them shows that
68       p is composite; if p passes all these tests, it is considered prime.
69
70       BN_is_prime_fasttest_ex(), when called with do_trial_division == 1,
71       first attempts trial division by a number of small primes; if no
72       divisors are found by this test and cb is not NULL, BN_GENCB_call(cb,
73       1, -1) is called.  If do_trial_division == 0, this test is skipped.
74
75       Both BN_is_prime_ex() and BN_is_prime_fasttest_ex() perform a Miller-
76       Rabin probabilistic primality test with nchecks iterations. If nchecks
77       == BN_prime_checks, a number of iterations is used that yields a false
78       positive rate of at most 2^-80 for random input.
79
80       If cb is not NULL, BN_GENCB_call(cb, 1, j) is called after the j-th
81       iteration (j = 0, 1, ...). ctx is a pre-allocated BN_CTX (to save the
82       overhead of allocating and freeing the structure in a loop), or NULL.
83
84       BN_GENCB_call calls the callback function held in the BN_GENCB
85       structure and passes the ints a and b as arguments. There are two types
86       of BN_GENCB structure that are supported: "new" style and "old" style.
87       New programs should prefer the "new" style, whilst the "old" style is
88       provided for backwards compatibility purposes.
89
90       For "new" style callbacks a BN_GENCB structure should be initialised
91       with a call to BN_GENCB_set, where gencb is a BN_GENCB *, callback is
92       of type int (*callback)(int, int, BN_GENCB *) and cb_arg is a void *.
93       "Old" style callbacks are the same except they are initialised with a
94       call to BN_GENCB_set_old and callback is of type void (*callback)(int,
95       int, void *).
96
97       A callback is invoked through a call to BN_GENCB_call. This will check
98       the type of the callback and will invoke callback(a, b, gencb) for new
99       style callbacks or callback(a, b, cb_arg) for old style.
100
101       BN_generate_prime (deprecated) works in the same way as
102       BN_generate_prime_ex but expects an old style callback function
103       directly in the callback parameter, and an argument to pass to it in
104       the cb_arg. Similarly BN_is_prime and BN_is_prime_fasttest are
105       deprecated and can be compared to BN_is_prime_ex and
106       BN_is_prime_fasttest_ex respectively.
107

RETURN VALUES

109       BN_generate_prime_ex() return 1 on success or 0 on error.
110
111       BN_is_prime_ex(), BN_is_prime_fasttest_ex(), BN_is_prime() and
112       BN_is_prime_fasttest() return 0 if the number is composite, 1 if it is
113       prime with an error probability of less than 0.25^nchecks, and -1 on
114       error.
115
116       BN_generate_prime() returns the prime number on success, NULL
117       otherwise.
118
119       Callback functions should return 1 on success or 0 on error.
120
121       The error codes can be obtained by ERR_get_error(3).
122

SEE ALSO

124       bn(3), ERR_get_error(3), rand(3)
125

HISTORY

127       The cb_arg arguments to BN_generate_prime() and to BN_is_prime() were
128       added in SSLeay 0.9.0. The ret argument to BN_generate_prime() was
129       added in SSLeay 0.9.1.  BN_is_prime_fasttest() was added in OpenSSL
130       0.9.5.
131
132
133
1341.0.2o                            2020-08-01              BN_generate_prime(3)
Impressum