選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

570 行
21 KiB

  1. /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #ifndef OPENSSL_HEADER_PEM_H
  57. #define OPENSSL_HEADER_PEM_H
  58. #include <openssl/base64.h>
  59. #include <openssl/bio.h>
  60. #include <openssl/cipher.h>
  61. #include <openssl/digest.h>
  62. #include <openssl/evp.h>
  63. #include <openssl/stack.h>
  64. #include <openssl/x509.h>
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. #define PEM_BUFSIZE 1024
  69. #define PEM_OBJ_UNDEF 0
  70. #define PEM_OBJ_X509 1
  71. #define PEM_OBJ_X509_REQ 2
  72. #define PEM_OBJ_CRL 3
  73. #define PEM_OBJ_SSL_SESSION 4
  74. #define PEM_OBJ_PRIV_KEY 10
  75. #define PEM_OBJ_PRIV_RSA 11
  76. #define PEM_OBJ_PRIV_DSA 12
  77. #define PEM_OBJ_PRIV_DH 13
  78. #define PEM_OBJ_PUB_RSA 14
  79. #define PEM_OBJ_PUB_DSA 15
  80. #define PEM_OBJ_PUB_DH 16
  81. #define PEM_OBJ_DHPARAMS 17
  82. #define PEM_OBJ_DSAPARAMS 18
  83. #define PEM_OBJ_PRIV_RSA_PUBLIC 19
  84. #define PEM_OBJ_PRIV_ECDSA 20
  85. #define PEM_OBJ_PUB_ECDSA 21
  86. #define PEM_OBJ_ECPARAMETERS 22
  87. #define PEM_ERROR 30
  88. #define PEM_DEK_DES_CBC 40
  89. #define PEM_DEK_IDEA_CBC 45
  90. #define PEM_DEK_DES_EDE 50
  91. #define PEM_DEK_DES_ECB 60
  92. #define PEM_DEK_RSA 70
  93. #define PEM_DEK_RSA_MD2 80
  94. #define PEM_DEK_RSA_MD5 90
  95. #define PEM_MD_MD2 NID_md2
  96. #define PEM_MD_MD5 NID_md5
  97. #define PEM_MD_SHA NID_sha
  98. #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
  99. #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
  100. #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
  101. #define PEM_STRING_X509_OLD "X509 CERTIFICATE"
  102. #define PEM_STRING_X509 "CERTIFICATE"
  103. #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
  104. #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
  105. #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
  106. #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
  107. #define PEM_STRING_X509_CRL "X509 CRL"
  108. #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
  109. #define PEM_STRING_PUBLIC "PUBLIC KEY"
  110. #define PEM_STRING_RSA "RSA PRIVATE KEY"
  111. #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
  112. #define PEM_STRING_DSA "DSA PRIVATE KEY"
  113. #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
  114. #define PEM_STRING_PKCS7 "PKCS7"
  115. #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
  116. #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
  117. #define PEM_STRING_PKCS8INF "PRIVATE KEY"
  118. #define PEM_STRING_DHPARAMS "DH PARAMETERS"
  119. #define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS"
  120. #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
  121. #define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
  122. #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
  123. #define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
  124. #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
  125. #define PEM_STRING_PARAMETERS "PARAMETERS"
  126. #define PEM_STRING_CMS "CMS"
  127. /* Note that this structure is initialised by PEM_SealInit and cleaned up
  128. by PEM_SealFinal (at least for now) */
  129. typedef struct PEM_Encode_Seal_st
  130. {
  131. EVP_ENCODE_CTX encode;
  132. EVP_MD_CTX md;
  133. EVP_CIPHER_CTX cipher;
  134. } PEM_ENCODE_SEAL_CTX;
  135. /* enc_type is one off */
  136. #define PEM_TYPE_ENCRYPTED 10
  137. #define PEM_TYPE_MIC_ONLY 20
  138. #define PEM_TYPE_MIC_CLEAR 30
  139. #define PEM_TYPE_CLEAR 40
  140. typedef struct pem_recip_st
  141. {
  142. char *name;
  143. X509_NAME *dn;
  144. int cipher;
  145. int key_enc;
  146. /* char iv[8]; unused and wrong size */
  147. } PEM_USER;
  148. typedef struct pem_ctx_st
  149. {
  150. int type; /* what type of object */
  151. struct {
  152. int version;
  153. int mode;
  154. } proc_type;
  155. char *domain;
  156. struct {
  157. int cipher;
  158. /* unused, and wrong size
  159. unsigned char iv[8]; */
  160. } DEK_info;
  161. PEM_USER *originator;
  162. int num_recipient;
  163. PEM_USER **recipient;
  164. EVP_MD *md; /* signature type */
  165. int md_enc; /* is the md encrypted or not? */
  166. int md_len; /* length of md_data */
  167. char *md_data; /* message digest, could be pkey encrypted */
  168. EVP_CIPHER *dec; /* date encryption cipher */
  169. int key_len; /* key length */
  170. unsigned char *key; /* key */
  171. /* unused, and wrong size
  172. unsigned char iv[8]; */
  173. int data_enc; /* is the data encrypted */
  174. int data_len;
  175. unsigned char *data;
  176. } PEM_CTX;
  177. /* These macros make the PEM_read/PEM_write functions easier to maintain and
  178. * write. Now they are all implemented with either:
  179. * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
  180. */
  181. #ifdef OPENSSL_NO_FP_API
  182. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
  183. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
  184. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
  185. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
  186. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
  187. #else
  188. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
  189. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
  190. { \
  191. return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
  192. }
  193. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
  194. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \
  195. { \
  196. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
  197. }
  198. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
  199. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \
  200. { \
  201. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
  202. }
  203. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
  204. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  205. unsigned char *kstr, int klen, pem_password_cb *cb, \
  206. void *u) \
  207. { \
  208. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  209. }
  210. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
  211. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  212. unsigned char *kstr, int klen, pem_password_cb *cb, \
  213. void *u) \
  214. { \
  215. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  216. }
  217. #endif
  218. #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  219. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
  220. { \
  221. return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
  222. }
  223. #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  224. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \
  225. { \
  226. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
  227. }
  228. #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  229. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \
  230. { \
  231. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
  232. }
  233. #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  234. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  235. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  236. { \
  237. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
  238. }
  239. #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  240. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  241. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  242. { \
  243. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
  244. }
  245. #define IMPLEMENT_PEM_write(name, type, str, asn1) \
  246. IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  247. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  248. #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
  249. IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  250. IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
  251. #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
  252. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  253. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  254. #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
  255. IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  256. IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
  257. #define IMPLEMENT_PEM_read(name, type, str, asn1) \
  258. IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  259. IMPLEMENT_PEM_read_fp(name, type, str, asn1)
  260. #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
  261. IMPLEMENT_PEM_read(name, type, str, asn1) \
  262. IMPLEMENT_PEM_write(name, type, str, asn1)
  263. #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
  264. IMPLEMENT_PEM_read(name, type, str, asn1) \
  265. IMPLEMENT_PEM_write_const(name, type, str, asn1)
  266. #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
  267. IMPLEMENT_PEM_read(name, type, str, asn1) \
  268. IMPLEMENT_PEM_write_cb(name, type, str, asn1)
  269. /* These are the same except they are for the declarations */
  270. #if defined(OPENSSL_NO_FP_API)
  271. #define DECLARE_PEM_read_fp(name, type) /**/
  272. #define DECLARE_PEM_write_fp(name, type) /**/
  273. #define DECLARE_PEM_write_cb_fp(name, type) /**/
  274. #else
  275. #define DECLARE_PEM_read_fp(name, type) \
  276. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
  277. #define DECLARE_PEM_write_fp(name, type) \
  278. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
  279. #define DECLARE_PEM_write_fp_const(name, type) \
  280. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
  281. #define DECLARE_PEM_write_cb_fp(name, type) \
  282. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  283. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  284. #endif
  285. #ifndef OPENSSL_NO_BIO
  286. #define DECLARE_PEM_read_bio(name, type) \
  287. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
  288. #define DECLARE_PEM_write_bio(name, type) \
  289. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
  290. #define DECLARE_PEM_write_bio_const(name, type) \
  291. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
  292. #define DECLARE_PEM_write_cb_bio(name, type) \
  293. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  294. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  295. #else
  296. #define DECLARE_PEM_read_bio(name, type) /**/
  297. #define DECLARE_PEM_write_bio(name, type) /**/
  298. #define DECLARE_PEM_write_bio_const(name, type) /**/
  299. #define DECLARE_PEM_write_cb_bio(name, type) /**/
  300. #endif
  301. #define DECLARE_PEM_write(name, type) \
  302. DECLARE_PEM_write_bio(name, type) \
  303. DECLARE_PEM_write_fp(name, type)
  304. #define DECLARE_PEM_write_const(name, type) \
  305. DECLARE_PEM_write_bio_const(name, type) \
  306. DECLARE_PEM_write_fp_const(name, type)
  307. #define DECLARE_PEM_write_cb(name, type) \
  308. DECLARE_PEM_write_cb_bio(name, type) \
  309. DECLARE_PEM_write_cb_fp(name, type)
  310. #define DECLARE_PEM_read(name, type) \
  311. DECLARE_PEM_read_bio(name, type) \
  312. DECLARE_PEM_read_fp(name, type)
  313. #define DECLARE_PEM_rw(name, type) \
  314. DECLARE_PEM_read(name, type) \
  315. DECLARE_PEM_write(name, type)
  316. #define DECLARE_PEM_rw_const(name, type) \
  317. DECLARE_PEM_read(name, type) \
  318. DECLARE_PEM_write_const(name, type)
  319. #define DECLARE_PEM_rw_cb(name, type) \
  320. DECLARE_PEM_read(name, type) \
  321. DECLARE_PEM_write_cb(name, type)
  322. #if 1
  323. /* "userdata": new with OpenSSL 0.9.4 */
  324. typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
  325. #else
  326. /* OpenSSL 0.9.3, 0.9.3a */
  327. typedef int pem_password_cb(char *buf, int size, int rwflag);
  328. #endif
  329. OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
  330. OPENSSL_EXPORT int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u);
  331. #ifndef OPENSSL_NO_BIO
  332. OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len);
  333. OPENSSL_EXPORT int PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
  334. OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, pem_password_cb *cb, void *u);
  335. OPENSSL_EXPORT void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u);
  336. OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, const EVP_CIPHER *enc,unsigned char *kstr,int klen, pem_password_cb *cb, void *u);
  337. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  338. OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
  339. #endif
  340. OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len);
  341. OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len);
  342. OPENSSL_EXPORT void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u);
  343. OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, void *x,const EVP_CIPHER *enc,unsigned char *kstr, int klen,pem_password_cb *callback, void *u);
  344. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  345. OPENSSL_EXPORT int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
  346. OPENSSL_EXPORT void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl);
  347. OPENSSL_EXPORT int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv);
  348. OPENSSL_EXPORT void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
  349. OPENSSL_EXPORT void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
  350. OPENSSL_EXPORT int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey);
  351. OPENSSL_EXPORT int PEM_def_callback(char *buf, int num, int w, void *key);
  352. OPENSSL_EXPORT void PEM_proc_type(char *buf, int type);
  353. OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len, char *str);
  354. DECLARE_PEM_rw(X509, X509)
  355. DECLARE_PEM_rw(X509_AUX, X509)
  356. DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
  357. DECLARE_PEM_rw(X509_REQ, X509_REQ)
  358. DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
  359. DECLARE_PEM_rw(X509_CRL, X509_CRL)
  360. /* DECLARE_PEM_rw(PKCS7, PKCS7) */
  361. DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
  362. DECLARE_PEM_rw(PKCS8, X509_SIG)
  363. DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  364. DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
  365. DECLARE_PEM_rw_const(RSAPublicKey, RSA)
  366. DECLARE_PEM_rw(RSA_PUBKEY, RSA)
  367. #ifndef OPENSSL_NO_DSA
  368. DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
  369. DECLARE_PEM_rw(DSA_PUBKEY, DSA)
  370. DECLARE_PEM_rw_const(DSAparams, DSA)
  371. #endif
  372. DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)
  373. DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
  374. DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
  375. DECLARE_PEM_rw_const(DHparams, DH)
  376. DECLARE_PEM_write_const(DHxparams, DH)
  377. DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
  378. DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
  379. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  380. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *);
  381. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
  382. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  383. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  384. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
  385. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  386. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  387. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  388. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, char *kstr,int klen, pem_password_cb *cd, void *u);
  389. OPENSSL_EXPORT EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
  390. OPENSSL_EXPORT int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x);
  391. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
  392. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
  393. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
  394. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in);
  395. OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
  396. OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
  397. OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
  398. OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u);
  399. void ERR_load_PEM_strings(void);
  400. #ifdef __cplusplus
  401. }
  402. #endif
  403. #define PEM_F_PEM_read_bio_DHparams 100
  404. #define PEM_F_load_iv 101
  405. #define PEM_F_PEM_write 102
  406. #define PEM_F_do_pk8pkey_fp 103
  407. #define PEM_F_PEM_read_PrivateKey 104
  408. #define PEM_F_PEM_read_DHparams 105
  409. #define PEM_F_PEM_ASN1_read_bio 106
  410. #define PEM_F_PEM_ASN1_read 107
  411. #define PEM_F_PEM_get_EVP_CIPHER_INFO 108
  412. #define PEM_F_PEM_X509_INFO_read 109
  413. #define PEM_F_PEM_read_bio_Parameters 110
  414. #define PEM_F_PEM_read 111
  415. #define PEM_F_PEM_X509_INFO_read_bio 112
  416. #define PEM_F_PEM_X509_INFO_write_bio 113
  417. #define PEM_F_PEM_ASN1_write 114
  418. #define PEM_F_d2i_PKCS8PrivateKey_bio 115
  419. #define PEM_F_d2i_PKCS8PrivateKey_fp 116
  420. #define PEM_F_PEM_read_bio_PrivateKey 117
  421. #define PEM_F_PEM_write_PrivateKey 118
  422. #define PEM_F_PEM_ASN1_write_bio 119
  423. #define PEM_F_PEM_do_header 120
  424. #define PEM_F_PEM_write_bio 121
  425. #define PEM_F_do_pk8pkey 122
  426. #define PEM_F_PEM_read_bio 123
  427. #define PEM_R_NO_START_LINE 100
  428. #define PEM_R_NOT_PROC_TYPE 101
  429. #define PEM_R_SHORT_HEADER 102
  430. #define PEM_R_BAD_IV_CHARS 103
  431. #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 104
  432. #define PEM_R_BAD_END_LINE 105
  433. #define PEM_R_CIPHER_IS_NULL 106
  434. #define PEM_R_BAD_MAGIC_NUMBER 107
  435. #define PEM_R_BAD_DECRYPT 108
  436. #define PEM_R_UNSUPPORTED_ENCRYPTION 109
  437. #define PEM_R_PVK_DATA_TOO_SHORT 110
  438. #define PEM_R_PROBLEMS_GETTING_PASSWORD 111
  439. #define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 112
  440. #define PEM_R_BIO_WRITE_FAILURE 113
  441. #define PEM_R_INCONSISTENT_HEADER 114
  442. #define PEM_R_PUBLIC_KEY_NO_RSA 115
  443. #define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 116
  444. #define PEM_R_KEYBLOB_TOO_SHORT 117
  445. #define PEM_R_BAD_BASE64_DECODE 118
  446. #define PEM_R_READ_KEY 119
  447. #define PEM_R_BAD_PASSWORD_READ 120
  448. #define PEM_R_UNSUPPORTED_KEY_COMPONENTS 121
  449. #define PEM_R_UNSUPPORTED_CIPHER 122
  450. #define PEM_R_NOT_ENCRYPTED 123
  451. #define PEM_R_NOT_DEK_INFO 124
  452. #define PEM_R_BAD_VERSION_NUMBER 125
  453. #define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 126
  454. #define PEM_R_PVK_TOO_SHORT 127
  455. #endif /* OPENSSL_HEADER_PEM_H */