blob: fb3d86ca973382bd9c5adae44a97271d67121fe4 [file] [log] [blame]
Ulf Möller2186cd82000-01-11 22:35:21 +00001=pod
2
3=head1 NAME
4
Paul Yang665d8992017-08-02 02:19:43 +08005RSA_generate_key_ex, RSA_generate_key,
6RSA_generate_multi_prime_key - generate RSA key pair
Ulf Möller2186cd82000-01-11 22:35:21 +00007
8=head1 SYNOPSIS
9
10 #include <openssl/rsa.h>
11
Matt Caswellaafbe1c2013-06-12 23:42:08 +010012 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
Paul Yang665d8992017-08-02 02:19:43 +080013 int RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes, BIGNUM *e, BN_GENCB *cb);
Matt Caswellaafbe1c2013-06-12 23:42:08 +010014
15Deprecated:
16
Viktor Dukhovni98186eb2016-01-04 23:00:33 -050017 #if OPENSSL_API_COMPAT < 0x00908000L
Ulf Möller2186cd82000-01-11 22:35:21 +000018 RSA *RSA_generate_key(int num, unsigned long e,
Beat Bollie9b77242017-01-20 19:58:49 +010019 void (*callback)(int, int, void *), void *cb_arg);
Viktor Dukhovni98186eb2016-01-04 23:00:33 -050020 #endif
Ulf Möller2186cd82000-01-11 22:35:21 +000021
22=head1 DESCRIPTION
23
Paul Yang665d8992017-08-02 02:19:43 +080024RSA_generate_key_ex() generates a 2-prime RSA key pair and stores it in the
25B<RSA> structure provided in B<rsa>. The pseudo-random number generator must
Matt Caswellaafbe1c2013-06-12 23:42:08 +010026be seeded prior to calling RSA_generate_key_ex().
Ulf Möller2186cd82000-01-11 22:35:21 +000027
Paul Yang665d8992017-08-02 02:19:43 +080028RSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
29it in the B<RSA> structure provided in B<rsa>. The number of primes is given by
30the B<primes> parameter. The pseudo-random number generator must be seeded prior
31to calling RSA_generate_multi_prime_key().
32
33The modulus size will be of length B<bits>, the number of primes to form the
34modulus will be B<primes>, and the public exponent will be B<e>. Key sizes
35with B<num> E<lt> 1024 should be considered insecure. The exponent is an odd
36number, typically 3, 17 or 65537.
Ulf Möller2186cd82000-01-11 22:35:21 +000037
Andy Polyakov3bded9c2017-11-24 22:45:45 +010038In order to maintain adequate security level, the maximum number of permitted
39B<primes> depends on modulus bit length:
40
41 <1024 | >=1024 | >=4096 | >=8192
42 ------+--------+--------+-------
43 2 | 3 | 4 | 5
44
Ulf Möller2186cd82000-01-11 22:35:21 +000045A callback function may be used to provide feedback about the
Matt Caswellaafbe1c2013-06-12 23:42:08 +010046progress of the key generation. If B<cb> is not B<NULL>, it
47will be called as follows using the BN_GENCB_call() function
Rich Salz9b869742015-08-17 15:21:33 -040048described on the L<BN_generate_prime(3)> page.
Ulf Möller2186cd82000-01-11 22:35:21 +000049
Rich Salzb3696a52017-09-02 09:35:50 -040050RSA_generate_prime() is similar to RSA_generate_prime_ex() but
51expects an old-style callback function; see
52L<BN_generate_prime(3)> for information on the old-style callback.
53
Rich Salz2f61bc22017-04-07 13:37:47 -040054=over 2
Ulf Möller2186cd82000-01-11 22:35:21 +000055
56=item *
57
58While a random prime number is generated, it is called as
Rich Salz9b869742015-08-17 15:21:33 -040059described in L<BN_generate_prime(3)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000060
61=item *
62
63When the n-th randomly generated prime is rejected as not
Matt Caswellaafbe1c2013-06-12 23:42:08 +010064suitable for the key, B<BN_GENCB_call(cb, 2, n)> is called.
Ulf Möller2186cd82000-01-11 22:35:21 +000065
66=item *
67
68When a random p has been found with p-1 relatively prime to B<e>,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010069it is called as B<BN_GENCB_call(cb, 3, 0)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000070
71=back
72
Paul Yang665d8992017-08-02 02:19:43 +080073The process is then repeated for prime q and other primes (if any)
74with B<BN_GENCB_call(cb, 3, i)> where B<i> indicates the i-th prime.
Matt Caswellaafbe1c2013-06-12 23:42:08 +010075
Paul Yang1f13ad32017-12-25 17:50:39 +080076=head1 RETURN VALUES
Ulf Möller2186cd82000-01-11 22:35:21 +000077
Paul Yang665d8992017-08-02 02:19:43 +080078RSA_generate_multi_prime_key() returns 1 on success or 0 on error.
Rich Salzbb6c5e72017-02-05 10:29:22 -050079RSA_generate_key_ex() returns 1 on success or 0 on error.
Rich Salz9b869742015-08-17 15:21:33 -040080The error codes can be obtained by L<ERR_get_error(3)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000081
Rich Salzb3696a52017-09-02 09:35:50 -040082RSA_generate_key() returns a pointer to the RSA structure or
83B<NULL> if the key generation fails.
84
Ulf Möller2186cd82000-01-11 22:35:21 +000085=head1 BUGS
86
Matt Caswellaafbe1c2013-06-12 23:42:08 +010087B<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
Ulf Möller2186cd82000-01-11 22:35:21 +000088
Ulf Möller2186cd82000-01-11 22:35:21 +000089=head1 SEE ALSO
90
Andy Polyakov3bded9c2017-11-24 22:45:45 +010091L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)>
Rich Salzb3696a52017-09-02 09:35:50 -040092
93=head1 HISTORY
94
95RSA_generate_key() was deprecated in OpenSSL 0.9.8; use
96RSA_generate_key_ex() intsead.
Ulf Möller2186cd82000-01-11 22:35:21 +000097
Rich Salze2f92612016-05-18 11:44:05 -040098=head1 COPYRIGHT
99
Paul Yang61f805c2018-01-16 01:01:46 +0800100Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
Rich Salze2f92612016-05-18 11:44:05 -0400101
102Licensed under the OpenSSL license (the "License"). You may not use
103this file except in compliance with the License. You can obtain a copy
104in the file LICENSE in the source distribution or at
105L<https://www.openssl.org/source/license.html>.
106
107=cut