Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 5 | RSA_generate_key_ex, RSA_generate_key, |
| 6 | RSA_generate_multi_prime_key - generate RSA key pair |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 7 | |
| 8 | =head1 SYNOPSIS |
| 9 | |
| 10 | #include <openssl/rsa.h> |
| 11 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 12 | int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 13 | int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb); |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 14 | |
| 15 | Deprecated: |
| 16 | |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 17 | #if OPENSSL_API_COMPAT < 0x00908000L |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 18 | RSA *RSA_generate_key(int num, unsigned long e, |
Beat Bolli | e9b7724 | 2017-01-20 19:58:49 +0100 | [diff] [blame] | 19 | void (*callback)(int, int, void *), void *cb_arg); |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 20 | #endif |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 21 | |
| 22 | =head1 DESCRIPTION |
| 23 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 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 |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 26 | be seeded prior to calling RSA_generate_key_ex(). |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 27 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 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. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 37 | |
Andy Polyakov | 3bded9c | 2017-11-24 22:45:45 +0100 | [diff] [blame] | 38 | In order to maintain adequate security level, the maximum number of permitted |
| 39 | B<primes> depends on modulus bit length: |
| 40 | |
| 41 | <1024 | >=1024 | >=4096 | >=8192 |
| 42 | ------+--------+--------+------- |
| 43 | 2 | 3 | 4 | 5 |
| 44 | |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 45 | A callback function may be used to provide feedback about the |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 46 | progress of the key generation. If B<cb> is not B<NULL>, it |
| 47 | will be called as follows using the BN_GENCB_call() function |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 48 | described on the L<BN_generate_prime(3)> page. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 49 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 50 | RSA_generate_prime() is similar to RSA_generate_prime_ex() but |
| 51 | expects an old-style callback function; see |
| 52 | L<BN_generate_prime(3)> for information on the old-style callback. |
| 53 | |
Rich Salz | 2f61bc2 | 2017-04-07 13:37:47 -0400 | [diff] [blame] | 54 | =over 2 |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 55 | |
| 56 | =item * |
| 57 | |
| 58 | While a random prime number is generated, it is called as |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 59 | described in L<BN_generate_prime(3)>. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 60 | |
| 61 | =item * |
| 62 | |
| 63 | When the n-th randomly generated prime is rejected as not |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 64 | suitable for the key, B<BN_GENCB_call(cb, 2, n)> is called. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 65 | |
| 66 | =item * |
| 67 | |
| 68 | When a random p has been found with p-1 relatively prime to B<e>, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 69 | it is called as B<BN_GENCB_call(cb, 3, 0)>. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 70 | |
| 71 | =back |
| 72 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 73 | The process is then repeated for prime q and other primes (if any) |
| 74 | with B<BN_GENCB_call(cb, 3, i)> where B<i> indicates the i-th prime. |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 75 | |
Paul Yang | 1f13ad3 | 2017-12-25 17:50:39 +0800 | [diff] [blame] | 76 | =head1 RETURN VALUES |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 77 | |
Paul Yang | 665d899 | 2017-08-02 02:19:43 +0800 | [diff] [blame] | 78 | RSA_generate_multi_prime_key() returns 1 on success or 0 on error. |
Rich Salz | bb6c5e7 | 2017-02-05 10:29:22 -0500 | [diff] [blame] | 79 | RSA_generate_key_ex() returns 1 on success or 0 on error. |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 80 | The error codes can be obtained by L<ERR_get_error(3)>. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 81 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 82 | RSA_generate_key() returns a pointer to the RSA structure or |
| 83 | B<NULL> if the key generation fails. |
| 84 | |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 85 | =head1 BUGS |
| 86 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 87 | B<BN_GENCB_call(cb, 2, x)> is used with two different meanings. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 88 | |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 89 | =head1 SEE ALSO |
| 90 | |
Andy Polyakov | 3bded9c | 2017-11-24 22:45:45 +0100 | [diff] [blame] | 91 | L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)> |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 92 | |
| 93 | =head1 HISTORY |
| 94 | |
| 95 | RSA_generate_key() was deprecated in OpenSSL 0.9.8; use |
| 96 | RSA_generate_key_ex() intsead. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 97 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 98 | =head1 COPYRIGHT |
| 99 | |
Paul Yang | 61f805c | 2018-01-16 01:01:46 +0800 | [diff] [blame] | 100 | Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 101 | |
| 102 | Licensed under the OpenSSL license (the "License"). You may not use |
| 103 | this file except in compliance with the License. You can obtain a copy |
| 104 | in the file LICENSE in the source distribution or at |
| 105 | L<https://www.openssl.org/source/license.html>. |
| 106 | |
| 107 | =cut |