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