1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5*b077aed3SPierre ProncheryEVP_RSA_gen,
6e71b7053SJung-uk KimRSA_generate_key_ex, RSA_generate_key,
7e71b7053SJung-uk KimRSA_generate_multi_prime_key - generate RSA key pair
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim=head1 SYNOPSIS
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim #include <openssl/rsa.h>
12e71b7053SJung-uk Kim
13*b077aed3SPierre Pronchery EVP_PKEY *EVP_RSA_gen(unsigned int bits);
14*b077aed3SPierre Pronchery
15*b077aed3SPierre ProncheryThe following functions have been deprecated since OpenSSL 3.0, and can be
16*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
17*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
18*b077aed3SPierre Pronchery
19e71b7053SJung-uk Kim int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
20e71b7053SJung-uk Kim int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
21e71b7053SJung-uk Kim
22*b077aed3SPierre ProncheryThe following function has been deprecated since OpenSSL 0.9.8, and can be
23*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
24*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
25e71b7053SJung-uk Kim
26da327cd2SJung-uk Kim RSA *RSA_generate_key(int bits, unsigned long e,
27e71b7053SJung-uk Kim                       void (*callback)(int, int, void *), void *cb_arg);
28e71b7053SJung-uk Kim
29e71b7053SJung-uk Kim=head1 DESCRIPTION
30e71b7053SJung-uk Kim
31*b077aed3SPierre ProncheryEVP_RSA_gen() generates a new RSA key pair with modulus size I<bits>.
32*b077aed3SPierre Pronchery
33*b077aed3SPierre ProncheryAll of the functions described below are deprecated.
34*b077aed3SPierre ProncheryApplications should instead use EVP_RSA_gen(), L<EVP_PKEY_Q_keygen(3)>, or
35*b077aed3SPierre ProncheryL<EVP_PKEY_keygen_init(3)> and L<EVP_PKEY_keygen(3)>.
36*b077aed3SPierre Pronchery
37e71b7053SJung-uk KimRSA_generate_key_ex() generates a 2-prime RSA key pair and stores it in the
38*b077aed3SPierre ProncheryB<RSA> structure provided in I<rsa>.
39e71b7053SJung-uk Kim
40e71b7053SJung-uk KimRSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
41*b077aed3SPierre Proncheryit in the B<RSA> structure provided in I<rsa>. The number of primes is given by
42*b077aed3SPierre Proncherythe I<primes> parameter.
43da327cd2SJung-uk KimIf the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
44da327cd2SJung-uk Kimexternal circumstances (see L<RAND(7)>), the operation will fail.
45e71b7053SJung-uk Kim
46*b077aed3SPierre ProncheryThe modulus size will be of length I<bits>, the number of primes to form the
47*b077aed3SPierre Proncherymodulus will be I<primes>, and the public exponent will be I<e>. Key sizes
48*b077aed3SPierre Proncherywith I<num> E<lt> 1024 should be considered insecure. The exponent is an odd
49e71b7053SJung-uk Kimnumber, typically 3, 17 or 65537.
50e71b7053SJung-uk Kim
51e71b7053SJung-uk KimIn order to maintain adequate security level, the maximum number of permitted
52*b077aed3SPierre ProncheryI<primes> depends on modulus bit length:
53e71b7053SJung-uk Kim
54e71b7053SJung-uk Kim   <1024 | >=1024 | >=4096 | >=8192
55e71b7053SJung-uk Kim   ------+--------+--------+-------
56e71b7053SJung-uk Kim     2   |   3    |   4    |   5
57e71b7053SJung-uk Kim
58e71b7053SJung-uk KimA callback function may be used to provide feedback about the
59*b077aed3SPierre Proncheryprogress of the key generation. If I<cb> is not NULL, it
60e71b7053SJung-uk Kimwill be called as follows using the BN_GENCB_call() function
61e71b7053SJung-uk Kimdescribed on the L<BN_generate_prime(3)> page.
62e71b7053SJung-uk Kim
63da327cd2SJung-uk KimRSA_generate_key() is similar to RSA_generate_key_ex() but
64e71b7053SJung-uk Kimexpects an old-style callback function; see
65e71b7053SJung-uk KimL<BN_generate_prime(3)> for information on the old-style callback.
66e71b7053SJung-uk Kim
67e71b7053SJung-uk Kim=over 2
68e71b7053SJung-uk Kim
69e71b7053SJung-uk Kim=item *
70e71b7053SJung-uk Kim
71e71b7053SJung-uk KimWhile a random prime number is generated, it is called as
72e71b7053SJung-uk Kimdescribed in L<BN_generate_prime(3)>.
73e71b7053SJung-uk Kim
74e71b7053SJung-uk Kim=item *
75e71b7053SJung-uk Kim
76e71b7053SJung-uk KimWhen the n-th randomly generated prime is rejected as not
77*b077aed3SPierre Proncherysuitable for the key, I<BN_GENCB_call(cb, 2, n)> is called.
78e71b7053SJung-uk Kim
79e71b7053SJung-uk Kim=item *
80e71b7053SJung-uk Kim
81*b077aed3SPierre ProncheryWhen a random p has been found with p-1 relatively prime to I<e>,
82*b077aed3SPierre Proncheryit is called as I<BN_GENCB_call(cb, 3, 0)>.
83e71b7053SJung-uk Kim
84e71b7053SJung-uk Kim=back
85e71b7053SJung-uk Kim
86e71b7053SJung-uk KimThe process is then repeated for prime q and other primes (if any)
87*b077aed3SPierre Proncherywith I<BN_GENCB_call(cb, 3, i)> where I<i> indicates the i-th prime.
88e71b7053SJung-uk Kim
89e71b7053SJung-uk Kim=head1 RETURN VALUES
90e71b7053SJung-uk Kim
91*b077aed3SPierre ProncheryEVP_RSA_gen() returns an I<EVP_PKEY> or NULL on failure.
92*b077aed3SPierre Pronchery
93e71b7053SJung-uk KimRSA_generate_multi_prime_key() returns 1 on success or 0 on error.
94e71b7053SJung-uk KimRSA_generate_key_ex() returns 1 on success or 0 on error.
95e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>.
96e71b7053SJung-uk Kim
97e71b7053SJung-uk KimRSA_generate_key() returns a pointer to the RSA structure or
98*b077aed3SPierre ProncheryNULL if the key generation fails.
99e71b7053SJung-uk Kim
100e71b7053SJung-uk Kim=head1 BUGS
101e71b7053SJung-uk Kim
102*b077aed3SPierre ProncheryI<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
103e71b7053SJung-uk Kim
104e71b7053SJung-uk Kim=head1 SEE ALSO
105e71b7053SJung-uk Kim
106*b077aed3SPierre ProncheryL<EVP_PKEY_Q_keygen(3)>
107*b077aed3SPierre ProncheryL<BN_generate_prime(3)>, L<ERR_get_error(3)>,
108*b077aed3SPierre ProncheryL<RAND_bytes(3)>, L<RAND(7)>
109e71b7053SJung-uk Kim
110e71b7053SJung-uk Kim=head1 HISTORY
111e71b7053SJung-uk Kim
112*b077aed3SPierre ProncheryEVP_RSA_gen() was added in OpenSSL 3.0.
113*b077aed3SPierre ProncheryAll other functions described here were deprecated in OpenSSL 3.0.
114*b077aed3SPierre ProncheryFor replacement see L<EVP_PKEY-RSA(7)>.
115e71b7053SJung-uk Kim
116e71b7053SJung-uk Kim=head1 COPYRIGHT
117e71b7053SJung-uk Kim
118*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
119e71b7053SJung-uk Kim
120*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
121e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
122e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
123e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
124e71b7053SJung-uk Kim
125e71b7053SJung-uk Kim=cut
126