1 .\" $OpenBSD: d2i_PrivateKey.3,v 1.5 2016/12/28 01:38:16 schwarze Exp $
2 .\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
4 .\" This file is a derived work.
5 .\" The changes are covered by the following Copyright and license:
7 .\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
9 .\" Permission to use, copy, modify, and distribute this software for any
10 .\" purpose with or without fee is hereby granted, provided that the above
11 .\" copyright notice and this permission notice appear in all copies.
13 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 .\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
22 .\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
24 .\" Redistribution and use in source and binary forms, with or without
25 .\" modification, are permitted provided that the following conditions
28 .\" 1. Redistributions of source code must retain the above copyright
29 .\" notice, this list of conditions and the following disclaimer.
31 .\" 2. Redistributions in binary form must reproduce the above copyright
32 .\" notice, this list of conditions and the following disclaimer in
33 .\" the documentation and/or other materials provided with the
36 .\" 3. All advertising materials mentioning features or use of this
37 .\" software must display the following acknowledgment:
38 .\" "This product includes software developed by the OpenSSL Project
39 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
41 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 .\" endorse or promote products derived from this software without
43 .\" prior written permission. For written permission, please contact
44 .\" openssl-core@openssl.org.
46 .\" 5. Products derived from this software may not be called "OpenSSL"
47 .\" nor may "OpenSSL" appear in their names without prior written
48 .\" permission of the OpenSSL Project.
50 .\" 6. Redistributions of any form whatsoever must retain the following
52 .\" "This product includes software developed by the OpenSSL Project
53 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
55 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
68 .Dd $Mdocdate: December 28 2016 $
73 .Nm d2i_AutoPrivateKey ,
75 .Nm d2i_PrivateKey_bio ,
76 .Nm d2i_PrivateKey_fp ,
77 .Nm i2d_PKCS8PrivateKeyInfo_bio ,
78 .Nm i2d_PKCS8PrivateKeyInfo_fp ,
81 .Nd decode and encode EVP_PKEY objects
87 .Fa "EVP_PKEY **val_out"
88 .Fa "const unsigned char **des_in"
92 .Fo d2i_AutoPrivateKey
93 .Fa "EVP_PKEY **val_out"
94 .Fa "const unsigned char **des_in"
99 .Fa "EVP_PKEY *val_in"
100 .Fa "unsigned char **des_out"
103 .Fo d2i_PrivateKey_bio
105 .Fa "EVP_PKEY **val_out"
108 .Fo d2i_PrivateKey_fp
110 .Fa "EVP_PKEY **val_out"
113 .Fo i2d_PKCS8PrivateKeyInfo_bio
115 .Fa "EVP_PKEY *val_in"
118 .Fo i2d_PKCS8PrivateKeyInfo_fp
120 .Fa "EVP_PKEY *val_in"
125 .Fa "EVP_PKEY **val_out"
126 .Fa "const unsigned char **des_in"
131 .Fa "EVP_PKEY *val_in"
132 .Fa "unsigned char **des_out"
135 These are algorithm-independent interfaces to decode and encode
136 private and public keys.
137 For details about the semantics, examples, caveats, and bugs, see
138 .Xr ASN1_item_d2i 3 .
141 decodes a private key using algorithm
143 It attempts to use any algorithm specific format or the PKCS#8 unencrypted
145 format defined in RFC 5208 section 5.
148 parameter should be a public key algorithm constant such as
150 An error occurs if the decoded key does not match
153 .Fn d2i_AutoPrivateKey
156 except that it attempts to automatically detect the algorithm.
158 .Fn d2i_PrivateKey_bio
160 .Fn d2i_PrivateKey_fp
163 except that they read from a
172 It uses an algorithm specific format or, if none is defined for
173 that key type, the PKCS#8 unencrypted
177 .Fn i2d_PKCS8PrivateKeyInfo_bio
179 .Fn i2d_PKCS8PrivateKeyInfo_fp
182 in PKCS#8 unencrypted
187 except that they don't use any algorithm-specific formats
188 and that they write to a
192 pointer rather than to a buffer.
194 All these functions use DER format and unencrypted keys.
195 Applications wishing to encrypt or decrypt private keys should use other
197 .Xr d2i_PKCS8PrivateKey_bio 3
207 .Fn d2i_AutoPrivateKey
208 (i.e. an existing structure is being reused) and the key format is
211 will be freed and replaced on a successful call.
215 .Xr d2i_DSAPublicKey 3 ,
216 .Xr o2i_ECPublicKey 3 ,
218 .Xr d2i_RSAPublicKey 3
221 and stores the result in the returned
227 .Xr i2d_DSAPublicKey 3 ,
228 .Xr i2o_ECPublicKey 3 ,
230 .Xr i2d_RSAPublicKey 3
231 depending on the algorithm used by
235 .Fn d2i_AutoPrivateKey ,
236 .Fn d2i_PrivateKey_bio ,
237 .Fn d2i_PrivateKey_fp ,
249 return the number of bytes successfully encoded or a negative value if
252 .Fn i2d_PKCS8PrivateKeyInfo_bio
254 .Fn i2d_PKCS8PrivateKeyInfo_fp
255 return 1 for success or 0 if an error occurs.
257 For all functions, the error code can be obtained by calling
258 .Xr ERR_get_error 3 .
260 .Xr d2i_PKCS8_PRIV_KEY_INFO 3 ,
261 .Xr d2i_PKCS8PrivateKey_bio 3 ,
262 .Xr EVP_PKEY_type 3 ,
263 .Xr PEM_write_PrivateKey 3 ,
264 .Xr PKCS8_PRIV_KEY_INFO_new 3
266 RFC 5208: Public-Key Cryptography Standards (PKCS) #8: Private-Key
267 Information Syntax Specification