Update all links so they will be rendered better.
[openssl.git] / doc / crypto / BN_generate_prime.pod
1 =pod
2
3 =head1 NAME
4
5 BN_generate_prime, BN_is_prime - Generate primes and test for primality
6
7 =head1 SYNOPSIS
8
9  #include <openssl/bn.h>
10
11  BIGNUM *BN_generate_prime(BIGNUM *ret, int num, int safe, BIGNUM *add,
12      BIGNUM *rem, void (*callback)(int, int, void *), void *cb_arg);
13
14  int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int, int, 
15      void *), BN_CTX *ctx, void *cb_arg);
16
17 =head1 DESCRIPTION
18
19 BN_generate_prime() generates a pseudo-random prime number of B<num>
20 bits.
21 If B<ret> is not NULL, it will be used to store the number.
22
23 If B<callback> is not B<NULL>, it is called as follows:
24
25 =over 4
26
27 =item *
28
29 B<callback(0, i, cb_arg)> is called after generating the i-th
30 potential prime number.
31
32 =item *
33
34 While the number is being tested for primality, B<callback(1, j,
35 cb_arg)> is called as described below.
36
37 =item *
38
39 When a prime has been found, B<callback(2, i, cb_arg)> is called.
40
41 =back
42
43 The prime may have to fulfill additional requirements for use in
44 Diffie-Hellman key exchange:
45
46 If B<add> is not NULL, the prime will fulfill the condition p % B<add>
47 == B<rem> (p % B<add> == 1 if B<rem> == NULL) in order to suit a given
48 generator.
49
50 If B<safe> is true, it will be a safe prime (i.e. a prime p so
51 that (p-1)/2 is also prime).
52
53 The PRNG must be seeded prior to calling BN_generate_prime().
54 The prime number generation has a negligible error probability.
55
56 BN_is_prime() tests if the number B<a> is prime. This is done by
57 performing a Miller-Rabin probabilistic primality test with B<checks>
58 iterations. If B<checks == BN_prime_check>, it uses a number
59 of iterations that yields a false positive rate of at most 2^-80 for
60 random input.
61
62 If B<callback> is not B<NULL>, B<callback(1, j, cb_arg)> is called
63 after the j-th iteration. B<ctx> is a pre-allocated B<BN_CTX> (to save
64 the overhead of allocating and freeing the structure in a loop), or
65 NULL.
66
67 =head1 RETURN VALUES
68
69 BN_generate_prime() returns the prime number on success, NULL otherwise.
70
71 BN_is_prime() returns 0 if the number is composite, 1 if it is
72 prime with an error probability of less than 0.25^B<checks>, and
73 -1 on error.
74
75 The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
76
77 =head1 SEE ALSO
78
79 L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>
80
81 =head1 HISTORY
82
83 The B<cb_arg> arguments to BN_generate_prime() and to BN_is_prime()
84 were added in SSLeay 0.9.0. The B<ret> argument to BN_generate_prime()
85 was added in SSLeay 0.9.1.
86
87 =cut