6e8e50c0ca705e5b9c96bc8f1f0521834efb4c89
[openssl.git] / doc / man3 / RSA_generate_key.pod
1 =pod
2
3 =head1 NAME
4
5 RSA_generate_key_ex, RSA_generate_key,
6 RSA_generate_multi_prime_key - generate RSA key pair
7
8 =head1 SYNOPSIS
9
10  #include <openssl/rsa.h>
11
12  int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
13  int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
14
15 Deprecated:
16
17  #if OPENSSL_API_COMPAT < 0x00908000L
18  RSA *RSA_generate_key(int num, unsigned long e,
19                        void (*callback)(int, int, void *), void *cb_arg);
20  #endif
21
22 =head1 DESCRIPTION
23
24 RSA_generate_key_ex() generates a 2-prime RSA key pair and stores it in the
25 B<RSA> structure provided in B<rsa>. The pseudo-random number generator must
26 be seeded prior to calling RSA_generate_key_ex().
27
28 RSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
29 it in the B<RSA> structure provided in B<rsa>. The number of primes is given by
30 the B<primes> parameter. The pseudo-random number generator must be seeded prior
31 to calling RSA_generate_multi_prime_key().
32
33 The modulus size will be of length B<bits>, the number of primes to form the
34 modulus will be B<primes>, and the public exponent will be B<e>. Key sizes
35 with B<num> E<lt> 1024 should be considered insecure. The exponent is an odd
36 number, typically 3, 17 or 65537.
37
38 A callback function may be used to provide feedback about the
39 progress of the key generation. If B<cb> is not B<NULL>, it
40 will be called as follows using the BN_GENCB_call() function
41 described on the L<BN_generate_prime(3)> page.
42
43 RSA_generate_prime() is similar to RSA_generate_prime_ex() but
44 expects an old-style callback function; see
45 L<BN_generate_prime(3)> for information on the old-style callback.
46
47 =over 2
48
49 =item *
50
51 While a random prime number is generated, it is called as
52 described in L<BN_generate_prime(3)>.
53
54 =item *
55
56 When the n-th randomly generated prime is rejected as not
57 suitable for the key, B<BN_GENCB_call(cb, 2, n)> is called.
58
59 =item *
60
61 When a random p has been found with p-1 relatively prime to B<e>,
62 it is called as B<BN_GENCB_call(cb, 3, 0)>.
63
64 =back
65
66 The process is then repeated for prime q and other primes (if any)
67 with B<BN_GENCB_call(cb, 3, i)> where B<i> indicates the i-th prime.
68
69 =head1 RETURN VALUE
70
71 RSA_generate_multi_prime_key() returns 1 on success or 0 on error.
72 RSA_generate_key_ex() returns 1 on success or 0 on error.
73 The error codes can be obtained by L<ERR_get_error(3)>.
74
75 RSA_generate_key() returns a pointer to the RSA structure or
76 B<NULL> if the key generation fails.
77
78 =head1 BUGS
79
80 B<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
81
82 =head1 SEE ALSO
83
84 L<ERR_get_error(3)>, L<RAND_bytes(3)>,
85 L<RSA_generate_key_ex(3)>, L<BN_generate_prime(3)>
86
87 =head1 HISTORY
88
89 RSA_generate_key() was deprecated in OpenSSL 0.9.8; use
90 RSA_generate_key_ex() intsead.
91
92 =head1 COPYRIGHT
93
94 Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
95
96 Licensed under the OpenSSL license (the "License").  You may not use
97 this file except in compliance with the License.  You can obtain a copy
98 in the file LICENSE in the source distribution or at
99 L<https://www.openssl.org/source/license.html>.
100
101 =cut