Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 5 | DSA_generate_parameters_ex, DSA_generate_parameters - generate DSA parameters |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
| 9 | #include <openssl/dsa.h> |
| 10 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 11 | int DSA_generate_parameters_ex(DSA *dsa, int bits, |
Beat Bolli | e9b7724 | 2017-01-20 19:58:49 +0100 | [diff] [blame] | 12 | const unsigned char *seed, int seed_len, |
| 13 | int *counter_ret, unsigned long *h_ret, |
| 14 | BN_GENCB *cb); |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 15 | |
| 16 | Deprecated: |
| 17 | |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 18 | #if OPENSSL_API_COMPAT < 0x00908000L |
Beat Bolli | e9b7724 | 2017-01-20 19:58:49 +0100 | [diff] [blame] | 19 | DSA *DSA_generate_parameters(int bits, unsigned char *seed, int seed_len, |
| 20 | int *counter_ret, unsigned long *h_ret, |
| 21 | void (*callback)(int, int, void *), void *cb_arg); |
Viktor Dukhovni | 98186eb | 2016-01-04 23:00:33 -0500 | [diff] [blame] | 22 | #endif |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 23 | |
| 24 | =head1 DESCRIPTION |
| 25 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 26 | DSA_generate_parameters_ex() generates primes p and q and a generator g |
| 27 | for use in the DSA and stores the result in B<dsa>. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 28 | |
Ismo Puustinen | f00a10b | 2015-08-07 22:14:47 -0400 | [diff] [blame] | 29 | B<bits> is the length of the prime p to be generated. |
| 30 | For lengths under 2048 bits, the length of q is 160 bits; for lengths |
Ben Kaduk | 36ac7bc | 2015-08-28 12:41:50 -0400 | [diff] [blame] | 31 | greater than or equal to 2048 bits, the length of q is set to 256 bits. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 32 | |
Ismo Puustinen | f00a10b | 2015-08-07 22:14:47 -0400 | [diff] [blame] | 33 | If B<seed> is NULL, the primes will be generated at random. |
| 34 | If B<seed_len> is less than the length of q, an error is returned. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 35 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 36 | DSA_generate_parameters_ex() places the iteration count in |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 37 | *B<counter_ret> and a counter used for finding a generator in |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 38 | *B<h_ret>, unless these are B<NULL>. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 39 | |
| 40 | A callback function may be used to provide feedback about the progress |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 41 | of the key generation. If B<cb> is not B<NULL>, it will be |
| 42 | called as shown below. For information on the BN_GENCB structure and the |
| 43 | BN_GENCB_call function discussed below, refer to |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 44 | L<BN_generate_prime(3)>. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 45 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 46 | DSA_generate_prime() is similar to DSA_generate_prime_ex() but |
| 47 | expects an old-style callback function; see |
| 48 | L<BN_generate_prime(3)> for information on the old-style callback. |
| 49 | |
Rich Salz | 2f61bc2 | 2017-04-07 13:37:47 -0400 | [diff] [blame] | 50 | =over 2 |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 51 | |
| 52 | =item * |
| 53 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 54 | When a candidate for q is generated, B<BN_GENCB_call(cb, 0, m++)> is called |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 55 | (m is 0 for the first candidate). |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 56 | |
| 57 | =item * |
| 58 | |
Bodo Möller | 1baa949 | 2000-01-30 03:32:28 +0000 | [diff] [blame] | 59 | When a candidate for q has passed a test by trial division, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 60 | B<BN_GENCB_call(cb, 1, -1)> is called. |
Bodo Möller | 1baa949 | 2000-01-30 03:32:28 +0000 | [diff] [blame] | 61 | While a candidate for q is tested by Miller-Rabin primality tests, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 62 | B<BN_GENCB_call(cb, 1, i)> is called in the outer loop |
Bodo Möller | 1baa949 | 2000-01-30 03:32:28 +0000 | [diff] [blame] | 63 | (once for each witness that confirms that the candidate may be prime); |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 64 | i is the loop counter (starting at 0). |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 65 | |
| 66 | =item * |
| 67 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 68 | When a prime q has been found, B<BN_GENCB_call(cb, 2, 0)> and |
| 69 | B<BN_GENCB_call(cb, 3, 0)> are called. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 70 | |
| 71 | =item * |
| 72 | |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 73 | Before a candidate for p (other than the first) is generated and tested, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 74 | B<BN_GENCB_call(cb, 0, counter)> is called. |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 75 | |
| 76 | =item * |
| 77 | |
Bodo Möller | 1baa949 | 2000-01-30 03:32:28 +0000 | [diff] [blame] | 78 | When a candidate for p has passed the test by trial division, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 79 | B<BN_GENCB_call(cb, 1, -1)> is called. |
Bodo Möller | 1baa949 | 2000-01-30 03:32:28 +0000 | [diff] [blame] | 80 | While it is tested by the Miller-Rabin primality test, |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 81 | B<BN_GENCB_call(cb, 1, i)> is called in the outer loop |
Bodo Möller | a87030a | 2000-01-30 02:23:03 +0000 | [diff] [blame] | 82 | (once for each witness that confirms that the candidate may be prime). |
| 83 | i is the loop counter (starting at 0). |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 84 | |
| 85 | =item * |
| 86 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 87 | When p has been found, B<BN_GENCB_call(cb, 2, 1)> is called. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 88 | |
| 89 | =item * |
| 90 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 91 | When the generator has been found, B<BN_GENCB_call(cb, 3, 1)> is called. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 92 | |
| 93 | =back |
| 94 | |
Paul Yang | 1f13ad3 | 2017-12-25 17:50:39 +0800 | [diff] [blame] | 95 | =head1 RETURN VALUES |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 96 | |
Matt Caswell | aafbe1c | 2013-06-12 23:42:08 +0100 | [diff] [blame] | 97 | DSA_generate_parameters_ex() returns a 1 on success, or 0 otherwise. |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 98 | The error codes can be obtained by L<ERR_get_error(3)>. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 99 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 100 | DSA_generate_parameters() returns a pointer to the DSA structure or |
| 101 | B<NULL> if the parameter generation fails. |
| 102 | |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 103 | =head1 BUGS |
| 104 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 105 | Seed lengths greater than 20 are not supported. |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 106 | |
| 107 | =head1 SEE ALSO |
| 108 | |
Richard Levitte | b97fdb5 | 2016-11-11 09:33:09 +0100 | [diff] [blame] | 109 | L<DSA_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>, |
Rich Salz | 9b86974 | 2015-08-17 15:21:33 -0400 | [diff] [blame] | 110 | L<DSA_free(3)>, L<BN_generate_prime(3)> |
Ulf Möller | 38e33ce | 2000-01-27 19:31:26 +0000 | [diff] [blame] | 111 | |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 112 | =head1 HISTORY |
| 113 | |
Rich Salz | 02eca5c | 2017-09-02 16:12:12 -0400 | [diff] [blame] | 114 | DSA_generate_parameters() was deprecated in OpenSSL 0.9.8; use |
Rich Salz | b3696a5 | 2017-09-02 09:35:50 -0400 | [diff] [blame] | 115 | DSA_generate_parameters_ex() instead. |
| 116 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 117 | =head1 COPYRIGHT |
| 118 | |
Paul Yang | 61f805c | 2018-01-16 01:01:46 +0800 | [diff] [blame] | 119 | Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 120 | |
| 121 | Licensed under the OpenSSL license (the "License"). You may not use |
| 122 | this file except in compliance with the License. You can obtain a copy |
| 123 | in the file LICENSE in the source distribution or at |
| 124 | L<https://www.openssl.org/source/license.html>. |
| 125 | |
| 126 | =cut |