summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pem')
-rw-r--r--src/lib/libcrypto/pem/Makefile.ssl162
-rw-r--r--src/lib/libcrypto/pem/ctx_size.c122
-rw-r--r--src/lib/libcrypto/pem/pem.err38
-rw-r--r--src/lib/libcrypto/pem/pem.h551
-rw-r--r--src/lib/libcrypto/pem/pem.org562
-rw-r--r--src/lib/libcrypto/pem/pem2.h60
-rw-r--r--src/lib/libcrypto/pem/pem_all.c429
-rw-r--r--src/lib/libcrypto/pem/pem_err.c121
-rw-r--r--src/lib/libcrypto/pem/pem_info.c60
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c273
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c41
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c27
12 files changed, 789 insertions, 1657 deletions
diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl
index fc04a88fd9..b4e7524ea2 100644
--- a/src/lib/libcrypto/pem/Makefile.ssl
+++ b/src/lib/libcrypto/pem/Makefile.ssl
@@ -7,30 +7,28 @@ TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=pem
19ERRC=pem_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24CTX_SIZE= ctx_size
25
26LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
27LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c $(ERRC).c 25LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c
28 26
29LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o $(ERRC).o 27LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o
30 28
31SRC= $(LIBSRC) 29SRC= $(LIBSRC)
32 30
33EXHEADER= pem.h 31EXHEADER= pem.h pem2.h
34HEADER= $(EXHEADER) 32HEADER= $(EXHEADER)
35 33
36ALL= $(GENERAL) $(SRC) $(HEADER) 34ALL= $(GENERAL) $(SRC) $(HEADER)
@@ -38,36 +36,27 @@ ALL= $(GENERAL) $(SRC) $(HEADER)
38top: 36top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) 37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40 38
41all: pem.h lib 39all: lib
42
43pem.h: $(CTX_SIZE)
44 ./$(CTX_SIZE) <pem.org >pem.new
45 if [ -f pem.h ]; then mv -f pem.h pem.old; fi
46 mv -f pem.new pem.h
47
48$(CTX_SIZE): $(CTX_SIZE).o
49 $(CC) $(CFLAGS) -o $(CTX_SIZE) $(CTX_SIZE).o
50 40
51lib: $(LIBOBJ) 41lib: $(LIBOBJ)
52 $(AR) $(LIB) $(LIBOBJ) 42 $(AR) $(LIB) $(LIBOBJ)
53 sh $(TOP)/util/ranlib.sh $(LIB) 43 $(RANLIB) $(LIB)
54 @touch lib 44 @touch lib
55 45
56files: 46files:
57 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
58 48
59links: 49links: $(EXHEADER)
60 /bin/rm -f Makefile 50 @$(TOP)/util/point.sh Makefile.ssl Makefile
61 $(TOP)/util/point.sh Makefile.ssl Makefile ; 51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 $(TOP)/util/mklink.sh ../../test $(TEST) 53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64 $(TOP)/util/mklink.sh ../../apps $(APPS)
65 54
66install: 55install:
67 @for i in $(EXHEADER) ; \ 56 @for i in $(EXHEADER) ; \
68 do \ 57 do \
69 (cp $$i $(INSTALLTOP)/include/$$i; \ 58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
70 chmod 644 $(INSTALLTOP)/include/$$i ); \ 59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
71 done; 60 done;
72 61
73tags: 62tags:
@@ -79,18 +68,121 @@ lint:
79 lint -DLINT $(INCLUDES) $(SRC)>fluff 68 lint -DLINT $(INCLUDES) $(SRC)>fluff
80 69
81depend: 70depend:
82 $(MAKEDEPEND) $(INCLUDES) $(CTX_SIZE).c $(LIBSRC) 71 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC)
83 72
84dclean: 73dclean:
85 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
86 mv -f Makefile.new $(MAKEFILE) 75 mv -f Makefile.new $(MAKEFILE)
87 76
88clean: 77clean:
89 /bin/rm -f $(CTX_SIZE) *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
90
91errors:
92 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # SPECIAL CASE .org
93 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
94 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
95 79
96# DO NOT DELETE THIS LINE -- make depend depends on it. 80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
83pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
84pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
85pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
86pem_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
87pem_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
88pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
89pem_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
90pem_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
91pem_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
92pem_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
93pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
94pem_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
95pem_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
96pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
97pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
98pem_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
99pem_all.o: ../cryptlib.h
100pem_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
101pem_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
102pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
103pem_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h
104pem_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
105pem_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
106pem_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
107pem_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
108pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
109pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
110pem_err.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
111pem_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
112pem_err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
113pem_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
114pem_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
115pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
116pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
117pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
118pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
119pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
120pem_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
121pem_info.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
122pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
123pem_info.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
124pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
125pem_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
126pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
127pem_info.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
128pem_info.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
129pem_info.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
130pem_info.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131pem_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
132pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
133pem_info.o: ../cryptlib.h
134pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
135pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
136pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
137pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
138pem_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
139pem_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
140pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
141pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
142pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
143pem_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
144pem_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
145pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
146pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
147pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
148pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
149pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
150pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151pem_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
152pem_lib.o: ../cryptlib.h
153pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157pem_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
158pem_seal.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
159pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
161pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
162pem_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
163pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
164pem_seal.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
165pem_seal.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
166pem_seal.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
167pem_seal.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
168pem_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
169pem_seal.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
170pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
171pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
172pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
173pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
174pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
175pem_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
176pem_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
177pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
178pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
179pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
180pem_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
181pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
182pem_sign.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
183pem_sign.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
184pem_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
185pem_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
186pem_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
187pem_sign.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
188pem_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
diff --git a/src/lib/libcrypto/pem/ctx_size.c b/src/lib/libcrypto/pem/ctx_size.c
deleted file mode 100644
index 87469bc4af..0000000000
--- a/src/lib/libcrypto/pem/ctx_size.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/* crypto/pem/ctx_size.c */
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#include <stdio.h>
60#include "cryptlib.h"
61#include "evp.h"
62
63int main(argc,argv)
64int argc;
65char *argv[];
66 {
67 int i,j;
68 char buf[256];
69
70 for (;;)
71 {
72 char *str;
73 buf[0]='\0';
74 fgets(buf,256,stdin);
75 if (buf[0] == '\0') break;
76
77 str="#define EVP_ENCODE_CTX_SIZE ";
78 if (strncmp(buf,str,strlen(str)) == 0)
79 {
80 printf("%s %d\n",str,(int)sizeof(EVP_ENCODE_CTX));
81 continue;
82 }
83 str="#define EVP_MD_SIZE ";
84 if (strncmp(buf,str,strlen(str)) == 0)
85 {
86 printf("%s %d\n",str,(int)sizeof(EVP_MD));
87 continue;
88 }
89 str="#define EVP_MD_CTX_SIZE ";
90 if (strncmp(buf,str,strlen(str)) == 0)
91 {
92 printf("%s %d\n",str,(int)sizeof(EVP_MD_CTX));
93 continue;
94 }
95 str="#define EVP_CIPHER_SIZE ";
96 if (strncmp(buf,str,strlen(str)) == 0)
97 {
98 printf("%s %d\n",str,(int)sizeof(EVP_CIPHER));
99 continue;
100 }
101 str="#define EVP_CIPHER_CTX_SIZE ";
102 if (strncmp(buf,str,strlen(str)) == 0)
103 {
104 printf("%s %d\n",str,(int)sizeof(EVP_CIPHER_CTX));
105 continue;
106 }
107
108 str="#define EVP_MAX_MD_SIZE ";
109 if (strncmp(buf,str,strlen(str)) == 0)
110 {
111 i=MD2_DIGEST_LENGTH;
112 j=MD5_DIGEST_LENGTH;
113 if (j > i) i=j;
114 j=SHA_DIGEST_LENGTH;
115 if (j > i) i=j;
116 printf("%s %d\n",str,i);
117 continue;
118 }
119 fputs(buf,stdout);
120 }
121 exit(0);
122 }
diff --git a/src/lib/libcrypto/pem/pem.err b/src/lib/libcrypto/pem/pem.err
deleted file mode 100644
index 0e523abf82..0000000000
--- a/src/lib/libcrypto/pem/pem.err
+++ /dev/null
@@ -1,38 +0,0 @@
1/* Error codes for the PEM functions. */
2
3/* Function codes. */
4#define PEM_F_DEF_CALLBACK 100
5#define PEM_F_LOAD_IV 101
6#define PEM_F_PEM_ASN1_READ 102
7#define PEM_F_PEM_ASN1_READ_BIO 103
8#define PEM_F_PEM_ASN1_WRITE 104
9#define PEM_F_PEM_ASN1_WRITE_BIO 105
10#define PEM_F_PEM_DO_HEADER 106
11#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
12#define PEM_F_PEM_READ 108
13#define PEM_F_PEM_READ_BIO 109
14#define PEM_F_PEM_SEALFINAL 110
15#define PEM_F_PEM_SEALINIT 111
16#define PEM_F_PEM_SIGNFINAL 112
17#define PEM_F_PEM_WRITE 113
18#define PEM_F_PEM_WRITE_BIO 114
19#define PEM_F_PEM_X509_INFO_READ 115
20#define PEM_F_PEM_X509_INFO_READ_BIO 116
21#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
22
23/* Reason codes. */
24#define PEM_R_BAD_BASE64_DECODE 100
25#define PEM_R_BAD_DECRYPT 101
26#define PEM_R_BAD_END_LINE 102
27#define PEM_R_BAD_IV_CHARS 103
28#define PEM_R_BAD_PASSWORD_READ 104
29#define PEM_R_NOT_DEK_INFO 105
30#define PEM_R_NOT_ENCRYPTED 106
31#define PEM_R_NOT_PROC_TYPE 107
32#define PEM_R_NO_START_LINE 108
33#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
34#define PEM_R_PUBLIC_KEY_NO_RSA 110
35#define PEM_R_READ_KEY 111
36#define PEM_R_SHORT_HEADER 112
37#define PEM_R_UNSUPPORTED_CIPHER 113
38#define PEM_R_UNSUPPORTED_ENCRYPTION 114
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index 55fbaeffe2..fc333e42c8 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -1,4 +1,4 @@
1/* crypto/pem/pem.org */ 1/* crypto/pem/pem.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,14 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify pem.org since pem.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_PEM_H 59#ifndef HEADER_PEM_H
68#define HEADER_PEM_H 60#define HEADER_PEM_H
69 61
@@ -71,8 +63,11 @@
71extern "C" { 63extern "C" {
72#endif 64#endif
73 65
74#include "evp.h" 66#include <openssl/evp.h>
75#include "x509.h" 67#include <openssl/x509.h>
68#include <openssl/pem2.h>
69
70#define PEM_BUFSIZE 1024
76 71
77#define PEM_OBJ_UNDEF 0 72#define PEM_OBJ_UNDEF 0
78#define PEM_OBJ_X509 1 73#define PEM_OBJ_X509 1
@@ -111,45 +106,17 @@ extern "C" {
111#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 106#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
112#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 107#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
113#define PEM_STRING_X509_CRL "X509 CRL" 108#define PEM_STRING_X509_CRL "X509 CRL"
114#define PEM_STRING_EVP_PKEY "PRIVATE KEY" 109#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
115#define PEM_STRING_RSA "RSA PRIVATE KEY" 110#define PEM_STRING_RSA "RSA PRIVATE KEY"
116#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 111#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
117#define PEM_STRING_DSA "DSA PRIVATE KEY" 112#define PEM_STRING_DSA "DSA PRIVATE KEY"
118#define PEM_STRING_PKCS7 "PKCS7" 113#define PEM_STRING_PKCS7 "PKCS7"
114#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
115#define PEM_STRING_PKCS8INF "PRIVATE KEY"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS" 116#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 117#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 118#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122 119
123#ifndef HEADER_ENVELOPE_H
124
125#define EVP_ENCODE_CTX_SIZE 96
126#define EVP_MD_SIZE 60
127#define EVP_MD_CTX_SIZE 152
128#define EVP_CIPHER_SIZE 40
129#define EVP_CIPHER_CTX_SIZE 4212
130#define EVP_MAX_MD_SIZE 20
131
132typedef struct evp_encode_ctx_st
133 {
134 char data[EVP_ENCODE_CTX_SIZE];
135 } EVP_ENCODE_CTX;
136
137typedef struct env_md_ctx_st
138 {
139 char data[EVP_MD_CTX_SIZE];
140 } EVP_MD_CTX;
141
142typedef struct evp_cipher_st
143 {
144 char data[EVP_CIPHER_SIZE];
145 } EVP_CIPHER;
146
147typedef struct evp_cipher_ctx_st
148 {
149 char data[EVP_CIPHER_CTX_SIZE];
150 } EVP_CIPHER_CTX;
151#endif
152
153 120
154typedef struct PEM_Encode_Seal_st 121typedef struct PEM_Encode_Seal_st
155 { 122 {
@@ -217,151 +184,322 @@ typedef struct pem_ctx_st
217 unsigned char *data; 184 unsigned char *data;
218 } PEM_CTX; 185 } PEM_CTX;
219 186
187/* These macros make the PEM_read/PEM_write functions easier to maintain and
188 * write. Now they are all implemented with either:
189 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
190 */
191
192#ifdef NO_FP_API
193
194#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
195#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
196#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
197
198#else
199
200#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
201type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
202{ \
203return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
204 cb,u)); \
205} \
206
207#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
208int PEM_write_##name(FILE *fp, type *x) \
209{ \
210return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
211 NULL,NULL,0,NULL,NULL)); \
212}
213
214#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
215int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
216 unsigned char *kstr, int klen, pem_password_cb *cb, \
217 void *u) \
218 { \
219 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
220 (char *)x,enc,kstr,klen,cb,u)); \
221 }
222
223#endif
224
225#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
226type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
227{ \
228return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
229 (char **)x,cb,u)); \
230}
231
232#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
233int PEM_write_bio_##name(BIO *bp, type *x) \
234{ \
235return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
236 NULL,NULL,0,NULL,NULL)); \
237}
238
239#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
240int 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((int (*)())i2d_##asn1,str,bp, \
244 (char *)x,enc,kstr,klen,cb,u)); \
245 }
246
247#define IMPLEMENT_PEM_write(name, type, str, asn1) \
248 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
249 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
250
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
255#define IMPLEMENT_PEM_read(name, type, str, asn1) \
256 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
257 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
258
259#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
260 IMPLEMENT_PEM_read(name, type, str, asn1) \
261 IMPLEMENT_PEM_write(name, type, str, asn1)
262
263#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
264 IMPLEMENT_PEM_read(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
266
267/* These are the same except they are for the declarations */
268
269#if defined(WIN16) || defined(NO_FP_API)
270
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
275#else
276
277#define DECLARE_PEM_read_fp(name, type) \
278 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
279
280#define DECLARE_PEM_write_fp(name, type) \
281 int PEM_write_##name(FILE *fp, type *x);
282
283#define DECLARE_PEM_write_cb_fp(name, type) \
284 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
285 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
286
287#endif
288
289#ifdef HEADER_BIO_H
290#define DECLARE_PEM_read_bio(name, type) \
291 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_bio(name, type) \
294 int PEM_write_bio_##name(BIO *bp, type *x);
295
296#define DECLARE_PEM_write_cb_bio(name, type) \
297 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#else
301
302#define DECLARE_PEM_read_bio(name, type) /**/
303#define DECLARE_PEM_write_bio(name, type) /**/
304#define DECLARE_PEM_write_cb_bio(name, type) /**/
305
306#endif
307
308#define DECLARE_PEM_write(name, type) \
309 DECLARE_PEM_write_bio(name, type) \
310 DECLARE_PEM_write_fp(name, type)
311
312#define DECLARE_PEM_write_cb(name, type) \
313 DECLARE_PEM_write_cb_bio(name, type) \
314 DECLARE_PEM_write_cb_fp(name, type)
315
316#define DECLARE_PEM_read(name, type) \
317 DECLARE_PEM_read_bio(name, type) \
318 DECLARE_PEM_read_fp(name, type)
319
320#define DECLARE_PEM_rw(name, type) \
321 DECLARE_PEM_read(name, type) \
322 DECLARE_PEM_write(name, type)
323
324#define DECLARE_PEM_rw_cb(name, type) \
325 DECLARE_PEM_read(name, type) \
326 DECLARE_PEM_write_cb(name, type)
327
220#ifdef SSLEAY_MACROS 328#ifdef SSLEAY_MACROS
221 329
222#define PEM_write_SSL_SESSION(fp,x) \ 330#define PEM_write_SSL_SESSION(fp,x) \
223 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ 331 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
224 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) 332 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
225#define PEM_write_X509(fp,x) \ 333#define PEM_write_X509(fp,x) \
226 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ 334 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
227 (char *)x, NULL,NULL,0,NULL) 335 (char *)x, NULL,NULL,0,NULL,NULL)
228#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ 336#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
229 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ 337 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
230 NULL,NULL,0,NULL) 338 NULL,NULL,0,NULL,NULL)
231#define PEM_write_X509_CRL(fp,x) \ 339#define PEM_write_X509_CRL(fp,x) \
232 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ 340 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
233 fp,(char *)x, NULL,NULL,0,NULL) 341 fp,(char *)x, NULL,NULL,0,NULL,NULL)
234#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ 342#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
235 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ 343 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
236 (char *)x,enc,kstr,klen,cb) 344 (char *)x,enc,kstr,klen,cb,u)
237#define PEM_write_RSAPublicKey(fp,x) \ 345#define PEM_write_RSAPublicKey(fp,x) \
238 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ 346 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
239 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) 347 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
240#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ 348#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
241 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ 349 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
242 (char *)x,enc,kstr,klen,cb) 350 (char *)x,enc,kstr,klen,cb,u)
243#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ 351#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
244 PEM_ASN1_write((int (*)())i2d_PrivateKey,\ 352 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
245 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 353 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
246 bp,(char *)x,enc,kstr,klen,cb) 354 bp,(char *)x,enc,kstr,klen,cb,u)
247#define PEM_write_PKCS7(fp,x) \ 355#define PEM_write_PKCS7(fp,x) \
248 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ 356 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
249 (char *)x, NULL,NULL,0,NULL) 357 (char *)x, NULL,NULL,0,NULL,NULL)
250#define PEM_write_DHparams(fp,x) \ 358#define PEM_write_DHparams(fp,x) \
251 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ 359 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
252 (char *)x,NULL,NULL,0,NULL) 360 (char *)x,NULL,NULL,0,NULL,NULL)
253 361
254#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ 362#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
255 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) 363 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
256#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ 364 PEM_STRING_X509,fp, \
257 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) 365 (char *)x, NULL,NULL,0,NULL,NULL)
258#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ 366
259 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) 367#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
260#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ 368 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
261 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) 369#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
262#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ 370 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
263 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) 371#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
264#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ 372 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
265 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) 373#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
266#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ 374 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
267 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) 375#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
268#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ 376 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
269 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) 377#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
270#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ 378 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
271 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) 379#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
272#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ 380 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
273 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) 381#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
382 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
383#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
384 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
385#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
386 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
387
388#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
389 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
390 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
391 (char **)x,cb,u)
274 392
275#define PEM_write_bio_SSL_SESSION(bp,x) \ 393#define PEM_write_bio_SSL_SESSION(bp,x) \
276 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ 394 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
277 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) 395 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
278#define PEM_write_bio_X509(bp,x) \ 396#define PEM_write_bio_X509(bp,x) \
279 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ 397 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
280 (char *)x, NULL,NULL,0,NULL) 398 (char *)x, NULL,NULL,0,NULL,NULL)
281#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ 399#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
282 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ 400 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
283 NULL,NULL,0,NULL) 401 NULL,NULL,0,NULL,NULL)
284#define PEM_write_bio_X509_CRL(bp,x) \ 402#define PEM_write_bio_X509_CRL(bp,x) \
285 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ 403 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
286 bp,(char *)x, NULL,NULL,0,NULL) 404 bp,(char *)x, NULL,NULL,0,NULL,NULL)
287#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ 405#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
288 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ 406 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
289 bp,(char *)x,enc,kstr,klen,cb) 407 bp,(char *)x,enc,kstr,klen,cb,u)
290#define PEM_write_bio_RSAPublicKey(bp,x) \ 408#define PEM_write_bio_RSAPublicKey(bp,x) \
291 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ 409 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
292 PEM_STRING_RSA_PUBLIC,\ 410 PEM_STRING_RSA_PUBLIC,\
293 bp,(char *)x,NULL,NULL,0,NULL) 411 bp,(char *)x,NULL,NULL,0,NULL,NULL)
294#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ 412#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
295 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ 413 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
296 bp,(char *)x,enc,kstr,klen,cb) 414 bp,(char *)x,enc,kstr,klen,cb,u)
297#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ 415#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
298 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ 416 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
299 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 417 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
300 bp,(char *)x,enc,kstr,klen,cb) 418 bp,(char *)x,enc,kstr,klen,cb,u)
301#define PEM_write_bio_PKCS7(bp,x) \ 419#define PEM_write_bio_PKCS7(bp,x) \
302 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ 420 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
303 (char *)x, NULL,NULL,0,NULL) 421 (char *)x, NULL,NULL,0,NULL,NULL)
304#define PEM_write_bio_DHparams(bp,x) \ 422#define PEM_write_bio_DHparams(bp,x) \
305 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ 423 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
306 bp,(char *)x,NULL,NULL,0,NULL) 424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
307#define PEM_write_bio_DSAparams(bp,x) \ 425#define PEM_write_bio_DSAparams(bp,x) \
308 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ 426 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
309 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) 427 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
310 428
311#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ 429#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
312 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) 430 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
313#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ 431 PEM_STRING_X509,bp, \
314 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) 432 (char *)x, NULL,NULL,0,NULL,NULL)
315#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ 433
316 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) 434#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
317#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ 435 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
318 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) 436#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
319#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ 437 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
320 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) 438#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
321#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ 439 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
322 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) 440#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
323#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ 441 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
324 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) 442#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
325#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ 443 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
326 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) 444#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
327 445 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
328#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ 446#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
329 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) 447 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
330#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ 448#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
331 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) 449 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
332#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ 450
333 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) 451#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
453#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
455#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
457
458#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
459 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
461 (char **)x,cb,u)
334 462
335#endif 463#endif
336 464
337#ifndef NOPROTO 465#if 1
466/* "userdata": new with OpenSSL 0.9.4 */
467typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
468#else
469/* OpenSSL 0.9.3, 0.9.3a */
470typedef int pem_password_cb(char *buf, int size, int rwflag);
471#endif
472
338int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 473int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
339int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, 474int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
340 int (*callback)()); 475 pem_password_cb *callback,void *u);
341 476
342#ifdef HEADER_BIO_H 477#ifdef HEADER_BIO_H
343int PEM_read_bio(BIO *bp, char **name, char **header, 478int PEM_read_bio(BIO *bp, char **name, char **header,
344 unsigned char **data,long *len); 479 unsigned char **data,long *len);
345int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, 480int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
346 long len); 481 long len);
347char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, 482char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
348 int (*cb)()); 483 pem_password_cb *cb, void *u);
349int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, 484int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
350 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); 485 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
351STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); 486 pem_password_cb *cb, void *u);
487STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
352int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, 488int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
353 unsigned char *kstr, int klen, int (*cb)()); 489 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
354#endif 490#endif
355 491
356#ifndef WIN16 492#ifndef WIN16
357int PEM_read(FILE *fp, char **name, char **header, 493int PEM_read(FILE *fp, char **name, char **header,
358 unsigned char **data,long *len); 494 unsigned char **data,long *len);
359int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); 495int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
360char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, 496char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
361 int (*cb)()); 497 pem_password_cb *cb, void *u);
362int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, 498int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
363 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); 499 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
364STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); 500 pem_password_cb *callback, void *u);
501STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
502 pem_password_cb *cb, void *u);
365#endif 503#endif
366 504
367int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, 505int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
@@ -380,142 +518,64 @@ int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
380void ERR_load_PEM_strings(void); 518void ERR_load_PEM_strings(void);
381 519
382void PEM_proc_type(char *buf, int type); 520void PEM_proc_type(char *buf, int type);
383void PEM_dek_info(char *buf, char *type, int len, char *str); 521void PEM_dek_info(char *buf, const char *type, int len, char *str);
384 522
385#ifndef SSLEAY_MACROS 523#ifndef SSLEAY_MACROS
386 524
387#ifndef WIN16 525#ifdef VMS
388X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); 526#include <openssl/vms_idhacks.h>
389X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)());
390X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)());
391RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)());
392RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)());
393DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)());
394EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)());
395PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)());
396DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)());
397DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)());
398int PEM_write_X509(FILE *fp,X509 *x);
399int PEM_write_X509_REQ(FILE *fp,X509_REQ *x);
400int PEM_write_X509_CRL(FILE *fp,X509_CRL *x);
401int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr,
402 int klen,int (*cb)());
403int PEM_write_RSAPublicKey(FILE *fp,RSA *x);
404int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr,
405 int klen,int (*cb)());
406int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc,
407 unsigned char *kstr,int klen,int (*cb)());
408int PEM_write_PKCS7(FILE *fp,PKCS7 *x);
409int PEM_write_DHparams(FILE *fp,DH *x);
410int PEM_write_DSAparams(FILE *fp,DSA *x);
411#endif 527#endif
412 528
413#ifdef HEADER_BIO_H 529DECLARE_PEM_rw(X509, X509)
414X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); 530
415X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); 531DECLARE_PEM_rw(X509_REQ, X509_REQ)
416X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); 532
417RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); 533DECLARE_PEM_rw(X509_CRL, X509_CRL)
418RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); 534
419DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); 535DECLARE_PEM_rw(PKCS7, PKCS7)
420EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); 536
421PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); 537DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
422DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); 538
423DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); 539DECLARE_PEM_rw(PKCS8, X509_SIG)
424int PEM_write_bio_X509(BIO *bp,X509 *x); 540
425int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); 541DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
426int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); 542
427int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, 543#ifndef NO_RSA
428 unsigned char *kstr,int klen,int (*cb)()); 544
429int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); 545DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
430int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, 546
431 unsigned char *kstr,int klen,int (*cb)()); 547DECLARE_PEM_rw(RSAPublicKey, RSA)
432int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, 548
433 unsigned char *kstr,int klen,int (*cb)());
434int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x);
435int PEM_write_bio_DHparams(BIO *bp,DH *x);
436int PEM_write_bio_DSAparams(BIO *bp,DSA *x);
437#endif 549#endif
438 550
439#endif /* SSLEAY_MACROS */ 551#ifndef NO_DSA
440 552
553DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
441 554
442#else 555DECLARE_PEM_rw(DSAparams, DSA)
443 556
444int PEM_get_EVP_CIPHER_INFO();
445int PEM_do_header();
446int PEM_read_bio();
447int PEM_write_bio();
448#ifndef WIN16
449int PEM_read();
450int PEM_write();
451STACK * PEM_X509_INFO_read();
452char * PEM_ASN1_read();
453int PEM_ASN1_write();
454#endif 557#endif
455STACK * PEM_X509_INFO_read_bio();
456int PEM_X509_INFO_write_bio();
457char * PEM_ASN1_read_bio();
458int PEM_ASN1_write_bio();
459int PEM_SealInit();
460void PEM_SealUpdate();
461int PEM_SealFinal();
462int PEM_SignFinal();
463 558
464void ERR_load_PEM_strings(); 559#ifndef NO_DH
465 560
466void PEM_proc_type(); 561DECLARE_PEM_rw(DHparams, DH)
467void PEM_dek_info();
468 562
469#ifndef SSLEAY_MACROS
470#ifndef WIN16
471X509 *PEM_read_X509();
472X509_REQ *PEM_read_X509_REQ();
473X509_CRL *PEM_read_X509_CRL();
474RSA *PEM_read_RSAPrivateKey();
475RSA *PEM_read_RSAPublicKey();
476DSA *PEM_read_DSAPrivateKey();
477EVP_PKEY *PEM_read_PrivateKey();
478PKCS7 *PEM_read_PKCS7();
479DH *PEM_read_DHparams();
480DSA *PEM_read_DSAparams();
481int PEM_write_X509();
482int PEM_write_X509_REQ();
483int PEM_write_X509_CRL();
484int PEM_write_RSAPrivateKey();
485int PEM_write_RSAPublicKey();
486int PEM_write_DSAPrivateKey();
487int PEM_write_PrivateKey();
488int PEM_write_PKCS7();
489int PEM_write_DHparams();
490int PEM_write_DSAparams();
491#endif 563#endif
492 564
493X509 *PEM_read_bio_X509(); 565DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
494X509_REQ *PEM_read_bio_X509_REQ();
495X509_CRL *PEM_read_bio_X509_CRL();
496RSA *PEM_read_bio_RSAPrivateKey();
497RSA *PEM_read_bio_RSAPublicKey();
498DSA *PEM_read_bio_DSAPrivateKey();
499EVP_PKEY *PEM_read_bio_PrivateKey();
500PKCS7 *PEM_read_bio_PKCS7();
501DH *PEM_read_bio_DHparams();
502DSA *PEM_read_bio_DSAparams();
503int PEM_write_bio_X509();
504int PEM_write_bio_X509_REQ();
505int PEM_write_bio_X509_CRL();
506int PEM_write_bio_RSAPrivateKey();
507int PEM_write_bio_RSAPublicKey();
508int PEM_write_bio_DSAPrivateKey();
509int PEM_write_bio_PrivateKey();
510int PEM_write_bio_PKCS7();
511int PEM_write_bio_DHparams();
512int PEM_write_bio_DSAparams();
513 566
567int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
568 char *, int, pem_password_cb *, void *);
569int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
570 char *kstr,int klen, pem_password_cb *cd, void *u);
514#endif /* SSLEAY_MACROS */ 571#endif /* SSLEAY_MACROS */
515 572
516#endif
517 573
518/* BEGIN ERROR CODES */ 574/* BEGIN ERROR CODES */
575/* The following lines are auto generated by the script mkerr.pl. Any changes
576 * made after this point may be overwritten when the script is next run.
577 */
578
519/* Error codes for the PEM functions. */ 579/* Error codes for the PEM functions. */
520 580
521/* Function codes. */ 581/* Function codes. */
@@ -526,6 +586,7 @@ int PEM_write_bio_DSAparams();
526#define PEM_F_PEM_ASN1_WRITE 104 586#define PEM_F_PEM_ASN1_WRITE 104
527#define PEM_F_PEM_ASN1_WRITE_BIO 105 587#define PEM_F_PEM_ASN1_WRITE_BIO 105
528#define PEM_F_PEM_DO_HEADER 106 588#define PEM_F_PEM_DO_HEADER 106
589#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
529#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 590#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
530#define PEM_F_PEM_READ 108 591#define PEM_F_PEM_READ 108
531#define PEM_F_PEM_READ_BIO 109 592#define PEM_F_PEM_READ_BIO 109
@@ -534,6 +595,7 @@ int PEM_write_bio_DSAparams();
534#define PEM_F_PEM_SIGNFINAL 112 595#define PEM_F_PEM_SIGNFINAL 112
535#define PEM_F_PEM_WRITE 113 596#define PEM_F_PEM_WRITE 113
536#define PEM_F_PEM_WRITE_BIO 114 597#define PEM_F_PEM_WRITE_BIO 114
598#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
537#define PEM_F_PEM_X509_INFO_READ 115 599#define PEM_F_PEM_X509_INFO_READ 115
538#define PEM_F_PEM_X509_INFO_READ_BIO 116 600#define PEM_F_PEM_X509_INFO_READ_BIO 116
539#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 601#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
@@ -544,6 +606,7 @@ int PEM_write_bio_DSAparams();
544#define PEM_R_BAD_END_LINE 102 606#define PEM_R_BAD_END_LINE 102
545#define PEM_R_BAD_IV_CHARS 103 607#define PEM_R_BAD_IV_CHARS 103
546#define PEM_R_BAD_PASSWORD_READ 104 608#define PEM_R_BAD_PASSWORD_READ 104
609#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
547#define PEM_R_NOT_DEK_INFO 105 610#define PEM_R_NOT_DEK_INFO 105
548#define PEM_R_NOT_ENCRYPTED 106 611#define PEM_R_NOT_ENCRYPTED 106
549#define PEM_R_NOT_PROC_TYPE 107 612#define PEM_R_NOT_PROC_TYPE 107
@@ -554,7 +617,7 @@ int PEM_write_bio_DSAparams();
554#define PEM_R_SHORT_HEADER 112 617#define PEM_R_SHORT_HEADER 112
555#define PEM_R_UNSUPPORTED_CIPHER 113 618#define PEM_R_UNSUPPORTED_CIPHER 113
556#define PEM_R_UNSUPPORTED_ENCRYPTION 114 619#define PEM_R_UNSUPPORTED_ENCRYPTION 114
557 620
558#ifdef __cplusplus 621#ifdef __cplusplus
559} 622}
560#endif 623#endif
diff --git a/src/lib/libcrypto/pem/pem.org b/src/lib/libcrypto/pem/pem.org
deleted file mode 100644
index 38952509dd..0000000000
--- a/src/lib/libcrypto/pem/pem.org
+++ /dev/null
@@ -1,562 +0,0 @@
1/* crypto/pem/pem.org */
2/* Copyright (C) 1995-1997 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/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify pem.org since pem.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_PEM_H
68#define HEADER_PEM_H
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#include "evp.h"
75#include "x509.h"
76
77#define PEM_OBJ_UNDEF 0
78#define PEM_OBJ_X509 1
79#define PEM_OBJ_X509_REQ 2
80#define PEM_OBJ_CRL 3
81#define PEM_OBJ_SSL_SESSION 4
82#define PEM_OBJ_PRIV_KEY 10
83#define PEM_OBJ_PRIV_RSA 11
84#define PEM_OBJ_PRIV_DSA 12
85#define PEM_OBJ_PRIV_DH 13
86#define PEM_OBJ_PUB_RSA 14
87#define PEM_OBJ_PUB_DSA 15
88#define PEM_OBJ_PUB_DH 16
89#define PEM_OBJ_DHPARAMS 17
90#define PEM_OBJ_DSAPARAMS 18
91#define PEM_OBJ_PRIV_RSA_PUBLIC 19
92
93#define PEM_ERROR 30
94#define PEM_DEK_DES_CBC 40
95#define PEM_DEK_IDEA_CBC 45
96#define PEM_DEK_DES_EDE 50
97#define PEM_DEK_DES_ECB 60
98#define PEM_DEK_RSA 70
99#define PEM_DEK_RSA_MD2 80
100#define PEM_DEK_RSA_MD5 90
101
102#define PEM_MD_MD2 NID_md2
103#define PEM_MD_MD5 NID_md5
104#define PEM_MD_SHA NID_sha
105#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
106#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
107#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
108
109#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
110#define PEM_STRING_X509 "CERTIFICATE"
111#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
112#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
113#define PEM_STRING_X509_CRL "X509 CRL"
114#define PEM_STRING_EVP_PKEY "PRIVATE KEY"
115#define PEM_STRING_RSA "RSA PRIVATE KEY"
116#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
117#define PEM_STRING_DSA "DSA PRIVATE KEY"
118#define PEM_STRING_PKCS7 "PKCS7"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122
123#ifndef HEADER_ENVELOPE_H
124
125#define EVP_ENCODE_CTX_SIZE 92
126#define EVP_MD_SIZE 48
127#define EVP_MD_CTX_SIZE 152
128#define EVP_CIPHER_SIZE 28
129#define EVP_CIPHER_CTX_SIZE 4212
130#define EVP_MAX_MD_SIZE 20
131
132typedef struct evp_encode_ctx_st
133 {
134 char data[EVP_ENCODE_CTX_SIZE];
135 } EVP_ENCODE_CTX;
136
137typedef struct env_md_ctx_st
138 {
139 char data[EVP_MD_CTX_SIZE];
140 } EVP_MD_CTX;
141
142typedef struct evp_cipher_st
143 {
144 char data[EVP_CIPHER_SIZE];
145 } EVP_CIPHER;
146
147typedef struct evp_cipher_ctx_st
148 {
149 char data[EVP_CIPHER_CTX_SIZE];
150 } EVP_CIPHER_CTX;
151#endif
152
153
154typedef struct PEM_Encode_Seal_st
155 {
156 EVP_ENCODE_CTX encode;
157 EVP_MD_CTX md;
158 EVP_CIPHER_CTX cipher;
159 } PEM_ENCODE_SEAL_CTX;
160
161/* enc_type is one off */
162#define PEM_TYPE_ENCRYPTED 10
163#define PEM_TYPE_MIC_ONLY 20
164#define PEM_TYPE_MIC_CLEAR 30
165#define PEM_TYPE_CLEAR 40
166
167typedef struct pem_recip_st
168 {
169 char *name;
170 X509_NAME *dn;
171
172 int cipher;
173 int key_enc;
174 char iv[8];
175 } PEM_USER;
176
177typedef struct pem_ctx_st
178 {
179 int type; /* what type of object */
180
181 struct {
182 int version;
183 int mode;
184 } proc_type;
185
186 char *domain;
187
188 struct {
189 int cipher;
190 unsigned char iv[8];
191 } DEK_info;
192
193 PEM_USER *originator;
194
195 int num_recipient;
196 PEM_USER **recipient;
197
198#ifdef HEADER_STACK_H
199 STACK *x509_chain; /* certificate chain */
200#else
201 char *x509_chain; /* certificate chain */
202#endif
203 EVP_MD *md; /* signature type */
204
205 int md_enc; /* is the md encrypted or not? */
206 int md_len; /* length of md_data */
207 char *md_data; /* message digest, could be pkey encrypted */
208
209 EVP_CIPHER *dec; /* date encryption cipher */
210 int key_len; /* key length */
211 unsigned char *key; /* key */
212 unsigned char iv[8]; /* the iv */
213
214
215 int data_enc; /* is the data encrypted */
216 int data_len;
217 unsigned char *data;
218 } PEM_CTX;
219
220#ifdef SSLEAY_MACROS
221
222#define PEM_write_SSL_SESSION(fp,x) \
223 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
224 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL)
225#define PEM_write_X509(fp,x) \
226 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
227 (char *)x, NULL,NULL,0,NULL)
228#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
229 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
230 NULL,NULL,0,NULL)
231#define PEM_write_X509_CRL(fp,x) \
232 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
233 fp,(char *)x, NULL,NULL,0,NULL)
234#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \
235 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
236 (char *)x,enc,kstr,klen,cb)
237#define PEM_write_RSAPublicKey(fp,x) \
238 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
239 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL)
240#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \
241 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
242 (char *)x,enc,kstr,klen,cb)
243#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \
244 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
245 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
246 bp,(char *)x,enc,kstr,klen,cb)
247#define PEM_write_PKCS7(fp,x) \
248 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
249 (char *)x, NULL,NULL,0,NULL)
250#define PEM_write_DHparams(fp,x) \
251 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
252 (char *)x,NULL,NULL,0,NULL)
253
254#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \
255 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb)
256#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \
257 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb)
258#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \
259 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb)
260#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \
261 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb)
262#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
263 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb)
264#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
265 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)
266#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \
267 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb)
268#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \
269 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb)
270#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \
271 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb)
272#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \
273 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb)
274
275#define PEM_write_bio_SSL_SESSION(bp,x) \
276 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
277 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL)
278#define PEM_write_bio_X509(bp,x) \
279 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
280 (char *)x, NULL,NULL,0,NULL)
281#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
282 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
283 NULL,NULL,0,NULL)
284#define PEM_write_bio_X509_CRL(bp,x) \
285 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
286 bp,(char *)x, NULL,NULL,0,NULL)
287#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \
288 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
289 bp,(char *)x,enc,kstr,klen,cb)
290#define PEM_write_bio_RSAPublicKey(bp,x) \
291 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
292 PEM_STRING_RSA_PUBLIC,\
293 bp,(char *)x,NULL,NULL,0,NULL)
294#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \
295 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
296 bp,(char *)x,enc,kstr,klen,cb)
297#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \
298 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
299 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
300 bp,(char *)x,enc,kstr,klen,cb)
301#define PEM_write_bio_PKCS7(bp,x) \
302 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
303 (char *)x, NULL,NULL,0,NULL)
304#define PEM_write_bio_DHparams(bp,x) \
305 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
306 bp,(char *)x,NULL,NULL,0,NULL)
307#define PEM_write_bio_DSAparams(bp,x) \
308 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
309 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL)
310
311#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \
312 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb)
313#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \
314 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb)
315#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \
316 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb)
317#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \
318 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb)
319#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
320 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb)
321#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
322 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)
323#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
324 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb)
325#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \
326 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb)
327
328#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \
329 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb)
330#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \
331 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb)
332#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
333 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb)
334
335#endif
336
337#ifndef NOPROTO
338int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
339int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
340 int (*callback)());
341
342#ifdef HEADER_BIO_H
343int PEM_read_bio(BIO *bp, char **name, char **header,
344 unsigned char **data,long *len);
345int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data,
346 long len);
347char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x,
348 int (*cb)());
349int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x,
350 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
351STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)());
352int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
353 unsigned char *kstr, int klen, int (*cb)());
354#endif
355
356#ifndef WIN16
357int PEM_read(FILE *fp, char **name, char **header,
358 unsigned char **data,long *len);
359int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
360char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,
361 int (*cb)());
362int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,
363 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
364STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)());
365#endif
366
367int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
368 EVP_MD *md_type, unsigned char **ek, int *ekl,
369 unsigned char *iv, EVP_PKEY **pubk, int npubk);
370void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
371 unsigned char *in, int inl);
372int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
373 unsigned char *out, int *outl, EVP_PKEY *priv);
374
375void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
376void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
377int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
378 unsigned int *siglen, EVP_PKEY *pkey);
379
380void ERR_load_PEM_strings(void);
381
382void PEM_proc_type(char *buf, int type);
383void PEM_dek_info(char *buf, char *type, int len, char *str);
384
385#ifndef SSLEAY_MACROS
386
387#ifndef WIN16
388X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)());
389X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)());
390X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)());
391RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)());
392RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)());
393DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)());
394EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)());
395PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)());
396DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)());
397DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)());
398int PEM_write_X509(FILE *fp,X509 *x);
399int PEM_write_X509_REQ(FILE *fp,X509_REQ *x);
400int PEM_write_X509_CRL(FILE *fp,X509_CRL *x);
401int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr,
402 int klen,int (*cb)());
403int PEM_write_RSAPublicKey(FILE *fp,RSA *x);
404int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr,
405 int klen,int (*cb)());
406int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc,
407 unsigned char *kstr,int klen,int (*cb)());
408int PEM_write_PKCS7(FILE *fp,PKCS7 *x);
409int PEM_write_DHparams(FILE *fp,DH *x);
410int PEM_write_DSAparams(FILE *fp,DSA *x);
411#endif
412
413#ifdef HEADER_BIO_H
414X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)());
415X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)());
416X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)());
417RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)());
418RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)());
419DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)());
420EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)());
421PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)());
422DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)());
423DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)());
424int PEM_write_bio_X509(BIO *bp,X509 *x);
425int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x);
426int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x);
427int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc,
428 unsigned char *kstr,int klen,int (*cb)());
429int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x);
430int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc,
431 unsigned char *kstr,int klen,int (*cb)());
432int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc,
433 unsigned char *kstr,int klen,int (*cb)());
434int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x);
435int PEM_write_bio_DHparams(BIO *bp,DH *x);
436int PEM_write_bio_DSAparams(BIO *bp,DSA *x);
437#endif
438
439#endif /* SSLEAY_MACROS */
440
441
442#else
443
444int PEM_get_EVP_CIPHER_INFO();
445int PEM_do_header();
446int PEM_read_bio();
447int PEM_write_bio();
448#ifndef WIN16
449int PEM_read();
450int PEM_write();
451STACK * PEM_X509_INFO_read();
452char * PEM_ASN1_read();
453int PEM_ASN1_write();
454#endif
455STACK * PEM_X509_INFO_read_bio();
456int PEM_X509_INFO_write_bio();
457char * PEM_ASN1_read_bio();
458int PEM_ASN1_write_bio();
459int PEM_SealInit();
460void PEM_SealUpdate();
461int PEM_SealFinal();
462int PEM_SignFinal();
463
464void ERR_load_PEM_strings();
465
466void PEM_proc_type();
467void PEM_dek_info();
468
469#ifndef SSLEAY_MACROS
470#ifndef WIN16
471X509 *PEM_read_X509();
472X509_REQ *PEM_read_X509_REQ();
473X509_CRL *PEM_read_X509_CRL();
474RSA *PEM_read_RSAPrivateKey();
475RSA *PEM_read_RSAPublicKey();
476DSA *PEM_read_DSAPrivateKey();
477EVP_PKEY *PEM_read_PrivateKey();
478PKCS7 *PEM_read_PKCS7();
479DH *PEM_read_DHparams();
480DSA *PEM_read_DSAparams();
481int PEM_write_X509();
482int PEM_write_X509_REQ();
483int PEM_write_X509_CRL();
484int PEM_write_RSAPrivateKey();
485int PEM_write_RSAPublicKey();
486int PEM_write_DSAPrivateKey();
487int PEM_write_PrivateKey();
488int PEM_write_PKCS7();
489int PEM_write_DHparams();
490int PEM_write_DSAparams();
491#endif
492
493X509 *PEM_read_bio_X509();
494X509_REQ *PEM_read_bio_X509_REQ();
495X509_CRL *PEM_read_bio_X509_CRL();
496RSA *PEM_read_bio_RSAPrivateKey();
497RSA *PEM_read_bio_RSAPublicKey();
498DSA *PEM_read_bio_DSAPrivateKey();
499EVP_PKEY *PEM_read_bio_PrivateKey();
500PKCS7 *PEM_read_bio_PKCS7();
501DH *PEM_read_bio_DHparams();
502DSA *PEM_read_bio_DSAparams();
503int PEM_write_bio_X509();
504int PEM_write_bio_X509_REQ();
505int PEM_write_bio_X509_CRL();
506int PEM_write_bio_RSAPrivateKey();
507int PEM_write_bio_RSAPublicKey();
508int PEM_write_bio_DSAPrivateKey();
509int PEM_write_bio_PrivateKey();
510int PEM_write_bio_PKCS7();
511int PEM_write_bio_DHparams();
512int PEM_write_bio_DSAparams();
513
514#endif /* SSLEAY_MACROS */
515
516#endif
517
518/* BEGIN ERROR CODES */
519/* Error codes for the PEM functions. */
520
521/* Function codes. */
522#define PEM_F_DEF_CALLBACK 100
523#define PEM_F_LOAD_IV 101
524#define PEM_F_PEM_ASN1_READ 102
525#define PEM_F_PEM_ASN1_READ_BIO 103
526#define PEM_F_PEM_ASN1_WRITE 104
527#define PEM_F_PEM_ASN1_WRITE_BIO 105
528#define PEM_F_PEM_DO_HEADER 106
529#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
530#define PEM_F_PEM_READ 108
531#define PEM_F_PEM_READ_BIO 109
532#define PEM_F_PEM_SEALFINAL 110
533#define PEM_F_PEM_SEALINIT 111
534#define PEM_F_PEM_SIGNFINAL 112
535#define PEM_F_PEM_WRITE 113
536#define PEM_F_PEM_WRITE_BIO 114
537#define PEM_F_PEM_X509_INFO_READ 115
538#define PEM_F_PEM_X509_INFO_READ_BIO 116
539#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
540
541/* Reason codes. */
542#define PEM_R_BAD_BASE64_DECODE 100
543#define PEM_R_BAD_DECRYPT 101
544#define PEM_R_BAD_END_LINE 102
545#define PEM_R_BAD_IV_CHARS 103
546#define PEM_R_BAD_PASSWORD_READ 104
547#define PEM_R_NOT_DEK_INFO 105
548#define PEM_R_NOT_ENCRYPTED 106
549#define PEM_R_NOT_PROC_TYPE 107
550#define PEM_R_NO_START_LINE 108
551#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
552#define PEM_R_PUBLIC_KEY_NO_RSA 110
553#define PEM_R_READ_KEY 111
554#define PEM_R_SHORT_HEADER 112
555#define PEM_R_UNSUPPORTED_CIPHER 113
556#define PEM_R_UNSUPPORTED_ENCRYPTION 114
557
558#ifdef __cplusplus
559}
560#endif
561#endif
562
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h
new file mode 100644
index 0000000000..4a016aacd2
--- /dev/null
+++ b/src/lib/libcrypto/pem/pem2.h
@@ -0,0 +1,60 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60void ERR_load_PEM_strings(void);
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
index d1cda7aabe..bc473f3cff 100644
--- a/src/lib/libcrypto/pem/pem_all.c
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -59,430 +59,55 @@
59#include <stdio.h> 59#include <stdio.h>
60#undef SSLEAY_MACROS 60#undef SSLEAY_MACROS
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pkcs7.h" 65#include <openssl/pkcs7.h>
66#include "pem.h" 66#include <openssl/pem.h>
67 67
68#ifndef NO_FP_API 68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69/* The X509 functions */
70X509 *PEM_read_X509(fp,x,cb)
71FILE *fp;
72X509 **x;
73int (*cb)();
74 {
75 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
76 PEM_STRING_X509,fp,(char **)x,cb));
77 }
78#endif
79
80X509 *PEM_read_bio_X509(bp,x,cb)
81BIO *bp;
82X509 **x;
83int (*cb)();
84 {
85 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
86 PEM_STRING_X509,bp,(char **)x,cb));
87 }
88
89#ifndef NO_FP_API
90int PEM_write_X509(fp,x)
91FILE *fp;
92X509 *x;
93 {
94 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
95 (char *)x, NULL,NULL,0,NULL));
96 }
97#endif
98 69
99int PEM_write_bio_X509(bp,x) 70IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
100BIO *bp;
101X509 *x;
102 {
103 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
104 (char *)x, NULL,NULL,0,NULL));
105 }
106 71
107#ifndef NO_FP_API 72IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
108/* The X509_REQ functions */
109X509_REQ *PEM_read_X509_REQ(fp,x,cb)
110FILE *fp;
111X509_REQ **x;
112int (*cb)();
113 {
114 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
115 PEM_STRING_X509_REQ,fp,(char **)x,cb));
116 }
117#endif
118 73
119X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) 74IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
120BIO *bp;
121X509_REQ **x;
122int (*cb)();
123 {
124 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
125 PEM_STRING_X509_REQ,bp,(char **)x,cb));
126 }
127 75
128#ifndef NO_FP_API 76IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
129int PEM_write_X509_REQ(fp,x) 77 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
130FILE *fp;
131X509_REQ *x;
132 {
133 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
134 (char *)x, NULL,NULL,0,NULL));
135 }
136#endif
137 78
138int PEM_write_bio_X509_REQ(bp,x) 79IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
139BIO *bp; 80IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
140X509_REQ *x; 81 PKCS8_PRIV_KEY_INFO)
141 {
142 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
143 bp,(char *)x, NULL,NULL,0,NULL));
144 }
145
146#ifndef NO_FP_API
147/* The X509_CRL functions */
148X509_CRL *PEM_read_X509_CRL(fp,x,cb)
149FILE *fp;
150X509_CRL **x;
151int (*cb)();
152 {
153 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
154 PEM_STRING_X509_CRL,fp,(char **)x,cb));
155 }
156#endif
157
158X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
159BIO *bp;
160X509_CRL **x;
161int (*cb)();
162 {
163 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
164 PEM_STRING_X509_CRL,bp,(char **)x,cb));
165 }
166
167#ifndef NO_FP_API
168int PEM_write_X509_CRL(fp,x)
169FILE *fp;
170X509_CRL *x;
171 {
172 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
173 (char *)x, NULL,NULL,0,NULL));
174 }
175#endif
176
177int PEM_write_bio_X509_CRL(bp,x)
178BIO *bp;
179X509_CRL *x;
180 {
181 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
182 bp,(char *)x, NULL,NULL,0,NULL));
183 }
184 82
185#ifndef NO_RSA 83#ifndef NO_RSA
186#ifndef NO_FP_API
187/* The RSAPrivateKey functions */
188RSA *PEM_read_RSAPrivateKey(fp,x,cb)
189FILE *fp;
190RSA **x;
191int (*cb)();
192 {
193 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
194 PEM_STRING_RSA,fp,(char **)x,cb));
195 }
196
197RSA *PEM_read_RSAPublicKey(fp,x,cb)
198FILE *fp;
199RSA **x;
200int (*cb)();
201 {
202 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
203 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
204 }
205#endif
206 84
207RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) 85IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
208BIO *bp;
209RSA **x;
210int (*cb)();
211 {
212 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
213 PEM_STRING_RSA,bp,(char **)x,cb));
214 }
215 86
216RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) 87IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
217BIO *bp;
218RSA **x;
219int (*cb)();
220 {
221 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
222 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
223 }
224 88
225#ifndef NO_FP_API
226int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
227FILE *fp;
228RSA *x;
229EVP_CIPHER *enc;
230unsigned char *kstr;
231int klen;
232int (*cb)();
233 {
234 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
235 (char *)x,enc,kstr,klen,cb));
236 }
237
238int PEM_write_RSAPublicKey(fp,x)
239FILE *fp;
240RSA *x;
241 {
242 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
243 PEM_STRING_RSA_PUBLIC,fp,
244 (char *)x,NULL,NULL,0,NULL));
245 }
246#endif 89#endif
247 90
248int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
249BIO *bp;
250RSA *x;
251EVP_CIPHER *enc;
252unsigned char *kstr;
253int klen;
254int (*cb)();
255 {
256 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
257 bp,(char *)x,enc,kstr,klen,cb));
258 }
259
260int PEM_write_bio_RSAPublicKey(bp,x)
261BIO *bp;
262RSA *x;
263 {
264 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
265 PEM_STRING_RSA_PUBLIC,
266 bp,(char *)x,NULL,NULL,0,NULL));
267 }
268#endif /* !NO_RSA */
269
270#ifndef NO_DSA 91#ifndef NO_DSA
271#ifndef NO_FP_API
272/* The DSAPrivateKey functions */
273DSA *PEM_read_DSAPrivateKey(fp,x,cb)
274FILE *fp;
275DSA **x;
276int (*cb)();
277 {
278 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
279 PEM_STRING_DSA,fp,(char **)x,cb));
280 }
281#endif
282
283DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
284BIO *bp;
285DSA **x;
286int (*cb)();
287 {
288 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
289 PEM_STRING_DSA,bp,(char **)x,cb));
290 }
291
292#ifndef NO_FP_API
293int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
294FILE *fp;
295DSA *x;
296EVP_CIPHER *enc;
297unsigned char *kstr;
298int klen;
299int (*cb)();
300 {
301 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
302 (char *)x,enc,kstr,klen,cb));
303 }
304#endif
305 92
306int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) 93IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
307BIO *bp;
308DSA *x;
309EVP_CIPHER *enc;
310unsigned char *kstr;
311int klen;
312int (*cb)();
313 {
314 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
315 bp,(char *)x,enc,kstr,klen,cb));
316 }
317#endif
318
319#ifndef NO_FP_API
320/* The PrivateKey functions */
321EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
322FILE *fp;
323EVP_PKEY **x;
324int (*cb)();
325 {
326 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
327 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
328 }
329#endif
330
331EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
332BIO *bp;
333EVP_PKEY **x;
334int (*cb)();
335 {
336 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
337 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
338 }
339
340#ifndef NO_FP_API
341int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
342FILE *fp;
343EVP_PKEY *x;
344EVP_CIPHER *enc;
345unsigned char *kstr;
346int klen;
347int (*cb)();
348 {
349 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
350 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
351 fp,(char *)x,enc,kstr,klen,cb));
352 }
353#endif
354 94
355int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) 95IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
356BIO *bp;
357EVP_PKEY *x;
358EVP_CIPHER *enc;
359unsigned char *kstr;
360int klen;
361int (*cb)();
362 {
363 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
364 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
365 bp,(char *)x,enc,kstr,klen,cb));
366 }
367 96
368#ifndef NO_FP_API
369/* The PKCS7 functions */
370PKCS7 *PEM_read_PKCS7(fp,x,cb)
371FILE *fp;
372PKCS7 **x;
373int (*cb)();
374 {
375 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
376 PEM_STRING_PKCS7,fp,(char **)x,cb));
377 }
378#endif 97#endif
379 98
380PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
381BIO *bp;
382PKCS7 **x;
383int (*cb)();
384 {
385 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
386 PEM_STRING_PKCS7,bp,(char **)x,cb));
387 }
388
389#ifndef NO_FP_API
390int PEM_write_PKCS7(fp,x)
391FILE *fp;
392PKCS7 *x;
393 {
394 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
395 (char *)x, NULL,NULL,0,NULL));
396 }
397#endif
398
399int PEM_write_bio_PKCS7(bp,x)
400BIO *bp;
401PKCS7 *x;
402 {
403 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
404 (char *)x, NULL,NULL,0,NULL));
405 }
406
407#ifndef NO_DH 99#ifndef NO_DH
408#ifndef NO_FP_API
409/* The DHparams functions */
410DH *PEM_read_DHparams(fp,x,cb)
411FILE *fp;
412DH **x;
413int (*cb)();
414 {
415 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
416 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
417 }
418#endif
419 100
420DH *PEM_read_bio_DHparams(bp,x,cb) 101IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
421BIO *bp;
422DH **x;
423int (*cb)();
424 {
425 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
426 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
427 }
428 102
429#ifndef NO_FP_API
430int PEM_write_DHparams(fp,x)
431FILE *fp;
432DH *x;
433 {
434 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
435 (char *)x, NULL,NULL,0,NULL));
436 }
437#endif 103#endif
438 104
439int PEM_write_bio_DHparams(bp,x)
440BIO *bp;
441DH *x;
442 {
443 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
444 bp,(char *)x, NULL,NULL,0,NULL));
445 }
446#endif
447
448#ifndef NO_DSA
449#ifndef NO_FP_API
450/* The DSAparams functions */
451DSA *PEM_read_DSAparams(fp,x,cb)
452FILE *fp;
453DSA **x;
454int (*cb)();
455 {
456 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
457 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
458 }
459#endif
460
461DSA *PEM_read_bio_DSAparams(bp,x,cb)
462BIO *bp;
463DSA **x;
464int (*cb)();
465 {
466 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
467 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
468 }
469
470#ifndef NO_FP_API
471int PEM_write_DSAparams(fp,x)
472FILE *fp;
473DSA *x;
474 {
475 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
476 (char *)x, NULL,NULL,0,NULL));
477 }
478#endif
479
480int PEM_write_bio_DSAparams(bp,x)
481BIO *bp;
482DSA *x;
483 {
484 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
485 bp,(char *)x, NULL,NULL,0,NULL));
486 }
487#endif
488 105
106/* The PrivateKey case is not that straightforward.
107 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
108 * does not work, RSA and DSA keys have specific strings.
109 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
110 * appropriate.)
111 */
112IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
113IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index e17fcdb540..fa70f60998 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -1,63 +1,65 @@
1/* lib/pem/pem_err.c */ 1/* crypto/pem/pem_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 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 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "pem.h" 62#include <openssl/pem.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -70,6 +72,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
70{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, 72{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
71{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, 73{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
72{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, 74{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
75{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
73{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, 76{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
74{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, 77{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
75{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, 78{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
@@ -78,10 +81,11 @@ static ERR_STRING_DATA PEM_str_functs[]=
78{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, 81{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
79{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, 82{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
80{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, 83{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
84{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
81{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, 85{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
82{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, 86{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, 87{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
84{0,NULL}, 88{0,NULL}
85 }; 89 };
86 90
87static ERR_STRING_DATA PEM_str_reasons[]= 91static ERR_STRING_DATA PEM_str_reasons[]=
@@ -91,6 +95,7 @@ static ERR_STRING_DATA PEM_str_reasons[]=
91{PEM_R_BAD_END_LINE ,"bad end line"}, 95{PEM_R_BAD_END_LINE ,"bad end line"},
92{PEM_R_BAD_IV_CHARS ,"bad iv chars"}, 96{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
93{PEM_R_BAD_PASSWORD_READ ,"bad password read"}, 97{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
98{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
94{PEM_R_NOT_DEK_INFO ,"not dek info"}, 99{PEM_R_NOT_DEK_INFO ,"not dek info"},
95{PEM_R_NOT_ENCRYPTED ,"not encrypted"}, 100{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
96{PEM_R_NOT_PROC_TYPE ,"not proc type"}, 101{PEM_R_NOT_PROC_TYPE ,"not proc type"},
@@ -101,17 +106,17 @@ static ERR_STRING_DATA PEM_str_reasons[]=
101{PEM_R_SHORT_HEADER ,"short header"}, 106{PEM_R_SHORT_HEADER ,"short header"},
102{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, 107{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
103{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, 108{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
104{0,NULL}, 109{0,NULL}
105 }; 110 };
106 111
107#endif 112#endif
108 113
109void ERR_load_PEM_strings() 114void ERR_load_PEM_strings(void)
110 { 115 {
111 static int init=1; 116 static int init=1;
112 117
113 if (init); 118 if (init)
114 {; 119 {
115 init=0; 120 init=0;
116#ifndef NO_ERR 121#ifndef NO_ERR
117 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); 122 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs);
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 4b69833b62..fec18a4c2e 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -58,20 +58,17 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pem.h" 65#include <openssl/pem.h>
66 66
67#ifndef NO_FP_API 67#ifndef NO_FP_API
68STACK *PEM_X509_INFO_read(fp,sk,cb) 68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69FILE *fp;
70STACK *sk;
71int (*cb)();
72 { 69 {
73 BIO *b; 70 BIO *b;
74 STACK *ret; 71 STACK_OF(X509_INFO) *ret;
75 72
76 if ((b=BIO_new(BIO_s_file())) == NULL) 73 if ((b=BIO_new(BIO_s_file())) == NULL)
77 { 74 {
@@ -79,29 +76,26 @@ int (*cb)();
79 return(0); 76 return(0);
80 } 77 }
81 BIO_set_fp(b,fp,BIO_NOCLOSE); 78 BIO_set_fp(b,fp,BIO_NOCLOSE);
82 ret=PEM_X509_INFO_read_bio(b,sk,cb); 79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
83 BIO_free(b); 80 BIO_free(b);
84 return(ret); 81 return(ret);
85 } 82 }
86#endif 83#endif
87 84
88STACK *PEM_X509_INFO_read_bio(bp,sk,cb) 85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
89BIO *bp;
90STACK *sk;
91int (*cb)();
92 { 86 {
93 X509_INFO *xi=NULL; 87 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL,**pp; 88 char *name=NULL,*header=NULL,**pp;
95 unsigned char *data=NULL,*p; 89 unsigned char *data=NULL,*p;
96 long len,error=0; 90 long len,error=0;
97 int ok=0; 91 int ok=0;
98 STACK *ret=NULL; 92 STACK_OF(X509_INFO) *ret=NULL;
99 unsigned int i,raw; 93 unsigned int i,raw;
100 char *(*d2i)(); 94 char *(*d2i)();
101 95
102 if (sk == NULL) 96 if (sk == NULL)
103 { 97 {
104 if ((ret=sk_new_null()) == NULL) 98 if ((ret=sk_X509_INFO_new_null()) == NULL)
105 { 99 {
106 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); 100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
107 goto err; 101 goto err;
@@ -132,7 +126,7 @@ start:
132 d2i=(char *(*)())d2i_X509; 126 d2i=(char *(*)())d2i_X509;
133 if (xi->x509 != NULL) 127 if (xi->x509 != NULL)
134 { 128 {
135 if (!sk_push(ret,(char *)xi)) goto err; 129 if (!sk_X509_INFO_push(ret,xi)) goto err;
136 if ((xi=X509_INFO_new()) == NULL) goto err; 130 if ((xi=X509_INFO_new()) == NULL) goto err;
137 goto start; 131 goto start;
138 } 132 }
@@ -143,7 +137,7 @@ start:
143 d2i=(char *(*)())d2i_X509_CRL; 137 d2i=(char *(*)())d2i_X509_CRL;
144 if (xi->crl != NULL) 138 if (xi->crl != NULL)
145 { 139 {
146 if (!sk_push(ret,(char *)xi)) goto err; 140 if (!sk_X509_INFO_push(ret,xi)) goto err;
147 if ((xi=X509_INFO_new()) == NULL) goto err; 141 if ((xi=X509_INFO_new()) == NULL) goto err;
148 goto start; 142 goto start;
149 } 143 }
@@ -156,7 +150,7 @@ start:
156 d2i=(char *(*)())d2i_RSAPrivateKey; 150 d2i=(char *(*)())d2i_RSAPrivateKey;
157 if (xi->x_pkey != NULL) 151 if (xi->x_pkey != NULL)
158 { 152 {
159 if (!sk_push(ret,(char *)xi)) goto err; 153 if (!sk_X509_INFO_push(ret,xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err; 154 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start; 155 goto start;
162 } 156 }
@@ -180,7 +174,7 @@ start:
180 d2i=(char *(*)())d2i_DSAPrivateKey; 174 d2i=(char *(*)())d2i_DSAPrivateKey;
181 if (xi->x_pkey != NULL) 175 if (xi->x_pkey != NULL)
182 { 176 {
183 if (!sk_push(ret,(char *)xi)) goto err; 177 if (!sk_X509_INFO_push(ret,xi)) goto err;
184 if ((xi=X509_INFO_new()) == NULL) goto err; 178 if ((xi=X509_INFO_new()) == NULL) goto err;
185 goto start; 179 goto start;
186 } 180 }
@@ -211,7 +205,7 @@ start:
211 205
212 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) 206 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
213 goto err; 207 goto err;
214 if (!PEM_do_header(&cipher,data,&len,cb)) 208 if (!PEM_do_header(&cipher,data,&len,cb,u))
215 goto err; 209 goto err;
216 p=data; 210 p=data;
217 if (d2i(pp,&p,len) == NULL) 211 if (d2i(pp,&p,len) == NULL)
@@ -246,7 +240,7 @@ start:
246 if ((xi->x509 != NULL) || (xi->crl != NULL) || 240 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
247 (xi->x_pkey != NULL) || (xi->enc_data != NULL)) 241 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
248 { 242 {
249 if (!sk_push(ret,(char *)xi)) goto err; 243 if (!sk_X509_INFO_push(ret,xi)) goto err;
250 xi=NULL; 244 xi=NULL;
251 } 245 }
252 ok=1; 246 ok=1;
@@ -254,12 +248,12 @@ err:
254 if (xi != NULL) X509_INFO_free(xi); 248 if (xi != NULL) X509_INFO_free(xi);
255 if (!ok) 249 if (!ok)
256 { 250 {
257 for (i=0; ((int)i)<sk_num(ret); i++) 251 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
258 { 252 {
259 xi=(X509_INFO *)sk_value(ret,i); 253 xi=sk_X509_INFO_value(ret,i);
260 X509_INFO_free(xi); 254 X509_INFO_free(xi);
261 } 255 }
262 if (ret != sk) sk_free(ret); 256 if (ret != sk) sk_X509_INFO_free(ret);
263 ret=NULL; 257 ret=NULL;
264 } 258 }
265 259
@@ -271,19 +265,13 @@ err:
271 265
272 266
273/* A TJH addition */ 267/* A TJH addition */
274int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) 268int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
275BIO *bp; 269 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
276X509_INFO *xi;
277EVP_CIPHER *enc;
278unsigned char *kstr;
279int klen;
280int (*cb)();
281 { 270 {
282 EVP_CIPHER_CTX ctx; 271 EVP_CIPHER_CTX ctx;
283 int i,ret=0; 272 int i,ret=0;
284 unsigned char *data=NULL; 273 unsigned char *data=NULL;
285 char *objstr=NULL; 274 const char *objstr=NULL;
286#define PEM_BUFSIZE 1024
287 char buf[PEM_BUFSIZE]; 275 char buf[PEM_BUFSIZE];
288 unsigned char *iv=NULL; 276 unsigned char *iv=NULL;
289 277
@@ -340,7 +328,7 @@ int (*cb)();
340 /* normal optionally encrypted stuff */ 328 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp, 329 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa, 330 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb)<=0) 331 enc,kstr,klen,cb,u)<=0)
344 goto err; 332 goto err;
345#endif 333#endif
346 } 334 }
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 7a2c0ad83b..90f02011ba 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -58,36 +58,25 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "rand.h" 64#include <openssl/rand.h>
65#include "x509.h" 65#include <openssl/x509.h>
66#include "pem.h" 66#include <openssl/pem.h>
67#include <openssl/pkcs12.h>
67#ifndef NO_DES 68#ifndef NO_DES
68#include "des.h" 69#include <openssl/des.h>
69#endif 70#endif
70 71
71char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; 72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
72 73
73#define MIN_LENGTH 4 74#define MIN_LENGTH 4
74 75
75/* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); 76static int def_callback(char *buf, int num, int w, void *userdata);
76 * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
77 */
78
79#ifndef NOPROTO
80static int def_callback(char *buf, int num, int w);
81static int load_iv(unsigned char **fromp,unsigned char *to, int num); 77static int load_iv(unsigned char **fromp,unsigned char *to, int num);
82#else
83static int def_callback();
84static int load_iv();
85#endif
86 78
87static int def_callback(buf, num, w) 79static int def_callback(char *buf, int num, int w, void *userdata)
88char *buf;
89int num;
90int w;
91 { 80 {
92#ifdef NO_FP_API 81#ifdef NO_FP_API
93 /* We should not ever call the default callback routine from 82 /* We should not ever call the default callback routine from
@@ -96,7 +85,7 @@ int w;
96 return(-1); 85 return(-1);
97#else 86#else
98 int i,j; 87 int i,j;
99 char *prompt; 88 const char *prompt;
100 89
101 prompt=EVP_get_pw_prompt(); 90 prompt=EVP_get_pw_prompt();
102 if (prompt == NULL) 91 if (prompt == NULL)
@@ -123,11 +112,9 @@ int w;
123#endif 112#endif
124 } 113 }
125 114
126void PEM_proc_type(buf, type) 115void PEM_proc_type(char *buf, int type)
127char *buf;
128int type;
129 { 116 {
130 char *str; 117 const char *str;
131 118
132 if (type == PEM_TYPE_ENCRYPTED) 119 if (type == PEM_TYPE_ENCRYPTED)
133 str="ENCRYPTED"; 120 str="ENCRYPTED";
@@ -143,11 +130,7 @@ int type;
143 strcat(buf,"\n"); 130 strcat(buf,"\n");
144 } 131 }
145 132
146void PEM_dek_info(buf, type, len, str) 133void PEM_dek_info(char *buf, const char *type, int len, char *str)
147char *buf;
148char *type;
149int len;
150char *str;
151 { 134 {
152 static unsigned char map[17]="0123456789ABCDEF"; 135 static unsigned char map[17]="0123456789ABCDEF";
153 long i; 136 long i;
@@ -167,12 +150,8 @@ char *str;
167 } 150 }
168 151
169#ifndef NO_FP_API 152#ifndef NO_FP_API
170char *PEM_ASN1_read(d2i,name,fp, x, cb) 153char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
171char *(*d2i)(); 154 pem_password_cb *cb, void *u)
172char *name;
173FILE *fp;
174char **x;
175int (*cb)();
176 { 155 {
177 BIO *b; 156 BIO *b;
178 char *ret; 157 char *ret;
@@ -183,18 +162,14 @@ int (*cb)();
183 return(0); 162 return(0);
184 } 163 }
185 BIO_set_fp(b,fp,BIO_NOCLOSE); 164 BIO_set_fp(b,fp,BIO_NOCLOSE);
186 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); 165 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
187 BIO_free(b); 166 BIO_free(b);
188 return(ret); 167 return(ret);
189 } 168 }
190#endif 169#endif
191 170
192char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) 171char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
193char *(*d2i)(); 172 pem_password_cb *cb, void *u)
194char *name;
195BIO *bp;
196char **x;
197int (*cb)();
198 { 173 {
199 EVP_CIPHER_INFO cipher; 174 EVP_CIPHER_INFO cipher;
200 char *nm=NULL,*header=NULL; 175 char *nm=NULL,*header=NULL;
@@ -210,10 +185,14 @@ int (*cb)();
210 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 185 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
211 ((strcmp(nm,PEM_STRING_DSA) == 0) && 186 ((strcmp(nm,PEM_STRING_DSA) == 0) &&
212 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 187 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
188 ((strcmp(nm,PEM_STRING_PKCS8) == 0) &&
189 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
190 ((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&
191 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
213 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && 192 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&
214 (strcmp(name,PEM_STRING_X509) == 0)) || 193 (strcmp(name,PEM_STRING_X509) == 0)) ||
215 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && 194 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&
216 (strcmp(name,PEM_STRING_X509_REQ) == 0)) 195 (strcmp(name,PEM_STRING_X509_REQ) == 0))
217 ) 196 )
218 break; 197 break;
219 Free(nm); 198 Free(nm);
@@ -221,17 +200,41 @@ int (*cb)();
221 Free(data); 200 Free(data);
222 } 201 }
223 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; 202 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
224 if (!PEM_do_header(&cipher,data,&len,cb)) goto err; 203 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
225 p=data; 204 p=data;
226 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) 205 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {
227 {
228 if (strcmp(nm,PEM_STRING_RSA) == 0) 206 if (strcmp(nm,PEM_STRING_RSA) == 0)
229 ret=d2i(EVP_PKEY_RSA,x,&p,len); 207 ret=d2i(EVP_PKEY_RSA,x,&p,len);
230 else if (strcmp(nm,PEM_STRING_DSA) == 0) 208 else if (strcmp(nm,PEM_STRING_DSA) == 0)
231 ret=d2i(EVP_PKEY_DSA,x,&p,len); 209 ret=d2i(EVP_PKEY_DSA,x,&p,len);
210 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
211 PKCS8_PRIV_KEY_INFO *p8inf;
212 p8inf=d2i_PKCS8_PRIV_KEY_INFO(
213 (PKCS8_PRIV_KEY_INFO **) x, &p, len);
214 ret = (char *)EVP_PKCS82PKEY(p8inf);
215 PKCS8_PRIV_KEY_INFO_free(p8inf);
216 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
217 PKCS8_PRIV_KEY_INFO *p8inf;
218 X509_SIG *p8;
219 int klen;
220 char psbuf[PEM_BUFSIZE];
221 p8 = d2i_X509_SIG((X509_SIG **)x, &p, len);
222 if(!p8) goto p8err;
223 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
224 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
225 if (klen <= 0) {
226 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
227 PEM_R_BAD_PASSWORD_READ);
228 goto err;
229 }
230 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
231 X509_SIG_free(p8);
232 if(!p8inf) goto p8err;
233 ret = (char *)EVP_PKCS82PKEY(p8inf);
234 PKCS8_PRIV_KEY_INFO_free(p8inf);
232 } 235 }
233 else 236 } else ret=d2i(x,&p,len);
234 ret=d2i(x,&p,len); 237p8err:
235 if (ret == NULL) 238 if (ret == NULL)
236 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); 239 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
237err: 240err:
@@ -242,15 +245,9 @@ err:
242 } 245 }
243 246
244#ifndef NO_FP_API 247#ifndef NO_FP_API
245int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) 248int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
246int (*i2d)(); 249 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
247char *name; 250 pem_password_cb *callback, void *u)
248FILE *fp;
249char *x;
250EVP_CIPHER *enc;
251unsigned char *kstr;
252int klen;
253int (*callback)();
254 { 251 {
255 BIO *b; 252 BIO *b;
256 int ret; 253 int ret;
@@ -261,27 +258,20 @@ int (*callback)();
261 return(0); 258 return(0);
262 } 259 }
263 BIO_set_fp(b,fp,BIO_NOCLOSE); 260 BIO_set_fp(b,fp,BIO_NOCLOSE);
264 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); 261 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
265 BIO_free(b); 262 BIO_free(b);
266 return(ret); 263 return(ret);
267 } 264 }
268#endif 265#endif
269 266
270int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) 267int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
271int (*i2d)(); 268 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
272char *name; 269 pem_password_cb *callback, void *u)
273BIO *bp;
274char *x;
275EVP_CIPHER *enc;
276unsigned char *kstr;
277int klen;
278int (*callback)();
279 { 270 {
280 EVP_CIPHER_CTX ctx; 271 EVP_CIPHER_CTX ctx;
281 int dsize=0,i,j,ret=0; 272 int dsize=0,i,j,ret=0;
282 unsigned char *p,*data=NULL; 273 unsigned char *p,*data=NULL;
283 char *objstr=NULL; 274 const char *objstr=NULL;
284#define PEM_BUFSIZE 1024
285 char buf[PEM_BUFSIZE]; 275 char buf[PEM_BUFSIZE];
286 unsigned char key[EVP_MAX_KEY_LENGTH]; 276 unsigned char key[EVP_MAX_KEY_LENGTH];
287 unsigned char iv[EVP_MAX_IV_LENGTH]; 277 unsigned char iv[EVP_MAX_IV_LENGTH];
@@ -317,14 +307,18 @@ int (*callback)();
317 if (kstr == NULL) 307 if (kstr == NULL)
318 { 308 {
319 if (callback == NULL) 309 if (callback == NULL)
320 klen=def_callback(buf,PEM_BUFSIZE,1); 310 klen=def_callback(buf,PEM_BUFSIZE,1,u);
321 else 311 else
322 klen=(*callback)(buf,PEM_BUFSIZE,1); 312 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
323 if (klen <= 0) 313 if (klen <= 0)
324 { 314 {
325 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); 315 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
326 goto err; 316 goto err;
327 } 317 }
318#ifdef CHARSET_EBCDIC
319 /* Convert the pass phrase from EBCDIC */
320 ebcdic2ascii(buf, buf, klen);
321#endif
328 kstr=(unsigned char *)buf; 322 kstr=(unsigned char *)buf;
329 } 323 }
330 RAND_seed(data,i);/* put in the RSA key. */ 324 RAND_seed(data,i);/* put in the RSA key. */
@@ -363,11 +357,8 @@ err:
363 return(ret); 357 return(ret);
364 } 358 }
365 359
366int PEM_do_header(cipher, data, plen, callback) 360int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
367EVP_CIPHER_INFO *cipher; 361 pem_password_cb *callback,void *u)
368unsigned char *data;
369long *plen;
370int (*callback)();
371 { 362 {
372 int i,j,o,klen; 363 int i,j,o,klen;
373 long len; 364 long len;
@@ -379,14 +370,19 @@ int (*callback)();
379 370
380 if (cipher->cipher == NULL) return(1); 371 if (cipher->cipher == NULL) return(1);
381 if (callback == NULL) 372 if (callback == NULL)
382 klen=def_callback(buf,PEM_BUFSIZE,0); 373 klen=def_callback(buf,PEM_BUFSIZE,0,u);
383 else 374 else
384 klen=callback(buf,PEM_BUFSIZE,0); 375 klen=callback(buf,PEM_BUFSIZE,0,u);
385 if (klen <= 0) 376 if (klen <= 0)
386 { 377 {
387 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); 378 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
388 return(0); 379 return(0);
389 } 380 }
381#ifdef CHARSET_EBCDIC
382 /* Convert the pass phrase from EBCDIC */
383 ebcdic2ascii(buf, buf, klen);
384#endif
385
390 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), 386 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
391 (unsigned char *)buf,klen,1,key,NULL); 387 (unsigned char *)buf,klen,1,key,NULL);
392 388
@@ -407,12 +403,10 @@ int (*callback)();
407 return(1); 403 return(1);
408 } 404 }
409 405
410int PEM_get_EVP_CIPHER_INFO(header,cipher) 406int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
411char *header;
412EVP_CIPHER_INFO *cipher;
413 { 407 {
414 int o; 408 int o;
415 EVP_CIPHER *enc=NULL; 409 const EVP_CIPHER *enc=NULL;
416 char *p,c; 410 char *p,c;
417 411
418 cipher->cipher=NULL; 412 cipher->cipher=NULL;
@@ -438,9 +432,15 @@ EVP_CIPHER_INFO *cipher;
438 for (;;) 432 for (;;)
439 { 433 {
440 c= *header; 434 c= *header;
435#ifndef CHARSET_EBCDIC
441 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || 436 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
442 ((c >= '0') && (c <= '9')))) 437 ((c >= '0') && (c <= '9'))))
443 break; 438 break;
439#else
440 if (!( isupper(c) || (c == '-') ||
441 isdigit(c)))
442 break;
443#endif
444 header++; 444 header++;
445 } 445 }
446 *header='\0'; 446 *header='\0';
@@ -459,9 +459,7 @@ EVP_CIPHER_INFO *cipher;
459 return(1); 459 return(1);
460 } 460 }
461 461
462static int load_iv(fromp,to,num) 462static int load_iv(unsigned char **fromp, unsigned char *to, int num)
463unsigned char **fromp,*to;
464int num;
465 { 463 {
466 int v,i; 464 int v,i;
467 unsigned char *from; 465 unsigned char *from;
@@ -491,12 +489,8 @@ int num;
491 } 489 }
492 490
493#ifndef NO_FP_API 491#ifndef NO_FP_API
494int PEM_write(fp, name, header, data,len) 492int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
495FILE *fp; 493 long len)
496char *name;
497char *header;
498unsigned char *data;
499long len;
500 { 494 {
501 BIO *b; 495 BIO *b;
502 int ret; 496 int ret;
@@ -513,12 +507,8 @@ long len;
513 } 507 }
514#endif 508#endif
515 509
516int PEM_write_bio(bp, name, header, data,len) 510int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
517BIO *bp; 511 long len)
518char *name;
519char *header;
520unsigned char *data;
521long len;
522 { 512 {
523 int nlen,n,i,j,outl; 513 int nlen,n,i,j,outl;
524 unsigned char *buf; 514 unsigned char *buf;
@@ -573,12 +563,8 @@ err:
573 } 563 }
574 564
575#ifndef NO_FP_API 565#ifndef NO_FP_API
576int PEM_read(fp, name, header, data,len) 566int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
577FILE *fp; 567 long *len)
578char **name;
579char **header;
580unsigned char **data;
581long *len;
582 { 568 {
583 BIO *b; 569 BIO *b;
584 int ret; 570 int ret;
@@ -595,12 +581,8 @@ long *len;
595 } 581 }
596#endif 582#endif
597 583
598int PEM_read_bio(bp, name, header, data, len) 584int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
599BIO *bp; 585 long *len)
600char **name;
601char **header;
602unsigned char **data;
603long *len;
604 { 586 {
605 EVP_ENCODE_CTX ctx; 587 EVP_ENCODE_CTX ctx;
606 int end=0,i,k,bl=0,hl=0,nohead=0; 588 int end=0,i,k,bl=0,hl=0,nohead=0;
@@ -643,7 +625,7 @@ long *len;
643 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); 625 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
644 goto err; 626 goto err;
645 } 627 }
646 strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); 628 memcpy(nameB->data,&(buf[11]),i-6);
647 nameB->data[i-6]='\0'; 629 nameB->data[i-6]='\0';
648 break; 630 break;
649 } 631 }
@@ -668,7 +650,7 @@ long *len;
668 nohead=1; 650 nohead=1;
669 break; 651 break;
670 } 652 }
671 strncpy(&(headerB->data[hl]),buf,(unsigned int)i); 653 memcpy(&(headerB->data[hl]),buf,i);
672 headerB->data[hl+i]='\0'; 654 headerB->data[hl+i]='\0';
673 hl+=i; 655 hl+=i;
674 } 656 }
@@ -696,7 +678,7 @@ long *len;
696 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); 678 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
697 goto err; 679 goto err;
698 } 680 }
699 strncpy(&(dataB->data[bl]),buf,(unsigned int)i); 681 memcpy(&(dataB->data[bl]),buf,i);
700 dataB->data[bl+i]='\0'; 682 dataB->data[bl+i]='\0';
701 bl+=i; 683 bl+=i;
702 if (end) 684 if (end)
@@ -721,7 +703,7 @@ long *len;
721 } 703 }
722 i=strlen(nameB->data); 704 i=strlen(nameB->data);
723 if ( (strncmp(buf,"-----END ",9) != 0) || 705 if ( (strncmp(buf,"-----END ",9) != 0) ||
724 (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || 706 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
725 (strncmp(&(buf[9+i]),"-----\n",6) != 0)) 707 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
726 { 708 {
727 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); 709 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
@@ -760,3 +742,62 @@ err:
760 BUF_MEM_free(dataB); 742 BUF_MEM_free(dataB);
761 return(0); 743 return(0);
762 } 744 }
745
746/* This function writes a private key in PKCS#8 format: it is a "drop in"
747 * replacement for PEM_write_bio_PrivateKey(). As usual if 'enc' is NULL then
748 * it uses the unencrypted private key form. It uses PKCS#5 v2.0 password based
749 * encryption algorithms.
750 */
751
752int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
753 char *kstr, int klen,
754 pem_password_cb *cb, void *u)
755{
756 X509_SIG *p8;
757 PKCS8_PRIV_KEY_INFO *p8inf;
758 char buf[PEM_BUFSIZE];
759 int ret;
760 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
761 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
762 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
763 return 0;
764 }
765 if(enc) {
766 if(!kstr) {
767 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u);
768 else klen = cb(buf, PEM_BUFSIZE, 1, u);
769 if(klen <= 0) {
770 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
771 PEM_R_READ_KEY);
772 PKCS8_PRIV_KEY_INFO_free(p8inf);
773 return 0;
774 }
775
776 kstr = buf;
777 }
778 p8 = PKCS8_encrypt(-1, enc, kstr, klen, NULL, 0, 0, p8inf);
779 if(kstr == buf) memset(buf, 0, klen);
780 PKCS8_PRIV_KEY_INFO_free(p8inf);
781 ret = PEM_write_bio_PKCS8(bp, p8);
782 X509_SIG_free(p8);
783 return ret;
784 } else {
785 ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
786 PKCS8_PRIV_KEY_INFO_free(p8inf);
787 return ret;
788 }
789}
790
791int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
792 char *kstr, int klen, pem_password_cb *cb, void *u)
793{
794 BIO *bp;
795 int ret;
796 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
797 PEMerr(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,ERR_R_BUF_LIB);
798 return(0);
799 }
800 ret = PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u);
801 BIO_free(bp);
802 return ret;
803}
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index b4b36df453..23f95beb1e 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -56,23 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "rand.h" 63#include <openssl/rand.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "x509.h" 65#include <openssl/x509.h>
65#include "pem.h" 66#include <openssl/pem.h>
66 67
67int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) 68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
68PEM_ENCODE_SEAL_CTX *ctx; 69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
69EVP_CIPHER *type; 70 int npubk)
70EVP_MD *md_type;
71unsigned char **ek;
72int *ekl;
73unsigned char *iv;
74EVP_PKEY **pubk;
75int npubk;
76 { 71 {
77 unsigned char key[EVP_MAX_KEY_LENGTH]; 72 unsigned char key[EVP_MAX_KEY_LENGTH];
78 int ret= -1; 73 int ret= -1;
@@ -118,12 +113,8 @@ err:
118 return(ret); 113 return(ret);
119 } 114 }
120 115
121void PEM_SealUpdate(ctx,out,outl,in,inl) 116void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
122PEM_ENCODE_SEAL_CTX *ctx; 117 unsigned char *in, int inl)
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int inl;
127 { 118 {
128 unsigned char buffer[1600]; 119 unsigned char buffer[1600];
129 int i,j; 120 int i,j;
@@ -146,13 +137,8 @@ int inl;
146 } 137 }
147 } 138 }
148 139
149int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) 140int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
150PEM_ENCODE_SEAL_CTX *ctx; 141 unsigned char *out, int *outl, EVP_PKEY *priv)
151unsigned char *sig;
152int *sigl;
153unsigned char *out;
154int *outl;
155EVP_PKEY *priv;
156 { 142 {
157 unsigned char *s=NULL; 143 unsigned char *s=NULL;
158 int ret=0,j; 144 int ret=0,j;
@@ -189,3 +175,4 @@ err:
189 if (s != NULL) Free(s); 175 if (s != NULL) Free(s);
190 return(ret); 176 return(ret);
191 } 177 }
178#endif
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
index d56f9f9e14..aabafb702d 100644
--- a/src/lib/libcrypto/pem/pem_sign.c
+++ b/src/lib/libcrypto/pem/pem_sign.c
@@ -58,32 +58,25 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pem.h" 65#include <openssl/pem.h>
66 66
67void PEM_SignInit(ctx,type) 67void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
68EVP_MD_CTX *ctx;
69EVP_MD *type;
70 { 68 {
71 EVP_DigestInit(ctx,type); 69 EVP_DigestInit(ctx,type);
72 } 70 }
73 71
74void PEM_SignUpdate(ctx,data,count) 72void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
75EVP_MD_CTX *ctx; 73 unsigned int count)
76unsigned char *data;
77unsigned int count;
78 { 74 {
79 EVP_DigestUpdate(ctx,data,count); 75 EVP_DigestUpdate(ctx,data,count);
80 } 76 }
81 77
82int PEM_SignFinal(ctx,sigret,siglen,pkey) 78int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
83EVP_MD_CTX *ctx; 79 EVP_PKEY *pkey)
84unsigned char *sigret;
85unsigned int *siglen;
86EVP_PKEY *pkey;
87 { 80 {
88 unsigned char *m; 81 unsigned char *m;
89 int i,ret=0; 82 int i,ret=0;