5 RSA_generate_key_ex, RSA_generate_key,
6 RSA_generate_multi_prime_key - generate RSA key pair
10 #include <openssl/rsa.h>
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);
15 Deprecated since OpenSSL 0.9.8, can be hidden entirely by defining
16 B<OPENSSL_API_COMPAT> with a suitable version value, see
17 L<openssl_user_macros(7)>:
19 RSA *RSA_generate_key(int bits, unsigned long e,
20 void (*callback)(int, int, void *), void *cb_arg);
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().
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 random number generator must be seeded when
31 calling RSA_generate_multi_prime_key().
32 If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
33 external circumstances (see L<RAND(7)>), the operation will fail.
35 The modulus size will be of length B<bits>, the number of primes to form the
36 modulus will be B<primes>, and the public exponent will be B<e>. Key sizes
37 with B<num> E<lt> 1024 should be considered insecure. The exponent is an odd
38 number, typically 3, 17 or 65537.
40 In order to maintain adequate security level, the maximum number of permitted
41 B<primes> depends on modulus bit length:
43 <1024 | >=1024 | >=4096 | >=8192
44 ------+--------+--------+-------
47 A callback function may be used to provide feedback about the
48 progress of the key generation. If B<cb> is not B<NULL>, it
49 will be called as follows using the BN_GENCB_call() function
50 described on the L<BN_generate_prime(3)> page.
52 RSA_generate_key() is similar to RSA_generate_key_ex() but
53 expects an old-style callback function; see
54 L<BN_generate_prime(3)> for information on the old-style callback.
60 While a random prime number is generated, it is called as
61 described in L<BN_generate_prime(3)>.
65 When the n-th randomly generated prime is rejected as not
66 suitable for the key, B<BN_GENCB_call(cb, 2, n)> is called.
70 When a random p has been found with p-1 relatively prime to B<e>,
71 it is called as B<BN_GENCB_call(cb, 3, 0)>.
75 The process is then repeated for prime q and other primes (if any)
76 with B<BN_GENCB_call(cb, 3, i)> where B<i> indicates the i-th prime.
80 RSA_generate_multi_prime_key() returns 1 on success or 0 on error.
81 RSA_generate_key_ex() returns 1 on success or 0 on error.
82 The error codes can be obtained by L<ERR_get_error(3)>.
84 RSA_generate_key() returns a pointer to the RSA structure or
85 B<NULL> if the key generation fails.
89 B<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
93 L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)>,
98 RSA_generate_key() was deprecated in OpenSSL 0.9.8; use
99 RSA_generate_key_ex() instead.
103 Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
105 Licensed under the Apache License 2.0 (the "License"). You may not use
106 this file except in compliance with the License. You can obtain a copy
107 in the file LICENSE in the source distribution or at
108 L<https://www.openssl.org/source/license.html>.