summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/d2i_ECPKParameters.3
blob: 02f3c5c39b1d301e444f202de6fb30d1925d51d8 (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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
.\"	$OpenBSD: d2i_ECPKParameters.3,v 1.6 2016/12/06 14:54:55 schwarze Exp $
.\"	OpenSSL 05ea606a May 20 20:52:46 2016 -0400
.\"
.\" This file was written by Matt Caswell <matt@openssl.org>.
.\" Copyright (c) 2013, 2015 The OpenSSL Project.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\"    software must display the following acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\"    endorse or promote products derived from this software without
.\"    prior written permission. For written permission, please contact
.\"    openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\"    nor may "OpenSSL" appear in their names without prior written
.\"    permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\"    acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: December 6 2016 $
.Dt D2I_ECPKPARAMETERS 3
.Os
.Sh NAME
.Nm d2i_ECPKParameters ,
.Nm i2d_ECPKParameters ,
.Nm d2i_ECPKParameters_bio ,
.Nm i2d_ECPKParameters_bio ,
.Nm d2i_ECPKParameters_fp ,
.Nm i2d_ECPKParameters_fp ,
.Nm d2i_ECParameters ,
.Nm i2d_ECParameters ,
.Nm ECParameters_dup ,
.Nm d2i_ECPrivateKey ,
.Nm i2d_ECPrivateKey ,
.Nm o2i_ECPublicKey ,
.Nm i2o_ECPublicKey ,
.Nm ECPKParameters_print ,
.Nm ECPKParameters_print_fp ,
.Nm ECParameters_print ,
.Nm ECParameters_print_fp
.Nd decode and encode ASN.1 representations of elliptic curve entities
.Sh SYNOPSIS
.In openssl/ec.h
.Ft EC_GROUP *
.Fo d2i_ECPKParameters
.Fa "EC_GROUP **px"
.Fa "const unsigned char **in"
.Fa "long len"
.Fc
.Ft int
.Fo i2d_ECPKParameters
.Fa "const EC_GROUP *x"
.Fa "unsigned char **out"
.Fc
.Ft EC_GROUP *
.Fo d2i_ECPKParameters_bio
.Fa "BIO *bp"
.Fa "EC_GROUP **px"
.Fc
.Ft int
.Fo i2d_ECPKParameters_bio
.Fa "BIO *bp"
.Fa "EC_GROUP **px"
.Fc
.Ft EC_GROUP *
.Fo d2i_ECPKParameters_fp
.Fa "FILE *fp"
.Fa "EC_GROUP **px"
.Fc
.Ft int
.Fo i2d_ECPKParameters_fp
.Fa "FILE *fp"
.Fa "EC_GROUP **px"
.Fc
.Ft EC_KEY *
.Fo d2i_ECParameters
.Fa "EC_KEY **key"
.Fa "const unsigned char **in"
.Fa "long len"
.Fc
.Ft int
.Fo i2d_ECParameters
.Fa "EC_KEY *key"
.Fa "unsigned char **out"
.Fc
.Ft EC_KEY *
.Fo ECParameters_dup
.Fa "EC_KEY *key"
.Fc
.Ft EC_KEY *
.Fo d2i_ECPrivateKey
.Fa "EC_KEY **key"
.Fa "const unsigned char **in"
.Fa "long len"
.Fc
.Ft int
.Fo i2d_ECPrivateKey
.Fa "EC_KEY *key"
.Fa "unsigned char **out"
.Fc
.Ft EC_KEY *
.Fo o2i_ECPublicKey
.Fa "EC_KEY **key"
.Fa "const unsigned char **in"
.Fa "long len"
.Fc
.Ft int
.Fo i2o_ECPublicKey
.Fa "EC_KEY *key"
.Fa "unsigned char **out"
.Fc
.Ft int
.Fo ECPKParameters_print
.Fa "BIO *bp"
.Fa "const EC_GROUP *x"
.Fa "int off"
.Fc
.Ft int
.Fo ECPKParameters_print_fp
.Fa "FILE *fp"
.Fa "const EC_GROUP *x"
.Fa "int off"
.Fc
.Ft int
.Fo ECParameters_print
.Fa "BIO *bp"
.Fa "const EC_KEY *key"
.Fc
.Ft int
.Fo ECParameters_print_fp
.Fa "FILE *fp"
.Fa "const EC_KEY *key"
.Fc
.Sh DESCRIPTION
.Fn d2i_ECPKParameters
attempts to decode
.Fa len
bytes at
.Pf * Fa in .
If successful, a pointer to the
.Vt EC_GROUP
structure is returned.
If an error occurred, then
.Dv NULL
is returned.
If
.Fa px
is not
.Dv NULL ,
then the returned structure is written to
.Pf * Fa px .
If
.Pf * Fa px
is not
.Dv NULL ,
then it is assumed that
.Pf * Fa px
contains a valid
.Vt EC_GROUP
structure and an attempt is made to reuse it.
If the call is successful,
.Pf * Fa in
is incremented to the byte following the parsed data.
.Pp
.Fn i2d_ECPKParameters
encodes the structure pointed to by
.Fa x
into DER format.
If
.Fa out
is not
.Dv NULL ,
is writes the DER encoded data to the buffer at
.Pf * Fa out
and increments it to point after the data just written.
If the return value is negative, an error occurred, otherwise it returns
the length of the encoded data.
.Pp
If
.Pf * Fa out
is
.Dv NULL ,
memory will be allocated for a buffer and the encoded data written to it.
In this case
.Pf * Fa out
is not incremented, and it points to the start of the data just written.
.Pp
.Fn d2i_ECPKParameters_bio
is similar to
.Fn d2i_ECPKParameters
except it attempts to parse data from
.Vt BIO
.Fa bp .
.Fn d2i_ECPKParameters_fp
is similar to
.Fn d2i_ECPKParameters
except it attempts to parse data from the
.Vt FILE
pointer
.Fa fp .
.Fn i2d_ECPKParameters_bio
is similar to
.Fn i2d_ECPKParameters
except it writes the encoding of the structure
.Fa x
to
.Vt BIO
.Fa bp
and it returns 1 for success or 0 for failure.
.Fn i2d_ECPKParameters_fp
is similar to
.Fn i2d_ECPKParameters
except it writes the encoding of the structure
.Fa x
to
.Vt BIO
.Sy bp
and it returns 1 for success or 0 for failure.
These four functions are currently implemented as macros.
.Pp
.Fn d2i_ECParameters
does the same parsing as
.Fn d2i_ECPKParameters
but saves the result in the
.Fa group
field of an
.Vt EC_KEY
structure.
.Pp
.Fn i2d_ECParameters
produces the same output as
.Fn i2d_ECPKParameters
but uses
.Fa key->group
for input instead of
.Fa px .
.Pp
.Fn ECParameters_dup
copies
.Fa key
by calling
.Fn i2d_ECParameters
and
.Fn d2i_ECParameters .
.Pp
.Fn d2i_ECPrivateKey
interprets
.Fa len
bytes at
.Fa in
as a DER-encoded private key, decodes it, stores the result in
.Fa key
as described above, and returns a pointer to it.
.Pp
.Fn i2d_ECPrivateKey
encodes the private key
.Fa a
into DER format and writes it to
.Fa out
as described above.
.Pp
.Fn o2i_ECPublicKey
takes a string of
.Fa len
octets from
.Fa in ,
decodes them, and stores the resulting EC public key in the existing
.Pf * Fa key .
.Pp
.Fn i2o_ECPublicKey
encodes the public
.Fa key
into the octet string buffer
.Pf * Fa out .
If
.Pf * Fa out
is
.Dv NULL ,
a new buffer of the required size is allocated;
otherwise, the pointer is advanced to point to the octet
after the last one written.
.Pp
These functions are very similar to the X.509 functions described in
.Xr d2i_X509 3 ,
where further notes and examples are available.
.Pp
The
.Fn ECPKParameters_print
and
.Fn ECPKParameters_print_fp
functions print human-readable output of the public parameters of the
.Vt EC_GROUP
to
.Fa bp
or
.Fa fp .
The output lines are indented by
.Fa off
spaces.
.Pp
.Fn ECParameters_print
and
.Fn ECParameters_print_fp
print the parameter components of
.Fa key
to
.Fa bp
or
.Fa fp .
.Sh RETURN VALUES
.Fn d2i_ECPKParameters ,
.Fn d2i_ECPKParameters_bio ,
and
.Fn d2i_ECPKParameters_fp
return a valid
.Vt EC_GROUP
structure or
.Dv NULL
if an error occurs.
.Pp
.Fn d2i_ECParameters ,
.Fn ECParameters_dup ,
.Fn d2i_ECPrivateKey ,
and
.Fn o2i_ECPublicKey
return a valid
.Vt EC_KEY
structure or
.Dv NULL
if an error occurs.
.Pp
.Fn i2d_ECPKParameters ,
.Fn i2d_ECParameters ,
.Fn i2d_ECPrivateKey ,
and
.Fn i2o_ECPublicKey
return the number of bytes successfully encoded or a negative value if
an error occurs.
.Pp
.Fn i2d_ECPKParameters_bio ,
.Fn i2d_ECPKParameters_fp ,
.Fn ECPKParameters_print ,
.Fn ECPKParameters_print_fp ,
.Fn ECParameters_print ,
and
.Fn ECParameters_print_fp
return 1 for success or 0 if an error occurs.
.Sh SEE ALSO
.Xr d2i_X509 3 ,
.Xr ec 3 ,
.Xr EC_GFp_simple_method 3 ,
.Xr EC_GROUP_copy 3 ,
.Xr EC_GROUP_new 3 ,
.Xr EC_KEY_new 3 ,
.Xr EC_POINT_add 3 ,
.Xr EC_POINT_new 3