1/* $OpenBSD: pem_all.c,v 1.21 2023/07/07 13:40:44 beck Exp $ */ 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * 9 * This library is free for commercial and non-commercial use as long as 10 * the following conditions are aheared to. The following conditions 11 * apply to all code found in this distribution, be it the RC4, RSA, 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 * included with this distribution is covered by the same copyright terms 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 * 16 * Copyright remains Eric Young's, and as such any Copyright notices in 17 * the code are not to be removed. 18 * If this package is used in a product, Eric Young should be given attribution 19 * as the author of the parts of the library used. 20 * This can be in the form of a textual message at program startup or 21 * in documentation (online or textual) provided with the package. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * "This product includes cryptographic software written by 34 * Eric Young (eay@cryptsoft.com)" 35 * The word 'cryptographic' can be left out if the rouines from the library 36 * being used are not cryptographic related :-). 37 * 4. If you include any Windows specific code (or a derivative thereof) from 38 * the apps directory (application code) you must include an acknowledgement: 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 * 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * The licence and distribution terms for any publically available version or 54 * derivative of this code cannot be changed. i.e. this code cannot simply be 55 * copied and put under another distribution licence 56 * [including the GNU Public Licence.] 57 */ 58/* ==================================================================== 59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 60 * 61 * Redistribution and use in source and binary forms, with or without 62 * modification, are permitted provided that the following conditions 63 * are met: 64 * 65 * 1. Redistributions of source code must retain the above copyright 66 * notice, this list of conditions and the following disclaimer. 67 * 68 * 2. Redistributions in binary form must reproduce the above copyright 69 * notice, this list of conditions and the following disclaimer in 70 * the documentation and/or other materials provided with the 71 * distribution. 72 * 73 * 3. All advertising materials mentioning features or use of this 74 * software must display the following acknowledgment: 75 * "This product includes software developed by the OpenSSL Project 76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 77 * 78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 79 * endorse or promote products derived from this software without 80 * prior written permission. For written permission, please contact 81 * openssl-core@openssl.org. 82 * 83 * 5. Products derived from this software may not be called "OpenSSL" 84 * nor may "OpenSSL" appear in their names without prior written 85 * permission of the OpenSSL Project. 86 * 87 * 6. Redistributions of any form whatsoever must retain the following 88 * acknowledgment: 89 * "This product includes software developed by the OpenSSL Project 90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 91 * 92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 103 * OF THE POSSIBILITY OF SUCH DAMAGE. 104 * ==================================================================== 105 * 106 * This product includes cryptographic software written by Eric Young 107 * (eay@cryptsoft.com). This product includes software written by Tim 108 * Hudson (tjh@cryptsoft.com). 109 * 110 */ 111 112#include <stdio.h> 113 114#include <openssl/opensslconf.h> 115 116#include <openssl/bio.h> 117#include <openssl/evp.h> 118#include <openssl/pem.h> 119#include <openssl/pkcs7.h> 120#include <openssl/x509.h> 121 122#ifndef OPENSSL_NO_DH 123#include <openssl/dh.h> 124#endif 125#ifndef OPENSSL_NO_DSA 126#include <openssl/dsa.h> 127#endif 128#ifndef OPENSSL_NO_RSA 129#include <openssl/rsa.h> 130#endif 131 132#ifndef OPENSSL_NO_RSA 133static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa); 134#endif 135#ifndef OPENSSL_NO_DSA 136static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa); 137#endif 138 139#ifndef OPENSSL_NO_EC 140static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey); 141#endif 142 143 144X509_REQ * 145PEM_read_X509_REQ(FILE *fp, X509_REQ **x, pem_password_cb *cb, void *u) 146{ 147 return PEM_ASN1_read((d2i_of_void *)d2i_X509_REQ, PEM_STRING_X509_REQ, fp, 148 (void **)x, cb, u); 149} 150LCRYPTO_ALIAS(PEM_read_X509_REQ); 151 152int 153PEM_write_X509_REQ(FILE *fp, X509_REQ *x) 154{ 155 return PEM_ASN1_write((i2d_of_void *)i2d_X509_REQ, PEM_STRING_X509_REQ, fp, 156 x, NULL, NULL, 0, NULL, NULL); 157} 158LCRYPTO_ALIAS(PEM_write_X509_REQ); 159 160X509_REQ * 161PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x, pem_password_cb *cb, void *u) 162{ 163 return PEM_ASN1_read_bio((d2i_of_void *)d2i_X509_REQ, PEM_STRING_X509_REQ, bp, 164 (void **)x, cb, u); 165} 166LCRYPTO_ALIAS(PEM_read_bio_X509_REQ); 167 168int 169PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x) 170{ 171 return PEM_ASN1_write_bio((i2d_of_void *)i2d_X509_REQ, PEM_STRING_X509_REQ, bp, 172 x, NULL, NULL, 0, NULL, NULL); 173} 174LCRYPTO_ALIAS(PEM_write_bio_X509_REQ); 175 176int 177PEM_write_X509_REQ_NEW(FILE *fp, X509_REQ *x) 178{ 179 return PEM_ASN1_write((i2d_of_void *)i2d_X509_REQ, PEM_STRING_X509_REQ_OLD, fp, 180 x, NULL, NULL, 0, NULL, NULL); 181} 182LCRYPTO_ALIAS(PEM_write_X509_REQ_NEW); 183 184int 185PEM_write_bio_X509_REQ_NEW(BIO *bp, X509_REQ *x) 186{ 187 return PEM_ASN1_write_bio((i2d_of_void *)i2d_X509_REQ, PEM_STRING_X509_REQ_OLD, bp, 188 x, NULL, NULL, 0, NULL, NULL); 189} 190LCRYPTO_ALIAS(PEM_write_bio_X509_REQ_NEW); 191 192X509_CRL * 193PEM_read_X509_CRL(FILE *fp, X509_CRL **x, pem_password_cb *cb, void *u) 194{ 195 return PEM_ASN1_read((d2i_of_void *)d2i_X509_CRL, PEM_STRING_X509_CRL, fp, 196 (void **)x, cb, u); 197} 198LCRYPTO_ALIAS(PEM_read_X509_CRL); 199 200int 201PEM_write_X509_CRL(FILE *fp, X509_CRL *x) 202{ 203 return PEM_ASN1_write((i2d_of_void *)i2d_X509_CRL, PEM_STRING_X509_CRL, fp, 204 x, NULL, NULL, 0, NULL, NULL); 205} 206LCRYPTO_ALIAS(PEM_write_X509_CRL); 207 208X509_CRL * 209PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x, pem_password_cb *cb, void *u) 210{ 211 return PEM_ASN1_read_bio((d2i_of_void *)d2i_X509_CRL, PEM_STRING_X509_CRL, bp, 212 (void **)x, cb, u); 213} 214LCRYPTO_ALIAS(PEM_read_bio_X509_CRL); 215 216int 217PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x) 218{ 219 return PEM_ASN1_write_bio((i2d_of_void *)i2d_X509_CRL, PEM_STRING_X509_CRL, bp, 220 x, NULL, NULL, 0, NULL, NULL); 221} 222LCRYPTO_ALIAS(PEM_write_bio_X509_CRL); 223 224PKCS7 * 225PEM_read_PKCS7(FILE *fp, PKCS7 **x, pem_password_cb *cb, void *u) 226{ 227 return PEM_ASN1_read((d2i_of_void *)d2i_PKCS7, PEM_STRING_PKCS7, fp, 228 (void **)x, cb, u); 229} 230LCRYPTO_ALIAS(PEM_read_PKCS7); 231 232int 233PEM_write_PKCS7(FILE *fp, PKCS7 *x) 234{ 235 return PEM_ASN1_write((i2d_of_void *)i2d_PKCS7, PEM_STRING_PKCS7, fp, 236 x, NULL, NULL, 0, NULL, NULL); 237} 238LCRYPTO_ALIAS(PEM_write_PKCS7); 239 240PKCS7 * 241PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, pem_password_cb *cb, void *u) 242{ 243 return PEM_ASN1_read_bio((d2i_of_void *)d2i_PKCS7, PEM_STRING_PKCS7, bp, 244 (void **)x, cb, u); 245} 246LCRYPTO_ALIAS(PEM_read_bio_PKCS7); 247 248int 249PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x) 250{ 251 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PKCS7, PEM_STRING_PKCS7, bp, 252 x, NULL, NULL, 0, NULL, NULL); 253} 254LCRYPTO_ALIAS(PEM_write_bio_PKCS7); 255 256#ifndef OPENSSL_NO_RSA 257 258/* We treat RSA or DSA private keys as a special case. 259 * 260 * For private keys we read in an EVP_PKEY structure with 261 * PEM_read_bio_PrivateKey() and extract the relevant private 262 * key: this means can handle "traditional" and PKCS#8 formats 263 * transparently. 264 */ 265 266static RSA * 267pkey_get_rsa(EVP_PKEY *key, RSA **rsa) 268{ 269 RSA *rtmp; 270 271 if (!key) 272 return NULL; 273 rtmp = EVP_PKEY_get1_RSA(key); 274 EVP_PKEY_free(key); 275 if (!rtmp) 276 return NULL; 277 if (rsa) { 278 RSA_free(*rsa); 279 *rsa = rtmp; 280 } 281 return rtmp; 282} 283 284RSA * 285PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, void *u) 286{ 287 EVP_PKEY *pktmp; 288 289 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 290 return pkey_get_rsa(pktmp, rsa); 291} 292LCRYPTO_ALIAS(PEM_read_RSAPrivateKey); 293 294int 295PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc, 296 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) 297{ 298 return PEM_ASN1_write((i2d_of_void *)i2d_RSAPrivateKey, PEM_STRING_RSA, fp, 299 x, enc, kstr, klen, cb, u); 300} 301LCRYPTO_ALIAS(PEM_write_RSAPrivateKey); 302 303RSA * 304PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, void *u) 305{ 306 EVP_PKEY *pktmp; 307 308 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 309 return pkey_get_rsa(pktmp, rsa); 310} 311LCRYPTO_ALIAS(PEM_read_bio_RSAPrivateKey); 312 313int 314PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, 315 const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, 316 void *u) 317{ 318 return PEM_ASN1_write_bio((i2d_of_void *)i2d_RSAPrivateKey, PEM_STRING_RSA, bp, 319 x, enc, kstr, klen, cb, u); 320} 321LCRYPTO_ALIAS(PEM_write_bio_RSAPrivateKey); 322 323RSA * 324PEM_read_RSAPublicKey(FILE *fp, RSA **x, pem_password_cb *cb, void *u) 325{ 326 return PEM_ASN1_read((d2i_of_void *)d2i_RSAPublicKey, PEM_STRING_RSA_PUBLIC, fp, 327 (void **)x, cb, u); 328} 329LCRYPTO_ALIAS(PEM_read_RSAPublicKey); 330 331int 332PEM_write_RSAPublicKey(FILE *fp, const RSA *x) 333{ 334 return PEM_ASN1_write((i2d_of_void *)i2d_RSAPublicKey, PEM_STRING_RSA_PUBLIC, fp, 335 (void *)x, NULL, NULL, 0, NULL, NULL); 336} 337LCRYPTO_ALIAS(PEM_write_RSAPublicKey); 338 339RSA * 340PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x, pem_password_cb *cb, void *u) 341{ 342 return PEM_ASN1_read_bio((d2i_of_void *)d2i_RSAPublicKey, PEM_STRING_RSA_PUBLIC, bp, 343 (void **)x, cb, u); 344} 345LCRYPTO_ALIAS(PEM_read_bio_RSAPublicKey); 346 347int 348PEM_write_bio_RSAPublicKey(BIO *bp, const RSA *x) 349{ 350 return PEM_ASN1_write_bio((i2d_of_void *)i2d_RSAPublicKey, PEM_STRING_RSA_PUBLIC, bp, 351 (void *)x, NULL, NULL, 0, NULL, NULL); 352} 353LCRYPTO_ALIAS(PEM_write_bio_RSAPublicKey); 354 355RSA * 356PEM_read_RSA_PUBKEY(FILE *fp, RSA **x, pem_password_cb *cb, void *u) 357{ 358 return PEM_ASN1_read((d2i_of_void *)d2i_RSA_PUBKEY, PEM_STRING_PUBLIC, fp, 359 (void **)x, cb, u); 360} 361LCRYPTO_ALIAS(PEM_read_RSA_PUBKEY); 362 363int 364PEM_write_RSA_PUBKEY(FILE *fp, RSA *x) 365{ 366 return PEM_ASN1_write((i2d_of_void *)i2d_RSA_PUBKEY, PEM_STRING_PUBLIC, fp, 367 x, NULL, NULL, 0, NULL, NULL); 368} 369LCRYPTO_ALIAS(PEM_write_RSA_PUBKEY); 370 371RSA * 372PEM_read_bio_RSA_PUBKEY(BIO *bp, RSA **x, pem_password_cb *cb, void *u) 373{ 374 return PEM_ASN1_read_bio((d2i_of_void *)d2i_RSA_PUBKEY, PEM_STRING_PUBLIC, bp, 375 (void **)x, cb, u); 376} 377LCRYPTO_ALIAS(PEM_read_bio_RSA_PUBKEY); 378 379int 380PEM_write_bio_RSA_PUBKEY(BIO *bp, RSA *x) 381{ 382 return PEM_ASN1_write_bio((i2d_of_void *)i2d_RSA_PUBKEY, PEM_STRING_PUBLIC, bp, 383 x, NULL, NULL, 0, NULL, NULL); 384} 385LCRYPTO_ALIAS(PEM_write_bio_RSA_PUBKEY); 386 387#endif 388 389#ifndef OPENSSL_NO_DSA 390 391static DSA * 392pkey_get_dsa(EVP_PKEY *key, DSA **dsa) 393{ 394 DSA *dtmp; 395 396 if (!key) 397 return NULL; 398 dtmp = EVP_PKEY_get1_DSA(key); 399 EVP_PKEY_free(key); 400 if (!dtmp) 401 return NULL; 402 if (dsa) { 403 DSA_free(*dsa); 404 *dsa = dtmp; 405 } 406 return dtmp; 407} 408 409DSA * 410PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, void *u) 411{ 412 EVP_PKEY *pktmp; 413 414 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 415 return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ 416} 417LCRYPTO_ALIAS(PEM_read_DSAPrivateKey); 418 419int 420PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc, 421 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) 422{ 423 return PEM_ASN1_write((i2d_of_void *)i2d_DSAPrivateKey, PEM_STRING_DSA, fp, 424 x, enc, kstr, klen, cb, u); 425} 426LCRYPTO_ALIAS(PEM_write_DSAPrivateKey); 427 428DSA * 429PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, void *u) 430{ 431 EVP_PKEY *pktmp; 432 433 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 434 return pkey_get_dsa(pktmp, dsa); /* will free pktmp */ 435} 436LCRYPTO_ALIAS(PEM_read_bio_DSAPrivateKey); 437 438int 439PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, 440 const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, 441 void *u) 442{ 443 return PEM_ASN1_write_bio((i2d_of_void *)i2d_DSAPrivateKey, PEM_STRING_DSA, bp, 444 x, enc, kstr, klen, cb, u); 445} 446LCRYPTO_ALIAS(PEM_write_bio_DSAPrivateKey); 447 448DSA * 449PEM_read_DSA_PUBKEY(FILE *fp, DSA **x, pem_password_cb *cb, void *u) 450{ 451 return PEM_ASN1_read((d2i_of_void *)d2i_DSA_PUBKEY, PEM_STRING_PUBLIC, fp, 452 (void **)x, cb, u); 453} 454LCRYPTO_ALIAS(PEM_read_DSA_PUBKEY); 455 456int 457PEM_write_DSA_PUBKEY(FILE *fp, DSA *x) 458{ 459 return PEM_ASN1_write((i2d_of_void *)i2d_DSA_PUBKEY, PEM_STRING_PUBLIC, fp, 460 x, NULL, NULL, 0, NULL, NULL); 461} 462LCRYPTO_ALIAS(PEM_write_DSA_PUBKEY); 463 464int 465PEM_write_bio_DSA_PUBKEY(BIO *bp, DSA *x) 466{ 467 return PEM_ASN1_write_bio((i2d_of_void *)i2d_DSA_PUBKEY, PEM_STRING_PUBLIC, bp, 468 x, NULL, NULL, 0, NULL, NULL); 469} 470LCRYPTO_ALIAS(PEM_write_bio_DSA_PUBKEY); 471 472DSA * 473PEM_read_bio_DSA_PUBKEY(BIO *bp, DSA **x, pem_password_cb *cb, void *u) 474{ 475 return PEM_ASN1_read_bio((d2i_of_void *)d2i_DSA_PUBKEY, PEM_STRING_PUBLIC, bp, 476 (void **)x, cb, u); 477} 478LCRYPTO_ALIAS(PEM_read_bio_DSA_PUBKEY); 479 480DSA * 481PEM_read_DSAparams(FILE *fp, DSA **x, pem_password_cb *cb, void *u) 482{ 483 return PEM_ASN1_read((d2i_of_void *)d2i_DSAparams, PEM_STRING_DSAPARAMS, fp, 484 (void **)x, cb, u); 485} 486LCRYPTO_ALIAS(PEM_read_DSAparams); 487 488int 489PEM_write_DSAparams(FILE *fp, const DSA *x) 490{ 491 return PEM_ASN1_write((i2d_of_void *)i2d_DSAparams, PEM_STRING_DSAPARAMS, fp, 492 (void *)x, NULL, NULL, 0, NULL, NULL); 493} 494LCRYPTO_ALIAS(PEM_write_DSAparams); 495 496DSA * 497PEM_read_bio_DSAparams(BIO *bp, DSA **x, pem_password_cb *cb, void *u) 498{ 499 return PEM_ASN1_read_bio((d2i_of_void *)d2i_DSAparams, PEM_STRING_DSAPARAMS, bp, 500 (void **)x, cb, u); 501} 502LCRYPTO_ALIAS(PEM_read_bio_DSAparams); 503 504int 505PEM_write_bio_DSAparams(BIO *bp, const DSA *x) 506{ 507 return PEM_ASN1_write_bio((i2d_of_void *)i2d_DSAparams, PEM_STRING_DSAPARAMS, bp, 508 (void *)x, NULL, NULL, 0, NULL, NULL); 509} 510LCRYPTO_ALIAS(PEM_write_bio_DSAparams); 511 512#endif 513 514 515#ifndef OPENSSL_NO_EC 516static EC_KEY * 517pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey) 518{ 519 EC_KEY *dtmp; 520 521 if (!key) 522 return NULL; 523 dtmp = EVP_PKEY_get1_EC_KEY(key); 524 EVP_PKEY_free(key); 525 if (!dtmp) 526 return NULL; 527 if (eckey) { 528 EC_KEY_free(*eckey); 529 *eckey = dtmp; 530 } 531 return dtmp; 532} 533 534EC_GROUP * 535PEM_read_ECPKParameters(FILE *fp, EC_GROUP **x, pem_password_cb *cb, void *u) 536{ 537 return PEM_ASN1_read((d2i_of_void *)d2i_ECPKParameters, PEM_STRING_ECPARAMETERS, fp, 538 (void **)x, cb, u); 539} 540LCRYPTO_ALIAS(PEM_read_ECPKParameters); 541 542int 543PEM_write_ECPKParameters(FILE *fp, const EC_GROUP *x) 544{ 545 return PEM_ASN1_write((i2d_of_void *)i2d_ECPKParameters, PEM_STRING_ECPARAMETERS, fp, 546 (void *)x, NULL, NULL, 0, NULL, NULL); 547} 548LCRYPTO_ALIAS(PEM_write_ECPKParameters); 549 550EC_GROUP * 551PEM_read_bio_ECPKParameters(BIO *bp, EC_GROUP **x, pem_password_cb *cb, void *u) 552{ 553 return PEM_ASN1_read_bio((d2i_of_void *)d2i_ECPKParameters, PEM_STRING_ECPARAMETERS, bp, 554 (void **)x, cb, u); 555} 556LCRYPTO_ALIAS(PEM_read_bio_ECPKParameters); 557 558int 559PEM_write_bio_ECPKParameters(BIO *bp, const EC_GROUP *x) 560{ 561 return PEM_ASN1_write_bio((i2d_of_void *)i2d_ECPKParameters, PEM_STRING_ECPARAMETERS, bp, 562 (void *)x, NULL, NULL, 0, NULL, NULL); 563} 564LCRYPTO_ALIAS(PEM_write_bio_ECPKParameters); 565 566EC_KEY * 567PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, void *u) 568{ 569 EVP_PKEY *pktmp; 570 571 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 572 return pkey_get_eckey(pktmp, eckey); /* will free pktmp */ 573} 574LCRYPTO_ALIAS(PEM_read_ECPrivateKey); 575 576int 577PEM_write_ECPrivateKey(FILE *fp, EC_KEY *x, const EVP_CIPHER *enc, 578 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) 579{ 580 return PEM_ASN1_write((i2d_of_void *)i2d_ECPrivateKey, PEM_STRING_ECPRIVATEKEY, fp, 581 x, enc, kstr, klen, cb, u); 582} 583LCRYPTO_ALIAS(PEM_write_ECPrivateKey); 584 585EC_KEY * 586PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, void *u) 587{ 588 EVP_PKEY *pktmp; 589 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 590 return pkey_get_eckey(pktmp, key); /* will free pktmp */ 591} 592LCRYPTO_ALIAS(PEM_read_bio_ECPrivateKey); 593 594int 595PEM_write_bio_ECPrivateKey(BIO *bp, EC_KEY *x, 596 const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, 597 void *u) 598{ 599 return PEM_ASN1_write_bio((i2d_of_void *)i2d_ECPrivateKey, PEM_STRING_ECPRIVATEKEY, bp, 600 x, enc, kstr, klen, cb, u); 601} 602LCRYPTO_ALIAS(PEM_write_bio_ECPrivateKey); 603 604EC_KEY * 605PEM_read_EC_PUBKEY(FILE *fp, EC_KEY **x, pem_password_cb *cb, void *u) 606{ 607 return PEM_ASN1_read((d2i_of_void *)d2i_EC_PUBKEY, PEM_STRING_PUBLIC, fp, 608 (void **)x, cb, u); 609} 610LCRYPTO_ALIAS(PEM_read_EC_PUBKEY); 611 612int 613PEM_write_EC_PUBKEY(FILE *fp, EC_KEY *x) 614{ 615 return PEM_ASN1_write((i2d_of_void *)i2d_EC_PUBKEY, PEM_STRING_PUBLIC, fp, 616 x, NULL, NULL, 0, NULL, NULL); 617} 618LCRYPTO_ALIAS(PEM_write_EC_PUBKEY); 619 620EC_KEY * 621PEM_read_bio_EC_PUBKEY(BIO *bp, EC_KEY **x, pem_password_cb *cb, void *u) 622{ 623 return PEM_ASN1_read_bio((d2i_of_void *)d2i_EC_PUBKEY, PEM_STRING_PUBLIC, bp, 624 (void **)x, cb, u); 625} 626LCRYPTO_ALIAS(PEM_read_bio_EC_PUBKEY); 627 628int 629PEM_write_bio_EC_PUBKEY(BIO *bp, EC_KEY *x) 630{ 631 return PEM_ASN1_write_bio((i2d_of_void *)i2d_EC_PUBKEY, PEM_STRING_PUBLIC, bp, 632 x, NULL, NULL, 0, NULL, NULL); 633} 634LCRYPTO_ALIAS(PEM_write_bio_EC_PUBKEY); 635 636#endif 637 638#ifndef OPENSSL_NO_DH 639 640DH * 641PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u) 642{ 643 return PEM_ASN1_read((d2i_of_void *)d2i_DHparams, PEM_STRING_DHPARAMS, fp, 644 (void **)x, cb, u); 645} 646LCRYPTO_ALIAS(PEM_read_DHparams); 647 648int 649PEM_write_DHparams(FILE *fp, const DH *x) 650{ 651 return PEM_ASN1_write((i2d_of_void *)i2d_DHparams, PEM_STRING_DHPARAMS, fp, 652 (void *)x, NULL, NULL, 0, NULL, NULL); 653} 654LCRYPTO_ALIAS(PEM_write_DHparams); 655 656DH * 657PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) 658{ 659 return PEM_ASN1_read_bio((d2i_of_void *)d2i_DHparams, PEM_STRING_DHPARAMS, bp, 660 (void **)x, cb, u); 661} 662LCRYPTO_ALIAS(PEM_read_bio_DHparams); 663 664int 665PEM_write_bio_DHparams(BIO *bp, const DH *x) 666{ 667 return PEM_ASN1_write_bio((i2d_of_void *)i2d_DHparams, PEM_STRING_DHPARAMS, bp, 668 (void *)x, NULL, NULL, 0, NULL, NULL); 669} 670LCRYPTO_ALIAS(PEM_write_bio_DHparams); 671 672#endif 673 674EVP_PKEY * 675PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) 676{ 677 return PEM_ASN1_read((d2i_of_void *)d2i_PUBKEY, PEM_STRING_PUBLIC, fp, 678 (void **)x, cb, u); 679} 680LCRYPTO_ALIAS(PEM_read_PUBKEY); 681 682int 683PEM_write_PUBKEY(FILE *fp, EVP_PKEY *x) 684{ 685 return PEM_ASN1_write((i2d_of_void *)i2d_PUBKEY, PEM_STRING_PUBLIC, fp, 686 x, NULL, NULL, 0, NULL, NULL); 687} 688LCRYPTO_ALIAS(PEM_write_PUBKEY); 689 690EVP_PKEY * 691PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) 692{ 693 return PEM_ASN1_read_bio((d2i_of_void *)d2i_PUBKEY, PEM_STRING_PUBLIC, bp, 694 (void **)x, cb, u); 695} 696LCRYPTO_ALIAS(PEM_read_bio_PUBKEY); 697 698int 699PEM_write_bio_PUBKEY(BIO *bp, EVP_PKEY *x) 700{ 701 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PUBKEY, PEM_STRING_PUBLIC, bp, 702 x, NULL, NULL, 0, NULL, NULL); 703} 704LCRYPTO_ALIAS(PEM_write_bio_PUBKEY); 705