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.ssl336
-rw-r--r--src/lib/libcrypto/pem/pem.h255
-rw-r--r--src/lib/libcrypto/pem/pem_all.c194
-rw-r--r--src/lib/libcrypto/pem/pem_err.c28
-rw-r--r--src/lib/libcrypto/pem/pem_info.c40
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c100
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c109
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c2
-rw-r--r--src/lib/libcrypto/pem/pem_x509.c1
-rw-r--r--src/lib/libcrypto/pem/pem_xaux.c1
10 files changed, 299 insertions, 767 deletions
diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl
deleted file mode 100644
index d3043eb401..0000000000
--- a/src/lib/libcrypto/pem/Makefile.ssl
+++ /dev/null
@@ -1,336 +0,0 @@
1#
2# SSLeay/crypto/pem/Makefile
3#
4
5DIR= pem
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c \
27 pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c
28
29LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o \
30 pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= pem.h pem2.h
35HEADER= $(EXHEADER)
36
37ALL= $(GENERAL) $(SRC) $(HEADER)
38
39top:
40 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
41
42all: lib
43
44lib: $(LIBOBJ)
45 $(AR) $(LIB) $(LIBOBJ)
46 $(RANLIB) $(LIB) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links: $(EXHEADER)
53 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
54 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
55 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
56 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
57
58install:
59 @for i in $(EXHEADER) ; \
60 do \
61 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
62 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
63 done;
64
65tags:
66 ctags $(SRC)
67
68tests:
69
70lint:
71 lint -DLINT $(INCLUDES) $(SRC)>fluff
72
73depend:
74 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
75
76dclean:
77 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
78 mv -f Makefile.new $(MAKEFILE)
79
80clean:
81 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
82
83# DO NOT DELETE THIS LINE -- make depend depends on it.
84
85pem_all.o: ../../e_os.h ../../include/openssl/aes.h
86pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
88pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
89pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
90pem_all.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
91pem_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
92pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93pem_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
94pem_all.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
95pem_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
96pem_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
97pem_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98pem_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
99pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
100pem_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
101pem_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
102pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
103pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
104pem_all.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
105pem_all.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
106pem_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_all.c
107pem_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
108pem_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
109pem_err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
110pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
111pem_err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
112pem_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
113pem_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
114pem_err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
115pem_err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
116pem_err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
117pem_err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
118pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
119pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
120pem_err.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
121pem_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
122pem_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
123pem_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
124pem_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
125pem_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
126pem_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
127pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
128pem_err.o: pem_err.c
129pem_info.o: ../../e_os.h ../../include/openssl/aes.h
130pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
131pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
132pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
133pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
134pem_info.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
135pem_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
136pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
137pem_info.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
138pem_info.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
139pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
140pem_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
141pem_info.o: ../../include/openssl/opensslconf.h
142pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
143pem_info.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
144pem_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
145pem_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
146pem_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
147pem_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
148pem_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
149pem_info.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
150pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
151pem_info.o: ../cryptlib.h pem_info.c
152pem_lib.o: ../../e_os.h ../../include/openssl/aes.h
153pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157pem_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
158pem_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
159pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
161pem_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
162pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
163pem_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
164pem_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
165pem_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
166pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
167pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
168pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
169pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
170pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
171pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
172pem_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
173pem_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
174pem_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_lib.c
175pem_oth.o: ../../e_os.h ../../include/openssl/aes.h
176pem_oth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
177pem_oth.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
178pem_oth.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
179pem_oth.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
180pem_oth.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
181pem_oth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
182pem_oth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
183pem_oth.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
184pem_oth.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
185pem_oth.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
186pem_oth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
187pem_oth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
188pem_oth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
189pem_oth.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
190pem_oth.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
191pem_oth.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
192pem_oth.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
193pem_oth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
194pem_oth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
195pem_oth.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
196pem_oth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
197pem_oth.o: ../cryptlib.h pem_oth.c
198pem_pk8.o: ../../e_os.h ../../include/openssl/aes.h
199pem_pk8.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
200pem_pk8.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
201pem_pk8.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
202pem_pk8.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
203pem_pk8.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
204pem_pk8.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
205pem_pk8.o: ../../include/openssl/err.h ../../include/openssl/evp.h
206pem_pk8.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
207pem_pk8.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
208pem_pk8.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
209pem_pk8.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
210pem_pk8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
211pem_pk8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
212pem_pk8.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
213pem_pk8.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
214pem_pk8.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
215pem_pk8.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
216pem_pk8.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
217pem_pk8.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
218pem_pk8.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
219pem_pk8.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
220pem_pk8.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pk8.c
221pem_pkey.o: ../../e_os.h ../../include/openssl/aes.h
222pem_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
223pem_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
224pem_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
225pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
226pem_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
227pem_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
228pem_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
229pem_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
230pem_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
231pem_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
232pem_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
233pem_pkey.o: ../../include/openssl/opensslconf.h
234pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
235pem_pkey.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
236pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
237pem_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
238pem_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
239pem_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
240pem_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
241pem_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
242pem_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
243pem_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
244pem_pkey.o: ../cryptlib.h pem_pkey.c
245pem_seal.o: ../../e_os.h ../../include/openssl/aes.h
246pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
247pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
248pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
249pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
250pem_seal.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
251pem_seal.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
252pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
253pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
254pem_seal.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
255pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
256pem_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
257pem_seal.o: ../../include/openssl/opensslconf.h
258pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
259pem_seal.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
260pem_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
261pem_seal.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
262pem_seal.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
263pem_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
264pem_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
265pem_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
266pem_seal.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
267pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_seal.c
268pem_sign.o: ../../e_os.h ../../include/openssl/aes.h
269pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
270pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
271pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
272pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
273pem_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
274pem_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
275pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
276pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
277pem_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
278pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
279pem_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
280pem_sign.o: ../../include/openssl/opensslconf.h
281pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
282pem_sign.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
283pem_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
284pem_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
285pem_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
286pem_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
287pem_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
288pem_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
289pem_sign.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
290pem_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_sign.c
291pem_x509.o: ../../e_os.h ../../include/openssl/aes.h
292pem_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
293pem_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
294pem_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
295pem_x509.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
296pem_x509.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
297pem_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
298pem_x509.o: ../../include/openssl/err.h ../../include/openssl/evp.h
299pem_x509.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
300pem_x509.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
301pem_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
302pem_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
303pem_x509.o: ../../include/openssl/opensslconf.h
304pem_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
305pem_x509.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
306pem_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
307pem_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
308pem_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
309pem_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
310pem_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
311pem_x509.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
312pem_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
313pem_x509.o: ../cryptlib.h pem_x509.c
314pem_xaux.o: ../../e_os.h ../../include/openssl/aes.h
315pem_xaux.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
316pem_xaux.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
317pem_xaux.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
318pem_xaux.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
319pem_xaux.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
320pem_xaux.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
321pem_xaux.o: ../../include/openssl/err.h ../../include/openssl/evp.h
322pem_xaux.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
323pem_xaux.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
324pem_xaux.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
325pem_xaux.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
326pem_xaux.o: ../../include/openssl/opensslconf.h
327pem_xaux.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
328pem_xaux.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
329pem_xaux.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
330pem_xaux.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
331pem_xaux.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
332pem_xaux.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
333pem_xaux.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
334pem_xaux.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
335pem_xaux.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
336pem_xaux.o: ../cryptlib.h pem_xaux.c
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index 6c193f1cbf..8a6ababe3a 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -134,6 +134,7 @@ extern "C" {
134#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" 134#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
135#define PEM_STRING_ECPARAMETERS "EC PARAMETERS" 135#define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
136#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" 136#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
137#define PEM_STRING_PARAMETERS "PARAMETERS"
137#define PEM_STRING_CMS "CMS" 138#define PEM_STRING_CMS "CMS"
138 139
139 /* Note that this structure is initialised by PEM_SealInit and cleaned up 140 /* Note that this structure is initialised by PEM_SealInit and cleaned up
@@ -183,11 +184,8 @@ typedef struct pem_ctx_st
183 int num_recipient; 184 int num_recipient;
184 PEM_USER **recipient; 185 PEM_USER **recipient;
185 186
186#ifndef OPENSSL_NO_STACK 187 /* XXX(ben): don#t think this is used!
187 STACK *x509_chain; /* certificate chain */ 188 STACK *x509_chain; / * certificate chain */
188#else
189 char *x509_chain; /* certificate chain */
190#endif
191 EVP_MD *md; /* signature type */ 189 EVP_MD *md; /* signature type */
192 190
193 int md_enc; /* is the md encrypted or not? */ 191 int md_enc; /* is the md encrypted or not? */
@@ -224,28 +222,19 @@ typedef struct pem_ctx_st
224#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 222#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
225type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ 223type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
226{ \ 224{ \
227 return (type*)PEM_ASN1_read(CHECKED_D2I_OF(type, d2i_##asn1), \ 225return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
228 str, fp, \
229 CHECKED_PPTR_OF(type, x), \
230 cb, u); \
231} 226}
232 227
233#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 228#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
234int PEM_write_##name(FILE *fp, type *x) \ 229int PEM_write_##name(FILE *fp, type *x) \
235{ \ 230{ \
236 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 231return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
237 str, fp, \
238 CHECKED_PTR_OF(type, x), \
239 NULL, NULL, 0, NULL, NULL); \
240} 232}
241 233
242#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 234#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
243int PEM_write_##name(FILE *fp, const type *x) \ 235int PEM_write_##name(FILE *fp, const type *x) \
244{ \ 236{ \
245 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ 237return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
246 str, fp, \
247 CHECKED_PTR_OF(const type, x), \
248 NULL, NULL, 0, NULL, NULL); \
249} 238}
250 239
251#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 240#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
@@ -253,10 +242,7 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
253 unsigned char *kstr, int klen, pem_password_cb *cb, \ 242 unsigned char *kstr, int klen, pem_password_cb *cb, \
254 void *u) \ 243 void *u) \
255 { \ 244 { \
256 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 245 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
257 str, fp, \
258 CHECKED_PTR_OF(type, x), \
259 enc, kstr, klen, cb, u); \
260 } 246 }
261 247
262#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 248#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
@@ -264,10 +250,7 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
264 unsigned char *kstr, int klen, pem_password_cb *cb, \ 250 unsigned char *kstr, int klen, pem_password_cb *cb, \
265 void *u) \ 251 void *u) \
266 { \ 252 { \
267 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ 253 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
268 str, fp, \
269 CHECKED_PTR_OF(const type, x), \
270 enc, kstr, klen, cb, u); \
271 } 254 }
272 255
273#endif 256#endif
@@ -275,48 +258,33 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
275#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 258#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
276type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ 259type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
277{ \ 260{ \
278 return (type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i_##asn1), \ 261return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
279 str, bp, \
280 CHECKED_PPTR_OF(type, x), \
281 cb, u); \
282} 262}
283 263
284#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 264#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
285int PEM_write_bio_##name(BIO *bp, type *x) \ 265int PEM_write_bio_##name(BIO *bp, type *x) \
286{ \ 266{ \
287 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 267return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
288 str, bp, \
289 CHECKED_PTR_OF(type, x), \
290 NULL, NULL, 0, NULL, NULL); \
291} 268}
292 269
293#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 270#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
294int PEM_write_bio_##name(BIO *bp, const type *x) \ 271int PEM_write_bio_##name(BIO *bp, const type *x) \
295{ \ 272{ \
296 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ 273return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
297 str, bp, \
298 CHECKED_PTR_OF(const type, x), \
299 NULL, NULL, 0, NULL, NULL); \
300} 274}
301 275
302#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 276#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
303int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 277int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
304 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 278 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
305 { \ 279 { \
306 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 280 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
307 str, bp, \
308 CHECKED_PTR_OF(type, x), \
309 enc, kstr, klen, cb, u); \
310 } 281 }
311 282
312#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 283#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
313int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 284int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
314 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 285 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
315 { \ 286 { \
316 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ 287 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
317 str, bp, \
318 CHECKED_PTR_OF(const type, x), \
319 enc, kstr, klen, cb, u); \
320 } 288 }
321 289
322#define IMPLEMENT_PEM_write(name, type, str, asn1) \ 290#define IMPLEMENT_PEM_write(name, type, str, asn1) \
@@ -353,11 +321,10 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
353 321
354/* These are the same except they are for the declarations */ 322/* These are the same except they are for the declarations */
355 323
356#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API) 324#if defined(OPENSSL_NO_FP_API)
357 325
358#define DECLARE_PEM_read_fp(name, type) /**/ 326#define DECLARE_PEM_read_fp(name, type) /**/
359#define DECLARE_PEM_write_fp(name, type) /**/ 327#define DECLARE_PEM_write_fp(name, type) /**/
360#define DECLARE_PEM_write_fp_const(name, type) /**/
361#define DECLARE_PEM_write_cb_fp(name, type) /**/ 328#define DECLARE_PEM_write_cb_fp(name, type) /**/
362 329
363#else 330#else
@@ -428,138 +395,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
428 DECLARE_PEM_read(name, type) \ 395 DECLARE_PEM_read(name, type) \
429 DECLARE_PEM_write_cb(name, type) 396 DECLARE_PEM_write_cb(name, type)
430 397
431#ifdef SSLEAY_MACROS
432
433#define PEM_write_SSL_SESSION(fp,x) \
434 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
435 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
436#define PEM_write_X509(fp,x) \
437 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
438 (char *)x, NULL,NULL,0,NULL,NULL)
439#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
440 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
441 NULL,NULL,0,NULL,NULL)
442#define PEM_write_X509_CRL(fp,x) \
443 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
444 fp,(char *)x, NULL,NULL,0,NULL,NULL)
445#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
446 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
447 (char *)x,enc,kstr,klen,cb,u)
448#define PEM_write_RSAPublicKey(fp,x) \
449 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
450 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
451#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
452 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
453 (char *)x,enc,kstr,klen,cb,u)
454#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
455 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
456 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
457 bp,(char *)x,enc,kstr,klen,cb,u)
458#define PEM_write_PKCS7(fp,x) \
459 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
460 (char *)x, NULL,NULL,0,NULL,NULL)
461#define PEM_write_DHparams(fp,x) \
462 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
463 (char *)x,NULL,NULL,0,NULL,NULL)
464
465#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
466 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
467 PEM_STRING_X509,fp, \
468 (char *)x, NULL,NULL,0,NULL,NULL)
469
470#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
471 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
472#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
473 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
474#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
475 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
476#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
477 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
478#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
479 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
480#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
481 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
482#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
483 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
484#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
485 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
486#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
487 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
488#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
489 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
490
491#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
492 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
493 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
494 (char **)x,cb,u)
495
496#define PEM_write_bio_X509(bp,x) \
497 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
498 (char *)x, NULL,NULL,0,NULL,NULL)
499#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
500 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
501 NULL,NULL,0,NULL,NULL)
502#define PEM_write_bio_X509_CRL(bp,x) \
503 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
504 bp,(char *)x, NULL,NULL,0,NULL,NULL)
505#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
506 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
507 bp,(char *)x,enc,kstr,klen,cb,u)
508#define PEM_write_bio_RSAPublicKey(bp,x) \
509 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
510 PEM_STRING_RSA_PUBLIC,\
511 bp,(char *)x,NULL,NULL,0,NULL,NULL)
512#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
513 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
514 bp,(char *)x,enc,kstr,klen,cb,u)
515#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
516 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
517 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
518 bp,(char *)x,enc,kstr,klen,cb,u)
519#define PEM_write_bio_PKCS7(bp,x) \
520 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
521 (char *)x, NULL,NULL,0,NULL,NULL)
522#define PEM_write_bio_DHparams(bp,x) \
523 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
524 bp,(char *)x,NULL,NULL,0,NULL,NULL)
525#define PEM_write_bio_DSAparams(bp,x) \
526 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
527 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
528
529#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
530 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
531 PEM_STRING_X509,bp, \
532 (char *)x, NULL,NULL,0,NULL,NULL)
533
534#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
535 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
536#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
537 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
538#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
539 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
540#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
541 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
542#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
543 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
544#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
545 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
546#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
547 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
548
549#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
550 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
551#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
552 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
553#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
554 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
555
556#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
557 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
558 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
559 (char **)x,cb,u)
560
561#endif
562
563#if 1 398#if 1
564/* "userdata": new with OpenSSL 0.9.4 */ 399/* "userdata": new with OpenSSL 0.9.4 */
565typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); 400typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
@@ -581,40 +416,25 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char
581 pem_password_cb *cb, void *u); 416 pem_password_cb *cb, void *u);
582void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, 417void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp,
583 void **x, pem_password_cb *cb, void *u); 418 void **x, pem_password_cb *cb, void *u);
584 419int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x,
585#define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \
586 ((type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i), \
587 name, bp, \
588 CHECKED_PPTR_OF(type, x), \
589 cb, u))
590
591int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,
592 const EVP_CIPHER *enc,unsigned char *kstr,int klen, 420 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
593 pem_password_cb *cb, void *u); 421 pem_password_cb *cb, void *u);
594 422
595#define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \
596 (PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d), \
597 name, bp, \
598 CHECKED_PTR_OF(type, x), \
599 enc, kstr, klen, cb, u))
600
601STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 423STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
602int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, 424int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
603 unsigned char *kstr, int klen, pem_password_cb *cd, void *u); 425 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
604#endif 426#endif
605 427
606#ifndef OPENSSL_SYS_WIN16
607int PEM_read(FILE *fp, char **name, char **header, 428int PEM_read(FILE *fp, char **name, char **header,
608 unsigned char **data,long *len); 429 unsigned char **data,long *len);
609int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); 430int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
610void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 431void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
611 pem_password_cb *cb, void *u); 432 pem_password_cb *cb, void *u);
612int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, 433int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp,
613 char *x,const EVP_CIPHER *enc,unsigned char *kstr, 434 void *x,const EVP_CIPHER *enc,unsigned char *kstr,
614 int klen,pem_password_cb *callback, void *u); 435 int klen,pem_password_cb *callback, void *u);
615STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, 436STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
616 pem_password_cb *cb, void *u); 437 pem_password_cb *cb, void *u);
617#endif
618 438
619int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, 439int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
620 EVP_MD *md_type, unsigned char **ek, int *ekl, 440 EVP_MD *md_type, unsigned char **ek, int *ekl,
@@ -633,7 +453,6 @@ int PEM_def_callback(char *buf, int num, int w, void *key);
633void PEM_proc_type(char *buf, int type); 453void PEM_proc_type(char *buf, int type);
634void PEM_dek_info(char *buf, const char *type, int len, char *str); 454void PEM_dek_info(char *buf, const char *type, int len, char *str);
635 455
636#ifndef SSLEAY_MACROS
637 456
638#include <openssl/symhacks.h> 457#include <openssl/symhacks.h>
639 458
@@ -719,7 +538,21 @@ EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, vo
719int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, 538int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
720 char *kstr,int klen, pem_password_cb *cd, void *u); 539 char *kstr,int klen, pem_password_cb *cd, void *u);
721 540
722#endif /* SSLEAY_MACROS */ 541EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
542int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x);
543
544
545EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
546EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
547EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
548EVP_PKEY *b2i_PublicKey_bio(BIO *in);
549int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
550int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
551#ifndef OPENSSL_NO_RC4
552EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
553int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
554 pem_password_cb *cb, void *u);
555#endif
723 556
724 557
725/* BEGIN ERROR CODES */ 558/* BEGIN ERROR CODES */
@@ -731,10 +564,22 @@ void ERR_load_PEM_strings(void);
731/* Error codes for the PEM functions. */ 564/* Error codes for the PEM functions. */
732 565
733/* Function codes. */ 566/* Function codes. */
567#define PEM_F_B2I_DSS 127
568#define PEM_F_B2I_PVK_BIO 128
569#define PEM_F_B2I_RSA 129
570#define PEM_F_CHECK_BITLEN_DSA 130
571#define PEM_F_CHECK_BITLEN_RSA 131
734#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 572#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
735#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 573#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
574#define PEM_F_DO_B2I 132
575#define PEM_F_DO_B2I_BIO 133
576#define PEM_F_DO_BLOB_HEADER 134
736#define PEM_F_DO_PK8PKEY 126 577#define PEM_F_DO_PK8PKEY 126
737#define PEM_F_DO_PK8PKEY_FP 125 578#define PEM_F_DO_PK8PKEY_FP 125
579#define PEM_F_DO_PVK_BODY 135
580#define PEM_F_DO_PVK_HEADER 136
581#define PEM_F_I2B_PVK 137
582#define PEM_F_I2B_PVK_BIO 138
738#define PEM_F_LOAD_IV 101 583#define PEM_F_LOAD_IV 101
739#define PEM_F_PEM_ASN1_READ 102 584#define PEM_F_PEM_ASN1_READ 102
740#define PEM_F_PEM_ASN1_READ_BIO 103 585#define PEM_F_PEM_ASN1_READ_BIO 103
@@ -747,6 +592,7 @@ void ERR_load_PEM_strings(void);
747#define PEM_F_PEM_PK8PKEY 119 592#define PEM_F_PEM_PK8PKEY 119
748#define PEM_F_PEM_READ 108 593#define PEM_F_PEM_READ 108
749#define PEM_F_PEM_READ_BIO 109 594#define PEM_F_PEM_READ_BIO 109
595#define PEM_F_PEM_READ_BIO_PARAMETERS 140
750#define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 596#define PEM_F_PEM_READ_BIO_PRIVATEKEY 123
751#define PEM_F_PEM_READ_PRIVATEKEY 124 597#define PEM_F_PEM_READ_PRIVATEKEY 124
752#define PEM_F_PEM_SEALFINAL 110 598#define PEM_F_PEM_SEALFINAL 110
@@ -754,6 +600,7 @@ void ERR_load_PEM_strings(void);
754#define PEM_F_PEM_SIGNFINAL 112 600#define PEM_F_PEM_SIGNFINAL 112
755#define PEM_F_PEM_WRITE 113 601#define PEM_F_PEM_WRITE 113
756#define PEM_F_PEM_WRITE_BIO 114 602#define PEM_F_PEM_WRITE_BIO 114
603#define PEM_F_PEM_WRITE_PRIVATEKEY 139
757#define PEM_F_PEM_X509_INFO_READ 115 604#define PEM_F_PEM_X509_INFO_READ 115
758#define PEM_F_PEM_X509_INFO_READ_BIO 116 605#define PEM_F_PEM_X509_INFO_READ_BIO 116
759#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 606#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
@@ -763,18 +610,30 @@ void ERR_load_PEM_strings(void);
763#define PEM_R_BAD_DECRYPT 101 610#define PEM_R_BAD_DECRYPT 101
764#define PEM_R_BAD_END_LINE 102 611#define PEM_R_BAD_END_LINE 102
765#define PEM_R_BAD_IV_CHARS 103 612#define PEM_R_BAD_IV_CHARS 103
613#define PEM_R_BAD_MAGIC_NUMBER 116
766#define PEM_R_BAD_PASSWORD_READ 104 614#define PEM_R_BAD_PASSWORD_READ 104
615#define PEM_R_BAD_VERSION_NUMBER 117
616#define PEM_R_BIO_WRITE_FAILURE 118
617#define PEM_R_CIPHER_IS_NULL 127
767#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 618#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
619#define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119
620#define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120
621#define PEM_R_INCONSISTENT_HEADER 121
622#define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122
623#define PEM_R_KEYBLOB_TOO_SHORT 123
768#define PEM_R_NOT_DEK_INFO 105 624#define PEM_R_NOT_DEK_INFO 105
769#define PEM_R_NOT_ENCRYPTED 106 625#define PEM_R_NOT_ENCRYPTED 106
770#define PEM_R_NOT_PROC_TYPE 107 626#define PEM_R_NOT_PROC_TYPE 107
771#define PEM_R_NO_START_LINE 108 627#define PEM_R_NO_START_LINE 108
772#define PEM_R_PROBLEMS_GETTING_PASSWORD 109 628#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
773#define PEM_R_PUBLIC_KEY_NO_RSA 110 629#define PEM_R_PUBLIC_KEY_NO_RSA 110
630#define PEM_R_PVK_DATA_TOO_SHORT 124
631#define PEM_R_PVK_TOO_SHORT 125
774#define PEM_R_READ_KEY 111 632#define PEM_R_READ_KEY 111
775#define PEM_R_SHORT_HEADER 112 633#define PEM_R_SHORT_HEADER 112
776#define PEM_R_UNSUPPORTED_CIPHER 113 634#define PEM_R_UNSUPPORTED_CIPHER 113
777#define PEM_R_UNSUPPORTED_ENCRYPTION 114 635#define PEM_R_UNSUPPORTED_ENCRYPTION 114
636#define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126
778 637
779#ifdef __cplusplus 638#ifdef __cplusplus
780} 639}
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
index 69dd19bf2e..3e7a6093ad 100644
--- a/src/lib/libcrypto/pem/pem_all.c
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -110,7 +110,6 @@
110 */ 110 */
111 111
112#include <stdio.h> 112#include <stdio.h>
113#undef SSLEAY_MACROS
114#include "cryptlib.h" 113#include "cryptlib.h"
115#include <openssl/bio.h> 114#include <openssl/bio.h>
116#include <openssl/evp.h> 115#include <openssl/evp.h>
@@ -194,49 +193,7 @@ RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
194 193
195#endif 194#endif
196 195
197#ifdef OPENSSL_FIPS
198
199int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
200 unsigned char *kstr, int klen,
201 pem_password_cb *cb, void *u)
202{
203 EVP_PKEY *k;
204 int ret;
205 k = EVP_PKEY_new();
206 if (!k)
207 return 0;
208 EVP_PKEY_set1_RSA(k, x);
209
210 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
211 EVP_PKEY_free(k);
212 return ret;
213}
214
215#ifndef OPENSSL_NO_FP_API
216int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
217 unsigned char *kstr, int klen,
218 pem_password_cb *cb, void *u)
219{
220 EVP_PKEY *k;
221 int ret;
222 k = EVP_PKEY_new();
223 if (!k)
224 return 0;
225
226 EVP_PKEY_set1_RSA(k, x);
227
228 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
229 EVP_PKEY_free(k);
230 return ret;
231}
232#endif
233
234#else
235
236IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) 196IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
237
238#endif
239
240IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) 197IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
241IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) 198IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
242 199
@@ -263,50 +220,10 @@ DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
263{ 220{
264 EVP_PKEY *pktmp; 221 EVP_PKEY *pktmp;
265 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 222 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
266 return pkey_get_dsa(pktmp, dsa); 223 return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
267} 224}
268 225
269#ifdef OPENSSL_FIPS
270
271int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
272 unsigned char *kstr, int klen,
273 pem_password_cb *cb, void *u)
274{
275 EVP_PKEY *k;
276 int ret;
277 k = EVP_PKEY_new();
278 if (!k)
279 return 0;
280 EVP_PKEY_set1_DSA(k, x);
281
282 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
283 EVP_PKEY_free(k);
284 return ret;
285}
286
287#ifndef OPENSSL_NO_FP_API
288int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
289 unsigned char *kstr, int klen,
290 pem_password_cb *cb, void *u)
291{
292 EVP_PKEY *k;
293 int ret;
294 k = EVP_PKEY_new();
295 if (!k)
296 return 0;
297 EVP_PKEY_set1_DSA(k, x);
298 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
299 EVP_PKEY_free(k);
300 return ret;
301}
302#endif
303
304#else
305
306IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) 226IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
307
308#endif
309
310IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY) 227IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
311 228
312#ifndef OPENSSL_NO_FP_API 229#ifndef OPENSSL_NO_FP_API
@@ -316,7 +233,7 @@ DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
316{ 233{
317 EVP_PKEY *pktmp; 234 EVP_PKEY *pktmp;
318 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 235 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
319 return pkey_get_dsa(pktmp, dsa); 236 return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
320} 237}
321 238
322#endif 239#endif
@@ -347,54 +264,13 @@ EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,
347{ 264{
348 EVP_PKEY *pktmp; 265 EVP_PKEY *pktmp;
349 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); 266 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
350 return pkey_get_eckey(pktmp, key); 267 return pkey_get_eckey(pktmp, key); /* will free pktmp */
351} 268}
352 269
353IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters) 270IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters)
354 271
355
356
357#ifdef OPENSSL_FIPS
358
359int PEM_write_bio_ECPrivateKey(BIO *bp, EC_KEY *x, const EVP_CIPHER *enc,
360 unsigned char *kstr, int klen,
361 pem_password_cb *cb, void *u)
362{
363 EVP_PKEY *k;
364 int ret;
365 k = EVP_PKEY_new();
366 if (!k)
367 return 0;
368 EVP_PKEY_set1_EC_KEY(k, x);
369
370 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
371 EVP_PKEY_free(k);
372 return ret;
373}
374
375#ifndef OPENSSL_NO_FP_API
376int PEM_write_ECPrivateKey(FILE *fp, EC_KEY *x, const EVP_CIPHER *enc,
377 unsigned char *kstr, int klen,
378 pem_password_cb *cb, void *u)
379{
380 EVP_PKEY *k;
381 int ret;
382 k = EVP_PKEY_new();
383 if (!k)
384 return 0;
385 EVP_PKEY_set1_EC_KEY(k, x);
386 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
387 EVP_PKEY_free(k);
388 return ret;
389}
390#endif
391
392#else
393
394IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey) 272IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey)
395 273
396#endif
397
398IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY) 274IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
399 275
400#ifndef OPENSSL_NO_FP_API 276#ifndef OPENSSL_NO_FP_API
@@ -404,7 +280,7 @@ EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
404{ 280{
405 EVP_PKEY *pktmp; 281 EVP_PKEY *pktmp;
406 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 282 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
407 return pkey_get_eckey(pktmp, eckey); 283 return pkey_get_eckey(pktmp, eckey); /* will free pktmp */
408} 284}
409 285
410#endif 286#endif
@@ -417,66 +293,4 @@ IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
417 293
418#endif 294#endif
419 295
420
421/* The PrivateKey case is not that straightforward.
422 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
423 * does not work, RSA and DSA keys have specific strings.
424 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
425 * appropriate.)
426 */
427
428#ifdef OPENSSL_FIPS
429
430static const char *pkey_str(EVP_PKEY *x)
431 {
432 switch (x->type)
433 {
434 case EVP_PKEY_RSA:
435 return PEM_STRING_RSA;
436
437 case EVP_PKEY_DSA:
438 return PEM_STRING_DSA;
439
440 case EVP_PKEY_EC:
441 return PEM_STRING_ECPRIVATEKEY;
442
443 default:
444 return NULL;
445 }
446 }
447
448
449int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
450 unsigned char *kstr, int klen,
451 pem_password_cb *cb, void *u)
452 {
453 if (FIPS_mode())
454 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
455 (char *)kstr, klen, cb, u);
456 else
457 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
458 pkey_str(x), bp,(char *)x,enc,kstr,klen,cb,u);
459 }
460
461#ifndef OPENSSL_NO_FP_API
462int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
463 unsigned char *kstr, int klen,
464 pem_password_cb *cb, void *u)
465 {
466 if (FIPS_mode())
467 return PEM_write_PKCS8PrivateKey(fp, x, enc,
468 (char *)kstr, klen, cb, u);
469 else
470 return PEM_ASN1_write((i2d_of_void *)i2d_PrivateKey,
471 pkey_str(x), fp,(char *)x,enc,kstr,klen,cb,u);
472 }
473#endif
474
475#else
476IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:\
477 (x->type == EVP_PKEY_RSA)?PEM_STRING_RSA:PEM_STRING_ECPRIVATEKEY), PrivateKey)
478
479#endif
480
481IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) 296IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
482
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index 3133563d77..d644aeedd4 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -1,6 +1,6 @@
1/* crypto/pem/pem_err.c */ 1/* crypto/pem/pem_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -70,10 +70,22 @@
70 70
71static ERR_STRING_DATA PEM_str_functs[]= 71static ERR_STRING_DATA PEM_str_functs[]=
72 { 72 {
73{ERR_FUNC(PEM_F_B2I_DSS), "B2I_DSS"},
74{ERR_FUNC(PEM_F_B2I_PVK_BIO), "b2i_PVK_bio"},
75{ERR_FUNC(PEM_F_B2I_RSA), "B2I_RSA"},
76{ERR_FUNC(PEM_F_CHECK_BITLEN_DSA), "CHECK_BITLEN_DSA"},
77{ERR_FUNC(PEM_F_CHECK_BITLEN_RSA), "CHECK_BITLEN_RSA"},
73{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"}, 78{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
74{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"}, 79{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
80{ERR_FUNC(PEM_F_DO_B2I), "DO_B2I"},
81{ERR_FUNC(PEM_F_DO_B2I_BIO), "DO_B2I_BIO"},
82{ERR_FUNC(PEM_F_DO_BLOB_HEADER), "DO_BLOB_HEADER"},
75{ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"}, 83{ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"},
76{ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"}, 84{ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"},
85{ERR_FUNC(PEM_F_DO_PVK_BODY), "DO_PVK_BODY"},
86{ERR_FUNC(PEM_F_DO_PVK_HEADER), "DO_PVK_HEADER"},
87{ERR_FUNC(PEM_F_I2B_PVK), "I2B_PVK"},
88{ERR_FUNC(PEM_F_I2B_PVK_BIO), "i2b_PVK_bio"},
77{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"}, 89{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
78{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"}, 90{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
79{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"}, 91{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
@@ -86,6 +98,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
86{ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"}, 98{ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"},
87{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"}, 99{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
88{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"}, 100{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
101{ERR_FUNC(PEM_F_PEM_READ_BIO_PARAMETERS), "PEM_read_bio_Parameters"},
89{ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"}, 102{ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"},
90{ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"}, 103{ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"},
91{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"}, 104{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
@@ -93,6 +106,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
93{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"}, 106{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
94{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"}, 107{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
95{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"}, 108{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
109{ERR_FUNC(PEM_F_PEM_WRITE_PRIVATEKEY), "PEM_WRITE_PRIVATEKEY"},
96{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"}, 110{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
97{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"}, 111{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
98{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"}, 112{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
@@ -105,18 +119,30 @@ static ERR_STRING_DATA PEM_str_reasons[]=
105{ERR_REASON(PEM_R_BAD_DECRYPT) ,"bad decrypt"}, 119{ERR_REASON(PEM_R_BAD_DECRYPT) ,"bad decrypt"},
106{ERR_REASON(PEM_R_BAD_END_LINE) ,"bad end line"}, 120{ERR_REASON(PEM_R_BAD_END_LINE) ,"bad end line"},
107{ERR_REASON(PEM_R_BAD_IV_CHARS) ,"bad iv chars"}, 121{ERR_REASON(PEM_R_BAD_IV_CHARS) ,"bad iv chars"},
122{ERR_REASON(PEM_R_BAD_MAGIC_NUMBER) ,"bad magic number"},
108{ERR_REASON(PEM_R_BAD_PASSWORD_READ) ,"bad password read"}, 123{ERR_REASON(PEM_R_BAD_PASSWORD_READ) ,"bad password read"},
124{ERR_REASON(PEM_R_BAD_VERSION_NUMBER) ,"bad version number"},
125{ERR_REASON(PEM_R_BIO_WRITE_FAILURE) ,"bio write failure"},
126{ERR_REASON(PEM_R_CIPHER_IS_NULL) ,"cipher is null"},
109{ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"}, 127{ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"},
128{ERR_REASON(PEM_R_EXPECTING_PRIVATE_KEY_BLOB),"expecting private key blob"},
129{ERR_REASON(PEM_R_EXPECTING_PUBLIC_KEY_BLOB),"expecting public key blob"},
130{ERR_REASON(PEM_R_INCONSISTENT_HEADER) ,"inconsistent header"},
131{ERR_REASON(PEM_R_KEYBLOB_HEADER_PARSE_ERROR),"keyblob header parse error"},
132{ERR_REASON(PEM_R_KEYBLOB_TOO_SHORT) ,"keyblob too short"},
110{ERR_REASON(PEM_R_NOT_DEK_INFO) ,"not dek info"}, 133{ERR_REASON(PEM_R_NOT_DEK_INFO) ,"not dek info"},
111{ERR_REASON(PEM_R_NOT_ENCRYPTED) ,"not encrypted"}, 134{ERR_REASON(PEM_R_NOT_ENCRYPTED) ,"not encrypted"},
112{ERR_REASON(PEM_R_NOT_PROC_TYPE) ,"not proc type"}, 135{ERR_REASON(PEM_R_NOT_PROC_TYPE) ,"not proc type"},
113{ERR_REASON(PEM_R_NO_START_LINE) ,"no start line"}, 136{ERR_REASON(PEM_R_NO_START_LINE) ,"no start line"},
114{ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"}, 137{ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"},
115{ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA) ,"public key no rsa"}, 138{ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA) ,"public key no rsa"},
139{ERR_REASON(PEM_R_PVK_DATA_TOO_SHORT) ,"pvk data too short"},
140{ERR_REASON(PEM_R_PVK_TOO_SHORT) ,"pvk too short"},
116{ERR_REASON(PEM_R_READ_KEY) ,"read key"}, 141{ERR_REASON(PEM_R_READ_KEY) ,"read key"},
117{ERR_REASON(PEM_R_SHORT_HEADER) ,"short header"}, 142{ERR_REASON(PEM_R_SHORT_HEADER) ,"short header"},
118{ERR_REASON(PEM_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, 143{ERR_REASON(PEM_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
119{ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"}, 144{ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"},
145{ERR_REASON(PEM_R_UNSUPPORTED_KEY_COMPONENTS),"unsupported key components"},
120{0,NULL} 146{0,NULL}
121 }; 147 };
122 148
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 3a273f6f70..1b2be527ed 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -98,8 +98,8 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
98 long len,error=0; 98 long len,error=0;
99 int ok=0; 99 int ok=0;
100 STACK_OF(X509_INFO) *ret=NULL; 100 STACK_OF(X509_INFO) *ret=NULL;
101 unsigned int i,raw; 101 unsigned int i,raw,ptype;
102 d2i_of_void *d2i; 102 d2i_of_void *d2i = 0;
103 103
104 if (sk == NULL) 104 if (sk == NULL)
105 { 105 {
@@ -116,6 +116,7 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pe
116 for (;;) 116 for (;;)
117 { 117 {
118 raw=0; 118 raw=0;
119 ptype = 0;
119 i=PEM_read_bio(bp,&name,&header,&data,&len); 120 i=PEM_read_bio(bp,&name,&header,&data,&len);
120 if (i == 0) 121 if (i == 0)
121 { 122 {
@@ -166,7 +167,6 @@ start:
166#ifndef OPENSSL_NO_RSA 167#ifndef OPENSSL_NO_RSA
167 if (strcmp(name,PEM_STRING_RSA) == 0) 168 if (strcmp(name,PEM_STRING_RSA) == 0)
168 { 169 {
169 d2i=(D2I_OF(void))d2i_RSAPrivateKey;
170 if (xi->x_pkey != NULL) 170 if (xi->x_pkey != NULL)
171 { 171 {
172 if (!sk_X509_INFO_push(ret,xi)) goto err; 172 if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -178,10 +178,8 @@ start:
178 xi->enc_len=0; 178 xi->enc_len=0;
179 179
180 xi->x_pkey=X509_PKEY_new(); 180 xi->x_pkey=X509_PKEY_new();
181 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 181 ptype=EVP_PKEY_RSA;
182 goto err; 182 pp=&xi->x_pkey->dec_pkey;
183 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
184 pp=&(xi->x_pkey->dec_pkey->pkey.rsa);
185 if ((int)strlen(header) > 10) /* assume encrypted */ 183 if ((int)strlen(header) > 10) /* assume encrypted */
186 raw=1; 184 raw=1;
187 } 185 }
@@ -202,10 +200,8 @@ start:
202 xi->enc_len=0; 200 xi->enc_len=0;
203 201
204 xi->x_pkey=X509_PKEY_new(); 202 xi->x_pkey=X509_PKEY_new();
205 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 203 ptype = EVP_PKEY_DSA;
206 goto err; 204 pp=&xi->x_pkey->dec_pkey;
207 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
208 pp=&xi->x_pkey->dec_pkey->pkey.dsa;
209 if ((int)strlen(header) > 10) /* assume encrypted */ 205 if ((int)strlen(header) > 10) /* assume encrypted */
210 raw=1; 206 raw=1;
211 } 207 }
@@ -226,10 +222,8 @@ start:
226 xi->enc_len=0; 222 xi->enc_len=0;
227 223
228 xi->x_pkey=X509_PKEY_new(); 224 xi->x_pkey=X509_PKEY_new();
229 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 225 ptype = EVP_PKEY_EC;
230 goto err; 226 pp=&xi->x_pkey->dec_pkey;
231 xi->x_pkey->dec_pkey->type=EVP_PKEY_EC;
232 pp=&(xi->x_pkey->dec_pkey->pkey.ec);
233 if ((int)strlen(header) > 10) /* assume encrypted */ 227 if ((int)strlen(header) > 10) /* assume encrypted */
234 raw=1; 228 raw=1;
235 } 229 }
@@ -251,7 +245,15 @@ start:
251 if (!PEM_do_header(&cipher,data,&len,cb,u)) 245 if (!PEM_do_header(&cipher,data,&len,cb,u))
252 goto err; 246 goto err;
253 p=data; 247 p=data;
254 if (d2i(pp,&p,len) == NULL) 248 if (ptype)
249 {
250 if (!d2i_PrivateKey(ptype, pp, &p, len))
251 {
252 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
253 goto err;
254 }
255 }
256 else if (d2i(pp,&p,len) == NULL)
255 { 257 {
256 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); 258 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
257 goto err; 259 goto err;
@@ -337,6 +339,12 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
337 { 339 {
338 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) 340 if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
339 { 341 {
342 if (enc == NULL)
343 {
344 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_CIPHER_IS_NULL);
345 goto err;
346 }
347
340 /* copy from weirdo names into more normal things */ 348 /* copy from weirdo names into more normal things */
341 iv=xi->enc_cipher.iv; 349 iv=xi->enc_cipher.iv;
342 data=(unsigned char *)xi->enc_data; 350 data=(unsigned char *)xi->enc_data;
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index cbafefe416..42e4861bc1 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include <openssl/buffer.h> 62#include <openssl/buffer.h>
62#include <openssl/objects.h> 63#include <openssl/objects.h>
@@ -65,9 +66,13 @@
65#include <openssl/x509.h> 66#include <openssl/x509.h>
66#include <openssl/pem.h> 67#include <openssl/pem.h>
67#include <openssl/pkcs12.h> 68#include <openssl/pkcs12.h>
69#include "asn1_locl.h"
68#ifndef OPENSSL_NO_DES 70#ifndef OPENSSL_NO_DES
69#include <openssl/des.h> 71#include <openssl/des.h>
70#endif 72#endif
73#ifndef OPENSSL_NO_ENGINE
74#include <openssl/engine.h>
75#endif
71 76
72const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT; 77const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT;
73 78
@@ -75,6 +80,7 @@ const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT;
75 80
76static int load_iv(char **fromp,unsigned char *to, int num); 81static int load_iv(char **fromp,unsigned char *to, int num);
77static int check_pem(const char *nm, const char *name); 82static int check_pem(const char *nm, const char *name);
83int pem_check_suffix(const char *pem_str, const char *suffix);
78 84
79int PEM_def_callback(char *buf, int num, int w, void *key) 85int PEM_def_callback(char *buf, int num, int w, void *key)
80 { 86 {
@@ -99,7 +105,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
99 105
100 for (;;) 106 for (;;)
101 { 107 {
102 i=EVP_read_pw_string(buf,num,prompt,w); 108 i=EVP_read_pw_string_min(buf,MIN_LENGTH,num,prompt,w);
103 if (i != 0) 109 if (i != 0)
104 { 110 {
105 PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); 111 PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
@@ -183,20 +189,54 @@ static int check_pem(const char *nm, const char *name)
183 189
184 /* Make PEM_STRING_EVP_PKEY match any private key */ 190 /* Make PEM_STRING_EVP_PKEY match any private key */
185 191
186 if(!strcmp(nm,PEM_STRING_PKCS8) && 192 if(!strcmp(name,PEM_STRING_EVP_PKEY))
187 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 193 {
188 194 int slen;
189 if(!strcmp(nm,PEM_STRING_PKCS8INF) && 195 const EVP_PKEY_ASN1_METHOD *ameth;
190 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 196 if(!strcmp(nm,PEM_STRING_PKCS8))
191 197 return 1;
192 if(!strcmp(nm,PEM_STRING_RSA) && 198 if(!strcmp(nm,PEM_STRING_PKCS8INF))
193 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 199 return 1;
200 slen = pem_check_suffix(nm, "PRIVATE KEY");
201 if (slen > 0)
202 {
203 /* NB: ENGINE implementations wont contain
204 * a deprecated old private key decode function
205 * so don't look for them.
206 */
207 ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
208 if (ameth && ameth->old_priv_decode)
209 return 1;
210 }
211 return 0;
212 }
194 213
195 if(!strcmp(nm,PEM_STRING_DSA) && 214 if(!strcmp(name,PEM_STRING_PARAMETERS))
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 215 {
216 int slen;
217 const EVP_PKEY_ASN1_METHOD *ameth;
218 slen = pem_check_suffix(nm, "PARAMETERS");
219 if (slen > 0)
220 {
221 ENGINE *e;
222 ameth = EVP_PKEY_asn1_find_str(&e, nm, slen);
223 if (ameth)
224 {
225 int r;
226 if (ameth->param_decode)
227 r = 1;
228 else
229 r = 0;
230#ifndef OPENSSL_NO_ENGINE
231 if (e)
232 ENGINE_finish(e);
233#endif
234 return r;
235 }
236 }
237 return 0;
238 }
197 239
198 if(!strcmp(nm,PEM_STRING_ECPRIVATEKEY) &&
199 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
200 /* Permit older strings */ 240 /* Permit older strings */
201 241
202 if(!strcmp(nm,PEM_STRING_X509_OLD) && 242 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
@@ -219,6 +259,14 @@ static int check_pem(const char *nm, const char *name)
219 if(!strcmp(nm, PEM_STRING_PKCS7_SIGNED) && 259 if(!strcmp(nm, PEM_STRING_PKCS7_SIGNED) &&
220 !strcmp(name, PEM_STRING_PKCS7)) return 1; 260 !strcmp(name, PEM_STRING_PKCS7)) return 1;
221 261
262#ifndef OPENSSL_NO_CMS
263 if(!strcmp(nm, PEM_STRING_X509) &&
264 !strcmp(name, PEM_STRING_CMS)) return 1;
265 /* Allow CMS to be read from PKCS#7 headers */
266 if(!strcmp(nm, PEM_STRING_PKCS7) &&
267 !strcmp(name, PEM_STRING_CMS)) return 1;
268#endif
269
222 return 0; 270 return 0;
223} 271}
224 272
@@ -264,7 +312,7 @@ err:
264 312
265#ifndef OPENSSL_NO_FP_API 313#ifndef OPENSSL_NO_FP_API
266int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, 314int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
267 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 315 void *x, const EVP_CIPHER *enc, unsigned char *kstr,
268 int klen, pem_password_cb *callback, void *u) 316 int klen, pem_password_cb *callback, void *u)
269 { 317 {
270 BIO *b; 318 BIO *b;
@@ -283,7 +331,7 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
283#endif 331#endif
284 332
285int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, 333int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
286 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 334 void *x, const EVP_CIPHER *enc, unsigned char *kstr,
287 int klen, pem_password_cb *callback, void *u) 335 int klen, pem_password_cb *callback, void *u)
288 { 336 {
289 EVP_CIPHER_CTX ctx; 337 EVP_CIPHER_CTX ctx;
@@ -782,3 +830,25 @@ err:
782 BUF_MEM_free(dataB); 830 BUF_MEM_free(dataB);
783 return(0); 831 return(0);
784 } 832 }
833
834/* Check pem string and return prefix length.
835 * If for example the pem_str == "RSA PRIVATE KEY" and suffix = "PRIVATE KEY"
836 * the return value is 3 for the string "RSA".
837 */
838
839int pem_check_suffix(const char *pem_str, const char *suffix)
840 {
841 int pem_len = strlen(pem_str);
842 int suffix_len = strlen(suffix);
843 const char *p;
844 if (suffix_len + 1 >= pem_len)
845 return 0;
846 p = pem_str + pem_len - suffix_len;
847 if (strcmp(p, suffix))
848 return 0;
849 p--;
850 if (*p != ' ')
851 return 0;
852 return p - pem_str;
853 }
854
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index 4da4c31ce5..8ecf24903b 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -65,7 +65,12 @@
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66#include <openssl/pkcs12.h> 66#include <openssl/pkcs12.h>
67#include <openssl/pem.h> 67#include <openssl/pem.h>
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include "asn1_locl.h"
68 72
73int pem_check_suffix(const char *pem_str, const char *suffix);
69 74
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) 75EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 { 76 {
@@ -73,19 +78,14 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
73 const unsigned char *p=NULL; 78 const unsigned char *p=NULL;
74 unsigned char *data=NULL; 79 unsigned char *data=NULL;
75 long len; 80 long len;
81 int slen;
76 EVP_PKEY *ret=NULL; 82 EVP_PKEY *ret=NULL;
77 83
78 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u)) 84 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
79 return NULL; 85 return NULL;
80 p = data; 86 p = data;
81 87
82 if (strcmp(nm,PEM_STRING_RSA) == 0) 88 if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
83 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
84 else if (strcmp(nm,PEM_STRING_DSA) == 0)
85 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
86 else if (strcmp(nm,PEM_STRING_ECPRIVATEKEY) == 0)
87 ret=d2i_PrivateKey(EVP_PKEY_EC,x,&p,len);
88 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
89 PKCS8_PRIV_KEY_INFO *p8inf; 89 PKCS8_PRIV_KEY_INFO *p8inf;
90 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len); 90 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
91 if(!p8inf) goto p8err; 91 if(!p8inf) goto p8err;
@@ -119,7 +119,14 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
119 *x = ret; 119 *x = ret;
120 } 120 }
121 PKCS8_PRIV_KEY_INFO_free(p8inf); 121 PKCS8_PRIV_KEY_INFO_free(p8inf);
122 } 122 } else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0)
123 {
124 const EVP_PKEY_ASN1_METHOD *ameth;
125 ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
126 if (!ameth || !ameth->old_priv_decode)
127 goto p8err;
128 ret=d2i_PrivateKey(ameth->pkey_id,x,&p,len);
129 }
123p8err: 130p8err:
124 if (ret == NULL) 131 if (ret == NULL)
125 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB); 132 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);
@@ -130,6 +137,74 @@ err:
130 return(ret); 137 return(ret);
131 } 138 }
132 139
140int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
141 unsigned char *kstr, int klen,
142 pem_password_cb *cb, void *u)
143 {
144 char pem_str[80];
145 if (!x->ameth || x->ameth->priv_encode)
146 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
147 (char *)kstr, klen,
148 cb, u);
149
150 BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str);
151 return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
152 pem_str,bp,x,enc,kstr,klen,cb,u);
153 }
154
155EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
156 {
157 char *nm=NULL;
158 const unsigned char *p=NULL;
159 unsigned char *data=NULL;
160 long len;
161 int slen;
162 EVP_PKEY *ret=NULL;
163
164 if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_PARAMETERS,
165 bp, 0, NULL))
166 return NULL;
167 p = data;
168
169 if ((slen = pem_check_suffix(nm, "PARAMETERS")) > 0)
170 {
171 ret = EVP_PKEY_new();
172 if (!ret)
173 goto err;
174 if (!EVP_PKEY_set_type_str(ret, nm, slen)
175 || !ret->ameth->param_decode
176 || !ret->ameth->param_decode(ret, &p, len))
177 {
178 EVP_PKEY_free(ret);
179 ret = NULL;
180 goto err;
181 }
182 if(x)
183 {
184 if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
185 *x = ret;
186 }
187 }
188err:
189 if (ret == NULL)
190 PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS,ERR_R_ASN1_LIB);
191 OPENSSL_free(nm);
192 OPENSSL_free(data);
193 return(ret);
194 }
195
196int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x)
197 {
198 char pem_str[80];
199 if (!x->ameth || !x->ameth->param_encode)
200 return 0;
201
202 BIO_snprintf(pem_str, 80, "%s PARAMETERS", x->ameth->pem_str);
203 return PEM_ASN1_write_bio(
204 (i2d_of_void *)x->ameth->param_encode,
205 pem_str,bp,x,NULL,NULL,0,0,NULL);
206 }
207
133#ifndef OPENSSL_NO_FP_API 208#ifndef OPENSSL_NO_FP_API
134EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u) 209EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
135 { 210 {
@@ -146,4 +221,22 @@ EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void
146 BIO_free(b); 221 BIO_free(b);
147 return(ret); 222 return(ret);
148 } 223 }
224
225int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
226 unsigned char *kstr, int klen,
227 pem_password_cb *cb, void *u)
228 {
229 BIO *b;
230 int ret;
231
232 if ((b=BIO_new_fp(fp, BIO_NOCLOSE)) == NULL)
233 {
234 PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY,ERR_R_BUF_LIB);
235 return 0;
236 }
237 ret=PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
238 BIO_free(b);
239 return ret;
240 }
241
149#endif 242#endif
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 4e554e5481..59690b56ae 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -100,7 +100,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
100 100
101 EVP_CIPHER_CTX_init(&ctx->cipher); 101 EVP_CIPHER_CTX_init(&ctx->cipher);
102 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk); 102 ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
103 if (!ret) goto err; 103 if (ret <= 0) goto err;
104 104
105 /* base64 encode the keys */ 105 /* base64 encode the keys */
106 for (i=0; i<npubk; i++) 106 for (i=0; i<npubk; i++)
diff --git a/src/lib/libcrypto/pem/pem_x509.c b/src/lib/libcrypto/pem/pem_x509.c
index 3f709f13e6..b531057dc9 100644
--- a/src/lib/libcrypto/pem/pem_x509.c
+++ b/src/lib/libcrypto/pem/pem_x509.c
@@ -57,7 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h" 60#include "cryptlib.h"
62#include <openssl/bio.h> 61#include <openssl/bio.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c
index 7cc7491009..328f796200 100644
--- a/src/lib/libcrypto/pem/pem_xaux.c
+++ b/src/lib/libcrypto/pem/pem_xaux.c
@@ -57,7 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#undef SSLEAY_MACROS
61#include "cryptlib.h" 60#include "cryptlib.h"
62#include <openssl/bio.h> 61#include <openssl/bio.h>
63#include <openssl/evp.h> 62#include <openssl/evp.h>