155714Skris/* crypto/pem/pem_all.c */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 855714Skris * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1555714Skris * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 2255714Skris * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4055714Skris * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 5255714Skris * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 58160814Ssimon/* ==================================================================== 59160814Ssimon * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 60160814Ssimon * 61160814Ssimon * Redistribution and use in source and binary forms, with or without 62160814Ssimon * modification, are permitted provided that the following conditions 63160814Ssimon * are met: 64160814Ssimon * 65160814Ssimon * 1. Redistributions of source code must retain the above copyright 66160814Ssimon * notice, this list of conditions and the following disclaimer. 67160814Ssimon * 68160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 69160814Ssimon * notice, this list of conditions and the following disclaimer in 70160814Ssimon * the documentation and/or other materials provided with the 71160814Ssimon * distribution. 72160814Ssimon * 73160814Ssimon * 3. All advertising materials mentioning features or use of this 74160814Ssimon * software must display the following acknowledgment: 75160814Ssimon * "This product includes software developed by the OpenSSL Project 76160814Ssimon * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 77160814Ssimon * 78160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 79160814Ssimon * endorse or promote products derived from this software without 80160814Ssimon * prior written permission. For written permission, please contact 81160814Ssimon * openssl-core@openssl.org. 82160814Ssimon * 83160814Ssimon * 5. Products derived from this software may not be called "OpenSSL" 84160814Ssimon * nor may "OpenSSL" appear in their names without prior written 85160814Ssimon * permission of the OpenSSL Project. 86160814Ssimon * 87160814Ssimon * 6. Redistributions of any form whatsoever must retain the following 88160814Ssimon * acknowledgment: 89160814Ssimon * "This product includes software developed by the OpenSSL Project 90160814Ssimon * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 91160814Ssimon * 92160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 93160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 94160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 95160814Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 96160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 97160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 98160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 99160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 100160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 101160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 102160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 103160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 104160814Ssimon * ==================================================================== 105160814Ssimon * 106160814Ssimon * This product includes cryptographic software written by Eric Young 107160814Ssimon * (eay@cryptsoft.com). This product includes software written by Tim 108160814Ssimon * Hudson (tjh@cryptsoft.com). 109160814Ssimon * 110160814Ssimon */ 11155714Skris 11255714Skris#include <stdio.h> 11355714Skris#include "cryptlib.h" 11455714Skris#include <openssl/bio.h> 11555714Skris#include <openssl/evp.h> 11655714Skris#include <openssl/x509.h> 11755714Skris#include <openssl/pkcs7.h> 11855714Skris#include <openssl/pem.h> 119160814Ssimon#ifndef OPENSSL_NO_RSA 120160814Ssimon#include <openssl/rsa.h> 121160814Ssimon#endif 122160814Ssimon#ifndef OPENSSL_NO_DSA 123160814Ssimon#include <openssl/dsa.h> 124160814Ssimon#endif 125160814Ssimon#ifndef OPENSSL_NO_DH 126160814Ssimon#include <openssl/dh.h> 127160814Ssimon#endif 12855714Skris 129109998Smarkm#ifndef OPENSSL_NO_RSA 13059191Skrisstatic RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa); 13159191Skris#endif 132109998Smarkm#ifndef OPENSSL_NO_DSA 13359191Skrisstatic DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa); 13459191Skris#endif 13559191Skris 136160814Ssimon#ifndef OPENSSL_NO_EC 137160814Ssimonstatic EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey); 138160814Ssimon#endif 139160814Ssimon 14055714SkrisIMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) 14155714Skris 14259191SkrisIMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ) 14359191Skris 14455714SkrisIMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) 14555714Skris 14655714SkrisIMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) 14755714Skris 14855714SkrisIMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, 14955714Skris PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) 15055714Skris 15155714Skris 152109998Smarkm#ifndef OPENSSL_NO_RSA 15355714Skris 15459191Skris/* We treat RSA or DSA private keys as a special case. 15559191Skris * 15659191Skris * For private keys we read in an EVP_PKEY structure with 15759191Skris * PEM_read_bio_PrivateKey() and extract the relevant private 15859191Skris * key: this means can handle "traditional" and PKCS#8 formats 15959191Skris * transparently. 16059191Skris */ 16155714Skris 16259191Skrisstatic RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa) 16359191Skris{ 16459191Skris RSA *rtmp; 16559191Skris if(!key) return NULL; 16659191Skris rtmp = EVP_PKEY_get1_RSA(key); 16759191Skris EVP_PKEY_free(key); 16859191Skris if(!rtmp) return NULL; 16959191Skris if(rsa) { 17059191Skris RSA_free(*rsa); 17159191Skris *rsa = rtmp; 17259191Skris } 17359191Skris return rtmp; 17459191Skris} 17559191Skris 17659191SkrisRSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, 17759191Skris void *u) 17859191Skris{ 17959191Skris EVP_PKEY *pktmp; 18059191Skris pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 18159191Skris return pkey_get_rsa(pktmp, rsa); 18259191Skris} 18359191Skris 184109998Smarkm#ifndef OPENSSL_NO_FP_API 18559191Skris 18659191SkrisRSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, 18759191Skris void *u) 18859191Skris{ 18959191Skris EVP_PKEY *pktmp; 19059191Skris pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 19159191Skris return pkey_get_rsa(pktmp, rsa); 19259191Skris} 19359191Skris 19459191Skris#endif 19559191Skris 196246772Sjkim#ifdef OPENSSL_FIPS 197246772Sjkim 198246772Sjkimint PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc, 199246772Sjkim unsigned char *kstr, int klen, 200246772Sjkim pem_password_cb *cb, void *u) 201246772Sjkim{ 202246772Sjkim if (FIPS_mode()) 203246772Sjkim { 204246772Sjkim EVP_PKEY *k; 205246772Sjkim int ret; 206246772Sjkim k = EVP_PKEY_new(); 207246772Sjkim if (!k) 208246772Sjkim return 0; 209246772Sjkim EVP_PKEY_set1_RSA(k, x); 210246772Sjkim 211246772Sjkim ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u); 212246772Sjkim EVP_PKEY_free(k); 213246772Sjkim return ret; 214246772Sjkim } 215246772Sjkim else 216246772Sjkim return PEM_ASN1_write_bio((i2d_of_void *)i2d_RSAPrivateKey, 217246772Sjkim PEM_STRING_RSA,bp,x,enc,kstr,klen,cb,u); 218246772Sjkim} 219246772Sjkim 220246772Sjkim#ifndef OPENSSL_NO_FP_API 221246772Sjkimint PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc, 222246772Sjkim unsigned char *kstr, int klen, 223246772Sjkim pem_password_cb *cb, void *u) 224246772Sjkim{ 225246772Sjkim if (FIPS_mode()) 226246772Sjkim { 227246772Sjkim EVP_PKEY *k; 228246772Sjkim int ret; 229246772Sjkim k = EVP_PKEY_new(); 230246772Sjkim if (!k) 231246772Sjkim return 0; 232246772Sjkim 233246772Sjkim EVP_PKEY_set1_RSA(k, x); 234246772Sjkim 235246772Sjkim ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u); 236246772Sjkim EVP_PKEY_free(k); 237246772Sjkim return ret; 238246772Sjkim } 239246772Sjkim else 240246772Sjkim return PEM_ASN1_write((i2d_of_void *)i2d_RSAPrivateKey, 241246772Sjkim PEM_STRING_RSA,fp,x,enc,kstr,klen,cb,u); 242246772Sjkim} 243246772Sjkim#endif 244246772Sjkim 245246772Sjkim#else 246246772Sjkim 247160814SsimonIMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) 248246772Sjkim 249246772Sjkim#endif 250246772Sjkim 251160814SsimonIMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) 25259191SkrisIMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) 25355714Skris 25455714Skris#endif 25555714Skris 256109998Smarkm#ifndef OPENSSL_NO_DSA 25755714Skris 25859191Skrisstatic DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa) 25959191Skris{ 26059191Skris DSA *dtmp; 26159191Skris if(!key) return NULL; 26259191Skris dtmp = EVP_PKEY_get1_DSA(key); 26359191Skris EVP_PKEY_free(key); 26459191Skris if(!dtmp) return NULL; 26559191Skris if(dsa) { 26659191Skris DSA_free(*dsa); 26759191Skris *dsa = dtmp; 26859191Skris } 26959191Skris return dtmp; 27059191Skris} 27155714Skris 27259191SkrisDSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, 27359191Skris void *u) 27459191Skris{ 27559191Skris EVP_PKEY *pktmp; 27659191Skris pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 277238405Sjkim return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ 27859191Skris} 27959191Skris 280246772Sjkim#ifdef OPENSSL_FIPS 281246772Sjkim 282246772Sjkimint PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc, 283246772Sjkim unsigned char *kstr, int klen, 284246772Sjkim pem_password_cb *cb, void *u) 285246772Sjkim{ 286246772Sjkim if (FIPS_mode()) 287246772Sjkim { 288246772Sjkim EVP_PKEY *k; 289246772Sjkim int ret; 290246772Sjkim k = EVP_PKEY_new(); 291246772Sjkim if (!k) 292246772Sjkim return 0; 293246772Sjkim EVP_PKEY_set1_DSA(k, x); 294246772Sjkim 295246772Sjkim ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u); 296246772Sjkim EVP_PKEY_free(k); 297246772Sjkim return ret; 298246772Sjkim } 299246772Sjkim else 300246772Sjkim return PEM_ASN1_write_bio((i2d_of_void *)i2d_DSAPrivateKey, 301246772Sjkim PEM_STRING_DSA,bp,x,enc,kstr,klen,cb,u); 302246772Sjkim} 303246772Sjkim 304246772Sjkim#ifndef OPENSSL_NO_FP_API 305246772Sjkimint PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc, 306246772Sjkim unsigned char *kstr, int klen, 307246772Sjkim pem_password_cb *cb, void *u) 308246772Sjkim{ 309246772Sjkim if (FIPS_mode()) 310246772Sjkim { 311246772Sjkim EVP_PKEY *k; 312246772Sjkim int ret; 313246772Sjkim k = EVP_PKEY_new(); 314246772Sjkim if (!k) 315246772Sjkim return 0; 316246772Sjkim EVP_PKEY_set1_DSA(k, x); 317246772Sjkim ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u); 318246772Sjkim EVP_PKEY_free(k); 319246772Sjkim return ret; 320246772Sjkim } 321246772Sjkim else 322246772Sjkim return PEM_ASN1_write((i2d_of_void *)i2d_DSAPrivateKey, 323246772Sjkim PEM_STRING_DSA,fp,x,enc,kstr,klen,cb,u); 324246772Sjkim} 325246772Sjkim#endif 326246772Sjkim 327246772Sjkim#else 328246772Sjkim 329160814SsimonIMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) 330246772Sjkim 331246772Sjkim#endif 332246772Sjkim 333160814SsimonIMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY) 334142425Snectar 335160814Ssimon#ifndef OPENSSL_NO_FP_API 336142425Snectar 337160814SsimonDSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, 338160814Ssimon void *u) 339142425Snectar{ 340160814Ssimon EVP_PKEY *pktmp; 341160814Ssimon pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 342238405Sjkim return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ 343160814Ssimon} 344142425Snectar 345160814Ssimon#endif 346160814Ssimon 347160814SsimonIMPLEMENT_PEM_rw_const(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) 348160814Ssimon 349160814Ssimon#endif 350160814Ssimon 351160814Ssimon 352160814Ssimon#ifndef OPENSSL_NO_EC 353160814Ssimonstatic EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey) 354160814Ssimon{ 355160814Ssimon EC_KEY *dtmp; 356160814Ssimon if(!key) return NULL; 357160814Ssimon dtmp = EVP_PKEY_get1_EC_KEY(key); 358160814Ssimon EVP_PKEY_free(key); 359160814Ssimon if(!dtmp) return NULL; 360160814Ssimon if(eckey) 361160814Ssimon { 362160814Ssimon EC_KEY_free(*eckey); 363160814Ssimon *eckey = dtmp; 364160814Ssimon } 365160814Ssimon return dtmp; 366142425Snectar} 367142425Snectar 368160814SsimonEC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, 369160814Ssimon void *u) 370142425Snectar{ 371160814Ssimon EVP_PKEY *pktmp; 372160814Ssimon pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 373238405Sjkim return pkey_get_eckey(pktmp, key); /* will free pktmp */ 374142425Snectar} 375142425Snectar 376160814SsimonIMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters) 377142425Snectar 378246772Sjkim 379246772Sjkim 380246772Sjkim#ifdef OPENSSL_FIPS 381246772Sjkim 382246772Sjkimint PEM_write_bio_ECPrivateKey(BIO *bp, EC_KEY *x, const EVP_CIPHER *enc, 383246772Sjkim unsigned char *kstr, int klen, 384246772Sjkim pem_password_cb *cb, void *u) 385246772Sjkim{ 386246772Sjkim if (FIPS_mode()) 387246772Sjkim { 388246772Sjkim EVP_PKEY *k; 389246772Sjkim int ret; 390246772Sjkim k = EVP_PKEY_new(); 391246772Sjkim if (!k) 392246772Sjkim return 0; 393246772Sjkim EVP_PKEY_set1_EC_KEY(k, x); 394246772Sjkim 395246772Sjkim ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u); 396246772Sjkim EVP_PKEY_free(k); 397246772Sjkim return ret; 398246772Sjkim } 399246772Sjkim else 400246772Sjkim return PEM_ASN1_write_bio((i2d_of_void *)i2d_ECPrivateKey, 401246772Sjkim PEM_STRING_ECPRIVATEKEY, 402246772Sjkim bp,x,enc,kstr,klen,cb,u); 403246772Sjkim} 404246772Sjkim 405246772Sjkim#ifndef OPENSSL_NO_FP_API 406246772Sjkimint PEM_write_ECPrivateKey(FILE *fp, EC_KEY *x, const EVP_CIPHER *enc, 407246772Sjkim unsigned char *kstr, int klen, 408246772Sjkim pem_password_cb *cb, void *u) 409246772Sjkim{ 410246772Sjkim if (FIPS_mode()) 411246772Sjkim { 412246772Sjkim EVP_PKEY *k; 413246772Sjkim int ret; 414246772Sjkim k = EVP_PKEY_new(); 415246772Sjkim if (!k) 416246772Sjkim return 0; 417246772Sjkim EVP_PKEY_set1_EC_KEY(k, x); 418246772Sjkim ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u); 419246772Sjkim EVP_PKEY_free(k); 420246772Sjkim return ret; 421246772Sjkim } 422246772Sjkim else 423246772Sjkim return PEM_ASN1_write((i2d_of_void *)i2d_ECPrivateKey, 424246772Sjkim PEM_STRING_ECPRIVATEKEY, 425246772Sjkim fp,x,enc,kstr,klen,cb,u); 426246772Sjkim} 427246772Sjkim#endif 428246772Sjkim 429246772Sjkim#else 430246772Sjkim 431160814SsimonIMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey) 432142425Snectar 433246772Sjkim#endif 434246772Sjkim 435160814SsimonIMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY) 436142425Snectar 437109998Smarkm#ifndef OPENSSL_NO_FP_API 438160814Ssimon 439160814SsimonEC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, 440160814Ssimon void *u) 44159191Skris{ 44259191Skris EVP_PKEY *pktmp; 44359191Skris pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 444238405Sjkim return pkey_get_eckey(pktmp, eckey); /* will free pktmp */ 44559191Skris} 44659191Skris 44759191Skris#endif 44859191Skris 44955714Skris#endif 45055714Skris 451109998Smarkm#ifndef OPENSSL_NO_DH 45255714Skris 453160814SsimonIMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) 45455714Skris 45555714Skris#endif 45655714Skris 45759191SkrisIMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) 458