xref: /onnv-gate/usr/src/common/openssl/doc/crypto/RSA_generate_key.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=head1 NAME
4*2175Sjp161948
5*2175Sjp161948RSA_generate_key - generate RSA key pair
6*2175Sjp161948
7*2175Sjp161948=head1 SYNOPSIS
8*2175Sjp161948
9*2175Sjp161948 #include <openssl/rsa.h>
10*2175Sjp161948
11*2175Sjp161948 RSA *RSA_generate_key(int num, unsigned long e,
12*2175Sjp161948    void (*callback)(int,int,void *), void *cb_arg);
13*2175Sjp161948
14*2175Sjp161948=head1 DESCRIPTION
15*2175Sjp161948
16*2175Sjp161948RSA_generate_key() generates a key pair and returns it in a newly
17*2175Sjp161948allocated B<RSA> structure. The pseudo-random number generator must
18*2175Sjp161948be seeded prior to calling RSA_generate_key().
19*2175Sjp161948
20*2175Sjp161948The modulus size will be B<num> bits, and the public exponent will be
21*2175Sjp161948B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22*2175Sjp161948The exponent is an odd number, typically 3, 17 or 65537.
23*2175Sjp161948
24*2175Sjp161948A callback function may be used to provide feedback about the
25*2175Sjp161948progress of the key generation. If B<callback> is not B<NULL>, it
26*2175Sjp161948will be called as follows:
27*2175Sjp161948
28*2175Sjp161948=over 4
29*2175Sjp161948
30*2175Sjp161948=item *
31*2175Sjp161948
32*2175Sjp161948While a random prime number is generated, it is called as
33*2175Sjp161948described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
34*2175Sjp161948
35*2175Sjp161948=item *
36*2175Sjp161948
37*2175Sjp161948When the n-th randomly generated prime is rejected as not
38*2175Sjp161948suitable for the key, B<callback(2, n, cb_arg)> is called.
39*2175Sjp161948
40*2175Sjp161948=item *
41*2175Sjp161948
42*2175Sjp161948When a random p has been found with p-1 relatively prime to B<e>,
43*2175Sjp161948it is called as B<callback(3, 0, cb_arg)>.
44*2175Sjp161948
45*2175Sjp161948=back
46*2175Sjp161948
47*2175Sjp161948The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
48*2175Sjp161948
49*2175Sjp161948=head1 RETURN VALUE
50*2175Sjp161948
51*2175Sjp161948If key generation fails, RSA_generate_key() returns B<NULL>; the
52*2175Sjp161948error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
53*2175Sjp161948
54*2175Sjp161948=head1 BUGS
55*2175Sjp161948
56*2175Sjp161948B<callback(2, x, cb_arg)> is used with two different meanings.
57*2175Sjp161948
58*2175Sjp161948RSA_generate_key() goes into an infinite loop for illegal input values.
59*2175Sjp161948
60*2175Sjp161948=head1 SEE ALSO
61*2175Sjp161948
62*2175Sjp161948L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
63*2175Sjp161948L<RSA_free(3)|RSA_free(3)>
64*2175Sjp161948
65*2175Sjp161948=head1 HISTORY
66*2175Sjp161948
67*2175Sjp161948The B<cb_arg> argument was added in SSLeay 0.9.0.
68*2175Sjp161948
69*2175Sjp161948=cut
70