blob: 24e05bd8a719dff19de298c41cee54af4bfef82f [file] [log] [blame]
Ulf Möller2186cd82000-01-11 22:35:21 +00001=pod
2
3=head1 NAME
4
Matt Caswellaafbe1c2013-06-12 23:42:08 +01005RSA_generate_key_ex, RSA_generate_key - generate RSA key pair
Ulf Möller2186cd82000-01-11 22:35:21 +00006
7=head1 SYNOPSIS
8
9 #include <openssl/rsa.h>
10
Matt Caswellaafbe1c2013-06-12 23:42:08 +010011 int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
12
13Deprecated:
14
Viktor Dukhovni98186eb2016-01-04 23:00:33 -050015 #if OPENSSL_API_COMPAT < 0x00908000L
Ulf Möller2186cd82000-01-11 22:35:21 +000016 RSA *RSA_generate_key(int num, unsigned long e,
Rich Salzaebb9aa2016-07-19 09:27:53 -040017 void (*callback)(int, int, void *), void *cb_arg);
Viktor Dukhovni98186eb2016-01-04 23:00:33 -050018 #endif
Ulf Möller2186cd82000-01-11 22:35:21 +000019
20=head1 DESCRIPTION
21
Matt Caswellaafbe1c2013-06-12 23:42:08 +010022RSA_generate_key_ex() generates a key pair and stores it in the B<RSA>
23structure provided in B<rsa>. The pseudo-random number generator must
24be seeded prior to calling RSA_generate_key_ex().
Ulf Möller2186cd82000-01-11 22:35:21 +000025
Matt Caswellaafbe1c2013-06-12 23:42:08 +010026The modulus size will be of length B<bits>, and the public exponent will be
Ulf Möller2186cd82000-01-11 22:35:21 +000027B<e>. Key sizes with B<num> E<lt> 1024 should be considered insecure.
Ulf Möller592c0e02002-04-13 09:58:50 +000028The exponent is an odd number, typically 3, 17 or 65537.
Ulf Möller2186cd82000-01-11 22:35:21 +000029
30A callback function may be used to provide feedback about the
Matt Caswellaafbe1c2013-06-12 23:42:08 +010031progress of the key generation. If B<cb> is not B<NULL>, it
32will be called as follows using the BN_GENCB_call() function
Rich Salz9b869742015-08-17 15:21:33 -040033described on the L<BN_generate_prime(3)> page.
Ulf Möller2186cd82000-01-11 22:35:21 +000034
35=over 4
36
37=item *
38
39While a random prime number is generated, it is called as
Rich Salz9b869742015-08-17 15:21:33 -040040described in L<BN_generate_prime(3)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000041
42=item *
43
44When the n-th randomly generated prime is rejected as not
Matt Caswellaafbe1c2013-06-12 23:42:08 +010045suitable for the key, B<BN_GENCB_call(cb, 2, n)> is called.
Ulf Möller2186cd82000-01-11 22:35:21 +000046
47=item *
48
49When a random p has been found with p-1 relatively prime to B<e>,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010050it is called as B<BN_GENCB_call(cb, 3, 0)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000051
52=back
53
Matt Caswellaafbe1c2013-06-12 23:42:08 +010054The process is then repeated for prime q with B<BN_GENCB_call(cb, 3, 1)>.
55
Rich Salzbb6c5e72017-02-05 10:29:22 -050056RSA_generate_key() is deprecated (new applications should use
57RSA_generate_key_ex() instead). RSA_generate_key() works in the same way as
58RSA_generate_key_ex() except it uses "old style" call backs. See
Rich Salz9b869742015-08-17 15:21:33 -040059L<BN_generate_prime(3)> for further details.
Ulf Möller2186cd82000-01-11 22:35:21 +000060
Ulf Möller60b52452000-01-21 17:50:27 +000061=head1 RETURN VALUE
Ulf Möller2186cd82000-01-11 22:35:21 +000062
Rich Salzbb6c5e72017-02-05 10:29:22 -050063RSA_generate_key_ex() returns 1 on success or 0 on error.
64RSA_generate_key() returns the key on success or B<NULL> on error.
Matt Caswellaafbe1c2013-06-12 23:42:08 +010065
Rich Salz9b869742015-08-17 15:21:33 -040066The error codes can be obtained by L<ERR_get_error(3)>.
Ulf Möller2186cd82000-01-11 22:35:21 +000067
68=head1 BUGS
69
Matt Caswellaafbe1c2013-06-12 23:42:08 +010070B<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
Ulf Möller2186cd82000-01-11 22:35:21 +000071
72RSA_generate_key() goes into an infinite loop for illegal input values.
73
74=head1 SEE ALSO
75
Richard Levitteb97fdb52016-11-11 09:33:09 +010076L<ERR_get_error(3)>, L<RAND_bytes(3)>,
Rich Salz53934822016-06-09 16:39:19 -040077L<RSA_generate_key(3)>, L<BN_generate_prime(3)>
Ulf Möller2186cd82000-01-11 22:35:21 +000078
Rich Salze2f92612016-05-18 11:44:05 -040079=head1 COPYRIGHT
80
81Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
82
83Licensed under the OpenSSL license (the "License"). You may not use
84this file except in compliance with the License. You can obtain a copy
85in the file LICENSE in the source distribution or at
86L<https://www.openssl.org/source/license.html>.
87
88=cut