blob: 970f6a6b08afe9726238fca82f24e704a7c0fe5e [file] [log] [blame]
Ulf Möller38e33ce2000-01-27 19:31:26 +00001=pod
2
3=head1 NAME
4
Matt Caswellaafbe1c2013-06-12 23:42:08 +01005DSA_generate_parameters_ex, DSA_generate_parameters - generate DSA parameters
Ulf Möller38e33ce2000-01-27 19:31:26 +00006
7=head1 SYNOPSIS
8
9 #include <openssl/dsa.h>
10
Matt Caswellaafbe1c2013-06-12 23:42:08 +010011 int DSA_generate_parameters_ex(DSA *dsa, int bits,
Beat Bollie9b77242017-01-20 19:58:49 +010012 const unsigned char *seed, int seed_len,
13 int *counter_ret, unsigned long *h_ret,
14 BN_GENCB *cb);
Matt Caswellaafbe1c2013-06-12 23:42:08 +010015
16Deprecated:
17
Viktor Dukhovni98186eb2016-01-04 23:00:33 -050018 #if OPENSSL_API_COMPAT < 0x00908000L
Beat Bollie9b77242017-01-20 19:58:49 +010019 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 Dukhovni98186eb2016-01-04 23:00:33 -050022 #endif
Ulf Möller38e33ce2000-01-27 19:31:26 +000023
24=head1 DESCRIPTION
25
Matt Caswellaafbe1c2013-06-12 23:42:08 +010026DSA_generate_parameters_ex() generates primes p and q and a generator g
27for use in the DSA and stores the result in B<dsa>.
Ulf Möller38e33ce2000-01-27 19:31:26 +000028
Ismo Puustinenf00a10b2015-08-07 22:14:47 -040029B<bits> is the length of the prime p to be generated.
30For lengths under 2048 bits, the length of q is 160 bits; for lengths
Ben Kaduk36ac7bc2015-08-28 12:41:50 -040031greater than or equal to 2048 bits, the length of q is set to 256 bits.
Ulf Möller38e33ce2000-01-27 19:31:26 +000032
Ismo Puustinenf00a10b2015-08-07 22:14:47 -040033If B<seed> is NULL, the primes will be generated at random.
34If B<seed_len> is less than the length of q, an error is returned.
Ulf Möller38e33ce2000-01-27 19:31:26 +000035
Matt Caswellaafbe1c2013-06-12 23:42:08 +010036DSA_generate_parameters_ex() places the iteration count in
Ulf Möller38e33ce2000-01-27 19:31:26 +000037*B<counter_ret> and a counter used for finding a generator in
Bodo Möllera87030a2000-01-30 02:23:03 +000038*B<h_ret>, unless these are B<NULL>.
Ulf Möller38e33ce2000-01-27 19:31:26 +000039
40A callback function may be used to provide feedback about the progress
Matt Caswellaafbe1c2013-06-12 23:42:08 +010041of the key generation. If B<cb> is not B<NULL>, it will be
42called as shown below. For information on the BN_GENCB structure and the
43BN_GENCB_call function discussed below, refer to
Rich Salz9b869742015-08-17 15:21:33 -040044L<BN_generate_prime(3)>.
Ulf Möller38e33ce2000-01-27 19:31:26 +000045
Rich Salzb3696a52017-09-02 09:35:50 -040046DSA_generate_prime() is similar to DSA_generate_prime_ex() but
47expects an old-style callback function; see
48L<BN_generate_prime(3)> for information on the old-style callback.
49
Rich Salz2f61bc22017-04-07 13:37:47 -040050=over 2
Ulf Möller38e33ce2000-01-27 19:31:26 +000051
52=item *
53
Matt Caswellaafbe1c2013-06-12 23:42:08 +010054When a candidate for q is generated, B<BN_GENCB_call(cb, 0, m++)> is called
Bodo Möllera87030a2000-01-30 02:23:03 +000055(m is 0 for the first candidate).
Ulf Möller38e33ce2000-01-27 19:31:26 +000056
57=item *
58
Bodo Möller1baa9492000-01-30 03:32:28 +000059When a candidate for q has passed a test by trial division,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010060B<BN_GENCB_call(cb, 1, -1)> is called.
Bodo Möller1baa9492000-01-30 03:32:28 +000061While a candidate for q is tested by Miller-Rabin primality tests,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010062B<BN_GENCB_call(cb, 1, i)> is called in the outer loop
Bodo Möller1baa9492000-01-30 03:32:28 +000063(once for each witness that confirms that the candidate may be prime);
Bodo Möllera87030a2000-01-30 02:23:03 +000064i is the loop counter (starting at 0).
Ulf Möller38e33ce2000-01-27 19:31:26 +000065
66=item *
67
Matt Caswellaafbe1c2013-06-12 23:42:08 +010068When a prime q has been found, B<BN_GENCB_call(cb, 2, 0)> and
69B<BN_GENCB_call(cb, 3, 0)> are called.
Ulf Möller38e33ce2000-01-27 19:31:26 +000070
71=item *
72
Bodo Möllera87030a2000-01-30 02:23:03 +000073Before a candidate for p (other than the first) is generated and tested,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010074B<BN_GENCB_call(cb, 0, counter)> is called.
Bodo Möllera87030a2000-01-30 02:23:03 +000075
76=item *
77
Bodo Möller1baa9492000-01-30 03:32:28 +000078When a candidate for p has passed the test by trial division,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010079B<BN_GENCB_call(cb, 1, -1)> is called.
Bodo Möller1baa9492000-01-30 03:32:28 +000080While it is tested by the Miller-Rabin primality test,
Matt Caswellaafbe1c2013-06-12 23:42:08 +010081B<BN_GENCB_call(cb, 1, i)> is called in the outer loop
Bodo Möllera87030a2000-01-30 02:23:03 +000082(once for each witness that confirms that the candidate may be prime).
83i is the loop counter (starting at 0).
Ulf Möller38e33ce2000-01-27 19:31:26 +000084
85=item *
86
Matt Caswellaafbe1c2013-06-12 23:42:08 +010087When p has been found, B<BN_GENCB_call(cb, 2, 1)> is called.
Ulf Möller38e33ce2000-01-27 19:31:26 +000088
89=item *
90
Matt Caswellaafbe1c2013-06-12 23:42:08 +010091When the generator has been found, B<BN_GENCB_call(cb, 3, 1)> is called.
Ulf Möller38e33ce2000-01-27 19:31:26 +000092
93=back
94
Paul Yang1f13ad32017-12-25 17:50:39 +080095=head1 RETURN VALUES
Ulf Möller38e33ce2000-01-27 19:31:26 +000096
Matt Caswellaafbe1c2013-06-12 23:42:08 +010097DSA_generate_parameters_ex() returns a 1 on success, or 0 otherwise.
Rich Salz9b869742015-08-17 15:21:33 -040098The error codes can be obtained by L<ERR_get_error(3)>.
Ulf Möller38e33ce2000-01-27 19:31:26 +000099
Rich Salzb3696a52017-09-02 09:35:50 -0400100DSA_generate_parameters() returns a pointer to the DSA structure or
101B<NULL> if the parameter generation fails.
102
Ulf Möller38e33ce2000-01-27 19:31:26 +0000103=head1 BUGS
104
Rich Salzb3696a52017-09-02 09:35:50 -0400105Seed lengths greater than 20 are not supported.
Ulf Möller38e33ce2000-01-27 19:31:26 +0000106
107=head1 SEE ALSO
108
Richard Levitteb97fdb52016-11-11 09:33:09 +0100109L<DSA_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>,
Rich Salz9b869742015-08-17 15:21:33 -0400110L<DSA_free(3)>, L<BN_generate_prime(3)>
Ulf Möller38e33ce2000-01-27 19:31:26 +0000111
Rich Salzb3696a52017-09-02 09:35:50 -0400112=head1 HISTORY
113
Rich Salz02eca5c2017-09-02 16:12:12 -0400114DSA_generate_parameters() was deprecated in OpenSSL 0.9.8; use
Rich Salzb3696a52017-09-02 09:35:50 -0400115DSA_generate_parameters_ex() instead.
116
Rich Salze2f92612016-05-18 11:44:05 -0400117=head1 COPYRIGHT
118
Paul Yang61f805c2018-01-16 01:01:46 +0800119Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
Rich Salze2f92612016-05-18 11:44:05 -0400120
121Licensed under the OpenSSL license (the "License"). You may not use
122this file except in compliance with the License. You can obtain a copy
123in the file LICENSE in the source distribution or at
124L<https://www.openssl.org/source/license.html>.
125
126=cut