1 /* $OpenBSD: pem.h,v 1.19 2018/08/24 19:51:31 tb Exp $ */
2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3  * All rights reserved.
4  *
5  * This package is an SSL implementation written
6  * by Eric Young (eay@cryptsoft.com).
7  * The implementation was written so as to conform with Netscapes SSL.
8  *
9  * This library is free for commercial and non-commercial use as core.stdc.config.c_long as
10  * the following conditions are aheared to.  The following conditions
11  * apply to all code found in this distribution, be it the RC4, RSA,
12  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13  * included with this distribution is covered by the same copyright terms
14  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15  *
16  * Copyright remains Eric Young's, and as such any Copyright notices in
17  * the code are not to be removed.
18  * If this package is used in a product, Eric Young should be given attribution
19  * as the author of the parts of the library used.
20  * This can be in the form of a textual message at program startup or
21  * in documentation (online or textual) provided with the package.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *    "This product includes cryptographic software written by
34  *     Eric Young (eay@cryptsoft.com)"
35  *    The word 'cryptographic' can be left out if the rouines from the library
36  *    being used are not cryptographic related :-).
37  * 4. If you include any Windows specific code (or a derivative thereof) from
38  *    the apps directory (application code) you must include an acknowledgement:
39  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40  *
41  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  *
53  * The licence and distribution terms for any publically available version or
54  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55  * copied and put under another distribution licence
56  * [including the GNU Public Licence.]
57  */
58 module libressl_d.openssl.pem;
59 
60 
61 private static import core.stdc.config;
62 private static import libressl_d.compat.stdio;
63 private static import libressl_d.openssl.ec;
64 private static import libressl_d.openssl.objects;
65 private static import libressl_d.openssl.ossl_typ;
66 private static import libressl_d.openssl.pkcs7;
67 public import libressl_d.openssl.bio;
68 public import libressl_d.openssl.evp;
69 public import libressl_d.openssl.opensslconf;
70 public import libressl_d.openssl.pem2;
71 public import libressl_d.openssl.x509;
72 
73 enum HEADER_PEM_H = true;
74 
75 version (OPENSSL_NO_BIO) {
76 } else {
77 	public import libressl_d.openssl.bio;
78 }
79 
80 version (OPENSSL_NO_STACK) {
81 } else {
82 	public import libressl_d.openssl.stack;
83 }
84 
85 extern (C):
86 nothrow @nogc:
87 
88 enum PEM_BUFSIZE = 1024;
89 
90 enum PEM_OBJ_UNDEF = 0;
91 enum PEM_OBJ_X509 = 1;
92 enum PEM_OBJ_X509_REQ = 2;
93 enum PEM_OBJ_CRL = 3;
94 enum PEM_OBJ_SSL_SESSION = 4;
95 enum PEM_OBJ_PRIV_KEY = 10;
96 enum PEM_OBJ_PRIV_RSA = 11;
97 enum PEM_OBJ_PRIV_DSA = 12;
98 enum PEM_OBJ_PRIV_DH = 13;
99 enum PEM_OBJ_PUB_RSA = 14;
100 enum PEM_OBJ_PUB_DSA = 15;
101 enum PEM_OBJ_PUB_DH = 16;
102 enum PEM_OBJ_DHPARAMS = 17;
103 enum PEM_OBJ_DSAPARAMS = 18;
104 enum PEM_OBJ_PRIV_RSA_PUBLIC = 19;
105 enum PEM_OBJ_PRIV_ECDSA = 20;
106 enum PEM_OBJ_PUB_ECDSA = 21;
107 enum PEM_OBJ_ECPARAMETERS = 22;
108 
109 enum PEM_ERROR = 30;
110 enum PEM_DEK_DES_CBC = 40;
111 enum PEM_DEK_IDEA_CBC = 45;
112 enum PEM_DEK_DES_EDE = 50;
113 enum PEM_DEK_DES_ECB = 60;
114 enum PEM_DEK_RSA = 70;
115 enum PEM_DEK_RSA_MD2 = 80;
116 enum PEM_DEK_RSA_MD5 = 90;
117 
118 alias PEM_MD_MD2 = libressl_d.openssl.objects.NID_md2;
119 alias PEM_MD_MD5 = libressl_d.openssl.objects.NID_md5;
120 alias PEM_MD_SHA = libressl_d.openssl.objects.NID_sha;
121 alias PEM_MD_MD2_RSA = libressl_d.openssl.objects.NID_md2WithRSAEncryption;
122 alias PEM_MD_MD5_RSA = libressl_d.openssl.objects.NID_md5WithRSAEncryption;
123 alias PEM_MD_SHA_RSA = libressl_d.openssl.objects.NID_sha1WithRSAEncryption;
124 
125 enum PEM_STRING_X509_OLD = "X509 CERTIFICATE";
126 enum PEM_STRING_X509 = "CERTIFICATE";
127 enum PEM_STRING_X509_PAIR = "CERTIFICATE PAIR";
128 enum PEM_STRING_X509_TRUSTED = "TRUSTED CERTIFICATE";
129 enum PEM_STRING_X509_REQ_OLD = "NEW CERTIFICATE REQUEST";
130 enum PEM_STRING_X509_REQ = "CERTIFICATE REQUEST";
131 enum PEM_STRING_X509_CRL = "X509 CRL";
132 enum PEM_STRING_EVP_PKEY = "ANY PRIVATE KEY";
133 enum PEM_STRING_PUBLIC = "PUBLIC KEY";
134 enum PEM_STRING_RSA = "RSA PRIVATE KEY";
135 enum PEM_STRING_RSA_PUBLIC = "RSA PUBLIC KEY";
136 enum PEM_STRING_DSA = "DSA PRIVATE KEY";
137 enum PEM_STRING_DSA_PUBLIC = "DSA PUBLIC KEY";
138 enum PEM_STRING_PKCS7 = "PKCS7";
139 enum PEM_STRING_PKCS7_SIGNED = "PKCS #7 SIGNED DATA";
140 enum PEM_STRING_PKCS8 = "ENCRYPTED PRIVATE KEY";
141 enum PEM_STRING_PKCS8INF = "PRIVATE KEY";
142 enum PEM_STRING_DHPARAMS = "DH PARAMETERS";
143 enum PEM_STRING_SSL_SESSION = "SSL SESSION PARAMETERS";
144 enum PEM_STRING_DSAPARAMS = "DSA PARAMETERS";
145 enum PEM_STRING_ECDSA_PUBLIC = "ECDSA PUBLIC KEY";
146 enum PEM_STRING_ECPARAMETERS = "EC PARAMETERS";
147 enum PEM_STRING_ECPRIVATEKEY = "EC PRIVATE KEY";
148 enum PEM_STRING_PARAMETERS = "PARAMETERS";
149 enum PEM_STRING_CMS = "CMS";
150 
151 /**
152  * Note that this structure is initialised by PEM_SealInit and cleaned up
153  * by PEM_SealFinal (at least for now)
154  */
155 struct PEM_Encode_Seal_st
156 {
157 	libressl_d.openssl.evp.EVP_ENCODE_CTX encode;
158 	libressl_d.openssl.ossl_typ.EVP_MD_CTX md;
159 	libressl_d.openssl.ossl_typ.EVP_CIPHER_CTX cipher;
160 }
161 
162 alias PEM_ENCODE_SEAL_CTX = .PEM_Encode_Seal_st;
163 
164 /* enc_type is one off */
165 enum PEM_TYPE_ENCRYPTED = 10;
166 enum PEM_TYPE_MIC_ONLY = 20;
167 enum PEM_TYPE_MIC_CLEAR = 30;
168 enum PEM_TYPE_CLEAR = 40;
169 
170 struct pem_recip_st
171 {
172 	char* name;
173 	libressl_d.openssl.ossl_typ.X509_NAME* dn;
174 
175 	int cipher;
176 	int key_enc;
177 	/*
178 	//unused and wrong size
179 	char[8] iv;
180 	*/
181 }
182 
183 alias PEM_USER = .pem_recip_st;
184 
185 struct pem_ctx_st
186 {
187 	/**
188 	 * what type of object
189 	 */
190 	int type;
191 
192 	struct proc_type_
193 	{
194 		int version_;
195 		int mode;
196 	}
197 
198 	proc_type_ proc_type;
199 	char* domain;
200 
201 	struct DEK_info_
202 	{
203 		int cipher;
204 		/*
205 		//unused, and wrong size
206 		ubyte[8] iv;
207 		*/
208 	}
209 
210 	DEK_info_ DEK_info;
211 	.PEM_USER* originator;
212 
213 	int num_recipient;
214 	.PEM_USER** recipient;
215 
216 	/*
217 	XXX(ben): don#t think this is used!
218 	STACK* 509_chain;
219 	//certificate chain
220 	 */
221 
222 	/**
223 	 * signature type
224 	 */
225 	libressl_d.openssl.ossl_typ.EVP_MD* md;
226 
227 	/**
228 	 * is the md encrypted or not?
229 	 */
230 	int md_enc;
231 
232 	/**
233 	 * length of md_data
234 	 */
235 	int md_len;
236 
237 	/**
238 	 * message digest, could be pkey encrypted
239 	 */
240 	char* md_data;
241 
242 	/**
243 	 * date encryption cipher
244 	 */
245 	libressl_d.openssl.ossl_typ.EVP_CIPHER* dec;
246 
247 	/**
248 	 * key length
249 	 */
250 	int key_len;
251 
252 	/**
253 	 * key
254 	 */
255 	ubyte* key;
256 
257 	/*
258 	//unused, and wrong size
259 	ubyte[8] iv;
260 	*/
261 
262 	/**
263 	 * is the data encrypted
264 	 */
265 	int data_enc;
266 
267 	int data_len;
268 	ubyte* data;
269 }
270 
271 alias PEM_CTX = .pem_ctx_st;
272 
273 version (LIBRESSL_INTERNAL) {
274 } else {
275 	/*
276 	 * These macros make the PEM_read/PEM_write functions easier to maintain and
277 	 * write. Now they are all implemented with either:
278 	 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
279 	 */
280 
281 	//#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) type* PEM_read_##name(libressl_d.compat.stdio.FILE* fp, type** x, .pem_password_cb* cb, void* u) { return .PEM_ASN1_read((d2i_of_void*) d2i_##asn1, str, fp, cast(void**)(x), cb, u); }
282 
283 	//#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, type* x) { return .PEM_ASN1_write((i2d_of_void*) i2d_##asn1, str, fp, x, null, null, 0, null, null); }
284 
285 	//#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, const (type)* x) { return .PEM_ASN1_write((i2d_of_void*) i2d_##asn1, str, fp, cast(void*)(x), null, null, 0, null, null); }
286 
287 	//#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u) { return .PEM_ASN1_write((i2d_of_void*) i2d_##asn1, str, fp, x, enc, kstr, klen, cb, u); }
288 
289 	//#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u) { return .PEM_ASN1_write((i2d_of_void*) i2d_##asn1, str, fp, x, enc, kstr, klen, cb, u); }
290 
291 	//#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) type* PEM_read_bio_##name(libressl_d.openssl.bio.BIO* bp, type** x, .pem_password_cb* cb, void* u) { return .PEM_ASN1_read_bio((d2i_of_void*) d2i_##asn1, str, bp, cast(void**)(x), cb, u); }
292 
293 	//#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, type* x) { return .PEM_ASN1_write_bio((i2d_of_void*) i2d_##asn1, str, bp, x, null, null, 0, null, null); }
294 
295 	//#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, const (type)* x) { return .PEM_ASN1_write_bio((i2d_of_void*) i2d_##asn1, str, bp, cast(void*)(x), null, null, 0, null, null); }
296 
297 	//#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u) { return .PEM_ASN1_write_bio((i2d_of_void*) i2d_##asn1, str, bp, x, enc, kstr, klen, cb, u); }
298 
299 	//#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u) { return .PEM_ASN1_write_bio((i2d_of_void*) i2d_##asn1, str, bp, cast(void*)(x), enc, kstr, klen, cb, u); }
300 
301 	//#define IMPLEMENT_PEM_write(name, type, str, asn1) .IMPLEMENT_PEM_write_bio(name, type, str, asn1) .IMPLEMENT_PEM_write_fp(name, type, str, asn1)
302 
303 	//#define IMPLEMENT_PEM_write_const(name, type, str, asn1) .IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) .IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
304 
305 	//#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) .IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) .IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
306 
307 	//#define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) .IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) .IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
308 
309 	//#define IMPLEMENT_PEM_read(name, type, str, asn1) .IMPLEMENT_PEM_read_bio(name, type, str, asn1) .IMPLEMENT_PEM_read_fp(name, type, str, asn1)
310 
311 	//#define IMPLEMENT_PEM_rw(name, type, str, asn1) .IMPLEMENT_PEM_read(name, type, str, asn1) .IMPLEMENT_PEM_write(name, type, str, asn1)
312 
313 	//#define IMPLEMENT_PEM_rw_const(name, type, str, asn1) .IMPLEMENT_PEM_read(name, type, str, asn1) .IMPLEMENT_PEM_write_const(name, type, str, asn1)
314 
315 	//#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) .IMPLEMENT_PEM_read(name, type, str, asn1) .IMPLEMENT_PEM_write_cb(name, type, str, asn1)
316 }
317 
318 /* These are the same except they are for the declarations */
319 
320 //#define DECLARE_PEM_read_fp(name, type) type* PEM_read_##name(libressl_d.compat.stdio.FILE* fp, type** x, .pem_password_cb* cb, void* u);
321 
322 //#define DECLARE_PEM_write_fp(name, type) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, type* x);
323 
324 //#define DECLARE_PEM_write_fp_const(name, type) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, const (type)* x);
325 
326 //#define DECLARE_PEM_write_cb_fp(name, type) int PEM_write_##name(libressl_d.compat.stdio.FILE* fp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u);
327 
328 version (OPENSSL_NO_BIO) {
329 	/* */
330 	//#define DECLARE_PEM_read_bio(name, type)
331 
332 	/* */
333 	//#define DECLARE_PEM_write_bio(name, type)
334 
335 	/* */
336 	//#define DECLARE_PEM_write_bio_const(name, type)
337 
338 	/* */
339 	//#define DECLARE_PEM_write_cb_bio(name, type)
340 } else {
341 	//#define DECLARE_PEM_read_bio(name, type) type* PEM_read_bio_##name(libressl_d.openssl.bio.BIO* bp, type** x, .pem_password_cb* cb, void* u);
342 
343 	//#define DECLARE_PEM_write_bio(name, type) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, type* x);
344 
345 	//#define DECLARE_PEM_write_bio_const(name, type) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, const (type)* x);
346 
347 	//#define DECLARE_PEM_write_cb_bio(name, type) int PEM_write_bio_##name(libressl_d.openssl.bio.BIO* bp, type* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u);
348 }
349 
350 //#define DECLARE_PEM_write(name, type) .DECLARE_PEM_write_bio(name, type) .DECLARE_PEM_write_fp(name, type)
351 
352 //#define DECLARE_PEM_write_const(name, type) .DECLARE_PEM_write_bio_const(name, type) .DECLARE_PEM_write_fp_const(name, type)
353 
354 //#define DECLARE_PEM_write_cb(name, type) .DECLARE_PEM_write_cb_bio(name, type) .DECLARE_PEM_write_cb_fp(name, type)
355 
356 //#define DECLARE_PEM_read(name, type) .DECLARE_PEM_read_bio(name, type) .DECLARE_PEM_read_fp(name, type)
357 
358 //#define DECLARE_PEM_rw(name, type) .DECLARE_PEM_read(name, type) .DECLARE_PEM_write(name, type)
359 
360 //#define DECLARE_PEM_rw_const(name, type) .DECLARE_PEM_read(name, type) .DECLARE_PEM_write_const(name, type)
361 
362 //#define DECLARE_PEM_rw_cb(name, type) .DECLARE_PEM_read(name, type) .DECLARE_PEM_write_cb(name, type)
363 
364 alias pem_password_cb = extern (C) nothrow @nogc int function(char* buf, int size, int rwflag, void* userdata);
365 
366 int PEM_get_EVP_CIPHER_INFO(char* header, libressl_d.openssl.evp.EVP_CIPHER_INFO* cipher);
367 int PEM_do_header(libressl_d.openssl.evp.EVP_CIPHER_INFO* cipher, ubyte* data, core.stdc.config.c_long* len, .pem_password_cb* callback, void* u);
368 
369 version (OPENSSL_NO_BIO) {
370 } else {
371 	package alias d2i_of_void = void;
372 	package alias i2d_of_void = void;
373 
374 	int PEM_read_bio(libressl_d.openssl.bio.BIO* bp, char** name, char** header, ubyte** data, core.stdc.config.c_long* len);
375 	int PEM_write_bio(libressl_d.openssl.bio.BIO* bp, const (char)* name, const (char)* hdr, const (ubyte)* data, core.stdc.config.c_long len);
376 	int PEM_bytes_read_bio(ubyte** pdata, core.stdc.config.c_long* plen, char** pnm, const (char)* name, libressl_d.openssl.bio.BIO* bp, .pem_password_cb* cb, void* u);
377 	void* PEM_ASN1_read_bio(d2i_of_void* d2i, const (char)* name, libressl_d.openssl.bio.BIO* bp, void** x, .pem_password_cb* cb, void* u);
378 	int PEM_ASN1_write_bio(i2d_of_void* i2d, const (char)* name, libressl_d.openssl.bio.BIO* bp, void* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* cb, void* u);
379 
380 	libressl_d.openssl.x509.stack_st_X509_INFO* PEM_X509_INFO_read_bio(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.x509.stack_st_X509_INFO* sk, .pem_password_cb* cb, void* u);
381 	int PEM_X509_INFO_write_bio(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.x509.X509_INFO* xi, libressl_d.openssl.ossl_typ.EVP_CIPHER* enc, ubyte* kstr, int klen, .pem_password_cb* cd, void* u);
382 }
383 
384 int PEM_read(libressl_d.compat.stdio.FILE* fp, char** name, char** header, ubyte** data, core.stdc.config.c_long* len);
385 int PEM_write(libressl_d.compat.stdio.FILE* fp, const (char)* name, const (char)* hdr, const (ubyte)* data, core.stdc.config.c_long len);
386 void* PEM_ASN1_read(d2i_of_void* d2i, const (char)* name, libressl_d.compat.stdio.FILE* fp, void** x, .pem_password_cb* cb, void* u);
387 int PEM_ASN1_write(i2d_of_void* i2d, const (char)* name, libressl_d.compat.stdio.FILE* fp, void* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, ubyte* kstr, int klen, .pem_password_cb* callback, void* u);
388 libressl_d.openssl.x509.stack_st_X509_INFO* PEM_X509_INFO_read(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.x509.stack_st_X509_INFO* sk, .pem_password_cb* cb, void* u);
389 
390 int PEM_SealInit(.PEM_ENCODE_SEAL_CTX* ctx, libressl_d.openssl.ossl_typ.EVP_CIPHER* type, libressl_d.openssl.ossl_typ.EVP_MD* md_type, ubyte** ek, int* ekl, ubyte* iv, libressl_d.openssl.ossl_typ.EVP_PKEY** pubk, int npubk);
391 void PEM_SealUpdate(.PEM_ENCODE_SEAL_CTX* ctx, ubyte* out_, int* outl, ubyte* in_, int inl);
392 int PEM_SealFinal(.PEM_ENCODE_SEAL_CTX* ctx, ubyte* sig, int* sigl, ubyte* out_, int* outl, libressl_d.openssl.ossl_typ.EVP_PKEY* priv);
393 
394 int PEM_SignInit(libressl_d.openssl.ossl_typ.EVP_MD_CTX* ctx, libressl_d.openssl.ossl_typ.EVP_MD* type);
395 int PEM_SignUpdate(libressl_d.openssl.ossl_typ.EVP_MD_CTX* ctx, ubyte* d, uint cnt);
396 int PEM_SignFinal(libressl_d.openssl.ossl_typ.EVP_MD_CTX* ctx, ubyte* sigret, uint* siglen, libressl_d.openssl.ossl_typ.EVP_PKEY* pkey);
397 
398 int PEM_def_callback(char* buf, int num, int w, void* key);
399 void PEM_proc_type(char* buf, int type);
400 void PEM_dek_info(char* buf, const (char)* type, int len, char* str);
401 
402 //.DECLARE_PEM_rw(libressl_d.openssl.ossl_typ.X509, libressl_d.openssl.ossl_typ.X509)
403 
404 //.DECLARE_PEM_rw(X509_AUX, libressl_d.openssl.ossl_typ.X509)
405 
406 //.DECLARE_PEM_rw(libressl_d.openssl.x509.X509_CERT_PAIR, libressl_d.openssl.x509.X509_CERT_PAIR)
407 
408 //.DECLARE_PEM_rw(libressl_d.openssl.x509.X509_REQ, libressl_d.openssl.x509.X509_REQ) .DECLARE_PEM_write(X509_REQ_NEW, libressl_d.openssl.x509.X509_REQ)
409 
410 //.DECLARE_PEM_rw(libressl_d.openssl.ossl_typ.X509_CRL, libressl_d.openssl.ossl_typ.X509_CRL)
411 
412 //.DECLARE_PEM_rw(libressl_d.openssl.pkcs7.PKCS7, libressl_d.openssl.pkcs7.PKCS7)
413 
414 //.DECLARE_PEM_rw(libressl_d.openssl.x509.NETSCAPE_CERT_SEQUENCE, libressl_d.openssl.x509.NETSCAPE_CERT_SEQUENCE)
415 
416 //.DECLARE_PEM_rw(PKCS8, libressl_d.openssl.x509.X509_SIG)
417 
418 //.DECLARE_PEM_rw(libressl_d.openssl.ossl_typ.PKCS8_PRIV_KEY_INFO, libressl_d.openssl.ossl_typ.PKCS8_PRIV_KEY_INFO)
419 
420 version (OPENSSL_NO_RSA) {
421 } else {
422 	//.DECLARE_PEM_rw_cb(RSAPrivateKey, libressl_d.openssl.ossl_typ.RSA)
423 
424 	//.DECLARE_PEM_rw_const(RSAPublicKey, libressl_d.openssl.ossl_typ.RSA) .DECLARE_PEM_rw(RSA_PUBKEY, libressl_d.openssl.ossl_typ.RSA)
425 }
426 
427 version (OPENSSL_NO_DSA) {
428 } else {
429 	//.DECLARE_PEM_rw_cb(DSAPrivateKey, libressl_d.openssl.ossl_typ.DSA)
430 
431 	//.DECLARE_PEM_rw(DSA_PUBKEY, libressl_d.openssl.ossl_typ.DSA)
432 
433 	//.DECLARE_PEM_rw_const(DSAparams, libressl_d.openssl.ossl_typ.DSA)
434 }
435 
436 version (OPENSSL_NO_EC) {
437 } else {
438 	//.DECLARE_PEM_rw_const(ECPKParameters, libressl_d.openssl.ec.EC_GROUP) .DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) .DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
439 }
440 
441 version (OPENSSL_NO_DH) {
442 } else {
443 	//.DECLARE_PEM_rw_const(DHparams, libressl_d.openssl.ossl_typ.DH)
444 }
445 
446 //.DECLARE_PEM_rw_cb(PrivateKey, libressl_d.openssl.ossl_typ.EVP_PKEY)
447 
448 //.DECLARE_PEM_rw(PUBKEY, libressl_d.openssl.ossl_typ.EVP_PKEY)
449 
450 int PEM_write_bio_PKCS8PrivateKey_nid(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, int nid, char* kstr, int klen, .pem_password_cb* cb, void* u);
451 int PEM_write_bio_PKCS8PrivateKey(libressl_d.openssl.bio.BIO*, libressl_d.openssl.ossl_typ.EVP_PKEY*, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)*, char*, int, .pem_password_cb*, void*);
452 int i2d_PKCS8PrivateKey_bio(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, char* kstr, int klen, .pem_password_cb* cb, void* u);
453 int i2d_PKCS8PrivateKey_nid_bio(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, int nid, char* kstr, int klen, .pem_password_cb* cb, void* u);
454 libressl_d.openssl.ossl_typ.EVP_PKEY* d2i_PKCS8PrivateKey_bio(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY** x, .pem_password_cb* cb, void* u);
455 
456 int i2d_PKCS8PrivateKey_fp(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, char* kstr, int klen, .pem_password_cb* cb, void* u);
457 int i2d_PKCS8PrivateKey_nid_fp(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, int nid, char* kstr, int klen, .pem_password_cb* cb, void* u);
458 int PEM_write_PKCS8PrivateKey_nid(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, int nid, char* kstr, int klen, .pem_password_cb* cb, void* u);
459 
460 libressl_d.openssl.ossl_typ.EVP_PKEY* d2i_PKCS8PrivateKey_fp(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.ossl_typ.EVP_PKEY** x, .pem_password_cb* cb, void* u);
461 
462 int PEM_write_PKCS8PrivateKey(libressl_d.compat.stdio.FILE* fp, libressl_d.openssl.ossl_typ.EVP_PKEY* x, const (libressl_d.openssl.ossl_typ.EVP_CIPHER)* enc, char* kstr, int klen, .pem_password_cb* cd, void* u);
463 
464 libressl_d.openssl.ossl_typ.EVP_PKEY* PEM_read_bio_Parameters(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY** x);
465 int PEM_write_bio_Parameters(libressl_d.openssl.bio.BIO* bp, libressl_d.openssl.ossl_typ.EVP_PKEY* x);
466 
467 libressl_d.openssl.ossl_typ.EVP_PKEY* b2i_PrivateKey(const (ubyte)** in_, core.stdc.config.c_long length_);
468 libressl_d.openssl.ossl_typ.EVP_PKEY* b2i_PublicKey(const (ubyte)** in_, core.stdc.config.c_long length_);
469 libressl_d.openssl.ossl_typ.EVP_PKEY* b2i_PrivateKey_bio(libressl_d.openssl.bio.BIO* in_);
470 libressl_d.openssl.ossl_typ.EVP_PKEY* b2i_PublicKey_bio(libressl_d.openssl.bio.BIO* in_);
471 int i2b_PrivateKey_bio(libressl_d.openssl.bio.BIO* out_, libressl_d.openssl.ossl_typ.EVP_PKEY* pk);
472 int i2b_PublicKey_bio(libressl_d.openssl.bio.BIO* out_, libressl_d.openssl.ossl_typ.EVP_PKEY* pk);
473 
474 version (OPENSSL_NO_RC4) {
475 } else {
476 	libressl_d.openssl.ossl_typ.EVP_PKEY* b2i_PVK_bio(libressl_d.openssl.bio.BIO* in_, .pem_password_cb* cb, void* u);
477 	int i2b_PVK_bio(libressl_d.openssl.bio.BIO* out_, libressl_d.openssl.ossl_typ.EVP_PKEY* pk, int enclevel, .pem_password_cb* cb, void* u);
478 }
479 
480 /* BEGIN ERROR CODES */
481 /*
482  * The following lines are auto generated by the script mkerr.pl. Any changes
483  * made after this point may be overwritten when the script is next run.
484  */
485 void ERR_load_PEM_strings();
486 
487 /* Error codes for the PEM functions. */
488 
489 /* Function codes. */
490 enum PEM_F_B2I_DSS = 127;
491 enum PEM_F_B2I_PVK_BIO = 128;
492 enum PEM_F_B2I_RSA = 129;
493 enum PEM_F_CHECK_BITLEN_DSA = 130;
494 enum PEM_F_CHECK_BITLEN_RSA = 131;
495 enum PEM_F_D2I_PKCS8PRIVATEKEY_BIO = 120;
496 enum PEM_F_D2I_PKCS8PRIVATEKEY_FP = 121;
497 enum PEM_F_DO_B2I = 132;
498 enum PEM_F_DO_B2I_BIO = 133;
499 enum PEM_F_DO_BLOB_HEADER = 134;
500 enum PEM_F_DO_PK8PKEY = 126;
501 enum PEM_F_DO_PK8PKEY_FP = 125;
502 enum PEM_F_DO_PVK_BODY = 135;
503 enum PEM_F_DO_PVK_HEADER = 136;
504 enum PEM_F_I2B_PVK = 137;
505 enum PEM_F_I2B_PVK_BIO = 138;
506 enum PEM_F_LOAD_IV = 101;
507 enum PEM_F_PEM_ASN1_READ = 102;
508 enum PEM_F_PEM_ASN1_READ_BIO = 103;
509 enum PEM_F_PEM_ASN1_WRITE = 104;
510 enum PEM_F_PEM_ASN1_WRITE_BIO = 105;
511 enum PEM_F_PEM_DEF_CALLBACK = 100;
512 enum PEM_F_PEM_DO_HEADER = 106;
513 enum PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY = 118;
514 enum PEM_F_PEM_GET_EVP_CIPHER_INFO = 107;
515 enum PEM_F_PEM_PK8PKEY = 119;
516 enum PEM_F_PEM_READ = 108;
517 enum PEM_F_PEM_READ_BIO = 109;
518 enum PEM_F_PEM_READ_BIO_PARAMETERS = 140;
519 enum PEM_F_PEM_READ_BIO_PRIVATEKEY = 123;
520 enum PEM_F_PEM_READ_PRIVATEKEY = 124;
521 enum PEM_F_PEM_SEALFINAL = 110;
522 enum PEM_F_PEM_SEALINIT = 111;
523 enum PEM_F_PEM_SIGNFINAL = 112;
524 enum PEM_F_PEM_WRITE = 113;
525 enum PEM_F_PEM_WRITE_BIO = 114;
526 enum PEM_F_PEM_WRITE_PRIVATEKEY = 139;
527 enum PEM_F_PEM_X509_INFO_READ = 115;
528 enum PEM_F_PEM_X509_INFO_READ_BIO = 116;
529 enum PEM_F_PEM_X509_INFO_WRITE_BIO = 117;
530 
531 /* Reason codes. */
532 enum PEM_R_BAD_BASE64_DECODE = 100;
533 enum PEM_R_BAD_DECRYPT = 101;
534 enum PEM_R_BAD_END_LINE = 102;
535 enum PEM_R_BAD_IV_CHARS = 103;
536 enum PEM_R_BAD_MAGIC_NUMBER = 116;
537 enum PEM_R_BAD_PASSWORD_READ = 104;
538 enum PEM_R_BAD_VERSION_NUMBER = 117;
539 enum PEM_R_BIO_WRITE_FAILURE = 118;
540 enum PEM_R_CIPHER_IS_NULL = 127;
541 enum PEM_R_ERROR_CONVERTING_PRIVATE_KEY = 115;
542 enum PEM_R_EXPECTING_PRIVATE_KEY_BLOB = 119;
543 enum PEM_R_EXPECTING_PUBLIC_KEY_BLOB = 120;
544 enum PEM_R_INCONSISTENT_HEADER = 121;
545 enum PEM_R_KEYBLOB_HEADER_PARSE_ERROR = 122;
546 enum PEM_R_KEYBLOB_TOO_SHORT = 123;
547 enum PEM_R_NOT_DEK_INFO = 105;
548 enum PEM_R_NOT_ENCRYPTED = 106;
549 enum PEM_R_NOT_PROC_TYPE = 107;
550 enum PEM_R_NO_START_LINE = 108;
551 enum PEM_R_PROBLEMS_GETTING_PASSWORD = 109;
552 enum PEM_R_PUBLIC_KEY_NO_RSA = 110;
553 enum PEM_R_PVK_DATA_TOO_SHORT = 124;
554 enum PEM_R_PVK_TOO_SHORT = 125;
555 enum PEM_R_READ_KEY = 111;
556 enum PEM_R_SHORT_HEADER = 112;
557 enum PEM_R_UNSUPPORTED_CIPHER = 113;
558 enum PEM_R_UNSUPPORTED_ENCRYPTION = 114;
559 enum PEM_R_UNSUPPORTED_KEY_COMPONENTS = 126;