1 /* 2 * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #ifndef OPENSSL_PEM_H 11 # define OPENSSL_PEM_H 12 # pragma once 13 14 # include <openssl/macros.h> 15 # ifndef OPENSSL_NO_DEPRECATED_3_0 16 # define HEADER_PEM_H 17 # endif 18 19 # include <openssl/e_os2.h> 20 # include <openssl/bio.h> 21 # include <openssl/safestack.h> 22 # include <openssl/evp.h> 23 # include <openssl/x509.h> 24 # include <openssl/pemerr.h> 25 # ifndef OPENSSL_NO_STDIO 26 # include <stdio.h> 27 # endif 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 # define PEM_BUFSIZE 1024 34 35 # define PEM_STRING_X509_OLD "X509 CERTIFICATE" 36 # define PEM_STRING_X509 "CERTIFICATE" 37 # define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" 38 # define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 39 # define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 40 # define PEM_STRING_X509_CRL "X509 CRL" 41 # define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" 42 # define PEM_STRING_PUBLIC "PUBLIC KEY" 43 # define PEM_STRING_RSA "RSA PRIVATE KEY" 44 # define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 45 # define PEM_STRING_DSA "DSA PRIVATE KEY" 46 # define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" 47 # define PEM_STRING_PKCS7 "PKCS7" 48 # define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" 49 # define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" 50 # define PEM_STRING_PKCS8INF "PRIVATE KEY" 51 # define PEM_STRING_DHPARAMS "DH PARAMETERS" 52 # define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" 53 # define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 54 # define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 55 # define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" 56 # define PEM_STRING_ECPARAMETERS "EC PARAMETERS" 57 # define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" 58 # define PEM_STRING_PARAMETERS "PARAMETERS" 59 # define PEM_STRING_CMS "CMS" 60 # define PEM_STRING_SM2PRIVATEKEY "SM2 PRIVATE KEY" 61 # define PEM_STRING_SM2PARAMETERS "SM2 PARAMETERS" 62 # define PEM_STRING_ACERT "ATTRIBUTE CERTIFICATE" 63 64 # define PEM_TYPE_ENCRYPTED 10 65 # define PEM_TYPE_MIC_ONLY 20 66 # define PEM_TYPE_MIC_CLEAR 30 67 # define PEM_TYPE_CLEAR 40 68 69 /* 70 * These macros make the PEM_read/PEM_write functions easier to maintain and 71 * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or 72 * IMPLEMENT_PEM_rw_cb(...) 73 */ 74 75 # define PEM_read_cb_fnsig(name, type, INTYPE, readname) \ 76 type *PEM_##readname##_##name(INTYPE *out, type **x, \ 77 pem_password_cb *cb, void *u) 78 # define PEM_read_cb_ex_fnsig(name, type, INTYPE, readname) \ 79 type *PEM_##readname##_##name##_ex(INTYPE *out, type **x, \ 80 pem_password_cb *cb, void *u, \ 81 OSSL_LIB_CTX *libctx, \ 82 const char *propq) 83 84 # define PEM_write_fnsig(name, type, OUTTYPE, writename) \ 85 int PEM_##writename##_##name(OUTTYPE *out, const type *x) 86 # define PEM_write_cb_fnsig(name, type, OUTTYPE, writename) \ 87 int PEM_##writename##_##name(OUTTYPE *out, const type *x, \ 88 const EVP_CIPHER *enc, \ 89 const unsigned char *kstr, int klen, \ 90 pem_password_cb *cb, void *u) 91 # define PEM_write_ex_fnsig(name, type, OUTTYPE, writename) \ 92 int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \ 93 OSSL_LIB_CTX *libctx, \ 94 const char *propq) 95 # define PEM_write_cb_ex_fnsig(name, type, OUTTYPE, writename) \ 96 int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \ 97 const EVP_CIPHER *enc, \ 98 const unsigned char *kstr, int klen, \ 99 pem_password_cb *cb, void *u, \ 100 OSSL_LIB_CTX *libctx, \ 101 const char *propq) 102 103 # ifdef OPENSSL_NO_STDIO 104 105 # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ 106 # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ 107 # ifndef OPENSSL_NO_DEPRECATED_3_0 108 # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ 109 # endif 110 # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ 111 # ifndef OPENSSL_NO_DEPRECATED_3_0 112 # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ 113 # endif 114 # else 115 116 # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 117 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u) \ 118 { \ 119 return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str, fp, \ 120 (void **)x, cb, u); \ 121 } 122 123 # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 124 PEM_write_fnsig(name, type, FILE, write) \ 125 { \ 126 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \ 127 x, NULL, NULL, 0, NULL, NULL); \ 128 } 129 130 # ifndef OPENSSL_NO_DEPRECATED_3_0 131 # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 132 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 133 # endif 134 135 # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 136 PEM_write_cb_fnsig(name, type, FILE, write) \ 137 { \ 138 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \ 139 x, enc, kstr, klen, cb, u); \ 140 } 141 142 # ifndef OPENSSL_NO_DEPRECATED_3_0 143 # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 144 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 145 # endif 146 # endif 147 148 # define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 149 type *PEM_read_bio_##name(BIO *bp, type **x, \ 150 pem_password_cb *cb, void *u) \ 151 { \ 152 return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str, bp, \ 153 (void **)x, cb, u); \ 154 } 155 156 # define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 157 PEM_write_fnsig(name, type, BIO, write_bio) \ 158 { \ 159 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \ 160 x, NULL,NULL,0,NULL,NULL); \ 161 } 162 163 # ifndef OPENSSL_NO_DEPRECATED_3_0 164 # define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 165 IMPLEMENT_PEM_write_bio(name, type, str, asn1) 166 # endif 167 168 # define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 169 PEM_write_cb_fnsig(name, type, BIO, write_bio) \ 170 { \ 171 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \ 172 x, enc, kstr, klen, cb, u); \ 173 } 174 175 # ifndef OPENSSL_NO_DEPRECATED_3_0 176 # define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 177 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) 178 # endif 179 180 # define IMPLEMENT_PEM_write(name, type, str, asn1) \ 181 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 182 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 183 184 # ifndef OPENSSL_NO_DEPRECATED_3_0 185 # define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ 186 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 187 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 188 # endif 189 190 # define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 191 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 192 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 193 194 # ifndef OPENSSL_NO_DEPRECATED_3_0 195 # define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ 196 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 197 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 198 # endif 199 200 # define IMPLEMENT_PEM_read(name, type, str, asn1) \ 201 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 202 IMPLEMENT_PEM_read_fp(name, type, str, asn1) 203 204 # define IMPLEMENT_PEM_rw(name, type, str, asn1) \ 205 IMPLEMENT_PEM_read(name, type, str, asn1) \ 206 IMPLEMENT_PEM_write(name, type, str, asn1) 207 208 # ifndef OPENSSL_NO_DEPRECATED_3_0 209 # define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ 210 IMPLEMENT_PEM_read(name, type, str, asn1) \ 211 IMPLEMENT_PEM_write_const(name, type, str, asn1) 212 # endif 213 214 # define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 215 IMPLEMENT_PEM_read(name, type, str, asn1) \ 216 IMPLEMENT_PEM_write_cb(name, type, str, asn1) 217 218 /* These are the same except they are for the declarations */ 219 220 /* 221 * The mysterious 'extern' that's passed to some macros is innocuous, 222 * and is there to quiet pre-C99 compilers that may complain about empty 223 * arguments in macro calls. 224 */ 225 # if defined(OPENSSL_NO_STDIO) 226 227 # define DECLARE_PEM_read_fp_attr(attr, name, type) /**/ 228 # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) /**/ 229 # define DECLARE_PEM_write_fp_attr(attr, name, type) /**/ 230 # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) /**/ 231 # ifndef OPENSSL_NO_DEPRECATED_3_0 232 # define DECLARE_PEM_write_fp_const_attr(attr, name, type) /**/ 233 # endif 234 # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) /**/ 235 # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) /**/ 236 237 # else 238 239 # define DECLARE_PEM_read_fp_attr(attr, name, type) \ 240 attr PEM_read_cb_fnsig(name, type, FILE, read); 241 # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) \ 242 attr PEM_read_cb_fnsig(name, type, FILE, read); \ 243 attr PEM_read_cb_ex_fnsig(name, type, FILE, read); 244 245 # define DECLARE_PEM_write_fp_attr(attr, name, type) \ 246 attr PEM_write_fnsig(name, type, FILE, write); 247 # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) \ 248 attr PEM_write_fnsig(name, type, FILE, write); \ 249 attr PEM_write_ex_fnsig(name, type, FILE, write); 250 # ifndef OPENSSL_NO_DEPRECATED_3_0 251 # define DECLARE_PEM_write_fp_const_attr(attr, name, type) \ 252 attr PEM_write_fnsig(name, type, FILE, write); 253 # endif 254 # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) \ 255 attr PEM_write_cb_fnsig(name, type, FILE, write); 256 # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) \ 257 attr PEM_write_cb_fnsig(name, type, FILE, write); \ 258 attr PEM_write_cb_ex_fnsig(name, type, FILE, write); 259 260 # endif 261 262 # define DECLARE_PEM_read_fp(name, type) \ 263 DECLARE_PEM_read_fp_attr(extern, name, type) 264 # define DECLARE_PEM_write_fp(name, type) \ 265 DECLARE_PEM_write_fp_attr(extern, name, type) 266 # ifndef OPENSSL_NO_DEPRECATED_3_0 267 # define DECLARE_PEM_write_fp_const(name, type) \ 268 DECLARE_PEM_write_fp_const_attr(extern, name, type) 269 # endif 270 # define DECLARE_PEM_write_cb_fp(name, type) \ 271 DECLARE_PEM_write_cb_fp_attr(extern, name, type) 272 273 # define DECLARE_PEM_read_bio_attr(attr, name, type) \ 274 attr PEM_read_cb_fnsig(name, type, BIO, read_bio); 275 # define DECLARE_PEM_read_bio_ex_attr(attr, name, type) \ 276 attr PEM_read_cb_fnsig(name, type, BIO, read_bio); \ 277 attr PEM_read_cb_ex_fnsig(name, type, BIO, read_bio); 278 # define DECLARE_PEM_read_bio(name, type) \ 279 DECLARE_PEM_read_bio_attr(extern, name, type) 280 # define DECLARE_PEM_read_bio_ex(name, type) \ 281 DECLARE_PEM_read_bio_ex_attr(extern, name, type) 282 283 # define DECLARE_PEM_write_bio_attr(attr, name, type) \ 284 attr PEM_write_fnsig(name, type, BIO, write_bio); 285 # define DECLARE_PEM_write_bio_ex_attr(attr, name, type) \ 286 attr PEM_write_fnsig(name, type, BIO, write_bio); \ 287 attr PEM_write_ex_fnsig(name, type, BIO, write_bio); 288 # define DECLARE_PEM_write_bio(name, type) \ 289 DECLARE_PEM_write_bio_attr(extern, name, type) 290 # define DECLARE_PEM_write_bio_ex(name, type) \ 291 DECLARE_PEM_write_bio_ex_attr(extern, name, type) 292 293 # ifndef OPENSSL_NO_DEPRECATED_3_0 294 # define DECLARE_PEM_write_bio_const_attr(attr, name, type) \ 295 attr PEM_write_fnsig(name, type, BIO, write_bio); 296 # define DECLARE_PEM_write_bio_const(name, type) \ 297 DECLARE_PEM_write_bio_const_attr(extern, name, type) 298 # endif 299 300 # define DECLARE_PEM_write_cb_bio_attr(attr, name, type) \ 301 attr PEM_write_cb_fnsig(name, type, BIO, write_bio); 302 # define DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \ 303 attr PEM_write_cb_fnsig(name, type, BIO, write_bio); \ 304 attr PEM_write_cb_ex_fnsig(name, type, BIO, write_bio); 305 # define DECLARE_PEM_write_cb_bio(name, type) \ 306 DECLARE_PEM_write_cb_bio_attr(extern, name, type) 307 # define DECLARE_PEM_write_cb_ex_bio(name, type) \ 308 DECLARE_PEM_write_cb_bio_ex_attr(extern, name, type) 309 310 # define DECLARE_PEM_write_attr(attr, name, type) \ 311 DECLARE_PEM_write_bio_attr(attr, name, type) \ 312 DECLARE_PEM_write_fp_attr(attr, name, type) 313 # define DECLARE_PEM_write_ex_attr(attr, name, type) \ 314 DECLARE_PEM_write_bio_ex_attr(attr, name, type) \ 315 DECLARE_PEM_write_fp_ex_attr(attr, name, type) 316 # define DECLARE_PEM_write(name, type) \ 317 DECLARE_PEM_write_attr(extern, name, type) 318 # define DECLARE_PEM_write_ex(name, type) \ 319 DECLARE_PEM_write_ex_attr(extern, name, type) 320 # ifndef OPENSSL_NO_DEPRECATED_3_0 321 # define DECLARE_PEM_write_const_attr(attr, name, type) \ 322 DECLARE_PEM_write_bio_const_attr(attr, name, type) \ 323 DECLARE_PEM_write_fp_const_attr(attr, name, type) 324 # define DECLARE_PEM_write_const(name, type) \ 325 DECLARE_PEM_write_const_attr(extern, name, type) 326 # endif 327 # define DECLARE_PEM_write_cb_attr(attr, name, type) \ 328 DECLARE_PEM_write_cb_bio_attr(attr, name, type) \ 329 DECLARE_PEM_write_cb_fp_attr(attr, name, type) 330 # define DECLARE_PEM_write_cb_ex_attr(attr, name, type) \ 331 DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \ 332 DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) 333 # define DECLARE_PEM_write_cb(name, type) \ 334 DECLARE_PEM_write_cb_attr(extern, name, type) 335 # define DECLARE_PEM_write_cb_ex(name, type) \ 336 DECLARE_PEM_write_cb_ex_attr(extern, name, type) 337 # define DECLARE_PEM_read_attr(attr, name, type) \ 338 DECLARE_PEM_read_bio_attr(attr, name, type) \ 339 DECLARE_PEM_read_fp_attr(attr, name, type) 340 # define DECLARE_PEM_read_ex_attr(attr, name, type) \ 341 DECLARE_PEM_read_bio_ex_attr(attr, name, type) \ 342 DECLARE_PEM_read_fp_ex_attr(attr, name, type) 343 # define DECLARE_PEM_read(name, type) \ 344 DECLARE_PEM_read_attr(extern, name, type) 345 # define DECLARE_PEM_read_ex(name, type) \ 346 DECLARE_PEM_read_ex_attr(extern, name, type) 347 # define DECLARE_PEM_rw_attr(attr, name, type) \ 348 DECLARE_PEM_read_attr(attr, name, type) \ 349 DECLARE_PEM_write_attr(attr, name, type) 350 # define DECLARE_PEM_rw_ex_attr(attr, name, type) \ 351 DECLARE_PEM_read_ex_attr(attr, name, type) \ 352 DECLARE_PEM_write_ex_attr(attr, name, type) 353 # define DECLARE_PEM_rw(name, type) \ 354 DECLARE_PEM_rw_attr(extern, name, type) 355 # define DECLARE_PEM_rw_ex(name, type) \ 356 DECLARE_PEM_rw_ex_attr(extern, name, type) 357 # ifndef OPENSSL_NO_DEPRECATED_3_0 358 # define DECLARE_PEM_rw_const_attr(attr, name, type) \ 359 DECLARE_PEM_read_attr(attr, name, type) \ 360 DECLARE_PEM_write_const_attr(attr, name, type) 361 # define DECLARE_PEM_rw_const(name, type) \ 362 DECLARE_PEM_rw_const_attr(extern, name, type) 363 # endif 364 # define DECLARE_PEM_rw_cb_attr(attr, name, type) \ 365 DECLARE_PEM_read_attr(attr, name, type) \ 366 DECLARE_PEM_write_cb_attr(attr, name, type) 367 # define DECLARE_PEM_rw_cb_ex_attr(attr, name, type) \ 368 DECLARE_PEM_read_ex_attr(attr, name, type) \ 369 DECLARE_PEM_write_cb_ex_attr(attr, name, type) 370 # define DECLARE_PEM_rw_cb(name, type) \ 371 DECLARE_PEM_rw_cb_attr(extern, name, type) 372 # define DECLARE_PEM_rw_cb_ex(name, type) \ 373 DECLARE_PEM_rw_cb_ex_attr(extern, name, type) 374 375 int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 376 int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len, 377 pem_password_cb *callback, void *u); 378 379 int PEM_read_bio(BIO *bp, char **name, char **header, 380 unsigned char **data, long *len); 381 # define PEM_FLAG_SECURE 0x1 382 # define PEM_FLAG_EAY_COMPATIBLE 0x2 383 # define PEM_FLAG_ONLY_B64 0x4 384 int PEM_read_bio_ex(BIO *bp, char **name, char **header, 385 unsigned char **data, long *len, unsigned int flags); 386 int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm, 387 const char *name, BIO *bp, pem_password_cb *cb, 388 void *u); 389 int PEM_write_bio(BIO *bp, const char *name, const char *hdr, 390 const unsigned char *data, long len); 391 int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, 392 const char *name, BIO *bp, pem_password_cb *cb, 393 void *u); 394 void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, 395 pem_password_cb *cb, void *u); 396 int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, 397 const void *x, const EVP_CIPHER *enc, 398 const unsigned char *kstr, int klen, 399 pem_password_cb *cb, void *u); 400 int PEM_ASN1_write_bio_ctx(OSSL_i2d_of_void_ctx *i2d, void *vctx, 401 const char *name, BIO *bp, const void *x, 402 const EVP_CIPHER *enc, const unsigned char *kstr, 403 int klen, pem_password_cb *cb, void *u); 404 405 STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, 406 pem_password_cb *cb, void *u); 407 STACK_OF(X509_INFO) 408 *PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk, 409 pem_password_cb *cb, void *u, OSSL_LIB_CTX *libctx, 410 const char *propq); 411 412 int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc, 413 const unsigned char *kstr, int klen, 414 pem_password_cb *cd, void *u); 415 416 #ifndef OPENSSL_NO_STDIO 417 int PEM_read(FILE *fp, char **name, char **header, 418 unsigned char **data, long *len); 419 int PEM_write(FILE *fp, const char *name, const char *hdr, 420 const unsigned char *data, long len); 421 void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 422 pem_password_cb *cb, void *u); 423 int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, 424 const void *x, const EVP_CIPHER *enc, 425 const unsigned char *kstr, int klen, 426 pem_password_cb *callback, void *u); 427 STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, 428 pem_password_cb *cb, void *u); 429 STACK_OF(X509_INFO) 430 *PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, 431 void *u, OSSL_LIB_CTX *libctx, const char *propq); 432 #endif 433 434 int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); 435 int PEM_SignUpdate(EVP_MD_CTX *ctx, const unsigned char *d, unsigned int cnt); 436 int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, 437 unsigned int *siglen, EVP_PKEY *pkey); 438 439 /* The default pem_password_cb that's used internally */ 440 int PEM_def_callback(char *buf, int num, int rwflag, void *userdata); 441 void PEM_proc_type(char *buf, int type); 442 void PEM_dek_info(char *buf, const char *type, int len, const char *str); 443 444 # include <openssl/symhacks.h> 445 446 DECLARE_PEM_rw(X509, X509) 447 DECLARE_PEM_rw(X509_AUX, X509) 448 DECLARE_PEM_rw(X509_REQ, X509_REQ) 449 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) 450 DECLARE_PEM_rw(X509_CRL, X509_CRL) 451 DECLARE_PEM_rw(X509_PUBKEY, X509_PUBKEY) 452 DECLARE_PEM_rw(PKCS7, PKCS7) 453 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) 454 DECLARE_PEM_rw(PKCS8, X509_SIG) 455 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) 456 # ifndef OPENSSL_NO_DEPRECATED_3_0 457 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, RSAPrivateKey, RSA) 458 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSAPublicKey, RSA) 459 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSA_PUBKEY, RSA) 460 # endif 461 # ifndef OPENSSL_NO_DEPRECATED_3_0 462 # ifndef OPENSSL_NO_DSA 463 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, DSAPrivateKey, DSA) 464 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSA_PUBKEY, DSA) 465 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSAparams, DSA) 466 # endif 467 # endif 468 469 # ifndef OPENSSL_NO_DEPRECATED_3_0 470 # ifndef OPENSSL_NO_EC 471 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, ECPKParameters, EC_GROUP) 472 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, ECPrivateKey, EC_KEY) 473 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, EC_PUBKEY, EC_KEY) 474 # endif 475 # endif 476 477 # ifndef OPENSSL_NO_DH 478 # ifndef OPENSSL_NO_DEPRECATED_3_0 479 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DHparams, DH) 480 DECLARE_PEM_write_attr(OSSL_DEPRECATEDIN_3_0, DHxparams, DH) 481 # endif 482 # endif 483 DECLARE_PEM_rw_cb_ex(PrivateKey, EVP_PKEY) 484 DECLARE_PEM_rw_ex(PUBKEY, EVP_PKEY) 485 486 int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x, 487 const EVP_CIPHER *enc, 488 const unsigned char *kstr, int klen, 489 pem_password_cb *cb, void *u); 490 491 /* Why do these take a signed char *kstr? */ 492 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid, 493 const char *kstr, int klen, 494 pem_password_cb *cb, void *u); 495 int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, const EVP_CIPHER *, 496 const char *kstr, int klen, 497 pem_password_cb *cb, void *u); 498 int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc, 499 const char *kstr, int klen, 500 pem_password_cb *cb, void *u); 501 int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid, 502 const char *kstr, int klen, 503 pem_password_cb *cb, void *u); 504 EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, 505 void *u); 506 507 # ifndef OPENSSL_NO_STDIO 508 int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc, 509 const char *kstr, int klen, 510 pem_password_cb *cb, void *u); 511 int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid, 512 const char *kstr, int klen, 513 pem_password_cb *cb, void *u); 514 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid, 515 const char *kstr, int klen, 516 pem_password_cb *cb, void *u); 517 518 EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, 519 void *u); 520 521 int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc, 522 const char *kstr, int klen, 523 pem_password_cb *cd, void *u); 524 # endif 525 EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x, 526 OSSL_LIB_CTX *libctx, const char *propq); 527 EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); 528 int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x); 529 530 EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); 531 EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); 532 EVP_PKEY *b2i_PrivateKey_bio(BIO *in); 533 EVP_PKEY *b2i_PublicKey_bio(BIO *in); 534 int i2b_PrivateKey_bio(BIO *out, const EVP_PKEY *pk); 535 int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk); 536 EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); 537 EVP_PKEY *b2i_PVK_bio_ex(BIO *in, pem_password_cb *cb, void *u, 538 OSSL_LIB_CTX *libctx, const char *propq); 539 int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel, 540 pem_password_cb *cb, void *u); 541 int i2b_PVK_bio_ex(BIO *out, const EVP_PKEY *pk, int enclevel, 542 pem_password_cb *cb, void *u, 543 OSSL_LIB_CTX *libctx, const char *propq); 544 545 # ifdef __cplusplus 546 } 547 # endif 548 #endif 549