Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:48

0001 /*
0002  * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
0003  *
0004  * Licensed under the Apache License 2.0 (the "License").  You may not use
0005  * this file except in compliance with the License.  You can obtain a copy
0006  * in the file LICENSE in the source distribution or at
0007  * https://www.openssl.org/source/license.html
0008  */
0009 
0010 #ifndef OPENSSL_PEM_H
0011 # define OPENSSL_PEM_H
0012 # pragma once
0013 
0014 # include <openssl/macros.h>
0015 # ifndef OPENSSL_NO_DEPRECATED_3_0
0016 #  define HEADER_PEM_H
0017 # endif
0018 
0019 # include <openssl/e_os2.h>
0020 # include <openssl/bio.h>
0021 # include <openssl/safestack.h>
0022 # include <openssl/evp.h>
0023 # include <openssl/x509.h>
0024 # include <openssl/pemerr.h>
0025 # ifndef OPENSSL_NO_STDIO
0026 #  include <stdio.h>
0027 # endif
0028 
0029 #ifdef  __cplusplus
0030 extern "C" {
0031 #endif
0032 
0033 # define PEM_BUFSIZE             1024
0034 
0035 # define PEM_STRING_X509_OLD     "X509 CERTIFICATE"
0036 # define PEM_STRING_X509         "CERTIFICATE"
0037 # define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
0038 # define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
0039 # define PEM_STRING_X509_REQ     "CERTIFICATE REQUEST"
0040 # define PEM_STRING_X509_CRL     "X509 CRL"
0041 # define PEM_STRING_EVP_PKEY     "ANY PRIVATE KEY"
0042 # define PEM_STRING_PUBLIC       "PUBLIC KEY"
0043 # define PEM_STRING_RSA          "RSA PRIVATE KEY"
0044 # define PEM_STRING_RSA_PUBLIC   "RSA PUBLIC KEY"
0045 # define PEM_STRING_DSA          "DSA PRIVATE KEY"
0046 # define PEM_STRING_DSA_PUBLIC   "DSA PUBLIC KEY"
0047 # define PEM_STRING_PKCS7        "PKCS7"
0048 # define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
0049 # define PEM_STRING_PKCS8        "ENCRYPTED PRIVATE KEY"
0050 # define PEM_STRING_PKCS8INF     "PRIVATE KEY"
0051 # define PEM_STRING_DHPARAMS     "DH PARAMETERS"
0052 # define PEM_STRING_DHXPARAMS    "X9.42 DH PARAMETERS"
0053 # define PEM_STRING_SSL_SESSION  "SSL SESSION PARAMETERS"
0054 # define PEM_STRING_DSAPARAMS    "DSA PARAMETERS"
0055 # define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
0056 # define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
0057 # define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
0058 # define PEM_STRING_PARAMETERS   "PARAMETERS"
0059 # define PEM_STRING_CMS          "CMS"
0060 # define PEM_STRING_SM2PARAMETERS "SM2 PARAMETERS"
0061 # define PEM_STRING_ACERT        "ATTRIBUTE CERTIFICATE"
0062 
0063 # define PEM_TYPE_ENCRYPTED      10
0064 # define PEM_TYPE_MIC_ONLY       20
0065 # define PEM_TYPE_MIC_CLEAR      30
0066 # define PEM_TYPE_CLEAR          40
0067 
0068 /*
0069  * These macros make the PEM_read/PEM_write functions easier to maintain and
0070  * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or
0071  * IMPLEMENT_PEM_rw_cb(...)
0072  */
0073 
0074 # define PEM_read_cb_fnsig(name, type, INTYPE, readname)                \
0075     type *PEM_##readname##_##name(INTYPE *out, type **x,                \
0076                                  pem_password_cb *cb, void *u)
0077 # define PEM_read_cb_ex_fnsig(name, type, INTYPE, readname)             \
0078     type *PEM_##readname##_##name##_ex(INTYPE *out, type **x,           \
0079                                        pem_password_cb *cb, void *u,    \
0080                                        OSSL_LIB_CTX *libctx,            \
0081                                        const char *propq)
0082 
0083 # define PEM_write_fnsig(name, type, OUTTYPE, writename)                \
0084     int PEM_##writename##_##name(OUTTYPE *out, const type *x)
0085 # define PEM_write_cb_fnsig(name, type, OUTTYPE, writename)             \
0086     int PEM_##writename##_##name(OUTTYPE *out, const type *x,           \
0087                                  const EVP_CIPHER *enc,                 \
0088                                  const unsigned char *kstr, int klen,   \
0089                                  pem_password_cb *cb, void *u)
0090 # define PEM_write_ex_fnsig(name, type, OUTTYPE, writename)             \
0091     int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x,      \
0092                                       OSSL_LIB_CTX *libctx,             \
0093                                       const char *propq)
0094 # define PEM_write_cb_ex_fnsig(name, type, OUTTYPE, writename)          \
0095     int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x,      \
0096                                       const EVP_CIPHER *enc,            \
0097                                       const unsigned char *kstr, int klen, \
0098                                       pem_password_cb *cb, void *u,     \
0099                                       OSSL_LIB_CTX *libctx,             \
0100                                       const char *propq)
0101 
0102 # ifdef OPENSSL_NO_STDIO
0103 
0104 #  define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
0105 #  define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
0106 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0107 #   define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
0108 #  endif
0109 #  define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
0110 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0111 #   define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
0112 #  endif
0113 # else
0114 
0115 #  define IMPLEMENT_PEM_read_fp(name, type, str, asn1)                  \
0116     type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u) \
0117     {                                                                   \
0118         return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str, fp,        \
0119                              (void **)x, cb, u);                        \
0120     }
0121 
0122 #  define IMPLEMENT_PEM_write_fp(name, type, str, asn1)                 \
0123     PEM_write_fnsig(name, type, FILE, write)                            \
0124     {                                                                   \
0125         return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out,      \
0126                               x, NULL, NULL, 0, NULL, NULL);            \
0127     }
0128 
0129 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0130 #   define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)  \
0131     IMPLEMENT_PEM_write_fp(name, type, str, asn1)
0132 #  endif
0133 
0134 #  define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)              \
0135     PEM_write_cb_fnsig(name, type, FILE, write)                         \
0136     {                                                                   \
0137         return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out,      \
0138                               x, enc, kstr, klen, cb, u);               \
0139     }
0140 
0141 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0142 #   define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)       \
0143     IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
0144 #  endif
0145 # endif
0146 
0147 # define IMPLEMENT_PEM_read_bio(name, type, str, asn1)                  \
0148     type *PEM_read_bio_##name(BIO *bp, type **x,                        \
0149                               pem_password_cb *cb, void *u)             \
0150     {                                                                   \
0151         return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str, bp,    \
0152                                  (void **)x, cb, u);                    \
0153     }
0154 
0155 # define IMPLEMENT_PEM_write_bio(name, type, str, asn1)                 \
0156     PEM_write_fnsig(name, type, BIO, write_bio)                         \
0157     {                                                                   \
0158         return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out,  \
0159                                   x, NULL,NULL,0,NULL,NULL);            \
0160     }
0161 
0162 # ifndef OPENSSL_NO_DEPRECATED_3_0
0163 #  define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1)   \
0164     IMPLEMENT_PEM_write_bio(name, type, str, asn1)
0165 # endif
0166 
0167 # define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)              \
0168     PEM_write_cb_fnsig(name, type, BIO, write_bio)                      \
0169     {                                                                   \
0170         return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out,  \
0171                                   x, enc, kstr, klen, cb, u);           \
0172     }
0173 
0174 # ifndef OPENSSL_NO_DEPRECATED_3_0
0175 #  define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1)  \
0176     IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)
0177 # endif
0178 
0179 # define IMPLEMENT_PEM_write(name, type, str, asn1) \
0180         IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
0181         IMPLEMENT_PEM_write_fp(name, type, str, asn1)
0182 
0183 # ifndef OPENSSL_NO_DEPRECATED_3_0
0184 #  define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
0185         IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
0186         IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
0187 # endif
0188 
0189 # define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
0190         IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
0191         IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
0192 
0193 # ifndef OPENSSL_NO_DEPRECATED_3_0
0194 #  define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
0195         IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
0196         IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
0197 # endif
0198 
0199 # define IMPLEMENT_PEM_read(name, type, str, asn1) \
0200         IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
0201         IMPLEMENT_PEM_read_fp(name, type, str, asn1)
0202 
0203 # define IMPLEMENT_PEM_rw(name, type, str, asn1) \
0204         IMPLEMENT_PEM_read(name, type, str, asn1) \
0205         IMPLEMENT_PEM_write(name, type, str, asn1)
0206 
0207 # ifndef OPENSSL_NO_DEPRECATED_3_0
0208 #  define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
0209         IMPLEMENT_PEM_read(name, type, str, asn1) \
0210         IMPLEMENT_PEM_write_const(name, type, str, asn1)
0211 # endif
0212 
0213 # define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
0214         IMPLEMENT_PEM_read(name, type, str, asn1) \
0215         IMPLEMENT_PEM_write_cb(name, type, str, asn1)
0216 
0217 /* These are the same except they are for the declarations */
0218 
0219 /*
0220  * The mysterious 'extern' that's passed to some macros is innocuous,
0221  * and is there to quiet pre-C99 compilers that may complain about empty
0222  * arguments in macro calls.
0223  */
0224 # if defined(OPENSSL_NO_STDIO)
0225 
0226 #  define DECLARE_PEM_read_fp_attr(attr, name, type) /**/
0227 #  define DECLARE_PEM_read_fp_ex_attr(attr, name, type) /**/
0228 #  define DECLARE_PEM_write_fp_attr(attr, name, type) /**/
0229 #  define DECLARE_PEM_write_fp_ex_attr(attr, name, type) /**/
0230 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0231 #   define DECLARE_PEM_write_fp_const_attr(attr, name, type) /**/
0232 #  endif
0233 #  define DECLARE_PEM_write_cb_fp_attr(attr, name, type) /**/
0234 #  define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) /**/
0235 
0236 # else
0237 
0238 #  define DECLARE_PEM_read_fp_attr(attr, name, type)                        \
0239     attr PEM_read_cb_fnsig(name, type, FILE, read);
0240 #  define DECLARE_PEM_read_fp_ex_attr(attr, name, type)                     \
0241     attr PEM_read_cb_fnsig(name, type, FILE, read);                         \
0242     attr PEM_read_cb_ex_fnsig(name, type, FILE, read);
0243 
0244 #  define DECLARE_PEM_write_fp_attr(attr, name, type)                       \
0245     attr PEM_write_fnsig(name, type, FILE, write);
0246 #  define DECLARE_PEM_write_fp_ex_attr(attr, name, type)                    \
0247     attr PEM_write_fnsig(name, type, FILE, write);                          \
0248     attr PEM_write_ex_fnsig(name, type, FILE, write);
0249 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0250 #   define DECLARE_PEM_write_fp_const_attr(attr, name, type)                \
0251     attr PEM_write_fnsig(name, type, FILE, write);
0252 #  endif
0253 #  define DECLARE_PEM_write_cb_fp_attr(attr, name, type)                    \
0254     attr PEM_write_cb_fnsig(name, type, FILE, write);
0255 #  define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type)                 \
0256     attr PEM_write_cb_fnsig(name, type, FILE, write);                       \
0257     attr PEM_write_cb_ex_fnsig(name, type, FILE, write);
0258 
0259 # endif
0260 
0261 # define DECLARE_PEM_read_fp(name, type)                                    \
0262     DECLARE_PEM_read_fp_attr(extern, name, type)
0263 # define DECLARE_PEM_write_fp(name, type)                                   \
0264     DECLARE_PEM_write_fp_attr(extern, name, type)
0265 # ifndef OPENSSL_NO_DEPRECATED_3_0
0266 #   define DECLARE_PEM_write_fp_const(name, type)                           \
0267     DECLARE_PEM_write_fp_const_attr(extern, name, type)
0268 # endif
0269 # define DECLARE_PEM_write_cb_fp(name, type)                                \
0270     DECLARE_PEM_write_cb_fp_attr(extern, name, type)
0271 
0272 #  define DECLARE_PEM_read_bio_attr(attr, name, type)                       \
0273     attr PEM_read_cb_fnsig(name, type, BIO, read_bio);
0274 #  define DECLARE_PEM_read_bio_ex_attr(attr, name, type)                    \
0275     attr PEM_read_cb_fnsig(name, type, BIO, read_bio);                      \
0276     attr PEM_read_cb_ex_fnsig(name, type, BIO, read_bio);
0277 # define DECLARE_PEM_read_bio(name, type)                                   \
0278     DECLARE_PEM_read_bio_attr(extern, name, type)
0279 # define DECLARE_PEM_read_bio_ex(name, type)                                \
0280     DECLARE_PEM_read_bio_ex_attr(extern, name, type)
0281 
0282 # define DECLARE_PEM_write_bio_attr(attr, name, type)                       \
0283     attr PEM_write_fnsig(name, type, BIO, write_bio);
0284 # define DECLARE_PEM_write_bio_ex_attr(attr, name, type)                    \
0285     attr PEM_write_fnsig(name, type, BIO, write_bio);                       \
0286     attr PEM_write_ex_fnsig(name, type, BIO, write_bio);
0287 # define DECLARE_PEM_write_bio(name, type)                                  \
0288     DECLARE_PEM_write_bio_attr(extern, name, type)
0289 # define DECLARE_PEM_write_bio_ex(name, type)                               \
0290     DECLARE_PEM_write_bio_ex_attr(extern, name, type)
0291 
0292 # ifndef OPENSSL_NO_DEPRECATED_3_0
0293 #  define DECLARE_PEM_write_bio_const_attr(attr, name, type)                \
0294     attr PEM_write_fnsig(name, type, BIO, write_bio);
0295 #  define DECLARE_PEM_write_bio_const(name, type)      \
0296     DECLARE_PEM_write_bio_const_attr(extern, name, type)
0297 # endif
0298 
0299 # define DECLARE_PEM_write_cb_bio_attr(attr, name, type)                    \
0300     attr PEM_write_cb_fnsig(name, type, BIO, write_bio);
0301 # define DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type)                 \
0302     attr PEM_write_cb_fnsig(name, type, BIO, write_bio);                    \
0303     attr PEM_write_cb_ex_fnsig(name, type, BIO, write_bio);
0304 # define DECLARE_PEM_write_cb_bio(name, type)                               \
0305     DECLARE_PEM_write_cb_bio_attr(extern, name, type)
0306 # define DECLARE_PEM_write_cb_ex_bio(name, type)                            \
0307     DECLARE_PEM_write_cb_bio_ex_attr(extern, name, type)
0308 
0309 # define DECLARE_PEM_write_attr(attr, name, type)                           \
0310     DECLARE_PEM_write_bio_attr(attr, name, type)                            \
0311     DECLARE_PEM_write_fp_attr(attr, name, type)
0312 # define DECLARE_PEM_write_ex_attr(attr, name, type)                        \
0313     DECLARE_PEM_write_bio_ex_attr(attr, name, type)                         \
0314     DECLARE_PEM_write_fp_ex_attr(attr, name, type)
0315 # define DECLARE_PEM_write(name, type) \
0316     DECLARE_PEM_write_attr(extern, name, type)
0317 # define DECLARE_PEM_write_ex(name, type) \
0318     DECLARE_PEM_write_ex_attr(extern, name, type)
0319 # ifndef OPENSSL_NO_DEPRECATED_3_0
0320 #  define DECLARE_PEM_write_const_attr(attr, name, type)                    \
0321     DECLARE_PEM_write_bio_const_attr(attr, name, type)                      \
0322     DECLARE_PEM_write_fp_const_attr(attr, name, type)
0323 #  define DECLARE_PEM_write_const(name, type)                               \
0324     DECLARE_PEM_write_const_attr(extern, name, type)
0325 # endif
0326 # define DECLARE_PEM_write_cb_attr(attr, name, type)                        \
0327     DECLARE_PEM_write_cb_bio_attr(attr, name, type)                         \
0328     DECLARE_PEM_write_cb_fp_attr(attr, name, type)
0329 # define DECLARE_PEM_write_cb_ex_attr(attr, name, type)                     \
0330     DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type)                      \
0331     DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type)
0332 # define DECLARE_PEM_write_cb(name, type)                                   \
0333     DECLARE_PEM_write_cb_attr(extern, name, type)
0334 # define DECLARE_PEM_write_cb_ex(name, type)                                \
0335     DECLARE_PEM_write_cb_ex_attr(extern, name, type)
0336 # define DECLARE_PEM_read_attr(attr, name, type)                            \
0337     DECLARE_PEM_read_bio_attr(attr, name, type)                             \
0338     DECLARE_PEM_read_fp_attr(attr, name, type)
0339 # define DECLARE_PEM_read_ex_attr(attr, name, type)                         \
0340     DECLARE_PEM_read_bio_ex_attr(attr, name, type)                          \
0341     DECLARE_PEM_read_fp_ex_attr(attr, name, type)
0342 # define DECLARE_PEM_read(name, type)                                       \
0343     DECLARE_PEM_read_attr(extern, name, type)
0344 # define DECLARE_PEM_read_ex(name, type)                                    \
0345     DECLARE_PEM_read_ex_attr(extern, name, type)
0346 # define DECLARE_PEM_rw_attr(attr, name, type)                              \
0347     DECLARE_PEM_read_attr(attr, name, type)                                 \
0348     DECLARE_PEM_write_attr(attr, name, type)
0349 # define DECLARE_PEM_rw_ex_attr(attr, name, type)                           \
0350     DECLARE_PEM_read_ex_attr(attr, name, type)                              \
0351     DECLARE_PEM_write_ex_attr(attr, name, type)
0352 # define DECLARE_PEM_rw(name, type) \
0353     DECLARE_PEM_rw_attr(extern, name, type)
0354 # define DECLARE_PEM_rw_ex(name, type) \
0355     DECLARE_PEM_rw_ex_attr(extern, name, type)
0356 # ifndef OPENSSL_NO_DEPRECATED_3_0
0357 #  define DECLARE_PEM_rw_const_attr(attr, name, type)                       \
0358     DECLARE_PEM_read_attr(attr, name, type)                                 \
0359     DECLARE_PEM_write_const_attr(attr, name, type)
0360 #  define DECLARE_PEM_rw_const(name, type) \
0361     DECLARE_PEM_rw_const_attr(extern, name, type)
0362 # endif
0363 # define DECLARE_PEM_rw_cb_attr(attr, name, type)                           \
0364     DECLARE_PEM_read_attr(attr, name, type)                                 \
0365     DECLARE_PEM_write_cb_attr(attr, name, type)
0366 # define DECLARE_PEM_rw_cb_ex_attr(attr, name, type)                        \
0367     DECLARE_PEM_read_ex_attr(attr, name, type)                              \
0368     DECLARE_PEM_write_cb_ex_attr(attr, name, type)
0369 # define DECLARE_PEM_rw_cb(name, type) \
0370     DECLARE_PEM_rw_cb_attr(extern, name, type)
0371 # define DECLARE_PEM_rw_cb_ex(name, type) \
0372     DECLARE_PEM_rw_cb_ex_attr(extern, name, type)
0373 
0374 int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
0375 int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len,
0376                   pem_password_cb *callback, void *u);
0377 
0378 int PEM_read_bio(BIO *bp, char **name, char **header,
0379                  unsigned char **data, long *len);
0380 #   define PEM_FLAG_SECURE             0x1
0381 #   define PEM_FLAG_EAY_COMPATIBLE     0x2
0382 #   define PEM_FLAG_ONLY_B64           0x4
0383 int PEM_read_bio_ex(BIO *bp, char **name, char **header,
0384                     unsigned char **data, long *len, unsigned int flags);
0385 int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
0386                               const char *name, BIO *bp, pem_password_cb *cb,
0387                               void *u);
0388 int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
0389                   const unsigned char *data, long len);
0390 int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
0391                        const char *name, BIO *bp, pem_password_cb *cb,
0392                        void *u);
0393 void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
0394                         pem_password_cb *cb, void *u);
0395 int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
0396                        const void *x, const EVP_CIPHER *enc,
0397                        const unsigned char *kstr, int klen,
0398                        pem_password_cb *cb, void *u);
0399 
0400 STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
0401                                             pem_password_cb *cb, void *u);
0402 STACK_OF(X509_INFO)
0403 *PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk,
0404                            pem_password_cb *cb, void *u, OSSL_LIB_CTX *libctx,
0405                            const char *propq);
0406 
0407 int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc,
0408                             const unsigned char *kstr, int klen,
0409                             pem_password_cb *cd, void *u);
0410 
0411 #ifndef OPENSSL_NO_STDIO
0412 int PEM_read(FILE *fp, char **name, char **header,
0413              unsigned char **data, long *len);
0414 int PEM_write(FILE *fp, const char *name, const char *hdr,
0415               const unsigned char *data, long len);
0416 void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
0417                     pem_password_cb *cb, void *u);
0418 int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
0419                    const void *x, const EVP_CIPHER *enc,
0420                    const unsigned char *kstr, int klen,
0421                    pem_password_cb *callback, void *u);
0422 STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
0423                                         pem_password_cb *cb, void *u);
0424 STACK_OF(X509_INFO)
0425 *PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
0426                        void *u, OSSL_LIB_CTX *libctx, const char *propq);
0427 #endif
0428 
0429 int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
0430 int PEM_SignUpdate(EVP_MD_CTX *ctx, const unsigned char *d, unsigned int cnt);
0431 int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
0432                   unsigned int *siglen, EVP_PKEY *pkey);
0433 
0434 /* The default pem_password_cb that's used internally */
0435 int PEM_def_callback(char *buf, int num, int rwflag, void *userdata);
0436 void PEM_proc_type(char *buf, int type);
0437 void PEM_dek_info(char *buf, const char *type, int len, const char *str);
0438 
0439 # include <openssl/symhacks.h>
0440 
0441 DECLARE_PEM_rw(X509, X509)
0442 DECLARE_PEM_rw(X509_AUX, X509)
0443 DECLARE_PEM_rw(X509_REQ, X509_REQ)
0444 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
0445 DECLARE_PEM_rw(X509_CRL, X509_CRL)
0446 DECLARE_PEM_rw(X509_PUBKEY, X509_PUBKEY)
0447 DECLARE_PEM_rw(PKCS7, PKCS7)
0448 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
0449 DECLARE_PEM_rw(PKCS8, X509_SIG)
0450 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
0451 # ifndef OPENSSL_NO_DEPRECATED_3_0
0452 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, RSAPrivateKey, RSA)
0453 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSAPublicKey, RSA)
0454 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSA_PUBKEY, RSA)
0455 # endif
0456 # ifndef OPENSSL_NO_DEPRECATED_3_0
0457 #  ifndef OPENSSL_NO_DSA
0458 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, DSAPrivateKey, DSA)
0459 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSA_PUBKEY, DSA)
0460 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSAparams, DSA)
0461 #  endif
0462 # endif
0463 
0464 # ifndef OPENSSL_NO_DEPRECATED_3_0
0465 #  ifndef OPENSSL_NO_EC
0466 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, ECPKParameters, EC_GROUP)
0467 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, ECPrivateKey, EC_KEY)
0468 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, EC_PUBKEY, EC_KEY)
0469 #  endif
0470 # endif
0471 
0472 # ifndef OPENSSL_NO_DH
0473 #  ifndef OPENSSL_NO_DEPRECATED_3_0
0474 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DHparams, DH)
0475 DECLARE_PEM_write_attr(OSSL_DEPRECATEDIN_3_0, DHxparams, DH)
0476 #  endif
0477 # endif
0478 DECLARE_PEM_rw_cb_ex(PrivateKey, EVP_PKEY)
0479 DECLARE_PEM_rw_ex(PUBKEY, EVP_PKEY)
0480 
0481 int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
0482                                          const EVP_CIPHER *enc,
0483                                          const unsigned char *kstr, int klen,
0484                                          pem_password_cb *cb, void *u);
0485 
0486 /* Why do these take a signed char *kstr? */
0487 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid,
0488                                       const char *kstr, int klen,
0489                                       pem_password_cb *cb, void *u);
0490 int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, const EVP_CIPHER *,
0491                                   const char *kstr, int klen,
0492                                   pem_password_cb *cb, void *u);
0493 int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
0494                             const char *kstr, int klen,
0495                             pem_password_cb *cb, void *u);
0496 int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
0497                                 const char *kstr, int klen,
0498                                 pem_password_cb *cb, void *u);
0499 EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
0500                                   void *u);
0501 
0502 # ifndef OPENSSL_NO_STDIO
0503 int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
0504                            const char *kstr, int klen,
0505                            pem_password_cb *cb, void *u);
0506 int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
0507                                const char *kstr, int klen,
0508                                pem_password_cb *cb, void *u);
0509 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
0510                                   const char *kstr, int klen,
0511                                   pem_password_cb *cb, void *u);
0512 
0513 EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
0514                                  void *u);
0515 
0516 int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
0517                               const char *kstr, int klen,
0518                               pem_password_cb *cd, void *u);
0519 # endif
0520 EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x,
0521                                      OSSL_LIB_CTX *libctx, const char *propq);
0522 EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
0523 int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x);
0524 
0525 EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
0526 EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
0527 EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
0528 EVP_PKEY *b2i_PublicKey_bio(BIO *in);
0529 int i2b_PrivateKey_bio(BIO *out, const EVP_PKEY *pk);
0530 int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk);
0531 EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
0532 EVP_PKEY *b2i_PVK_bio_ex(BIO *in, pem_password_cb *cb, void *u,
0533                          OSSL_LIB_CTX *libctx, const char *propq);
0534 int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel,
0535                 pem_password_cb *cb, void *u);
0536 int i2b_PVK_bio_ex(BIO *out, const EVP_PKEY *pk, int enclevel,
0537                    pem_password_cb *cb, void *u,
0538                    OSSL_LIB_CTX *libctx, const char *propq);
0539 
0540 # ifdef  __cplusplus
0541 }
0542 # endif
0543 #endif