5 RSA_generate_key - generate RSA key pair
9 #include <openssl/rsa.h>
11 RSA *RSA_generate_key(int num, unsigned long e,
12 void (*callback)(int,int,void *), void *cb_arg);
16 RSA_generate_key() generates a key pair and returns it in a newly
17 allocated B<RSA> structure. The pseudo-random number generator must
18 be seeded prior to calling RSA_generate_key().
20 The modulus size will be B<num> bits, and the public exponent will be
21 B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
22 The exponent is an odd number, typically 3, 17 or 65537.
24 A callback function may be used to provide feedback about the
25 progress of the key generation. If B<callback> is not B<NULL>, it
26 will be called as follows:
32 While a random prime number is generated, it is called as
33 described in L<BN_generate_prime(3)|BN_generate_prime(3)>.
37 When the n-th randomly generated prime is rejected as not
38 suitable for the key, B<callback(2, n, cb_arg)> is called.
42 When a random p has been found with p-1 relatively prime to B<e>,
43 it is called as B<callback(3, 0, cb_arg)>.
47 The process is then repeated for prime q with B<callback(3, 1, cb_arg)>.
51 If key generation fails, RSA_generate_key() returns B<NULL>; the
52 error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
56 B<callback(2, x, cb_arg)> is used with two different meanings.
58 RSA_generate_key() goes into an infinite loop for illegal input values.
62 L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>,
63 L<RSA_free(3)|RSA_free(3)>
67 The B<cb_arg> argument was added in SSLeay 0.9.0.