summaryrefslogtreecommitdiff
path: root/lib/libcrypto/man/EC_KEY_METHOD_new.3
blob: 383688b0ef5a2781ef425776e96f1f94f0d3d69c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
.\" $OpenBSD: EC_KEY_METHOD_new.3,v 1.1 2019/08/16 16:15:50 schwarze Exp $
.\" Copyright (c) 2019 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: August 16 2019 $
.Dt EC_KEY_METHOD_NEW 3
.Os
.Sh NAME
.Nm EC_KEY_METHOD_new ,
.Nm EC_KEY_METHOD_free ,
.Nm EC_KEY_METHOD_set_init ,
.Nm EC_KEY_METHOD_get_init ,
.Nm EC_KEY_METHOD_set_sign ,
.Nm EC_KEY_METHOD_get_sign ,
.Nm EC_KEY_METHOD_set_verify ,
.Nm EC_KEY_METHOD_get_verify ,
.Nm EC_KEY_METHOD_set_keygen ,
.Nm EC_KEY_METHOD_get_keygen ,
.Nm EC_KEY_METHOD_set_compute_key ,
.Nm EC_KEY_METHOD_get_compute_key ,
.Nm EC_KEY_OpenSSL ,
.Nm EC_KEY_set_default_method ,
.Nm EC_KEY_get_default_method ,
.Nm EC_KEY_new_method ,
.Nm EC_KEY_set_method ,
.Nm EC_KEY_get_method
.Nd custom EC_KEY implementations
.Sh SYNOPSIS
.In openssl/ec.h
.Ft EC_KEY_METHOD *
.Fo EC_KEY_METHOD_new
.Fa "const EC_KEY_METHOD *meth"
.Fc
.Ft void
.Fo EC_KEY_METHOD_free
.Fa "EC_KEY_METHOD *meth"
.Fc
.Ft void
.Fo EC_KEY_METHOD_set_init
.Fa "EC_KEY_METHOD *meth"
.Fa "int (*init)(EC_KEY *key)"
.Fa "void (*finish)(EC_KEY *key)"
.Fa "int (*copy)(EC_KEY *dest, const EC_KEY *src)"
.Fa "int (*set_group)(EC_KEY *key, const EC_GROUP *grp)"
.Fa "int (*set_private)(EC_KEY *key, const BIGNUM *priv_key)"
.Fa "int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_get_init
.Fa "const EC_KEY_METHOD *meth"
.Fa "int (**pinit)(EC_KEY *key)"
.Fa "void (**pfinish)(EC_KEY *key)"
.Fa "int (**pcopy)(EC_KEY *dest, const EC_KEY *src)"
.Fa "int (**pset_group)(EC_KEY *key, const EC_GROUP *grp)"
.Fa "int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key)"
.Fa "int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)"
.Fc
.In openssl/ecdsa.h
.Ft void
.Fo EC_KEY_METHOD_set_sign
.Fa "EC_KEY_METHOD *meth"
.Fa "int (*sign)(int type, const unsigned char *dgst, int dgstlen,\
 unsigned char *sig, unsigned int *siglen,\
 const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)"
.Fa "int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx,\
 BIGNUM **kinv, BIGNUM **rp)"
.Fa "ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgstlen,\
 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_get_sign
.Fa "const EC_KEY_METHOD *meth"
.Fa "int (**psign)(int type, const unsigned char *dgst, int dgstlen,\
 unsigned char *sig, unsigned int *siglen,\
 const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)"
.Fa "int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx,\
 BIGNUM **kinv, BIGNUM **rp)"
.Fa "ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, int dgstlen,\
 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_set_verify
.Fa "EC_KEY_METHOD *meth"
.Fa "int (*verify)(int type, const unsigned char *dgst, int dgst_len,\
 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)"
.Fa "int (*verify_sig)(const unsigned char *dgst, int dgst_len,\
 const ECDSA_SIG *sig, EC_KEY *eckey)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_get_verify
.Fa "const EC_KEY_METHOD *meth"
.Fa "int (**pverify)(int type, const unsigned char *dgst, int dgst_len,\
 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)"
.Fa "int (**pverify_sig)(const unsigned char *dgst, int dgst_len,\
 const ECDSA_SIG *sig, EC_KEY *eckey)"
.Fc
.In openssl/ec.h
.Ft void
.Fo EC_KEY_METHOD_set_keygen
.Fa "EC_KEY_METHOD *meth"
.Fa "int (*keygen)(EC_KEY *key)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_get_keygen
.Fa "const EC_KEY_METHOD *meth"
.Fa "int (**pkeygen)(EC_KEY *key)"
.Fc
.Ft void
.Fo EC_KEY_METHOD_set_compute_key
.Fa "EC_KEY_METHOD *meth"
.Fa "int (*ckey)(void *out, size_t outlen,\
 const EC_POINT *pub_key, EC_KEY *ecdh,\
 void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen))"
.Fc
.Ft void
.Fo EC_KEY_METHOD_get_compute_key
.Fa "const EC_KEY_METHOD *meth"
.Fa "int (**pck)(void *out, size_t outlen,\
 const EC_POINT *pub_key, EC_KEY *ecdh,\
 void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen))"
.Fc
.Ft const EC_KEY_METHOD *
.Fn EC_KEY_OpenSSL void
.Ft void
.Fo EC_KEY_set_default_method
.Fa "const EC_KEY_METHOD *meth"
.Fc
.Ft const EC_KEY_METHOD *
.Fn EC_KEY_get_default_method void
.Ft EC_KEY *
.Fo EC_KEY_new_method
.Fa "ENGINE *engine"
.Fc
.Ft int
.Fo EC_KEY_set_method
.Fa "EC_KEY *key"
.Fa "const EC_KEY_METHOD *meth"
.Fc
.Ft const EC_KEY_METHOD *
.Fo EC_KEY_get_method
.Fa "const EC_KEY *key"
.Fc
.Sh DESCRIPTION
An
.Vt EC_KEY_METHOD
object holds function pointers used for
.Vt EC_KEY
operations.
.Pp
.Fn EC_KEY_METHOD_new
creates a shallow copy of
.Fa meth ,
or an empty
.Vt EC_KEY_METHOD
object if
.Fa meth
is
.Dv NULL .
.Pp
.Fn EC_KEY_METHOD_free
frees
.Fa meth .
If
.Fa meth
is
.Dv NULL
or the return value of
.Fn EC_KEY_OpenSSL ,
no action occurs.
.Pp
.Fn EC_KEY_METHOD_set_init
and
.Fn EC_KEY_METHOD_get_init
set and retrieve optional callback functions called at the following places:
.Pp
.Bl -tag -width set_private -compact
.It Fa init
at the end of
.Fn EC_KEY_new_method
and
.Fn EC_KEY_set_method
.It Fa finish
at the beginning of
.Xr EC_KEY_free 3 ,
.Xr EC_KEY_copy 3 ,
and
.Fn EC_KEY_set_method
.It Fa copy
at the end of
.Xr EC_KEY_copy 3
.It Fa set_group
at the end of
.Xr EC_KEY_set_group 3
and
.Xr EC_KEY_new_by_curve_name 3
.It Fa set_private
at the beginning of
.Xr EC_KEY_set_private_key 3
.It Fa set_public
at the beginning of
.Xr EC_KEY_set_public_key 3
.El
.Pp
If any of these callbacks returns 0, the calling function fails.
By default, all these callbacks are
.Dv NULL .
Arguments of
.Fn EC_KEY_METHOD_get_init
can be set to
.Dv NULL
to selectively retrieve callback function pointers.
.Pp
.Fn EC_KEY_METHOD_set_sign
and
.Fn EC_KEY_METHOD_get_sign
set and retrieve the functions implementing
.Xr ECDSA_sign_ex 3 ,
.Xr ECDSA_sign_setup 3 ,
and
.Xr ECDSA_do_sign_ex 3 .
.Pp
.Fn EC_KEY_METHOD_set_verify
and
.Fn EC_KEY_METHOD_get_verify
set and retrieve the functions implementing
.Xr ECDSA_verify 3
and
.Xr ECDSA_do_verify 3 .
.Pp
.Fn EC_KEY_METHOD_set_keygen
and
.Fn EC_KEY_METHOD_get_keygen
set and retrieve the function implementing
.Xr EC_KEY_generate_key 3 .
.Pp
.Fn EC_KEY_METHOD_set_compute_key
and
.Fn EC_KEY_METHOD_get_compute_key
set and retrieve the function implementing
.Xr ECDH_compute_key 3 .
.Pp
.Fn EC_KEY_set_default_method
chooses the
.Fa meth
to be used for the creation of new
.Vt EC_KEY
objects by future invocations of
.Fn EC_KEY_new_method ,
or reverts to the default implementation if
.Fa meth
is
.Dv NULL .
.Pp
.Fn EC_KEY_new_method
creates and initializes a new
.Vt EC_KEY
object using the given
.Fa engine ,
or the using the
.Vt EC_KEY_METHOD
set with
.Fn EC_KEY_set_default_method
if
.Fa engine
is
.Dv NULL ,
or using the default EC_KEY implementation by default.
.Pp
.Fn EC_KEY_set_method
dissociates the
.Fa key
from the
.Vt ENGINE
it is using, if any, and causes it to use
.Fa meth
in the future.
.Sh RETURN VALUES
.Fn EC_KEY_METHOD_new
returns the newly allocated
.Vt EC_KEY_METHOD
object or
.Dv NULL
if an error occurs.
.Pp
.Fn EC_KEY_OpenSSL
returns a static object representing the default EC_KEY implementation.
.Pp
.Fn EC_KEY_get_default_method
returns the
.Vt EC_KEY_METHOD
that
.Fn EC_KEY_new_method
will use for the creation of new
.Vt EC_KEY
objects in the future.
.Pp
.Fn EC_KEY_new_method
returns the newly allocated
.Vt EC_KEY
object or NULL if an error occurs.
.Pp
.Fn EC_KEY_set_method
returns 1 for success or 0 for failure.
.Pp
.Fn EC_KEY_get_method
returns the EC_KEY implementation used by the given
.Fa key .
.Sh SEE ALSO
.Xr EC_KEY_new 3 ,
.Xr ECDSA_sign 3
.Sh HISTORY
These functions first appeared in OpenSSL 1.1.0
and have been available since
.Ox 6.5 .