xref: /freebsd/crypto/openssl/doc/man3/RSA_generate_key.pod (revision da327cd22e88f26f6cab9d4c45805b512139aa11)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimRSA_generate_key_ex, RSA_generate_key,
6e71b7053SJung-uk KimRSA_generate_multi_prime_key - generate RSA key pair
7e71b7053SJung-uk Kim
8e71b7053SJung-uk Kim=head1 SYNOPSIS
9e71b7053SJung-uk Kim
10e71b7053SJung-uk Kim #include <openssl/rsa.h>
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
13e71b7053SJung-uk Kim int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
14e71b7053SJung-uk Kim
15e71b7053SJung-uk KimDeprecated:
16e71b7053SJung-uk Kim
17e71b7053SJung-uk Kim #if OPENSSL_API_COMPAT < 0x00908000L
18*da327cd2SJung-uk Kim RSA *RSA_generate_key(int bits, unsigned long e,
19e71b7053SJung-uk Kim                       void (*callback)(int, int, void *), void *cb_arg);
20e71b7053SJung-uk Kim #endif
21e71b7053SJung-uk Kim
22e71b7053SJung-uk Kim=head1 DESCRIPTION
23e71b7053SJung-uk Kim
24e71b7053SJung-uk KimRSA_generate_key_ex() generates a 2-prime RSA key pair and stores it in the
25e71b7053SJung-uk KimB<RSA> structure provided in B<rsa>. The pseudo-random number generator must
26e71b7053SJung-uk Kimbe seeded prior to calling RSA_generate_key_ex().
27e71b7053SJung-uk Kim
28e71b7053SJung-uk KimRSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
29e71b7053SJung-uk Kimit in the B<RSA> structure provided in B<rsa>. The number of primes is given by
30*da327cd2SJung-uk Kimthe B<primes> parameter. The random number generator must be seeded when
31*da327cd2SJung-uk Kimcalling RSA_generate_multi_prime_key().
32*da327cd2SJung-uk KimIf the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
33*da327cd2SJung-uk Kimexternal circumstances (see L<RAND(7)>), the operation will fail.
34e71b7053SJung-uk Kim
35e71b7053SJung-uk KimThe modulus size will be of length B<bits>, the number of primes to form the
36e71b7053SJung-uk Kimmodulus will be B<primes>, and the public exponent will be B<e>. Key sizes
37e71b7053SJung-uk Kimwith B<num> E<lt> 1024 should be considered insecure. The exponent is an odd
38e71b7053SJung-uk Kimnumber, typically 3, 17 or 65537.
39e71b7053SJung-uk Kim
40e71b7053SJung-uk KimIn order to maintain adequate security level, the maximum number of permitted
41e71b7053SJung-uk KimB<primes> depends on modulus bit length:
42e71b7053SJung-uk Kim
43e71b7053SJung-uk Kim   <1024 | >=1024 | >=4096 | >=8192
44e71b7053SJung-uk Kim   ------+--------+--------+-------
45e71b7053SJung-uk Kim     2   |   3    |   4    |   5
46e71b7053SJung-uk Kim
47e71b7053SJung-uk KimA callback function may be used to provide feedback about the
48e71b7053SJung-uk Kimprogress of the key generation. If B<cb> is not B<NULL>, it
49e71b7053SJung-uk Kimwill be called as follows using the BN_GENCB_call() function
50e71b7053SJung-uk Kimdescribed on the L<BN_generate_prime(3)> page.
51e71b7053SJung-uk Kim
52*da327cd2SJung-uk KimRSA_generate_key() is similar to RSA_generate_key_ex() but
53e71b7053SJung-uk Kimexpects an old-style callback function; see
54e71b7053SJung-uk KimL<BN_generate_prime(3)> for information on the old-style callback.
55e71b7053SJung-uk Kim
56e71b7053SJung-uk Kim=over 2
57e71b7053SJung-uk Kim
58e71b7053SJung-uk Kim=item *
59e71b7053SJung-uk Kim
60e71b7053SJung-uk KimWhile a random prime number is generated, it is called as
61e71b7053SJung-uk Kimdescribed in L<BN_generate_prime(3)>.
62e71b7053SJung-uk Kim
63e71b7053SJung-uk Kim=item *
64e71b7053SJung-uk Kim
65e71b7053SJung-uk KimWhen the n-th randomly generated prime is rejected as not
66e71b7053SJung-uk Kimsuitable for the key, B<BN_GENCB_call(cb, 2, n)> is called.
67e71b7053SJung-uk Kim
68e71b7053SJung-uk Kim=item *
69e71b7053SJung-uk Kim
70e71b7053SJung-uk KimWhen a random p has been found with p-1 relatively prime to B<e>,
71e71b7053SJung-uk Kimit is called as B<BN_GENCB_call(cb, 3, 0)>.
72e71b7053SJung-uk Kim
73e71b7053SJung-uk Kim=back
74e71b7053SJung-uk Kim
75e71b7053SJung-uk KimThe process is then repeated for prime q and other primes (if any)
76e71b7053SJung-uk Kimwith B<BN_GENCB_call(cb, 3, i)> where B<i> indicates the i-th prime.
77e71b7053SJung-uk Kim
78e71b7053SJung-uk Kim=head1 RETURN VALUES
79e71b7053SJung-uk Kim
80e71b7053SJung-uk KimRSA_generate_multi_prime_key() returns 1 on success or 0 on error.
81e71b7053SJung-uk KimRSA_generate_key_ex() returns 1 on success or 0 on error.
82e71b7053SJung-uk KimThe error codes can be obtained by L<ERR_get_error(3)>.
83e71b7053SJung-uk Kim
84e71b7053SJung-uk KimRSA_generate_key() returns a pointer to the RSA structure or
85e71b7053SJung-uk KimB<NULL> if the key generation fails.
86e71b7053SJung-uk Kim
87e71b7053SJung-uk Kim=head1 BUGS
88e71b7053SJung-uk Kim
89e71b7053SJung-uk KimB<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
90e71b7053SJung-uk Kim
91e71b7053SJung-uk Kim=head1 SEE ALSO
92e71b7053SJung-uk Kim
93*da327cd2SJung-uk KimL<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)>,
94*da327cd2SJung-uk KimL<RAND(7)>
95e71b7053SJung-uk Kim
96e71b7053SJung-uk Kim=head1 HISTORY
97e71b7053SJung-uk Kim
98e71b7053SJung-uk KimRSA_generate_key() was deprecated in OpenSSL 0.9.8; use
99e71b7053SJung-uk KimRSA_generate_key_ex() instead.
100e71b7053SJung-uk Kim
101e71b7053SJung-uk Kim=head1 COPYRIGHT
102e71b7053SJung-uk Kim
103*da327cd2SJung-uk KimCopyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
104e71b7053SJung-uk Kim
105e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
106e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
107e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
108e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
109e71b7053SJung-uk Kim
110e71b7053SJung-uk Kim=cut
111