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