summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EVP_PKEY_keygen.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/EVP_PKEY_keygen.3')
-rw-r--r--src/lib/libcrypto/man/EVP_PKEY_keygen.3235
1 files changed, 235 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EVP_PKEY_keygen.3 b/src/lib/libcrypto/man/EVP_PKEY_keygen.3
new file mode 100644
index 0000000000..8a5c7be0c6
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_PKEY_keygen.3
@@ -0,0 +1,235 @@
1.Dd $Mdocdate: November 3 2016 $
2.Dt EVP_PKEY_KEYGEN 3
3.Os
4.Sh NAME
5.Nm EVP_PKEY_keygen_init ,
6.Nm EVP_PKEY_keygen ,
7.Nm EVP_PKEY_paramgen_init ,
8.Nm EVP_PKEY_paramgen ,
9.Nm EVP_PKEY_CTX_set_cb ,
10.Nm EVP_PKEY_CTX_get_cb ,
11.Nm EVP_PKEY_CTX_get_keygen_info ,
12.Nm EVP_PKEY_CTX_set_app_data ,
13.Nm EVP_PKEY_CTX_get_app_data
14.Nd key and parameter generation functions
15.Sh SYNOPSIS
16.In openssl/evp.h
17.Ft int
18.Fo EVP_PKEY_keygen_init
19.Fa "EVP_PKEY_CTX *ctx"
20.Fc
21.Ft int
22.Fo EVP_PKEY_keygen
23.Fa "EVP_PKEY_CTX *ctx"
24.Fa "EVP_PKEY **ppkey"
25.Fc
26.Ft int
27.Fo EVP_PKEY_paramgen_init
28.Fa "EVP_PKEY_CTX *ctx"
29.Fc
30.Ft int
31.Fo EVP_PKEY_paramgen
32.Fa "EVP_PKEY_CTX *ctx"
33.Fa "EVP_PKEY **ppkey"
34.Fc
35.Ft typedef int
36.Fo EVP_PKEY_gen_cb
37.Fa "EVP_PKEY_CTX *ctx"
38.Fc
39.Ft void
40.Fo EVP_PKEY_CTX_set_cb
41.Fa "EVP_PKEY_CTX *ctx"
42.Fa "EVP_PKEY_gen_cb *cb"
43.Fc
44.Ft EVP_PKEY_gen_cb *
45.Fo EVP_PKEY_CTX_get_cb
46.Fa "EVP_PKEY_CTX *ctx"
47.Fc
48.Ft int
49.Fo EVP_PKEY_CTX_get_keygen_info
50.Fa "EVP_PKEY_CTX *ctx"
51.Fa "int idx"
52.Fc
53.Ft void
54.Fo EVP_PKEY_CTX_set_app_data
55.Fa "EVP_PKEY_CTX *ctx"
56.Fa "void *data"
57.Fc
58.Ft void *
59.Fo EVP_PKEY_CTX_get_app_data
60.Fa "EVP_PKEY_CTX *ctx"
61.Fc
62.Sh DESCRIPTION
63The
64.Fn EVP_PKEY_keygen_init
65function initializes a public key algorithm context using key
66.Fa ctx->pkey
67for a key generation operation.
68.Pp
69The
70.Fn EVP_PKEY_keygen
71function performs a key generation operation, the generated key is
72written to
73.Fa ppkey .
74.Pp
75The functions
76.Fn EVP_PKEY_paramgen_init
77and
78.Fn EVP_PKEY_paramgen
79are similar except parameters are generated.
80.Pp
81The function
82.Fn EVP_PKEY_CTX_set_cb
83sets the key or parameter generation callback to
84.Fa cb .
85The function
86.Fn EVP_PKEY_CTX_get_cb
87returns the key or parameter generation callback.
88.Pp
89The function
90.Fn EVP_PKEY_CTX_get_keygen_info
91returns parameters associated with the generation operation.
92If
93.Fa idx
94is -1, the total number of parameters available is returned.
95Any non negative value returns the value of that parameter.
96.Fn EVP_PKEY_CTX_get_keygen_info
97with a non-negative value for
98.Fa idx
99should only be called within the generation callback.
100.Pp
101If the callback returns 0, then the key generation operation is aborted
102and an error occurs.
103This might occur during a time consuming operation where a user clicks
104on a "cancel" button.
105.Pp
106The functions
107.Fn EVP_PKEY_CTX_set_app_data
108and
109.Fn EVP_PKEY_CTX_get_app_data
110set and retrieve an opaque pointer.
111This can be used to set some application defined value which can be
112retrieved in the callback: for example a handle which is used to update
113a "progress dialog".
114.Pp
115After the call to
116.Fn EVP_PKEY_keygen_init
117or
118.Fn EVP_PKEY_paramgen_init ,
119algorithm specific control operations can be performed to set any
120appropriate parameters for the operation.
121.Pp
122The functions
123.Fn EVP_PKEY_keygen
124and
125.Fn EVP_PKEY_paramgen
126can be called more than once on the same context if several operations
127are performed using the same parameters.
128.Pp
129The meaning of the parameters passed to the callback will depend on the
130algorithm and the specific implementation of the algorithm.
131Some might not give any useful information at all during key or
132parameter generation.
133Others might not even call the callback.
134.Pp
135The operation performed by key or parameter generation depends on the
136algorithm used.
137In some cases (e.g. EC with a supplied named curve) the "generation"
138option merely sets the appropriate fields in an
139.Vt EVP_PKEY
140structure.
141.Pp
142In OpenSSL, an
143.Vt EVP_PKEY
144structure containing a private key also contains the public key
145components and parameters (if any).
146An OpenSSL private key is equivalent to what some libraries call a "key
147pair".
148A private key can be used in functions which require the use of a public
149key or parameters.
150.Sh RETURN VALUES
151.Fn EVP_PKEY_keygen_init ,
152.Fn EVP_PKEY_paramgen_init ,
153.Fn EVP_PKEY_keygen ,
154and
155.Fn EVP_PKEY_paramgen
156return 1 for success and 0 or a negative value for failure.
157In particular, a return value of -2 indicates the operation is not
158supported by the public key algorithm.
159.Sh EXAMPLES
160Generate a 2048 bit RSA key:
161.Bd -literal
162#include <openssl/evp.h>
163#include <openssl/rsa.h>
164
165EVP_PKEY_CTX *ctx;
166EVP_PKEY *pkey = NULL;
167ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
168if (!ctx)
169 /* Error occurred */
170if (EVP_PKEY_keygen_init(ctx) <= 0)
171 /* Error */
172if (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, 2048) <= 0)
173 /* Error */
174
175/* Generate key */
176if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
177 /* Error */
178.Ed
179.Pp
180Generate a key from a set of parameters:
181.Bd -literal
182#include <openssl/evp.h>
183#include <openssl/rsa.h>
184
185EVP_PKEY_CTX *ctx;
186EVP_PKEY *pkey = NULL, *param;
187/* Assumed param is set up already */
188ctx = EVP_PKEY_CTX_new(param);
189if (!ctx)
190 /* Error occurred */
191if (EVP_PKEY_keygen_init(ctx) <= 0)
192 /* Error */
193
194/* Generate key */
195if (EVP_PKEY_keygen(ctx, &pkey) <= 0)
196 /* Error */
197.Ed
198.Pp
199Example of generation callback for OpenSSL public key implementations:
200.Bd -literal
201/* Application data is a BIO to output status to */
202
203EVP_PKEY_CTX_set_app_data(ctx, status_bio);
204
205static int
206genpkey_cb(EVP_PKEY_CTX *ctx)
207{
208 char c = '*';
209 BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
210 int p;
211
212 p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
213 if (p == 0)
214 c='.';
215 if (p == 1)
216 c='+';
217 if (p == 2)
218 c='*';
219 if (p == 3)
220 c='\en';
221 BIO_write(b,&c,1);
222 (void)BIO_flush(b);
223 return 1;
224}
225.Ed
226.Sh SEE ALSO
227.Xr EVP_PKEY_CTX_new 3 ,
228.Xr EVP_PKEY_decrypt 3 ,
229.Xr EVP_PKEY_derive 3 ,
230.Xr EVP_PKEY_encrypt 3 ,
231.Xr EVP_PKEY_sign 3 ,
232.Xr EVP_PKEY_verify 3 ,
233.Xr EVP_PKEY_verify_recover 3
234.Sh HISTORY
235These functions were first added to OpenSSL 1.0.0.