xref: /openbsd-src/lib/libcrypto/man/DSA_generate_parameters_ex.3 (revision b3d8295f3cd942c6ea4804dc602a677bb68323e4)
1*b3d8295fStb.\"	$OpenBSD: DSA_generate_parameters_ex.3,v 1.1 2023/12/29 19:15:15 tb Exp $
2*b3d8295fStb.\"	OpenSSL 9b86974e Aug 7 22:14:47 2015 -0400
3*b3d8295fStb.\"
4*b3d8295fStb.\" This file was written by Ulf Moeller <ulf@openssl.org>,
5*b3d8295fStb.\" Bodo Moeller <bodo@openssl.org>, and Matt Caswell <matt@openssl.org>.
6*b3d8295fStb.\" Copyright (c) 2000, 2013 The OpenSSL Project.  All rights reserved.
7*b3d8295fStb.\"
8*b3d8295fStb.\" Redistribution and use in source and binary forms, with or without
9*b3d8295fStb.\" modification, are permitted provided that the following conditions
10*b3d8295fStb.\" are met:
11*b3d8295fStb.\"
12*b3d8295fStb.\" 1. Redistributions of source code must retain the above copyright
13*b3d8295fStb.\"    notice, this list of conditions and the following disclaimer.
14*b3d8295fStb.\"
15*b3d8295fStb.\" 2. Redistributions in binary form must reproduce the above copyright
16*b3d8295fStb.\"    notice, this list of conditions and the following disclaimer in
17*b3d8295fStb.\"    the documentation and/or other materials provided with the
18*b3d8295fStb.\"    distribution.
19*b3d8295fStb.\"
20*b3d8295fStb.\" 3. All advertising materials mentioning features or use of this
21*b3d8295fStb.\"    software must display the following acknowledgment:
22*b3d8295fStb.\"    "This product includes software developed by the OpenSSL Project
23*b3d8295fStb.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24*b3d8295fStb.\"
25*b3d8295fStb.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26*b3d8295fStb.\"    endorse or promote products derived from this software without
27*b3d8295fStb.\"    prior written permission. For written permission, please contact
28*b3d8295fStb.\"    openssl-core@openssl.org.
29*b3d8295fStb.\"
30*b3d8295fStb.\" 5. Products derived from this software may not be called "OpenSSL"
31*b3d8295fStb.\"    nor may "OpenSSL" appear in their names without prior written
32*b3d8295fStb.\"    permission of the OpenSSL Project.
33*b3d8295fStb.\"
34*b3d8295fStb.\" 6. Redistributions of any form whatsoever must retain the following
35*b3d8295fStb.\"    acknowledgment:
36*b3d8295fStb.\"    "This product includes software developed by the OpenSSL Project
37*b3d8295fStb.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38*b3d8295fStb.\"
39*b3d8295fStb.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40*b3d8295fStb.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41*b3d8295fStb.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42*b3d8295fStb.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43*b3d8295fStb.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*b3d8295fStb.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45*b3d8295fStb.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46*b3d8295fStb.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*b3d8295fStb.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48*b3d8295fStb.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49*b3d8295fStb.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50*b3d8295fStb.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51*b3d8295fStb.\"
52*b3d8295fStb.Dd $Mdocdate: December 29 2023 $
53*b3d8295fStb.Dt DSA_GENERATE_PARAMETERS_EX 3
54*b3d8295fStb.Os
55*b3d8295fStb.Sh NAME
56*b3d8295fStb.\" .Nm DSA_generate_parameters is intentionally undocumented
57*b3d8295fStb.\" because it will be removed in the next major bump
58*b3d8295fStb.Nm DSA_generate_parameters_ex
59*b3d8295fStb.Nd generate DSA parameters
60*b3d8295fStb.Sh SYNOPSIS
61*b3d8295fStb.In openssl/dsa.h
62*b3d8295fStb.Ft int
63*b3d8295fStb.Fo DSA_generate_parameters_ex
64*b3d8295fStb.Fa "DSA *dsa"
65*b3d8295fStb.Fa "int bits"
66*b3d8295fStb.Fa "const unsigned char *seed"
67*b3d8295fStb.Fa "int seed_len"
68*b3d8295fStb.Fa "int *counter_ret"
69*b3d8295fStb.Fa "unsigned long *h_ret"
70*b3d8295fStb.Fa "BN_GENCB *cb"
71*b3d8295fStb.Fc
72*b3d8295fStb.Sh DESCRIPTION
73*b3d8295fStb.Fn DSA_generate_parameters_ex
74*b3d8295fStbgenerates primes p and q and a generator g for use in the DSA and stores
75*b3d8295fStbthe result in
76*b3d8295fStb.Fa dsa .
77*b3d8295fStb.Pp
78*b3d8295fStb.Fa bits
79*b3d8295fStbis the length of the prime to be generated; the DSS allows a maximum of
80*b3d8295fStb1024 bits.
81*b3d8295fStb.Pp
82*b3d8295fStbIf
83*b3d8295fStb.Fa seed
84*b3d8295fStbis
85*b3d8295fStb.Dv NULL
86*b3d8295fStbor
87*b3d8295fStb.Fa seed_len
88*b3d8295fStb< 20, the primes will be generated at random.
89*b3d8295fStbOtherwise, the seed is used to generate them.
90*b3d8295fStbIf the given seed does not yield a prime q, a new random seed is chosen
91*b3d8295fStband placed at
92*b3d8295fStb.Fa seed .
93*b3d8295fStb.Pp
94*b3d8295fStb.Fn DSA_generate_parameters_ex
95*b3d8295fStbplaces the iteration count in
96*b3d8295fStb.Pf * Fa counter_ret
97*b3d8295fStband a counter used for finding a generator in
98*b3d8295fStb.Pf * Fa h_ret ,
99*b3d8295fStbunless these are
100*b3d8295fStb.Dv NULL .
101*b3d8295fStb.Pp
102*b3d8295fStbA callback function may be used to provide feedback about the progress
103*b3d8295fStbof the key generation.
104*b3d8295fStbIf
105*b3d8295fStb.Fa cb
106*b3d8295fStbis not
107*b3d8295fStb.Dv NULL ,
108*b3d8295fStbit will be called as shown below.
109*b3d8295fStbFor information on the
110*b3d8295fStb.Vt BN_GENCB
111*b3d8295fStbstructure, refer to
112*b3d8295fStb.Xr BN_GENCB_call 3 .
113*b3d8295fStb.Bl -bullet
114*b3d8295fStb.It
115*b3d8295fStbWhen a candidate for q is generated,
116*b3d8295fStb.Fn BN_GENCB_call cb 0 m++
117*b3d8295fStbis called
118*b3d8295fStb.Pf ( Fa m
119*b3d8295fStbis 0 for the first candidate).
120*b3d8295fStb.It
121*b3d8295fStbWhen a candidate for q has passed a test by trial division,
122*b3d8295fStb.Fn BN_GENCB_call cb 1 -1
123*b3d8295fStbis called.
124*b3d8295fStbWhile a candidate for q is tested by Miller-Rabin primality tests,
125*b3d8295fStb.Fn BN_GENCB_call cb 1 i
126*b3d8295fStbis called in the outer loop (once for each witness that confirms that
127*b3d8295fStbthe candidate may be prime);
128*b3d8295fStb.Fa i
129*b3d8295fStbis the loop counter (starting at 0).
130*b3d8295fStb.It
131*b3d8295fStbWhen a prime q has been found,
132*b3d8295fStb.Fn BN_GENCB_call cb 2 0
133*b3d8295fStband
134*b3d8295fStb.Fn BN_GENCB_call cb 3 0
135*b3d8295fStbare called.
136*b3d8295fStb.It
137*b3d8295fStbBefore a candidate for p (other than the first) is generated and tested,
138*b3d8295fStb.Fn BN_GENCB_call cb 0 counter
139*b3d8295fStbis called.
140*b3d8295fStb.It
141*b3d8295fStbWhen a candidate for p has passed the test by trial division,
142*b3d8295fStb.Fn BN_GENCB_call cb 1 -1
143*b3d8295fStbis called.
144*b3d8295fStbWhile it is tested by the Miller-Rabin primality test,
145*b3d8295fStb.Fn BN_GENCB_call cb 1 i
146*b3d8295fStbis called in the outer loop (once for each witness that confirms that
147*b3d8295fStbthe candidate may be prime).
148*b3d8295fStb.Fa i
149*b3d8295fStbis the loop counter (starting at 0).
150*b3d8295fStb.It
151*b3d8295fStbWhen p has been found,
152*b3d8295fStb.Fn BN_GENCB_call cb 2 1
153*b3d8295fStbis called.
154*b3d8295fStb.It
155*b3d8295fStbWhen the generator has been found,
156*b3d8295fStb.Fn BN_GENCB_call cb 3 1
157*b3d8295fStbis called.
158*b3d8295fStb.El
159*b3d8295fStb.Sh RETURN VALUES
160*b3d8295fStb.Fn DSA_generate_parameters_ex
161*b3d8295fStbreturns a 1 on success, or 0 otherwise.
162*b3d8295fStb.Pp
163*b3d8295fStbThe error codes can be obtained by
164*b3d8295fStb.Xr ERR_get_error 3 .
165*b3d8295fStb.Sh SEE ALSO
166*b3d8295fStb.Xr BN_generate_prime 3 ,
167*b3d8295fStb.Xr DSA_get0_pqg 3 ,
168*b3d8295fStb.Xr DSA_new 3
169*b3d8295fStb.Sh HISTORY
170*b3d8295fStb.Fn DSA_generate_parameters_ex
171*b3d8295fStbfirst appeared in OpenSSL 0.9.8 and has been available since
172*b3d8295fStb.Ox 4.5 .
173*b3d8295fStb.Sh BUGS
174*b3d8295fStbSeed lengths > 20 are not supported.
175