Unleashed v1.4
[unleashed.git] / lib / libcrypto / man / X509_PUBKEY_new.3
blobd5af722e4294d332780bb1b470e6f849c3fe4b8b
1 .\" $OpenBSD: X509_PUBKEY_new.3,v 1.13 2018/03/27 17:35:50 schwarze Exp $
2 .\" full merge up to: OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3 .\"
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2016 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in
16 .\"    the documentation and/or other materials provided with the
17 .\"    distribution.
18 .\"
19 .\" 3. All advertising materials mentioning features or use of this
20 .\"    software must display the following acknowledgment:
21 .\"    "This product includes software developed by the OpenSSL Project
22 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 .\"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\"    endorse or promote products derived from this software without
26 .\"    prior written permission. For written permission, please contact
27 .\"    openssl-core@openssl.org.
28 .\"
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\"    nor may "OpenSSL" appear in their names without prior written
31 .\"    permission of the OpenSSL Project.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
50 .\"
51 .Dd $Mdocdate: March 27 2018 $
52 .Dt X509_PUBKEY_NEW 3
53 .Os
54 .Sh NAME
55 .Nm X509_PUBKEY_new ,
56 .Nm X509_PUBKEY_free ,
57 .Nm X509_PUBKEY_set ,
58 .Nm X509_PUBKEY_get0 ,
59 .Nm X509_PUBKEY_get ,
60 .Nm d2i_PUBKEY ,
61 .Nm i2d_PUBKEY ,
62 .Nm d2i_PUBKEY_bio ,
63 .Nm d2i_PUBKEY_fp ,
64 .Nm i2d_PUBKEY_fp ,
65 .Nm i2d_PUBKEY_bio ,
66 .Nm X509_PUBKEY_set0_param ,
67 .Nm X509_PUBKEY_get0_param
68 .Nd X.509 SubjectPublicKeyInfo structure
69 .Sh SYNOPSIS
70 .In openssl/x509.h
71 .Ft X509_PUBKEY *
72 .Fn X509_PUBKEY_new void
73 .Ft void
74 .Fo X509_PUBKEY_free
75 .Fa "X509_PUBKEY *a"
76 .Fc
77 .Ft int
78 .Fo X509_PUBKEY_set
79 .Fa "X509_PUBKEY **x"
80 .Fa "EVP_PKEY *pkey"
81 .Fc
82 .Ft EVP_PKEY *
83 .Fo X509_PUBKEY_get0
84 .Fa "X509_PUBKEY *key"
85 .Fc
86 .Ft EVP_PKEY *
87 .Fo X509_PUBKEY_get
88 .Fa "X509_PUBKEY *key"
89 .Fc
90 .Ft EVP_PKEY *
91 .Fo d2i_PUBKEY
92 .Fa "EVP_PKEY **a"
93 .Fa "const unsigned char **pp"
94 .Fa "long length"
95 .Fc
96 .Ft int
97 .Fo i2d_PUBKEY
98 .Fa "EVP_PKEY *a"
99 .Fa "unsigned char **pp"
101 .Ft EVP_PKEY *
102 .Fo d2i_PUBKEY_bio
103 .Fa "BIO *bp"
104 .Fa "EVP_PKEY **a"
106 .Ft EVP_PKEY *
107 .Fo d2i_PUBKEY_fp
108 .Fa "FILE *fp"
109 .Fa "EVP_PKEY **a"
111 .Ft int
112 .Fo i2d_PUBKEY_fp
113 .Fa "FILE *fp"
114 .Fa "EVP_PKEY *pkey"
116 .Ft int
117 .Fo i2d_PUBKEY_bio
118 .Fa "BIO *bp"
119 .Fa "EVP_PKEY *pkey"
121 .Ft int
122 .Fo X509_PUBKEY_set0_param
123 .Fa "X509_PUBKEY *pub"
124 .Fa "ASN1_OBJECT *aobj"
125 .Fa "int ptype"
126 .Fa "void *pval"
127 .Fa "unsigned char *penc"
128 .Fa "int penclen"
130 .Ft int
131 .Fo X509_PUBKEY_get0_param
132 .Fa "ASN1_OBJECT **ppkalg"
133 .Fa "const unsigned char **pk"
134 .Fa "int *ppklen"
135 .Fa "X509_ALGOR **pa"
136 .Fa "X509_PUBKEY *pub"
138 .Sh DESCRIPTION
140 .Vt X509_PUBKEY
141 structure represents the ASN.1
142 .Vt SubjectPublicKeyInfo
143 structure defined in RFC 5280 section 4.1 and used in certificates
144 and certificate requests.
146 .Fn X509_PUBKEY_new
147 allocates and initializes an
148 .Vt X509_PUBKEY
149 structure.
151 .Fn X509_PUBKEY_free
152 frees up the
153 .Vt X509_PUBKEY
154 structure
155 .Fa a .
157 .Fa a
158 is a
159 .Dv NULL
160 pointer, no action occurs.
162 .Fn X509_PUBKEY_set
163 sets the public key in
164 .Pf * Fa x
165 to the public key contained in the
166 .Vt EVP_PKEY
167 structure
168 .Fa pkey .
170 .Pf * Fa x
171 is not
172 .Dv NULL ,
173 any existing public key structure will be freed.
175 .Fn X509_PUBKEY_get0
176 returns the public key contained in
177 .Fa key .
178 The returned value is an internal pointer which must not be freed after use.
180 .Fn X509_PUBKEY_get
181 is similar to
182 .Fn X509_PUBKEY_get0
183 except that the reference
184 count on the returned key is incremented so it must be freed using
185 .Xr EVP_PKEY_free 3
186 after use.
188 .Fn d2i_PUBKEY
190 .Fn i2d_PUBKEY
191 decode and encode an
192 .Vt EVP_PKEY
193 structure using
194 .Vt SubjectPublicKeyInfo
195 format.
196 For details about the semantics, examples, caveats, and bugs, see
197 .Xr ASN1_item_d2i 3 .
198 .Fn d2i_PUBKEY_bio ,
199 .Fn d2i_PUBKEY_fp ,
200 .Fn i2d_PUBKEY_bio
202 .Fn i2d_PUBKEY_fp
203 are similar except they decode or encode using a
204 .Vt BIO
206 .Vt FILE
207 pointer.
209 .Fn X509_PUBKEY_set0_param
210 sets the public key parameters of
211 .Fa pub .
212 The OID associated with the algorithm is set to
213 .Fa aobj .
214 The type of the algorithm parameters is set to
215 .Fa ptype
216 using the structure
217 .Fa pval .
218 The encoding of the public key itself is set to the
219 .Fa penclen
220 bytes contained in buffer
221 .Fa penc .
222 On success ownership of all the supplied parameters is passed to
223 .Fa pub
224 so they must not be freed after the call.
226 .Fn X509_PUBKEY_get0_param
227 retrieves the public key parameters from
228 .Fa pub ,
229 .Pf * Fa ppkalg
230 is set to the associated OID and the encoding consists of
231 .Pf * Fa ppklen
232 bytes at
233 .Pf * Fa pk ,
235 .Pf * Fa pa
236 is set to the associated
237 .Vt AlgorithmIdentifier
238 for the public key.
239 If the value of any of these parameters is not required,
240 it can be set to
241 .Dv NULL .
242 All of the retrieved pointers are internal and must not be freed after
243 the call.
244 .Sh RETURN VALUES
245 If the allocation fails,
246 .Fn X509_PUBKEY_new
247 returns
248 .Dv NULL
249 and sets an error code that can be obtained by
250 .Xr ERR_get_error 3 .
251 Otherwise it returns a pointer to the newly allocated structure.
253 .Fn X509_PUBKEY_get0 ,
254 .Fn X509_PUBKEY_get ,
255 .Fn d2i_PUBKEY ,
256 .Fn d2i_PUBKEY_bio ,
258 .Fn d2i_PUBKEY_fp
259 return a pointer to an
260 .Vt EVP_PKEY
261 structure or
262 .Dv NULL
263 if an error occurs.
265 .Fn i2d_PUBKEY
266 returns the number of bytes successfully encoded or a negative value
267 if an error occurs.
269 .Fn X509_PUBKEY_set ,
270 .Fn X509_PUBKEY_set0_param ,
271 .Fn X509_PUBKEY_get0_param ,
272 .Fn i2d_PUBKEY_fp ,
274 .Fn i2d_PUBKEY_bio
275 return 1 for success and 0 if an error occurred.
276 .Sh SEE ALSO
277 .Xr d2i_X509 3 ,
278 .Xr ERR_get_error 3 ,
279 .Xr EVP_PKEY_asn1_set_public 3 ,
280 .Xr X509_ALGOR_new 3 ,
281 .Xr X509_get_pubkey 3
282 .Sh STANDARDS
283 RFC 5280: Internet X.509 Public Key Infrastructure Certificate and
284 Certificate Revocation List (CRL) Profile
285 .Sh HISTORY
286 .Fn X509_PUBKEY_new
288 .Fn X509_PUBKEY_free
289 appeared in SSLeay 0.4 or earlier.
290 .Fn X509_PUBKEY_set
292 .Fn X509_PUBKEY_get
293 first appeared in SSLeay 0.8.0.
294 These functions have been available since
295 .Ox 2.4 .
297 .Fn d2i_PUBKEY
299 .Fn i2d_PUBKEY
300 first appeared in OpenSSL 0.9.5 and have been available since
301 .Ox 2.7 .
303 .Fn d2i_PUBKEY_bio ,
304 .Fn d2i_PUBKEY_fp ,
305 .Fn i2d_PUBKEY_fp ,
307 .Fn i2d_PUBKEY_bio
308 first appeared in OpenSSL 0.9.6 and have been available since
309 .Ox 2.9 .
311 .Fn X509_PUBKEY_set0_param
313 .Fn X509_PUBKEY_get0_param
314 first appeared in OpenSSL 1.0.0 and have been available since
315 .Ox 4.9 .
317 .Fn X509_PUBKEY_get0
318 first appeared in OpenSSL 1.1.0 and has been available since
319 .Ox 6.3 .