1*1b959929Stb /* $OpenBSD: pem.h,v 1.28 2024/05/11 05:41:28 tb Exp $ */ 25b37fcf3Sryker /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 35b37fcf3Sryker * All rights reserved. 45b37fcf3Sryker * 55b37fcf3Sryker * This package is an SSL implementation written 65b37fcf3Sryker * by Eric Young (eay@cryptsoft.com). 75b37fcf3Sryker * The implementation was written so as to conform with Netscapes SSL. 85b37fcf3Sryker * 95b37fcf3Sryker * This library is free for commercial and non-commercial use as long as 105b37fcf3Sryker * the following conditions are aheared to. The following conditions 115b37fcf3Sryker * apply to all code found in this distribution, be it the RC4, RSA, 125b37fcf3Sryker * lhash, DES, etc., code; not just the SSL code. The SSL documentation 135b37fcf3Sryker * included with this distribution is covered by the same copyright terms 145b37fcf3Sryker * except that the holder is Tim Hudson (tjh@cryptsoft.com). 155b37fcf3Sryker * 165b37fcf3Sryker * Copyright remains Eric Young's, and as such any Copyright notices in 175b37fcf3Sryker * the code are not to be removed. 185b37fcf3Sryker * If this package is used in a product, Eric Young should be given attribution 195b37fcf3Sryker * as the author of the parts of the library used. 205b37fcf3Sryker * This can be in the form of a textual message at program startup or 215b37fcf3Sryker * in documentation (online or textual) provided with the package. 225b37fcf3Sryker * 235b37fcf3Sryker * Redistribution and use in source and binary forms, with or without 245b37fcf3Sryker * modification, are permitted provided that the following conditions 255b37fcf3Sryker * are met: 265b37fcf3Sryker * 1. Redistributions of source code must retain the copyright 275b37fcf3Sryker * notice, this list of conditions and the following disclaimer. 285b37fcf3Sryker * 2. Redistributions in binary form must reproduce the above copyright 295b37fcf3Sryker * notice, this list of conditions and the following disclaimer in the 305b37fcf3Sryker * documentation and/or other materials provided with the distribution. 315b37fcf3Sryker * 3. All advertising materials mentioning features or use of this software 325b37fcf3Sryker * must display the following acknowledgement: 335b37fcf3Sryker * "This product includes cryptographic software written by 345b37fcf3Sryker * Eric Young (eay@cryptsoft.com)" 355b37fcf3Sryker * The word 'cryptographic' can be left out if the rouines from the library 365b37fcf3Sryker * being used are not cryptographic related :-). 375b37fcf3Sryker * 4. If you include any Windows specific code (or a derivative thereof) from 385b37fcf3Sryker * the apps directory (application code) you must include an acknowledgement: 395b37fcf3Sryker * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 405b37fcf3Sryker * 415b37fcf3Sryker * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 425b37fcf3Sryker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 435b37fcf3Sryker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 445b37fcf3Sryker * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 455b37fcf3Sryker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 465b37fcf3Sryker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 475b37fcf3Sryker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 485b37fcf3Sryker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 495b37fcf3Sryker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 505b37fcf3Sryker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 515b37fcf3Sryker * SUCH DAMAGE. 525b37fcf3Sryker * 535b37fcf3Sryker * The licence and distribution terms for any publically available version or 545b37fcf3Sryker * derivative of this code cannot be changed. i.e. this code cannot simply be 555b37fcf3Sryker * copied and put under another distribution licence 565b37fcf3Sryker * [including the GNU Public Licence.] 575b37fcf3Sryker */ 585b37fcf3Sryker 595b37fcf3Sryker #ifndef HEADER_PEM_H 605b37fcf3Sryker #define HEADER_PEM_H 615b37fcf3Sryker 6220175b85Sjsing #include <openssl/opensslconf.h> 6320175b85Sjsing 64da347917Sbeck #ifndef OPENSSL_NO_BIO 65c109e398Sbeck #include <openssl/bio.h> 665b37fcf3Sryker #endif 67da347917Sbeck #ifndef OPENSSL_NO_STACK 68c109e398Sbeck #include <openssl/stack.h> 69c109e398Sbeck #endif 70913ec974Sbeck #include <openssl/evp.h> 71913ec974Sbeck #include <openssl/x509.h> 72913ec974Sbeck 73c109e398Sbeck #ifdef __cplusplus 74c109e398Sbeck extern "C" { 75c109e398Sbeck #endif 76c109e398Sbeck 77913ec974Sbeck #define PEM_BUFSIZE 1024 785b37fcf3Sryker 795b37fcf3Sryker #define PEM_OBJ_UNDEF 0 805b37fcf3Sryker #define PEM_OBJ_X509 1 815b37fcf3Sryker #define PEM_OBJ_X509_REQ 2 825b37fcf3Sryker #define PEM_OBJ_CRL 3 835b37fcf3Sryker #define PEM_OBJ_SSL_SESSION 4 845b37fcf3Sryker #define PEM_OBJ_PRIV_KEY 10 855b37fcf3Sryker #define PEM_OBJ_PRIV_RSA 11 865b37fcf3Sryker #define PEM_OBJ_PRIV_DSA 12 875b37fcf3Sryker #define PEM_OBJ_PRIV_DH 13 885b37fcf3Sryker #define PEM_OBJ_PUB_RSA 14 895b37fcf3Sryker #define PEM_OBJ_PUB_DSA 15 905b37fcf3Sryker #define PEM_OBJ_PUB_DH 16 915b37fcf3Sryker #define PEM_OBJ_DHPARAMS 17 925b37fcf3Sryker #define PEM_OBJ_DSAPARAMS 18 935b37fcf3Sryker #define PEM_OBJ_PRIV_RSA_PUBLIC 19 944fcf65c5Sdjm #define PEM_OBJ_PRIV_ECDSA 20 954fcf65c5Sdjm #define PEM_OBJ_PUB_ECDSA 21 964fcf65c5Sdjm #define PEM_OBJ_ECPARAMETERS 22 975b37fcf3Sryker 985b37fcf3Sryker #define PEM_ERROR 30 995b37fcf3Sryker #define PEM_DEK_DES_CBC 40 1005b37fcf3Sryker #define PEM_DEK_IDEA_CBC 45 1015b37fcf3Sryker #define PEM_DEK_DES_EDE 50 1025b37fcf3Sryker #define PEM_DEK_DES_ECB 60 1035b37fcf3Sryker #define PEM_DEK_RSA 70 1045b37fcf3Sryker #define PEM_DEK_RSA_MD2 80 1055b37fcf3Sryker #define PEM_DEK_RSA_MD5 90 1065b37fcf3Sryker 1075b37fcf3Sryker #define PEM_MD_MD2 NID_md2 1085b37fcf3Sryker #define PEM_MD_MD5 NID_md5 1095b37fcf3Sryker #define PEM_MD_SHA NID_sha 1105b37fcf3Sryker #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption 1115b37fcf3Sryker #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption 1125b37fcf3Sryker #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption 1135b37fcf3Sryker 1145b37fcf3Sryker #define PEM_STRING_X509_OLD "X509 CERTIFICATE" 1155b37fcf3Sryker #define PEM_STRING_X509 "CERTIFICATE" 116ba5406e9Sbeck #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" 1175b37fcf3Sryker #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 1185b37fcf3Sryker #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 1195b37fcf3Sryker #define PEM_STRING_X509_CRL "X509 CRL" 120913ec974Sbeck #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" 121ba5406e9Sbeck #define PEM_STRING_PUBLIC "PUBLIC KEY" 1225b37fcf3Sryker #define PEM_STRING_RSA "RSA PRIVATE KEY" 1235b37fcf3Sryker #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 1245b37fcf3Sryker #define PEM_STRING_DSA "DSA PRIVATE KEY" 125ba5406e9Sbeck #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" 1265b37fcf3Sryker #define PEM_STRING_PKCS7 "PKCS7" 127e6841c1dSdjm #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" 128913ec974Sbeck #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" 129913ec974Sbeck #define PEM_STRING_PKCS8INF "PRIVATE KEY" 1305b37fcf3Sryker #define PEM_STRING_DHPARAMS "DH PARAMETERS" 1315b37fcf3Sryker #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 1325b37fcf3Sryker #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 1334fcf65c5Sdjm #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" 1344fcf65c5Sdjm #define PEM_STRING_ECPARAMETERS "EC PARAMETERS" 1354fcf65c5Sdjm #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" 1360a5d6edeSdjm #define PEM_STRING_PARAMETERS "PARAMETERS" 1374fcf65c5Sdjm #define PEM_STRING_CMS "CMS" 1385b37fcf3Sryker 1395b37fcf3Sryker /* enc_type is one off */ 1405b37fcf3Sryker #define PEM_TYPE_ENCRYPTED 10 1415b37fcf3Sryker #define PEM_TYPE_MIC_ONLY 20 1425b37fcf3Sryker #define PEM_TYPE_MIC_CLEAR 30 1435b37fcf3Sryker #define PEM_TYPE_CLEAR 40 1445b37fcf3Sryker 1459b27cab4Sjsing #ifndef LIBRESSL_INTERNAL 146913ec974Sbeck /* These macros make the PEM_read/PEM_write functions easier to maintain and 147913ec974Sbeck * write. Now they are all implemented with either: 148913ec974Sbeck * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) 149913ec974Sbeck */ 150913ec974Sbeck 151913ec974Sbeck #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 152913ec974Sbeck type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ 153913ec974Sbeck { \ 1540a5d6edeSdjm return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ 1554fcf65c5Sdjm } 156913ec974Sbeck 157913ec974Sbeck #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 158913ec974Sbeck int PEM_write_##name(FILE *fp, type *x) \ 159913ec974Sbeck { \ 1600a5d6edeSdjm return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ 1614fcf65c5Sdjm } 1624fcf65c5Sdjm 1634fcf65c5Sdjm #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 1644fcf65c5Sdjm int PEM_write_##name(FILE *fp, const type *x) \ 1654fcf65c5Sdjm { \ 1660a5d6edeSdjm return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ 167913ec974Sbeck } 168913ec974Sbeck 169913ec974Sbeck #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 170913ec974Sbeck int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 171913ec974Sbeck unsigned char *kstr, int klen, pem_password_cb *cb, \ 172913ec974Sbeck void *u) \ 173913ec974Sbeck { \ 1740a5d6edeSdjm return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 1754fcf65c5Sdjm } 1764fcf65c5Sdjm 1774fcf65c5Sdjm #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 1784fcf65c5Sdjm int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 1794fcf65c5Sdjm unsigned char *kstr, int klen, pem_password_cb *cb, \ 1804fcf65c5Sdjm void *u) \ 1814fcf65c5Sdjm { \ 1820a5d6edeSdjm return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 183913ec974Sbeck } 184913ec974Sbeck 185913ec974Sbeck 186913ec974Sbeck #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 187913ec974Sbeck type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ 188913ec974Sbeck { \ 1890a5d6edeSdjm return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ 190913ec974Sbeck } 191913ec974Sbeck 192913ec974Sbeck #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 193913ec974Sbeck int PEM_write_bio_##name(BIO *bp, type *x) \ 194913ec974Sbeck { \ 1950a5d6edeSdjm return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ 1964fcf65c5Sdjm } 1974fcf65c5Sdjm 1984fcf65c5Sdjm #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 1994fcf65c5Sdjm int PEM_write_bio_##name(BIO *bp, const type *x) \ 2004fcf65c5Sdjm { \ 2010a5d6edeSdjm return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ 202913ec974Sbeck } 203913ec974Sbeck 204913ec974Sbeck #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 205913ec974Sbeck int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 206913ec974Sbeck unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 207913ec974Sbeck { \ 2080a5d6edeSdjm return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ 2094fcf65c5Sdjm } 2104fcf65c5Sdjm 2114fcf65c5Sdjm #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 2124fcf65c5Sdjm int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 2134fcf65c5Sdjm unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 2144fcf65c5Sdjm { \ 2150a5d6edeSdjm return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ 216913ec974Sbeck } 217913ec974Sbeck 218913ec974Sbeck #define IMPLEMENT_PEM_write(name, type, str, asn1) \ 219913ec974Sbeck IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 220913ec974Sbeck IMPLEMENT_PEM_write_fp(name, type, str, asn1) 221913ec974Sbeck 2224fcf65c5Sdjm #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ 2234fcf65c5Sdjm IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 2244fcf65c5Sdjm IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 2254fcf65c5Sdjm 226913ec974Sbeck #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 227913ec974Sbeck IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 228913ec974Sbeck IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 229913ec974Sbeck 2304fcf65c5Sdjm #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ 2314fcf65c5Sdjm IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 2324fcf65c5Sdjm IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 2334fcf65c5Sdjm 234913ec974Sbeck #define IMPLEMENT_PEM_read(name, type, str, asn1) \ 235913ec974Sbeck IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 236913ec974Sbeck IMPLEMENT_PEM_read_fp(name, type, str, asn1) 237913ec974Sbeck 238913ec974Sbeck #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ 239913ec974Sbeck IMPLEMENT_PEM_read(name, type, str, asn1) \ 240913ec974Sbeck IMPLEMENT_PEM_write(name, type, str, asn1) 241913ec974Sbeck 2424fcf65c5Sdjm #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ 2434fcf65c5Sdjm IMPLEMENT_PEM_read(name, type, str, asn1) \ 2444fcf65c5Sdjm IMPLEMENT_PEM_write_const(name, type, str, asn1) 2454fcf65c5Sdjm 246913ec974Sbeck #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 247913ec974Sbeck IMPLEMENT_PEM_read(name, type, str, asn1) \ 248913ec974Sbeck IMPLEMENT_PEM_write_cb(name, type, str, asn1) 249913ec974Sbeck 2509b27cab4Sjsing #endif 2519b27cab4Sjsing 252913ec974Sbeck /* These are the same except they are for the declarations */ 253913ec974Sbeck 254913ec974Sbeck 255913ec974Sbeck #define DECLARE_PEM_read_fp(name, type) \ 256913ec974Sbeck type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); 257913ec974Sbeck 258913ec974Sbeck #define DECLARE_PEM_write_fp(name, type) \ 259913ec974Sbeck int PEM_write_##name(FILE *fp, type *x); 260913ec974Sbeck 2614fcf65c5Sdjm #define DECLARE_PEM_write_fp_const(name, type) \ 2624fcf65c5Sdjm int PEM_write_##name(FILE *fp, const type *x); 2634fcf65c5Sdjm 264913ec974Sbeck #define DECLARE_PEM_write_cb_fp(name, type) \ 265913ec974Sbeck int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 266913ec974Sbeck unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 267913ec974Sbeck 268913ec974Sbeck 269da347917Sbeck #ifndef OPENSSL_NO_BIO 270913ec974Sbeck #define DECLARE_PEM_read_bio(name, type) \ 271913ec974Sbeck type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); 272913ec974Sbeck 273913ec974Sbeck #define DECLARE_PEM_write_bio(name, type) \ 274913ec974Sbeck int PEM_write_bio_##name(BIO *bp, type *x); 275913ec974Sbeck 2764fcf65c5Sdjm #define DECLARE_PEM_write_bio_const(name, type) \ 2774fcf65c5Sdjm int PEM_write_bio_##name(BIO *bp, const type *x); 2784fcf65c5Sdjm 279913ec974Sbeck #define DECLARE_PEM_write_cb_bio(name, type) \ 280913ec974Sbeck int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 281913ec974Sbeck unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 282913ec974Sbeck 283913ec974Sbeck #else 284913ec974Sbeck 285913ec974Sbeck #define DECLARE_PEM_read_bio(name, type) /**/ 286913ec974Sbeck #define DECLARE_PEM_write_bio(name, type) /**/ 28750c17820Sdjm #define DECLARE_PEM_write_bio_const(name, type) /**/ 288913ec974Sbeck #define DECLARE_PEM_write_cb_bio(name, type) /**/ 289913ec974Sbeck 290913ec974Sbeck #endif 291913ec974Sbeck 292913ec974Sbeck #define DECLARE_PEM_write(name, type) \ 293913ec974Sbeck DECLARE_PEM_write_bio(name, type) \ 294913ec974Sbeck DECLARE_PEM_write_fp(name, type) 295913ec974Sbeck 2964fcf65c5Sdjm #define DECLARE_PEM_write_const(name, type) \ 2974fcf65c5Sdjm DECLARE_PEM_write_bio_const(name, type) \ 2984fcf65c5Sdjm DECLARE_PEM_write_fp_const(name, type) 2994fcf65c5Sdjm 300913ec974Sbeck #define DECLARE_PEM_write_cb(name, type) \ 301913ec974Sbeck DECLARE_PEM_write_cb_bio(name, type) \ 302913ec974Sbeck DECLARE_PEM_write_cb_fp(name, type) 303913ec974Sbeck 304913ec974Sbeck #define DECLARE_PEM_read(name, type) \ 305913ec974Sbeck DECLARE_PEM_read_bio(name, type) \ 306913ec974Sbeck DECLARE_PEM_read_fp(name, type) 307913ec974Sbeck 308913ec974Sbeck #define DECLARE_PEM_rw(name, type) \ 309913ec974Sbeck DECLARE_PEM_read(name, type) \ 310913ec974Sbeck DECLARE_PEM_write(name, type) 311913ec974Sbeck 3124fcf65c5Sdjm #define DECLARE_PEM_rw_const(name, type) \ 3134fcf65c5Sdjm DECLARE_PEM_read(name, type) \ 3144fcf65c5Sdjm DECLARE_PEM_write_const(name, type) 3154fcf65c5Sdjm 316913ec974Sbeck #define DECLARE_PEM_rw_cb(name, type) \ 317913ec974Sbeck DECLARE_PEM_read(name, type) \ 318913ec974Sbeck DECLARE_PEM_write_cb(name, type) 319913ec974Sbeck 320913ec974Sbeck typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); 321913ec974Sbeck 3225b37fcf3Sryker int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 3235b37fcf3Sryker int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data, long *len, 324913ec974Sbeck pem_password_cb *callback, void *u); 3255b37fcf3Sryker 326da347917Sbeck #ifndef OPENSSL_NO_BIO 3275b37fcf3Sryker int PEM_read_bio(BIO *bp, char **name, char **header, 3285b37fcf3Sryker unsigned char **data, long *len); 329dffa7454Stb int PEM_write_bio(BIO *bp, const char *name, const char *hdr, 330dffa7454Stb const unsigned char *data, long len); 331a8b5ceceSjsing int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, 332a8b5ceceSjsing const char *name, BIO *bp, pem_password_cb *cb, void *u); 3334fcf65c5Sdjm void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, 3344fcf65c5Sdjm void **x, pem_password_cb *cb, void *u); 3350a5d6edeSdjm int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, 336913ec974Sbeck const EVP_CIPHER *enc, unsigned char *kstr, int klen, 337913ec974Sbeck pem_password_cb *cb, void *u); 3384fcf65c5Sdjm 339a8b5ceceSjsing STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, 340a8b5ceceSjsing STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 3415b37fcf3Sryker int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, 342913ec974Sbeck unsigned char *kstr, int klen, pem_password_cb *cd, void *u); 3435b37fcf3Sryker #endif 3445b37fcf3Sryker 3455b37fcf3Sryker int PEM_read(FILE *fp, char **name, char **header, 3465b37fcf3Sryker unsigned char **data, long *len); 347dffa7454Stb int PEM_write(FILE *fp, const char *name, const char *hdr, 348dffa7454Stb const unsigned char *data, long len); 3494fcf65c5Sdjm void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 350913ec974Sbeck pem_password_cb *cb, void *u); 3514fcf65c5Sdjm int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, 3520a5d6edeSdjm void *x, const EVP_CIPHER *enc, unsigned char *kstr, 3534fcf65c5Sdjm int klen, pem_password_cb *callback, void *u); 354913ec974Sbeck STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, 355913ec974Sbeck pem_password_cb *cb, void *u); 3565b37fcf3Sryker 35740ff503aStb int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); 35840ff503aStb int PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt); 3595b37fcf3Sryker int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, 3605b37fcf3Sryker unsigned int *siglen, EVP_PKEY *pkey); 3615b37fcf3Sryker 362da347917Sbeck int PEM_def_callback(char *buf, int num, int w, void *key); 3635b37fcf3Sryker void PEM_proc_type(char *buf, int type); 364913ec974Sbeck void PEM_dek_info(char *buf, const char *type, int len, char *str); 3655b37fcf3Sryker 3665b37fcf3Sryker 367913ec974Sbeck DECLARE_PEM_rw(X509, X509) 368913ec974Sbeck 369ba5406e9Sbeck DECLARE_PEM_rw(X509_AUX, X509) 370ba5406e9Sbeck 371913ec974Sbeck DECLARE_PEM_rw(X509_REQ, X509_REQ) 372ba5406e9Sbeck DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) 373913ec974Sbeck 374913ec974Sbeck DECLARE_PEM_rw(X509_CRL, X509_CRL) 375913ec974Sbeck 376913ec974Sbeck DECLARE_PEM_rw(PKCS7, PKCS7) 377913ec974Sbeck 378913ec974Sbeck DECLARE_PEM_rw(PKCS8, X509_SIG) 379913ec974Sbeck 380913ec974Sbeck DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) 381913ec974Sbeck 382da347917Sbeck #ifndef OPENSSL_NO_RSA 383913ec974Sbeck 384913ec974Sbeck DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) 385913ec974Sbeck 3864fcf65c5Sdjm DECLARE_PEM_rw_const(RSAPublicKey, RSA) 387ba5406e9Sbeck DECLARE_PEM_rw(RSA_PUBKEY, RSA) 388913ec974Sbeck 3895b37fcf3Sryker #endif 3905b37fcf3Sryker 391da347917Sbeck #ifndef OPENSSL_NO_DSA 392913ec974Sbeck 393913ec974Sbeck DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) 394913ec974Sbeck 395ba5406e9Sbeck DECLARE_PEM_rw(DSA_PUBKEY, DSA) 396ba5406e9Sbeck 3974fcf65c5Sdjm DECLARE_PEM_rw_const(DSAparams, DSA) 398913ec974Sbeck 399913ec974Sbeck #endif 400913ec974Sbeck 4014fcf65c5Sdjm #ifndef OPENSSL_NO_EC 4024fcf65c5Sdjm DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) 4034fcf65c5Sdjm DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) 4044fcf65c5Sdjm DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) 4054fcf65c5Sdjm #endif 4064fcf65c5Sdjm 407da347917Sbeck #ifndef OPENSSL_NO_DH 408913ec974Sbeck 4094fcf65c5Sdjm DECLARE_PEM_rw_const(DHparams, DH) 410913ec974Sbeck 411913ec974Sbeck #endif 412913ec974Sbeck 413913ec974Sbeck DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) 414913ec974Sbeck 415ba5406e9Sbeck DECLARE_PEM_rw(PUBKEY, EVP_PKEY) 416ba5406e9Sbeck 4176cb0895aStb int PEM_write_bio_PrivateKey_traditional(BIO *bp, EVP_PKEY *x, 4186cb0895aStb const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, 4196cb0895aStb void *u); 420ba5406e9Sbeck int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, 421ba5406e9Sbeck char *kstr, int klen, 422ba5406e9Sbeck pem_password_cb *cb, void *u); 423913ec974Sbeck int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, 424913ec974Sbeck char *, int, pem_password_cb *, void *); 425ba5406e9Sbeck int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, 426ba5406e9Sbeck char *kstr, int klen, 427ba5406e9Sbeck pem_password_cb *cb, void *u); 428ba5406e9Sbeck int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, 429ba5406e9Sbeck char *kstr, int klen, 430ba5406e9Sbeck pem_password_cb *cb, void *u); 431a8b5ceceSjsing EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, 432a8b5ceceSjsing void *u); 433ba5406e9Sbeck 434ba5406e9Sbeck int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, 435ba5406e9Sbeck char *kstr, int klen, 436ba5406e9Sbeck pem_password_cb *cb, void *u); 437ba5406e9Sbeck int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, 438ba5406e9Sbeck char *kstr, int klen, 439ba5406e9Sbeck pem_password_cb *cb, void *u); 440ba5406e9Sbeck int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, 441ba5406e9Sbeck char *kstr, int klen, 442ba5406e9Sbeck pem_password_cb *cb, void *u); 443ba5406e9Sbeck 444a8b5ceceSjsing EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, 445a8b5ceceSjsing void *u); 446ba5406e9Sbeck 447913ec974Sbeck int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, 448913ec974Sbeck char *kstr, int klen, pem_password_cb *cd, void *u); 449ba5406e9Sbeck 4500a5d6edeSdjm EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); 4510a5d6edeSdjm int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); 4520a5d6edeSdjm 4530a5d6edeSdjm 4540a5d6edeSdjm EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); 4550a5d6edeSdjm EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); 4560a5d6edeSdjm EVP_PKEY *b2i_PrivateKey_bio(BIO *in); 4570a5d6edeSdjm EVP_PKEY *b2i_PublicKey_bio(BIO *in); 4580a5d6edeSdjm int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); 4590a5d6edeSdjm int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); 4600a5d6edeSdjm #ifndef OPENSSL_NO_RC4 4610a5d6edeSdjm EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); 462a8b5ceceSjsing int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, 463a8b5ceceSjsing void *u); 4640a5d6edeSdjm #endif 4655b37fcf3Sryker 4665b37fcf3Sryker 467da347917Sbeck void ERR_load_PEM_strings(void); 468913ec974Sbeck 4695b37fcf3Sryker /* Error codes for the PEM functions. */ 4705b37fcf3Sryker 4715b37fcf3Sryker /* Function codes. */ 4720a5d6edeSdjm #define PEM_F_B2I_DSS 127 4730a5d6edeSdjm #define PEM_F_B2I_PVK_BIO 128 4740a5d6edeSdjm #define PEM_F_B2I_RSA 129 4750a5d6edeSdjm #define PEM_F_CHECK_BITLEN_DSA 130 4760a5d6edeSdjm #define PEM_F_CHECK_BITLEN_RSA 131 477ba5406e9Sbeck #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 478ba5406e9Sbeck #define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 4790a5d6edeSdjm #define PEM_F_DO_B2I 132 4800a5d6edeSdjm #define PEM_F_DO_B2I_BIO 133 4810a5d6edeSdjm #define PEM_F_DO_BLOB_HEADER 134 4824fcf65c5Sdjm #define PEM_F_DO_PK8PKEY 126 4834fcf65c5Sdjm #define PEM_F_DO_PK8PKEY_FP 125 4840a5d6edeSdjm #define PEM_F_DO_PVK_BODY 135 4850a5d6edeSdjm #define PEM_F_DO_PVK_HEADER 136 4860a5d6edeSdjm #define PEM_F_I2B_PVK 137 4870a5d6edeSdjm #define PEM_F_I2B_PVK_BIO 138 4885b37fcf3Sryker #define PEM_F_LOAD_IV 101 4895b37fcf3Sryker #define PEM_F_PEM_ASN1_READ 102 4905b37fcf3Sryker #define PEM_F_PEM_ASN1_READ_BIO 103 4915b37fcf3Sryker #define PEM_F_PEM_ASN1_WRITE 104 4925b37fcf3Sryker #define PEM_F_PEM_ASN1_WRITE_BIO 105 4934fcf65c5Sdjm #define PEM_F_PEM_DEF_CALLBACK 100 4945b37fcf3Sryker #define PEM_F_PEM_DO_HEADER 106 495913ec974Sbeck #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 4965b37fcf3Sryker #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 4974fcf65c5Sdjm #define PEM_F_PEM_PK8PKEY 119 4985b37fcf3Sryker #define PEM_F_PEM_READ 108 4995b37fcf3Sryker #define PEM_F_PEM_READ_BIO 109 5000a5d6edeSdjm #define PEM_F_PEM_READ_BIO_PARAMETERS 140 5014fcf65c5Sdjm #define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 5024fcf65c5Sdjm #define PEM_F_PEM_READ_PRIVATEKEY 124 5035b37fcf3Sryker #define PEM_F_PEM_SEALFINAL 110 5045b37fcf3Sryker #define PEM_F_PEM_SEALINIT 111 5055b37fcf3Sryker #define PEM_F_PEM_SIGNFINAL 112 5065b37fcf3Sryker #define PEM_F_PEM_WRITE 113 5075b37fcf3Sryker #define PEM_F_PEM_WRITE_BIO 114 5080a5d6edeSdjm #define PEM_F_PEM_WRITE_PRIVATEKEY 139 5095b37fcf3Sryker #define PEM_F_PEM_X509_INFO_READ 115 5105b37fcf3Sryker #define PEM_F_PEM_X509_INFO_READ_BIO 116 5115b37fcf3Sryker #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 5125b37fcf3Sryker 5135b37fcf3Sryker /* Reason codes. */ 5145b37fcf3Sryker #define PEM_R_BAD_BASE64_DECODE 100 5155b37fcf3Sryker #define PEM_R_BAD_DECRYPT 101 5165b37fcf3Sryker #define PEM_R_BAD_END_LINE 102 5175b37fcf3Sryker #define PEM_R_BAD_IV_CHARS 103 5180a5d6edeSdjm #define PEM_R_BAD_MAGIC_NUMBER 116 5195b37fcf3Sryker #define PEM_R_BAD_PASSWORD_READ 104 5200a5d6edeSdjm #define PEM_R_BAD_VERSION_NUMBER 117 5210a5d6edeSdjm #define PEM_R_BIO_WRITE_FAILURE 118 5220a5d6edeSdjm #define PEM_R_CIPHER_IS_NULL 127 523913ec974Sbeck #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 5240a5d6edeSdjm #define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119 5250a5d6edeSdjm #define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120 5260a5d6edeSdjm #define PEM_R_INCONSISTENT_HEADER 121 5270a5d6edeSdjm #define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122 5280a5d6edeSdjm #define PEM_R_KEYBLOB_TOO_SHORT 123 5295b37fcf3Sryker #define PEM_R_NOT_DEK_INFO 105 5305b37fcf3Sryker #define PEM_R_NOT_ENCRYPTED 106 5315b37fcf3Sryker #define PEM_R_NOT_PROC_TYPE 107 5325b37fcf3Sryker #define PEM_R_NO_START_LINE 108 5335b37fcf3Sryker #define PEM_R_PROBLEMS_GETTING_PASSWORD 109 5345b37fcf3Sryker #define PEM_R_PUBLIC_KEY_NO_RSA 110 5350a5d6edeSdjm #define PEM_R_PVK_DATA_TOO_SHORT 124 5360a5d6edeSdjm #define PEM_R_PVK_TOO_SHORT 125 5375b37fcf3Sryker #define PEM_R_READ_KEY 111 5385b37fcf3Sryker #define PEM_R_SHORT_HEADER 112 5395b37fcf3Sryker #define PEM_R_UNSUPPORTED_CIPHER 113 5405b37fcf3Sryker #define PEM_R_UNSUPPORTED_ENCRYPTION 114 5410a5d6edeSdjm #define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126 5425b37fcf3Sryker 5435b37fcf3Sryker #ifdef __cplusplus 5445b37fcf3Sryker } 5455b37fcf3Sryker #endif 5465b37fcf3Sryker #endif 547