Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 5 | RSA_generate_key_ex, RSA_generate_key - generate RSA key pair |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
| 9 | #include <openssl/rsa.h> |
| 10 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 11 | int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); |
| 12 | |
| 13 | Deprecated: |
| 14 | |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 15 | #if OPENSSL_API_COMPAT < 0x00908000L |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 16 | RSA *RSA_generate_key(int num, unsigned long e, |
Rich Salz | aebb9aa | 2016-07-19 09:27:53 -0400 | [diff] [blame] | 17 | void (*callback)(int, int, void *), void *cb_arg); |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 18 | #endif |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 19 | |
| 20 | =head1 DESCRIPTION |
| 21 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 22 | RSA_generate_key_ex() generates a key pair and stores it in the B<RSA> |
| 23 | structure provided in B<rsa>. The pseudo-random number generator must |
| 24 | be seeded prior to calling RSA_generate_key_ex(). |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 25 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 26 | The modulus size will be of length B<bits>, and the public exponent will be |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 27 | B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure. |
Ulf Möller | 592c0e0 | 2002-04-13 09:58:50 +0000 | [diff] [blame] | 28 | The exponent is an odd number, typically 3, 17 or 65537. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 29 | |
| 30 | A callback function may be used to provide feedback about the |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 31 | progress of the key generation. If B<cb> is not B<NULL>, it |
| 32 | will be called as follows using the BN_GENCB_call() function |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 33 | described on the L<BN_generate_prime(3)> page. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 34 | |
| 35 | =over 4 |
| 36 | |
| 37 | =item * |
| 38 | |
| 39 | While a random prime number is generated, it is called as |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 40 | described in L<BN_generate_prime(3)>. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 41 | |
| 42 | =item * |
| 43 | |
| 44 | When the n-th randomly generated prime is rejected as not |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 45 | 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] | 46 | |
| 47 | =item * |
| 48 | |
| 49 | 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] | 50 | it is called as B<BN_GENCB_call(cb, 3, 0)>. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 51 | |
| 52 | =back |
| 53 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 54 | The process is then repeated for prime q with B<BN_GENCB_call(cb, 3, 1)>. |
| 55 | |
Rich Salz | bb6c5e7 | 2017-02-05 10:29:22 -0500 | [diff] [blame] | 56 | RSA_generate_key() is deprecated (new applications should use |
| 57 | RSA_generate_key_ex() instead). RSA_generate_key() works in the same way as |
| 58 | RSA_generate_key_ex() except it uses "old style" call backs. See |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 59 | L<BN_generate_prime(3)> for further details. |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 60 | |
Ulf Möller | 60b5245 | 2000-01-21 17:50:27 +0000 | [diff] [blame] | 61 | =head1 RETURN VALUE |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 62 | |
Rich Salz | bb6c5e7 | 2017-02-05 10:29:22 -0500 | [diff] [blame] | 63 | RSA_generate_key_ex() returns 1 on success or 0 on error. |
| 64 | RSA_generate_key() returns the key on success or B<NULL> on error. |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 65 | |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 66 | 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] | 67 | |
| 68 | =head1 BUGS |
| 69 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 70 | 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] | 71 | |
| 72 | RSA_generate_key() goes into an infinite loop for illegal input values. |
| 73 | |
| 74 | =head1 SEE ALSO |
| 75 | |
Richard Levitte | b97fdb5 | 2016-11-11 09:33:09 +0100 | [diff] [blame] | 76 | L<ERR_get_error(3)>, L<RAND_bytes(3)>, |
Rich Salz | 5393482 | 2016-06-09 16:39:19 -0400 | [diff] [blame] | 77 | L<RSA_generate_key(3)>, L<BN_generate_prime(3)> |
Ulf Möller | 2186cd8 | 2000-01-11 22:35:21 +0000 | [diff] [blame] | 78 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 79 | =head1 COPYRIGHT |
| 80 | |
| 81 | Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. |
| 82 | |
| 83 | Licensed under the OpenSSL license (the "License"). You may not use |
| 84 | this file except in compliance with the License. You can obtain a copy |
| 85 | in the file LICENSE in the source distribution or at |
| 86 | L<https://www.openssl.org/source/license.html>. |
| 87 | |
| 88 | =cut |