summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/Makefile.ssl662
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c548
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c429
-rw-r--r--src/lib/libcrypto/evp/bio_md.c261
-rw-r--r--src/lib/libcrypto/evp/c_all.c75
-rw-r--r--src/lib/libcrypto/evp/digest.c312
-rw-r--r--src/lib/libcrypto/evp/e_aes.c101
-rw-r--r--src/lib/libcrypto/evp/e_bf.c88
-rw-r--r--src/lib/libcrypto/evp/e_cast.c90
-rw-r--r--src/lib/libcrypto/evp/e_des.c119
-rw-r--r--src/lib/libcrypto/evp/e_des3.c193
-rw-r--r--src/lib/libcrypto/evp/e_idea.c118
-rw-r--r--src/lib/libcrypto/evp/e_null.c101
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c229
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c136
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c122
-rw-r--r--src/lib/libcrypto/evp/encode.c444
-rw-r--r--src/lib/libcrypto/evp/evp.h844
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c507
-rw-r--r--src/lib/libcrypto/evp/evp_err.c160
-rw-r--r--src/lib/libcrypto/evp/evp_key.c172
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c142
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h227
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c136
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c412
-rw-r--r--src/lib/libcrypto/evp/evp_test.c4
-rw-r--r--src/lib/libcrypto/evp/m_dss.c95
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c95
-rw-r--r--src/lib/libcrypto/evp/m_md4.c96
-rw-r--r--src/lib/libcrypto/evp/m_md5.c96
-rw-r--r--src/lib/libcrypto/evp/m_null.c95
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c96
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c95
-rw-r--r--src/lib/libcrypto/evp/names.c123
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c151
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c250
-rw-r--r--src/lib/libcrypto/evp/p_dec.c87
-rw-r--r--src/lib/libcrypto/evp/p_enc.c86
-rw-r--r--src/lib/libcrypto/evp/p_lib.c337
-rw-r--r--src/lib/libcrypto/evp/p_open.c123
-rw-r--r--src/lib/libcrypto/evp/p_seal.c115
-rw-r--r--src/lib/libcrypto/evp/p_sign.c114
-rw-r--r--src/lib/libcrypto/evp/p_verify.c101
43 files changed, 8785 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl
new file mode 100644
index 0000000000..75f078af76
--- /dev/null
+++ b/src/lib/libcrypto/evp/Makefile.ssl
@@ -0,0 +1,662 @@
1#
2# SSLeay/crypto/evp/Makefile
3#
4
5DIR= evp
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=evp_test.c
23TESTDATA=evptests.txt
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= encode.c digest.c evp_enc.c evp_key.c evp_acnf.c \
28 e_des.c e_bf.c e_idea.c e_des3.c \
29 e_rc4.c e_aes.c names.c \
30 e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
31 m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
32 m_dss.c m_dss1.c m_mdc2.c m_ripemd.c \
33 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
34 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
35 c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
36 evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c
37
38LIBOBJ= encode.o digest.o evp_enc.o evp_key.o evp_acnf.o \
39 e_des.o e_bf.o e_idea.o e_des3.o \
40 e_rc4.o e_aes.o names.o \
41 e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o \
42 m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
43 m_dss.o m_dss1.o m_mdc2.o m_ripemd.o \
44 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
45 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
46 c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
47 evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o
48
49SRC= $(LIBSRC)
50
51EXHEADER= evp.h
52HEADER= $(EXHEADER)
53
54ALL= $(GENERAL) $(SRC) $(HEADER)
55
56top:
57 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
58
59all: lib
60
61lib: $(LIBOBJ)
62 $(AR) $(LIB) $(LIBOBJ)
63 $(RANLIB) $(LIB) || echo Never mind.
64 @touch lib
65
66files:
67 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
68
69links:
70 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
71 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
72 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
73 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TESTDATA)
74 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75
76install:
77 @for i in $(EXHEADER) ; \
78 do \
79 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
80 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
81 done;
82
83tags:
84 ctags $(SRC)
85
86tests:
87
88lint:
89 lint -DLINT $(INCLUDES) $(SRC)>fluff
90
91depend:
92 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC)
93
94dclean:
95 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
96 mv -f Makefile.new $(MAKEFILE)
97
98clean:
99 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
100
101# DO NOT DELETE THIS LINE -- make depend depends on it.
102
103bio_b64.o: ../../e_os.h ../../include/openssl/asn1.h
104bio_b64.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
105bio_b64.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
106bio_b64.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
107bio_b64.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
108bio_b64.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
109bio_b64.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
110bio_b64.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
111bio_b64.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
112bio_b64.o: ../cryptlib.h bio_b64.c
113bio_enc.o: ../../e_os.h ../../include/openssl/asn1.h
114bio_enc.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
115bio_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
116bio_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
117bio_enc.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
118bio_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
119bio_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
120bio_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
121bio_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
122bio_enc.o: ../cryptlib.h bio_enc.c
123bio_md.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
124bio_md.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
125bio_md.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
126bio_md.o: ../../include/openssl/err.h ../../include/openssl/evp.h
127bio_md.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
128bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
129bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130bio_md.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
131bio_md.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_md.c
132bio_ok.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
133bio_ok.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
134bio_ok.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
135bio_ok.o: ../../include/openssl/err.h ../../include/openssl/evp.h
136bio_ok.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
137bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
138bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
139bio_ok.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
140bio_ok.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
141bio_ok.o: ../cryptlib.h bio_ok.c
142c_all.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
143c_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
144c_all.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
145c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
146c_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
147c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
148c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149c_all.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
150c_all.o: ../../include/openssl/symhacks.h ../cryptlib.h c_all.c
151c_allc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
152c_allc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
153c_allc.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
154c_allc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
155c_allc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
156c_allc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
157c_allc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
158c_allc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
159c_allc.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
160c_allc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
161c_allc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
162c_allc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
163c_allc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_allc.c
164c_alld.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
165c_alld.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
166c_alld.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
167c_alld.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
168c_alld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
169c_alld.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
170c_alld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
171c_alld.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
172c_alld.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
173c_alld.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
174c_alld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
175c_alld.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
176c_alld.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_alld.c
177digest.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
178digest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
179digest.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
180digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
181digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h
182digest.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
183digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
184digest.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
185digest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
186digest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
187digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
188digest.o: ../../include/openssl/ui.h ../cryptlib.h digest.c
189e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
190e_aes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
191e_aes.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
192e_aes.o: ../../include/openssl/err.h ../../include/openssl/evp.h
193e_aes.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
194e_aes.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
195e_aes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
196e_aes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
197e_aes.o: ../../include/openssl/symhacks.h e_aes.c evp_locl.h
198e_bf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
199e_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
200e_bf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
201e_bf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
202e_bf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
203e_bf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
204e_bf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
205e_bf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
206e_bf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
207e_bf.o: ../cryptlib.h e_bf.c evp_locl.h
208e_cast.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
209e_cast.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
210e_cast.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
211e_cast.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
212e_cast.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
213e_cast.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
214e_cast.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215e_cast.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
216e_cast.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217e_cast.o: ../cryptlib.h e_cast.c evp_locl.h
218e_des.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
219e_des.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
220e_des.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
221e_des.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
222e_des.o: ../../include/openssl/err.h ../../include/openssl/evp.h
223e_des.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
224e_des.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
225e_des.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
226e_des.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
227e_des.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
228e_des.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des.c evp_locl.h
229e_des3.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
230e_des3.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
231e_des3.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
232e_des3.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
233e_des3.o: ../../include/openssl/err.h ../../include/openssl/evp.h
234e_des3.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
235e_des3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
236e_des3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
237e_des3.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
238e_des3.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
239e_des3.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des3.c evp_locl.h
240e_idea.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
241e_idea.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
242e_idea.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
243e_idea.o: ../../include/openssl/err.h ../../include/openssl/evp.h
244e_idea.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
245e_idea.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
246e_idea.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
247e_idea.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
248e_idea.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
249e_idea.o: ../cryptlib.h e_idea.c evp_locl.h
250e_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
251e_null.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
252e_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
253e_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
254e_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
255e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
256e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
257e_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
258e_null.o: ../../include/openssl/symhacks.h ../cryptlib.h e_null.c
259e_rc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
260e_rc2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
261e_rc2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
262e_rc2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
263e_rc2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
264e_rc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
265e_rc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
266e_rc2.o: ../../include/openssl/rc2.h ../../include/openssl/safestack.h
267e_rc2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
268e_rc2.o: ../cryptlib.h e_rc2.c evp_locl.h
269e_rc4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
270e_rc4.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
271e_rc4.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
272e_rc4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
273e_rc4.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
274e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
275e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
276e_rc4.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
277e_rc4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
278e_rc4.o: ../cryptlib.h e_rc4.c
279e_rc5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
280e_rc5.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
281e_rc5.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
282e_rc5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
283e_rc5.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
284e_rc5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
285e_rc5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
286e_rc5.o: ../../include/openssl/rc5.h ../../include/openssl/safestack.h
287e_rc5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
288e_rc5.o: ../cryptlib.h e_rc5.c evp_locl.h
289e_xcbc_d.o: ../../e_os.h ../../include/openssl/asn1.h
290e_xcbc_d.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
291e_xcbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
292e_xcbc_d.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
293e_xcbc_d.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
294e_xcbc_d.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
295e_xcbc_d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
296e_xcbc_d.o: ../../include/openssl/opensslconf.h
297e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
298e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
299e_xcbc_d.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
300e_xcbc_d.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_xcbc_d.c
301encode.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
302encode.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
303encode.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
304encode.o: ../../include/openssl/err.h ../../include/openssl/evp.h
305encode.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
306encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
307encode.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
308encode.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
309encode.o: ../../include/openssl/symhacks.h ../cryptlib.h encode.c
310evp_acnf.o: ../../e_os.h ../../include/openssl/asn1.h
311evp_acnf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
312evp_acnf.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
313evp_acnf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
314evp_acnf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
315evp_acnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
316evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
317evp_acnf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
318evp_acnf.o: ../../include/openssl/opensslconf.h
319evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
320evp_acnf.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
321evp_acnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
322evp_acnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
323evp_acnf.o: ../cryptlib.h evp_acnf.c
324evp_enc.o: ../../e_os.h ../../include/openssl/asn1.h
325evp_enc.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
326evp_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
327evp_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
328evp_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
329evp_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
330evp_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
331evp_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
332evp_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
333evp_enc.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
334evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
335evp_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
336evp_enc.o: ../cryptlib.h evp_enc.c evp_locl.h
337evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
338evp_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
339evp_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
340evp_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
341evp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
342evp_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
343evp_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
344evp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
345evp_err.o: evp_err.c
346evp_key.o: ../../e_os.h ../../include/openssl/asn1.h
347evp_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
348evp_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
349evp_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
350evp_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
351evp_key.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
352evp_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
353evp_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
354evp_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
355evp_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
356evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
357evp_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
358evp_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
359evp_key.o: ../cryptlib.h evp_key.c
360evp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
361evp_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
362evp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
363evp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
364evp_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
365evp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
366evp_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
367evp_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
368evp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
369evp_lib.o: ../cryptlib.h evp_lib.c
370evp_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
371evp_pbe.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
372evp_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
373evp_pbe.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
374evp_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
375evp_pbe.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
376evp_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
377evp_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
378evp_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
379evp_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
380evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
381evp_pbe.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
382evp_pbe.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pbe.c
383evp_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
384evp_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
385evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
386evp_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
387evp_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
388evp_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
389evp_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
390evp_pkey.o: ../../include/openssl/opensslconf.h
391evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
392evp_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
393evp_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
394evp_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
395evp_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
396evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pkey.c
397m_dss.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
398m_dss.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
399m_dss.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
400m_dss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
401m_dss.o: ../../include/openssl/err.h ../../include/openssl/evp.h
402m_dss.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
403m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
404m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
405m_dss.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
406m_dss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
407m_dss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
408m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
409m_dss.o: ../cryptlib.h m_dss.c
410m_dss1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
411m_dss1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
412m_dss1.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
413m_dss1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
414m_dss1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
415m_dss1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
416m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
417m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
418m_dss1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
419m_dss1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
420m_dss1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
421m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
422m_dss1.o: ../cryptlib.h m_dss1.c
423m_md2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
424m_md2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
425m_md2.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
426m_md2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
427m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
428m_md2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
429m_md2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
430m_md2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
431m_md2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
432m_md2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
433m_md2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
434m_md2.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
435m_md2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md2.c
436m_md4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
437m_md4.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
438m_md4.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
439m_md4.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
440m_md4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
441m_md4.o: ../../include/openssl/lhash.h ../../include/openssl/md4.h
442m_md4.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
443m_md4.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
444m_md4.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
445m_md4.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
446m_md4.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
447m_md4.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
448m_md4.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md4.c
449m_md5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
450m_md5.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
451m_md5.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
452m_md5.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
453m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
454m_md5.o: ../../include/openssl/lhash.h ../../include/openssl/md5.h
455m_md5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
456m_md5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
457m_md5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
458m_md5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
459m_md5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
460m_md5.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
461m_md5.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md5.c
462m_mdc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
463m_mdc2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
464m_mdc2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
465m_mdc2.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
466m_mdc2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
467m_mdc2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
468m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h
469m_mdc2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
470m_mdc2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
471m_mdc2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
472m_mdc2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
473m_mdc2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
474m_mdc2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
475m_mdc2.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
476m_mdc2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_mdc2.c
477m_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
478m_null.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
479m_null.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
480m_null.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
481m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
482m_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
483m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
484m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
485m_null.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
486m_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
487m_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
488m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
489m_null.o: ../cryptlib.h m_null.c
490m_ripemd.o: ../../e_os.h ../../include/openssl/asn1.h
491m_ripemd.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
492m_ripemd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
493m_ripemd.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
494m_ripemd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
495m_ripemd.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
496m_ripemd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
497m_ripemd.o: ../../include/openssl/opensslconf.h
498m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
499m_ripemd.o: ../../include/openssl/pkcs7.h ../../include/openssl/ripemd.h
500m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
501m_ripemd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
502m_ripemd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
503m_ripemd.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_ripemd.c
504m_sha.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
505m_sha.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
506m_sha.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
507m_sha.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
508m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h
509m_sha.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
510m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
511m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
512m_sha.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
513m_sha.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
514m_sha.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
515m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
516m_sha.o: ../cryptlib.h m_sha.c
517m_sha1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
518m_sha1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
519m_sha1.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
520m_sha1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
521m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
522m_sha1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
523m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
524m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
525m_sha1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
526m_sha1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
527m_sha1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
528m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
529m_sha1.o: ../cryptlib.h m_sha1.c
530names.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
531names.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
532names.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
533names.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
534names.o: ../../include/openssl/err.h ../../include/openssl/evp.h
535names.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
536names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
537names.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
538names.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
539names.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
540names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
541names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
542names.o: ../cryptlib.h names.c
543p5_crpt.o: ../../e_os.h ../../include/openssl/asn1.h
544p5_crpt.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
545p5_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
546p5_crpt.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
547p5_crpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
548p5_crpt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
549p5_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
550p5_crpt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
551p5_crpt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
552p5_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
553p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
554p5_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
555p5_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt.c
556p5_crpt2.o: ../../e_os.h ../../include/openssl/asn1.h
557p5_crpt2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
558p5_crpt2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
559p5_crpt2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
560p5_crpt2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
561p5_crpt2.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
562p5_crpt2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
563p5_crpt2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
564p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
565p5_crpt2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
566p5_crpt2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
567p5_crpt2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
568p5_crpt2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
569p5_crpt2.o: ../cryptlib.h p5_crpt2.c
570p_dec.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
571p_dec.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
572p_dec.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
573p_dec.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
574p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h
575p_dec.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
576p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
577p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
578p_dec.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
579p_dec.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
580p_dec.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
581p_dec.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
582p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_dec.c
583p_enc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
584p_enc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
585p_enc.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
586p_enc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
587p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
588p_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
589p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
590p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
591p_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
592p_enc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
593p_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
594p_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
595p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_enc.c
596p_lib.o: ../../e_os.h ../../include/openssl/asn1.h
597p_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
598p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
599p_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
600p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
601p_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
602p_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
603p_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
604p_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
605p_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
606p_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
607p_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
608p_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
609p_lib.o: ../cryptlib.h p_lib.c
610p_open.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
611p_open.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
612p_open.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
613p_open.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
614p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h
615p_open.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
616p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
617p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
618p_open.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
619p_open.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
620p_open.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
621p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
622p_open.o: ../cryptlib.h p_open.c
623p_seal.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
624p_seal.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
625p_seal.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
626p_seal.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
627p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
628p_seal.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
629p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
630p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
631p_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
632p_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
633p_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
634p_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
635p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_seal.c
636p_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
637p_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
638p_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
639p_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
640p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
641p_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
642p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
643p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
644p_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
645p_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
646p_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
647p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
648p_sign.o: ../cryptlib.h p_sign.c
649p_verify.o: ../../e_os.h ../../include/openssl/asn1.h
650p_verify.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
651p_verify.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
652p_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
653p_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
654p_verify.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
655p_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
656p_verify.o: ../../include/openssl/opensslconf.h
657p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
658p_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
659p_verify.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
660p_verify.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
661p_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
662p_verify.o: ../cryptlib.h p_verify.c
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
new file mode 100644
index 0000000000..f12eac1b55
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -0,0 +1,548 @@
1/* crypto/evp/bio_b64.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 <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int b64_write(BIO *h, const char *buf, int num);
66static int b64_read(BIO *h, char *buf, int size);
67/*static int b64_puts(BIO *h, const char *str); */
68/*static int b64_gets(BIO *h, char *str, int size); */
69static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int b64_new(BIO *h);
71static int b64_free(BIO *data);
72static long b64_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
73#define B64_BLOCK_SIZE 1024
74#define B64_BLOCK_SIZE2 768
75#define B64_NONE 0
76#define B64_ENCODE 1
77#define B64_DECODE 2
78
79typedef struct b64_struct
80 {
81 /*BIO *bio; moved to the BIO structure */
82 int buf_len;
83 int buf_off;
84 int tmp_len; /* used to find the start when decoding */
85 int tmp_nl; /* If true, scan until '\n' */
86 int encode;
87 int start; /* have we started decoding yet? */
88 int cont; /* <= 0 when finished */
89 EVP_ENCODE_CTX base64;
90 char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10];
91 char tmp[B64_BLOCK_SIZE];
92 } BIO_B64_CTX;
93
94static BIO_METHOD methods_b64=
95 {
96 BIO_TYPE_BASE64,"base64 encoding",
97 b64_write,
98 b64_read,
99 NULL, /* b64_puts, */
100 NULL, /* b64_gets, */
101 b64_ctrl,
102 b64_new,
103 b64_free,
104 b64_callback_ctrl,
105 };
106
107BIO_METHOD *BIO_f_base64(void)
108 {
109 return(&methods_b64);
110 }
111
112static int b64_new(BIO *bi)
113 {
114 BIO_B64_CTX *ctx;
115
116 ctx=(BIO_B64_CTX *)OPENSSL_malloc(sizeof(BIO_B64_CTX));
117 if (ctx == NULL) return(0);
118
119 ctx->buf_len=0;
120 ctx->tmp_len=0;
121 ctx->tmp_nl=0;
122 ctx->buf_off=0;
123 ctx->cont=1;
124 ctx->start=1;
125 ctx->encode=0;
126
127 bi->init=1;
128 bi->ptr=(char *)ctx;
129 bi->flags=0;
130 return(1);
131 }
132
133static int b64_free(BIO *a)
134 {
135 if (a == NULL) return(0);
136 OPENSSL_free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int b64_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
146 BIO_B64_CTX *ctx;
147 unsigned char *p,*q;
148
149 if (out == NULL) return(0);
150 ctx=(BIO_B64_CTX *)b->ptr;
151
152 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
153
154 if (ctx->encode != B64_DECODE)
155 {
156 ctx->encode=B64_DECODE;
157 ctx->buf_len=0;
158 ctx->buf_off=0;
159 ctx->tmp_len=0;
160 EVP_DecodeInit(&(ctx->base64));
161 }
162
163 /* First check if there are bytes decoded/encoded */
164 if (ctx->buf_len > 0)
165 {
166 i=ctx->buf_len-ctx->buf_off;
167 if (i > outl) i=outl;
168 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
169 ret=i;
170 out+=i;
171 outl-=i;
172 ctx->buf_off+=i;
173 if (ctx->buf_len == ctx->buf_off)
174 {
175 ctx->buf_len=0;
176 ctx->buf_off=0;
177 }
178 }
179
180 /* At this point, we have room of outl bytes and an empty
181 * buffer, so we should read in some more. */
182
183 ret_code=0;
184 while (outl > 0)
185 {
186 if (ctx->cont <= 0) break;
187
188 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
189 B64_BLOCK_SIZE-ctx->tmp_len);
190
191 if (i <= 0)
192 {
193 ret_code=i;
194
195 /* Should be continue next time we are called? */
196 if (!BIO_should_retry(b->next_bio))
197 ctx->cont=i;
198 /* else we should continue when called again */
199 break;
200 }
201 i+=ctx->tmp_len;
202
203 /* We need to scan, a line at a time until we
204 * have a valid line if we are starting. */
205 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
206 {
207 /* ctx->start=1; */
208 ctx->tmp_len=0;
209 }
210 else if (ctx->start)
211 {
212 q=p=(unsigned char *)ctx->tmp;
213 for (j=0; j<i; j++)
214 {
215 if (*(q++) != '\n') continue;
216
217 /* due to a previous very long line,
218 * we need to keep on scanning for a '\n'
219 * before we even start looking for
220 * base64 encoded stuff. */
221 if (ctx->tmp_nl)
222 {
223 p=q;
224 ctx->tmp_nl=0;
225 continue;
226 }
227
228 k=EVP_DecodeUpdate(&(ctx->base64),
229 (unsigned char *)ctx->buf,
230 &num,p,q-p);
231 if ((k <= 0) && (num == 0) && (ctx->start))
232 EVP_DecodeInit(&ctx->base64);
233 else
234 {
235 if (p != (unsigned char *)
236 &(ctx->tmp[0]))
237 {
238 i-=(p- (unsigned char *)
239 &(ctx->tmp[0]));
240 for (x=0; x < i; x++)
241 ctx->tmp[x]=p[x];
242 }
243 EVP_DecodeInit(&ctx->base64);
244 ctx->start=0;
245 break;
246 }
247 p=q;
248 }
249
250 /* we fell off the end without starting */
251 if (j == i)
252 {
253 /* Is this is one long chunk?, if so, keep on
254 * reading until a new line. */
255 if (p == (unsigned char *)&(ctx->tmp[0]))
256 {
257 ctx->tmp_nl=1;
258 ctx->tmp_len=0;
259 }
260 else if (p != q) /* finished on a '\n' */
261 {
262 n=q-p;
263 for (ii=0; ii<n; ii++)
264 ctx->tmp[ii]=p[ii];
265 ctx->tmp_len=n;
266 }
267 /* else finished on a '\n' */
268 continue;
269 }
270 else
271 ctx->tmp_len=0;
272 }
273
274 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
275 {
276 int z,jj;
277
278 jj=(i>>2)<<2;
279 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
280 (unsigned char *)ctx->tmp,jj);
281 if (jj > 2)
282 {
283 if (ctx->tmp[jj-1] == '=')
284 {
285 z--;
286 if (ctx->tmp[jj-2] == '=')
287 z--;
288 }
289 }
290 /* z is now number of output bytes and jj is the
291 * number consumed */
292 if (jj != i)
293 {
294 memcpy((unsigned char *)ctx->tmp,
295 (unsigned char *)&(ctx->tmp[jj]),i-jj);
296 ctx->tmp_len=i-jj;
297 }
298 ctx->buf_len=0;
299 if (z > 0)
300 {
301 ctx->buf_len=z;
302 i=1;
303 }
304 else
305 i=z;
306 }
307 else
308 {
309 i=EVP_DecodeUpdate(&(ctx->base64),
310 (unsigned char *)ctx->buf,&ctx->buf_len,
311 (unsigned char *)ctx->tmp,i);
312 }
313 ctx->cont=i;
314 ctx->buf_off=0;
315 if (i < 0)
316 {
317 ret_code=0;
318 ctx->buf_len=0;
319 break;
320 }
321
322 if (ctx->buf_len <= outl)
323 i=ctx->buf_len;
324 else
325 i=outl;
326
327 memcpy(out,ctx->buf,i);
328 ret+=i;
329 ctx->buf_off=i;
330 if (ctx->buf_off == ctx->buf_len)
331 {
332 ctx->buf_len=0;
333 ctx->buf_off=0;
334 }
335 outl-=i;
336 out+=i;
337 }
338 BIO_clear_retry_flags(b);
339 BIO_copy_next_retry(b);
340 return((ret == 0)?ret_code:ret);
341 }
342
343static int b64_write(BIO *b, const char *in, int inl)
344 {
345 int ret=inl,n,i;
346 BIO_B64_CTX *ctx;
347
348 ctx=(BIO_B64_CTX *)b->ptr;
349 BIO_clear_retry_flags(b);
350
351 if (ctx->encode != B64_ENCODE)
352 {
353 ctx->encode=B64_ENCODE;
354 ctx->buf_len=0;
355 ctx->buf_off=0;
356 ctx->tmp_len=0;
357 EVP_EncodeInit(&(ctx->base64));
358 }
359
360 n=ctx->buf_len-ctx->buf_off;
361 while (n > 0)
362 {
363 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
364 if (i <= 0)
365 {
366 BIO_copy_next_retry(b);
367 return(i);
368 }
369 ctx->buf_off+=i;
370 n-=i;
371 }
372 /* at this point all pending data has been written */
373 ctx->buf_off=0;
374 ctx->buf_len=0;
375
376 if ((in == NULL) || (inl <= 0)) return(0);
377
378 while (inl > 0)
379 {
380 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
381
382 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
383 {
384 if (ctx->tmp_len > 0)
385 {
386 n=3-ctx->tmp_len;
387 /* There's a teoretical possibility for this */
388 if (n > inl)
389 n=inl;
390 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
391 ctx->tmp_len+=n;
392 if (ctx->tmp_len < 3)
393 break;
394 ctx->buf_len=EVP_EncodeBlock(
395 (unsigned char *)ctx->buf,
396 (unsigned char *)ctx->tmp,
397 ctx->tmp_len);
398 /* Since we're now done using the temporary
399 buffer, the length should be 0'd */
400 ctx->tmp_len=0;
401 }
402 else
403 {
404 if (n < 3)
405 {
406 memcpy(&(ctx->tmp[0]),in,n);
407 ctx->tmp_len=n;
408 break;
409 }
410 n-=n%3;
411 ctx->buf_len=EVP_EncodeBlock(
412 (unsigned char *)ctx->buf,
413 (unsigned char *)in,n);
414 }
415 }
416 else
417 {
418 EVP_EncodeUpdate(&(ctx->base64),
419 (unsigned char *)ctx->buf,&ctx->buf_len,
420 (unsigned char *)in,n);
421 }
422 inl-=n;
423 in+=n;
424
425 ctx->buf_off=0;
426 n=ctx->buf_len;
427 while (n > 0)
428 {
429 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
430 if (i <= 0)
431 {
432 BIO_copy_next_retry(b);
433 return((ret == 0)?i:ret);
434 }
435 n-=i;
436 ctx->buf_off+=i;
437 }
438 ctx->buf_len=0;
439 ctx->buf_off=0;
440 }
441 return(ret);
442 }
443
444static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
445 {
446 BIO_B64_CTX *ctx;
447 long ret=1;
448 int i;
449
450 ctx=(BIO_B64_CTX *)b->ptr;
451
452 switch (cmd)
453 {
454 case BIO_CTRL_RESET:
455 ctx->cont=1;
456 ctx->start=1;
457 ctx->encode=B64_NONE;
458 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
459 break;
460 case BIO_CTRL_EOF: /* More to read */
461 if (ctx->cont <= 0)
462 ret=1;
463 else
464 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
465 break;
466 case BIO_CTRL_WPENDING: /* More to write in buffer */
467 ret=ctx->buf_len-ctx->buf_off;
468 if ((ret == 0) && (ctx->encode != B64_NONE)
469 && (ctx->base64.num != 0))
470 ret=1;
471 else if (ret <= 0)
472 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
473 break;
474 case BIO_CTRL_PENDING: /* More to read in buffer */
475 ret=ctx->buf_len-ctx->buf_off;
476 if (ret <= 0)
477 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
478 break;
479 case BIO_CTRL_FLUSH:
480 /* do a final write */
481again:
482 while (ctx->buf_len != ctx->buf_off)
483 {
484 i=b64_write(b,NULL,0);
485 if (i < 0)
486 {
487 ret=i;
488 break;
489 }
490 }
491 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
492 {
493 if (ctx->tmp_len != 0)
494 {
495 ctx->buf_len=EVP_EncodeBlock(
496 (unsigned char *)ctx->buf,
497 (unsigned char *)ctx->tmp,
498 ctx->tmp_len);
499 ctx->buf_off=0;
500 ctx->tmp_len=0;
501 goto again;
502 }
503 }
504 else if (ctx->encode != B64_NONE && ctx->base64.num != 0)
505 {
506 ctx->buf_off=0;
507 EVP_EncodeFinal(&(ctx->base64),
508 (unsigned char *)ctx->buf,
509 &(ctx->buf_len));
510 /* push out the bytes */
511 goto again;
512 }
513 /* Finally flush the underlying BIO */
514 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
515 break;
516
517 case BIO_C_DO_STATE_MACHINE:
518 BIO_clear_retry_flags(b);
519 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
520 BIO_copy_next_retry(b);
521 break;
522
523 case BIO_CTRL_DUP:
524 break;
525 case BIO_CTRL_INFO:
526 case BIO_CTRL_GET:
527 case BIO_CTRL_SET:
528 default:
529 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
530 break;
531 }
532 return(ret);
533 }
534
535static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
536 {
537 long ret=1;
538
539 if (b->next_bio == NULL) return(0);
540 switch (cmd)
541 {
542 default:
543 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
544 break;
545 }
546 return(ret);
547 }
548
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
new file mode 100644
index 0000000000..64fb2353af
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -0,0 +1,429 @@
1/* crypto/evp/bio_enc.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 <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int enc_write(BIO *h, const char *buf, int num);
66static int enc_read(BIO *h, char *buf, int size);
67/*static int enc_puts(BIO *h, const char *str); */
68/*static int enc_gets(BIO *h, char *str, int size); */
69static long enc_ctrl(BIO *h, int cmd, long arg1, void *arg2);
70static int enc_new(BIO *h);
71static int enc_free(BIO *data);
72static long enc_callback_ctrl(BIO *h, int cmd, bio_info_cb *fps);
73#define ENC_BLOCK_SIZE (1024*4)
74#define BUF_OFFSET EVP_MAX_BLOCK_LENGTH
75
76typedef struct enc_struct
77 {
78 int buf_len;
79 int buf_off;
80 int cont; /* <= 0 when finished */
81 int finished;
82 int ok; /* bad decrypt */
83 EVP_CIPHER_CTX cipher;
84 /* buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate
85 * can return up to a block more data than is presented to it
86 */
87 char buf[ENC_BLOCK_SIZE+BUF_OFFSET+2];
88 } BIO_ENC_CTX;
89
90static BIO_METHOD methods_enc=
91 {
92 BIO_TYPE_CIPHER,"cipher",
93 enc_write,
94 enc_read,
95 NULL, /* enc_puts, */
96 NULL, /* enc_gets, */
97 enc_ctrl,
98 enc_new,
99 enc_free,
100 enc_callback_ctrl,
101 };
102
103BIO_METHOD *BIO_f_cipher(void)
104 {
105 return(&methods_enc);
106 }
107
108static int enc_new(BIO *bi)
109 {
110 BIO_ENC_CTX *ctx;
111
112 ctx=(BIO_ENC_CTX *)OPENSSL_malloc(sizeof(BIO_ENC_CTX));
113 if (ctx == NULL) return(0);
114 EVP_CIPHER_CTX_init(&ctx->cipher);
115
116 ctx->buf_len=0;
117 ctx->buf_off=0;
118 ctx->cont=1;
119 ctx->finished=0;
120 ctx->ok=1;
121
122 bi->init=0;
123 bi->ptr=(char *)ctx;
124 bi->flags=0;
125 return(1);
126 }
127
128static int enc_free(BIO *a)
129 {
130 BIO_ENC_CTX *b;
131
132 if (a == NULL) return(0);
133 b=(BIO_ENC_CTX *)a->ptr;
134 EVP_CIPHER_CTX_cleanup(&(b->cipher));
135 memset(a->ptr,0,sizeof(BIO_ENC_CTX));
136 OPENSSL_free(a->ptr);
137 a->ptr=NULL;
138 a->init=0;
139 a->flags=0;
140 return(1);
141 }
142
143static int enc_read(BIO *b, char *out, int outl)
144 {
145 int ret=0,i;
146 BIO_ENC_CTX *ctx;
147
148 if (out == NULL) return(0);
149 ctx=(BIO_ENC_CTX *)b->ptr;
150
151 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
152
153 /* First check if there are bytes decoded/encoded */
154 if (ctx->buf_len > 0)
155 {
156 i=ctx->buf_len-ctx->buf_off;
157 if (i > outl) i=outl;
158 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
159 ret=i;
160 out+=i;
161 outl-=i;
162 ctx->buf_off+=i;
163 if (ctx->buf_len == ctx->buf_off)
164 {
165 ctx->buf_len=0;
166 ctx->buf_off=0;
167 }
168 }
169
170 /* At this point, we have room of outl bytes and an empty
171 * buffer, so we should read in some more. */
172
173 while (outl > 0)
174 {
175 if (ctx->cont <= 0) break;
176
177 /* read in at IV offset, read the EVP_Cipher
178 * documentation about why */
179 i=BIO_read(b->next_bio,&(ctx->buf[BUF_OFFSET]),ENC_BLOCK_SIZE);
180
181 if (i <= 0)
182 {
183 /* Should be continue next time we are called? */
184 if (!BIO_should_retry(b->next_bio))
185 {
186 ctx->cont=i;
187 i=EVP_CipherFinal_ex(&(ctx->cipher),
188 (unsigned char *)ctx->buf,
189 &(ctx->buf_len));
190 ctx->ok=i;
191 ctx->buf_off=0;
192 }
193 else
194 {
195 ret=(ret == 0)?i:ret;
196 break;
197 }
198 }
199 else
200 {
201 EVP_CipherUpdate(&(ctx->cipher),
202 (unsigned char *)ctx->buf,&ctx->buf_len,
203 (unsigned char *)&(ctx->buf[BUF_OFFSET]),i);
204 ctx->cont=1;
205 /* Note: it is possible for EVP_CipherUpdate to
206 * decrypt zero bytes because this is or looks like
207 * the final block: if this happens we should retry
208 * and either read more data or decrypt the final
209 * block
210 */
211 if(ctx->buf_len == 0) continue;
212 }
213
214 if (ctx->buf_len <= outl)
215 i=ctx->buf_len;
216 else
217 i=outl;
218 if (i <= 0) break;
219 memcpy(out,ctx->buf,i);
220 ret+=i;
221 ctx->buf_off=i;
222 outl-=i;
223 out+=i;
224 }
225
226 BIO_clear_retry_flags(b);
227 BIO_copy_next_retry(b);
228 return((ret == 0)?ctx->cont:ret);
229 }
230
231static int enc_write(BIO *b, const char *in, int inl)
232 {
233 int ret=0,n,i;
234 BIO_ENC_CTX *ctx;
235
236 ctx=(BIO_ENC_CTX *)b->ptr;
237 ret=inl;
238
239 BIO_clear_retry_flags(b);
240 n=ctx->buf_len-ctx->buf_off;
241 while (n > 0)
242 {
243 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
244 if (i <= 0)
245 {
246 BIO_copy_next_retry(b);
247 return(i);
248 }
249 ctx->buf_off+=i;
250 n-=i;
251 }
252 /* at this point all pending data has been written */
253
254 if ((in == NULL) || (inl <= 0)) return(0);
255
256 ctx->buf_off=0;
257 while (inl > 0)
258 {
259 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
260 EVP_CipherUpdate(&(ctx->cipher),
261 (unsigned char *)ctx->buf,&ctx->buf_len,
262 (unsigned char *)in,n);
263 inl-=n;
264 in+=n;
265
266 ctx->buf_off=0;
267 n=ctx->buf_len;
268 while (n > 0)
269 {
270 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
271 if (i <= 0)
272 {
273 BIO_copy_next_retry(b);
274 return(i);
275 }
276 n-=i;
277 ctx->buf_off+=i;
278 }
279 ctx->buf_len=0;
280 ctx->buf_off=0;
281 }
282 BIO_copy_next_retry(b);
283 return(ret);
284 }
285
286static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
287 {
288 BIO *dbio;
289 BIO_ENC_CTX *ctx,*dctx;
290 long ret=1;
291 int i;
292 EVP_CIPHER_CTX **c_ctx;
293
294 ctx=(BIO_ENC_CTX *)b->ptr;
295
296 switch (cmd)
297 {
298 case BIO_CTRL_RESET:
299 ctx->ok=1;
300 ctx->finished=0;
301 EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
302 ctx->cipher.encrypt);
303 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
304 break;
305 case BIO_CTRL_EOF: /* More to read */
306 if (ctx->cont <= 0)
307 ret=1;
308 else
309 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
310 break;
311 case BIO_CTRL_WPENDING:
312 ret=ctx->buf_len-ctx->buf_off;
313 if (ret <= 0)
314 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
315 break;
316 case BIO_CTRL_PENDING: /* More to read in buffer */
317 ret=ctx->buf_len-ctx->buf_off;
318 if (ret <= 0)
319 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
320 break;
321 case BIO_CTRL_FLUSH:
322 /* do a final write */
323again:
324 while (ctx->buf_len != ctx->buf_off)
325 {
326 i=enc_write(b,NULL,0);
327 if (i < 0)
328 {
329 ret=i;
330 break;
331 }
332 }
333
334 if (!ctx->finished)
335 {
336 ctx->finished=1;
337 ctx->buf_off=0;
338 ret=EVP_CipherFinal_ex(&(ctx->cipher),
339 (unsigned char *)ctx->buf,
340 &(ctx->buf_len));
341 ctx->ok=(int)ret;
342 if (ret <= 0) break;
343
344 /* push out the bytes */
345 goto again;
346 }
347
348 /* Finally flush the underlying BIO */
349 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
350 break;
351 case BIO_C_GET_CIPHER_STATUS:
352 ret=(long)ctx->ok;
353 break;
354 case BIO_C_DO_STATE_MACHINE:
355 BIO_clear_retry_flags(b);
356 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
357 BIO_copy_next_retry(b);
358 break;
359 case BIO_C_GET_CIPHER_CTX:
360 c_ctx=(EVP_CIPHER_CTX **)ptr;
361 (*c_ctx)= &(ctx->cipher);
362 b->init=1;
363 break;
364 case BIO_CTRL_DUP:
365 dbio=(BIO *)ptr;
366 dctx=(BIO_ENC_CTX *)dbio->ptr;
367 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
368 dbio->init=1;
369 break;
370 default:
371 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
372 break;
373 }
374 return(ret);
375 }
376
377static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
378 {
379 long ret=1;
380
381 if (b->next_bio == NULL) return(0);
382 switch (cmd)
383 {
384 default:
385 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
386 break;
387 }
388 return(ret);
389 }
390
391/*
392void BIO_set_cipher_ctx(b,c)
393BIO *b;
394EVP_CIPHER_ctx *c;
395 {
396 if (b == NULL) return;
397
398 if ((b->callback != NULL) &&
399 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
400 return;
401
402 b->init=1;
403 ctx=(BIO_ENC_CTX *)b->ptr;
404 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
405
406 if (b->callback != NULL)
407 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
408 }
409*/
410
411void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
412 unsigned char *i, int e)
413 {
414 BIO_ENC_CTX *ctx;
415
416 if (b == NULL) return;
417
418 if ((b->callback != NULL) &&
419 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
420 return;
421
422 b->init=1;
423 ctx=(BIO_ENC_CTX *)b->ptr;
424 EVP_CipherInit_ex(&(ctx->cipher),c,NULL, k,i,e);
425
426 if (b->callback != NULL)
427 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
428 }
429
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
new file mode 100644
index 0000000000..c632dfb202
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -0,0 +1,261 @@
1/* crypto/evp/bio_md.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 <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */
67
68static int md_write(BIO *h, char const *buf, int num);
69static int md_read(BIO *h, char *buf, int size);
70/*static int md_puts(BIO *h, const char *str); */
71static int md_gets(BIO *h, char *str, int size);
72static long md_ctrl(BIO *h, int cmd, long arg1, void *arg2);
73static int md_new(BIO *h);
74static int md_free(BIO *data);
75static long md_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
76
77static BIO_METHOD methods_md=
78 {
79 BIO_TYPE_MD,"message digest",
80 md_write,
81 md_read,
82 NULL, /* md_puts, */
83 md_gets,
84 md_ctrl,
85 md_new,
86 md_free,
87 md_callback_ctrl,
88 };
89
90BIO_METHOD *BIO_f_md(void)
91 {
92 return(&methods_md);
93 }
94
95static int md_new(BIO *bi)
96 {
97 EVP_MD_CTX *ctx;
98
99 ctx=EVP_MD_CTX_create();
100 if (ctx == NULL) return(0);
101
102 bi->init=0;
103 bi->ptr=(char *)ctx;
104 bi->flags=0;
105 return(1);
106 }
107
108static int md_free(BIO *a)
109 {
110 if (a == NULL) return(0);
111 EVP_MD_CTX_destroy(a->ptr);
112 a->ptr=NULL;
113 a->init=0;
114 a->flags=0;
115 return(1);
116 }
117
118static int md_read(BIO *b, char *out, int outl)
119 {
120 int ret=0;
121 EVP_MD_CTX *ctx;
122
123 if (out == NULL) return(0);
124 ctx=b->ptr;
125
126 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
127
128 ret=BIO_read(b->next_bio,out,outl);
129 if (b->init)
130 {
131 if (ret > 0)
132 {
133 EVP_DigestUpdate(ctx,(unsigned char *)out,
134 (unsigned int)ret);
135 }
136 }
137 BIO_clear_retry_flags(b);
138 BIO_copy_next_retry(b);
139 return(ret);
140 }
141
142static int md_write(BIO *b, const char *in, int inl)
143 {
144 int ret=0;
145 EVP_MD_CTX *ctx;
146
147 if ((in == NULL) || (inl <= 0)) return(0);
148 ctx=b->ptr;
149
150 if ((ctx != NULL) && (b->next_bio != NULL))
151 ret=BIO_write(b->next_bio,in,inl);
152 if (b->init)
153 {
154 if (ret > 0)
155 {
156 EVP_DigestUpdate(ctx,(unsigned char *)in,
157 (unsigned int)ret);
158 }
159 }
160 BIO_clear_retry_flags(b);
161 BIO_copy_next_retry(b);
162 return(ret);
163 }
164
165static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
166 {
167 EVP_MD_CTX *ctx,*dctx,**pctx;
168 const EVP_MD **ppmd;
169 EVP_MD *md;
170 long ret=1;
171 BIO *dbio;
172
173 ctx=b->ptr;
174
175 switch (cmd)
176 {
177 case BIO_CTRL_RESET:
178 if (b->init)
179 EVP_DigestInit_ex(ctx,ctx->digest, NULL);
180 else
181 ret=0;
182 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
183 break;
184 case BIO_C_GET_MD:
185 if (b->init)
186 {
187 ppmd=ptr;
188 *ppmd=ctx->digest;
189 }
190 else
191 ret=0;
192 break;
193 case BIO_C_GET_MD_CTX:
194 if (b->init)
195 {
196 pctx=ptr;
197 *pctx=ctx;
198 }
199 else
200 ret=0;
201 break;
202 case BIO_C_DO_STATE_MACHINE:
203 BIO_clear_retry_flags(b);
204 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
205 BIO_copy_next_retry(b);
206 break;
207
208 case BIO_C_SET_MD:
209 md=ptr;
210 EVP_DigestInit_ex(ctx,md, NULL);
211 b->init=1;
212 break;
213 case BIO_CTRL_DUP:
214 dbio=ptr;
215 dctx=dbio->ptr;
216 EVP_MD_CTX_copy_ex(dctx,ctx);
217 b->init=1;
218 break;
219 default:
220 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
221 break;
222 }
223 return(ret);
224 }
225
226static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
227 {
228 long ret=1;
229
230 if (b->next_bio == NULL) return(0);
231 switch (cmd)
232 {
233 default:
234 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
235 break;
236 }
237 return(ret);
238 }
239
240static int md_gets(BIO *bp, char *buf, int size)
241 {
242 EVP_MD_CTX *ctx;
243 unsigned int ret;
244
245
246 ctx=bp->ptr;
247 if (size < ctx->digest->md_size)
248 return(0);
249 EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret);
250 return((int)ret);
251 }
252
253/*
254static int md_puts(bp,str)
255BIO *bp;
256char *str;
257 {
258 return(-1);
259 }
260*/
261
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
new file mode 100644
index 0000000000..3d390dfbf1
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_all.c
@@ -0,0 +1,75 @@
1/* crypto/evp/c_all.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 <openssl/evp.h>
62
63#undef OpenSSL_add_all_algorithms
64
65void OpenSSL_add_all_algorithms(void)
66 {
67 OPENSSL_add_all_algorithms_noconf();
68 }
69
70void OPENSSL_add_all_algorithms_noconf(void)
71 {
72 OpenSSL_add_all_ciphers();
73 OpenSSL_add_all_digests();
74 ENGINE_setup_openbsd();
75 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
new file mode 100644
index 0000000000..a969ac69ed
--- /dev/null
+++ b/src/lib/libcrypto/evp/digest.c
@@ -0,0 +1,312 @@
1/* crypto/evp/digest.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 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113#include "cryptlib.h"
114#include <openssl/objects.h>
115#include <openssl/evp.h>
116#include <openssl/engine.h>
117
118void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
119 {
120 memset(ctx,'\0',sizeof *ctx);
121 }
122
123EVP_MD_CTX *EVP_MD_CTX_create(void)
124 {
125 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
126
127 EVP_MD_CTX_init(ctx);
128
129 return ctx;
130 }
131
132int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
133 {
134 EVP_MD_CTX_init(ctx);
135 return EVP_DigestInit_ex(ctx, type, NULL);
136 }
137
138int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
139 {
140 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
141 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
142 * so this context may already have an ENGINE! Try to avoid releasing
143 * the previous handle, re-querying for an ENGINE, and having a
144 * reinitialisation, when it may all be unecessary. */
145 if (ctx->engine && ctx->digest && (!type ||
146 (type && (type->type == ctx->digest->type))))
147 goto skip_to_init;
148 if (type)
149 {
150 /* Ensure an ENGINE left lying around from last time is cleared
151 * (the previous check attempted to avoid this if the same
152 * ENGINE and EVP_MD could be used). */
153 if(ctx->engine)
154 ENGINE_finish(ctx->engine);
155 if(impl)
156 {
157 if (!ENGINE_init(impl))
158 {
159 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
160 return 0;
161 }
162 }
163 else
164 /* Ask if an ENGINE is reserved for this job */
165 impl = ENGINE_get_digest_engine(type->type);
166 if(impl)
167 {
168 /* There's an ENGINE for this job ... (apparently) */
169 const EVP_MD *d = ENGINE_get_digest(impl, type->type);
170 if(!d)
171 {
172 /* Same comment from evp_enc.c */
173 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
174 return 0;
175 }
176 /* We'll use the ENGINE's private digest definition */
177 type = d;
178 /* Store the ENGINE functional reference so we know
179 * 'type' came from an ENGINE and we need to release
180 * it when done. */
181 ctx->engine = impl;
182 }
183 else
184 ctx->engine = NULL;
185 }
186 else if(!ctx->digest)
187 {
188 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET);
189 return 0;
190 }
191 if (ctx->digest != type)
192 {
193 if (ctx->digest && ctx->digest->ctx_size)
194 OPENSSL_free(ctx->md_data);
195 ctx->digest=type;
196 if (type->ctx_size)
197 ctx->md_data=OPENSSL_malloc(type->ctx_size);
198 }
199skip_to_init:
200 return ctx->digest->init(ctx);
201 }
202
203int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
204 unsigned int count)
205 {
206 return ctx->digest->update(ctx,data,(unsigned long)count);
207 }
208
209/* The caller can assume that this removes any secret data from the context */
210int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
211 {
212 int ret;
213 ret = EVP_DigestFinal_ex(ctx, md, size);
214 EVP_MD_CTX_cleanup(ctx);
215 return ret;
216 }
217
218/* The caller can assume that this removes any secret data from the context */
219int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
220 {
221 int ret;
222 ret=ctx->digest->final(ctx,md);
223 if (size != NULL)
224 *size=ctx->digest->md_size;
225 if (ctx->digest->cleanup)
226 {
227 ctx->digest->cleanup(ctx);
228 EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
229 }
230 memset(ctx->md_data,0,ctx->digest->ctx_size);
231 return ret;
232 }
233
234int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)
235 {
236 EVP_MD_CTX_init(out);
237 return EVP_MD_CTX_copy_ex(out, in);
238 }
239
240int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
241 {
242 if ((in == NULL) || (in->digest == NULL))
243 {
244 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
245 return 0;
246 }
247 /* Make sure it's safe to copy a digest context using an ENGINE */
248 if (in->engine && !ENGINE_init(in->engine))
249 {
250 EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB);
251 return 0;
252 }
253
254 EVP_MD_CTX_cleanup(out);
255 memcpy(out,in,sizeof *out);
256
257 if (out->digest->ctx_size)
258 {
259 out->md_data=OPENSSL_malloc(out->digest->ctx_size);
260 memcpy(out->md_data,in->md_data,out->digest->ctx_size);
261 }
262
263 if (out->digest->copy)
264 return out->digest->copy(out,in);
265
266 return 1;
267 }
268
269int EVP_Digest(void *data, unsigned int count,
270 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl)
271 {
272 EVP_MD_CTX ctx;
273 int ret;
274
275 EVP_MD_CTX_init(&ctx);
276 EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
277 ret=EVP_DigestInit_ex(&ctx, type, impl)
278 && EVP_DigestUpdate(&ctx, data, count)
279 && EVP_DigestFinal_ex(&ctx, md, size);
280 EVP_MD_CTX_cleanup(&ctx);
281
282 return ret;
283 }
284
285void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
286 {
287 EVP_MD_CTX_cleanup(ctx);
288 OPENSSL_free(ctx);
289 }
290
291/* This call frees resources associated with the context */
292int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
293 {
294 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
295 * because sometimes only copies of the context are ever finalised.
296 */
297 if (ctx->digest && ctx->digest->cleanup
298 && !EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
299 ctx->digest->cleanup(ctx);
300 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data)
301 {
302 memset(ctx->md_data,0,ctx->digest->ctx_size);
303 OPENSSL_free(ctx->md_data);
304 }
305 if(ctx->engine)
306 /* The EVP_MD we used belongs to an ENGINE, release the
307 * functional reference we held for this reason. */
308 ENGINE_finish(ctx->engine);
309 memset(ctx,'\0',sizeof *ctx);
310
311 return 1;
312 }
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
new file mode 100644
index 0000000000..c323fa2892
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -0,0 +1,101 @@
1/* ====================================================================
2 * Copyright (c) 2001 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 * openssl-core@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 */
50
51#ifndef OPENSSL_NO_AES
52#include <openssl/evp.h>
53#include <openssl/err.h>
54#include <string.h>
55#include <assert.h>
56#include <openssl/aes.h>
57#include "evp_locl.h"
58
59static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
60 const unsigned char *iv, int enc);
61
62typedef struct
63 {
64 AES_KEY ks;
65 } EVP_AES_KEY;
66
67#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
68
69IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
70 NID_aes_128, 16, 16, 16, 128,
71 0, aes_init_key, NULL,
72 EVP_CIPHER_set_asn1_iv,
73 EVP_CIPHER_get_asn1_iv,
74 NULL)
75IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
76 NID_aes_192, 16, 24, 16, 128,
77 0, aes_init_key, NULL,
78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
80 NULL)
81IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
82 NID_aes_256, 16, 32, 16, 128,
83 0, aes_init_key, NULL,
84 EVP_CIPHER_set_asn1_iv,
85 EVP_CIPHER_get_asn1_iv,
86 NULL)
87
88static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
89 const unsigned char *iv, int enc) {
90
91 if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
92 || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
93 || enc)
94 AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
95 else
96 AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
97
98 return 1;
99}
100
101#endif
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
new file mode 100644
index 0000000000..e74337567b
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_bf.c
@@ -0,0 +1,88 @@
1/* crypto/evp/e_bf.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#ifndef OPENSSL_NO_BF
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/blowfish.h>
66
67static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70typedef struct
71 {
72 BF_KEY ks;
73 } EVP_BF_KEY;
74
75#define data(ctx) EVP_C_DATA(EVP_BF_KEY,ctx)
76
77IMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
78 EVP_CIPH_VARIABLE_LENGTH, bf_init_key, NULL,
79 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
80
81static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
82 const unsigned char *iv, int enc)
83 {
84 BF_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
85 return 1;
86 }
87
88#endif
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
new file mode 100644
index 0000000000..3400fef187
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_cast.c
@@ -0,0 +1,90 @@
1/* crypto/evp/e_cast.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#ifndef OPENSSL_NO_CAST
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/cast.h>
67
68static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71typedef struct
72 {
73 CAST_KEY ks;
74 } EVP_CAST_KEY;
75
76#define data(ctx) EVP_C_DATA(EVP_CAST_KEY,ctx)
77
78IMPLEMENT_BLOCK_CIPHER(cast5, ks, CAST, EVP_CAST_KEY,
79 NID_cast5, 8, CAST_KEY_LENGTH, 8, 64,
80 EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL,
81 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
82
83static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
84 const unsigned char *iv, int enc)
85 {
86 CAST_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
87 return 1;
88 }
89
90#endif
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
new file mode 100644
index 0000000000..105266a4b3
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des.c
@@ -0,0 +1,119 @@
1/* crypto/evp/e_des.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#ifndef OPENSSL_NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv, int enc);
69
70/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
71
72static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
73 const unsigned char *in, unsigned int inl)
74{
75 BLOCK_CIPHER_ecb_loop()
76 DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);
77 return 1;
78}
79
80static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
81 const unsigned char *in, unsigned int inl)
82{
83 DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);
84 return 1;
85}
86
87static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
88 const unsigned char *in, unsigned int inl)
89{
90 DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
91 (DES_cblock *)ctx->iv, ctx->encrypt);
92 return 1;
93}
94
95static int des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
99 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
100 return 1;
101}
102
103BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
104 0, des_init_key, NULL,
105 EVP_CIPHER_set_asn1_iv,
106 EVP_CIPHER_get_asn1_iv,
107 NULL)
108
109
110static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc)
112 {
113 DES_cblock *deskey = (DES_cblock *)key;
114
115 DES_set_key_unchecked(deskey,ctx->cipher_data);
116 return 1;
117 }
118
119#endif
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
new file mode 100644
index 0000000000..077860e7b6
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des3.c
@@ -0,0 +1,193 @@
1/* crypto/evp/e_des3.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#ifndef OPENSSL_NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66
67static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69
70static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
71 const unsigned char *iv,int enc);
72
73typedef struct
74 {
75 DES_key_schedule ks1;/* key schedule */
76 DES_key_schedule ks2;/* key schedule (for ede) */
77 DES_key_schedule ks3;/* key schedule (for ede3) */
78 } DES_EDE_KEY;
79
80#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data)
81
82/* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
83
84static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
85 const unsigned char *in, unsigned int inl)
86{
87 BLOCK_CIPHER_ecb_loop()
88 DES_ecb3_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i),
89 &data(ctx)->ks1, &data(ctx)->ks2,
90 &data(ctx)->ks3,
91 ctx->encrypt);
92 return 1;
93}
94
95static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97{
98 DES_ede3_ofb64_encrypt(in, out, (long)inl,
99 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
100 (DES_cblock *)ctx->iv, &ctx->num);
101 return 1;
102}
103
104static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
105 const unsigned char *in, unsigned int inl)
106{
107#ifdef KSSL_DEBUG
108 {
109 int i;
110 char *cp;
111 printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", ctx, ctx->buf_len);
112 printf("\t iv= ");
113 for(i=0;i<8;i++)
114 printf("%02X",ctx->iv[i]);
115 printf("\n");
116 }
117#endif /* KSSL_DEBUG */
118 DES_ede3_cbc_encrypt(in, out, (long)inl,
119 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
120 (DES_cblock *)ctx->iv, ctx->encrypt);
121 return 1;
122}
123
124static int des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
125 const unsigned char *in, unsigned int inl)
126{
127 DES_ede3_cfb64_encrypt(in, out, (long)inl,
128 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
129 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
130 return 1;
131}
132
133BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
134 0, des_ede_init_key, NULL,
135 EVP_CIPHER_set_asn1_iv,
136 EVP_CIPHER_get_asn1_iv,
137 NULL)
138
139#define des_ede3_cfb_cipher des_ede_cfb_cipher
140#define des_ede3_ofb_cipher des_ede_ofb_cipher
141#define des_ede3_cbc_cipher des_ede_cbc_cipher
142#define des_ede3_ecb_cipher des_ede_ecb_cipher
143
144BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
145 0, des_ede3_init_key, NULL,
146 EVP_CIPHER_set_asn1_iv,
147 EVP_CIPHER_get_asn1_iv,
148 NULL)
149
150static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
151 const unsigned char *iv, int enc)
152 {
153 DES_cblock *deskey = (DES_cblock *)key;
154
155 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
156 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
157 memcpy(&data(ctx)->ks3,&data(ctx)->ks1,
158 sizeof(data(ctx)->ks1));
159 return 1;
160 }
161
162static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
163 const unsigned char *iv, int enc)
164 {
165 DES_cblock *deskey = (DES_cblock *)key;
166#ifdef KSSL_DEBUG
167 {
168 int i;
169 printf("des_ede3_init_key(ctx=%lx)\n", ctx);
170 printf("\tKEY= ");
171 for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
172 printf("\t IV= ");
173 for(i=0;i<8;i++) printf("%02X",iv[i]); printf("\n");
174 }
175#endif /* KSSL_DEBUG */
176
177 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
178 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
179 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3);
180
181 return 1;
182 }
183
184const EVP_CIPHER *EVP_des_ede(void)
185{
186 return &des_ede_ecb;
187}
188
189const EVP_CIPHER *EVP_des_ede3(void)
190{
191 return &des_ede3_ecb;
192}
193#endif
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
new file mode 100644
index 0000000000..ed838d3e62
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_idea.c
@@ -0,0 +1,118 @@
1/* crypto/evp/e_idea.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#ifndef OPENSSL_NO_IDEA
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/idea.h>
67
68static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71/* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special
72 * case
73 */
74
75static int idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
76 const unsigned char *in, unsigned int inl)
77{
78 BLOCK_CIPHER_ecb_loop()
79 idea_ecb_encrypt(in + i, out + i, ctx->cipher_data);
80 return 1;
81}
82
83/* Can't use IMPLEMENT_BLOCK_CIPHER because idea_ecb_encrypt is different */
84
85typedef struct
86 {
87 IDEA_KEY_SCHEDULE ks;
88 } EVP_IDEA_KEY;
89
90BLOCK_CIPHER_func_cbc(idea, idea, EVP_IDEA_KEY, ks)
91BLOCK_CIPHER_func_ofb(idea, idea, 64, EVP_IDEA_KEY, ks)
92BLOCK_CIPHER_func_cfb(idea, idea, 64, EVP_IDEA_KEY, ks)
93
94BLOCK_CIPHER_defs(idea, IDEA_KEY_SCHEDULE, NID_idea, 8, 16, 8, 64,
95 0, idea_init_key, NULL,
96 EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
97
98static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
99 const unsigned char *iv, int enc)
100 {
101 if(!enc) {
102 if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE) enc = 1;
103 else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE) enc = 1;
104 }
105 if (enc) idea_set_encrypt_key(key,ctx->cipher_data);
106 else
107 {
108 IDEA_KEY_SCHEDULE tmp;
109
110 idea_set_encrypt_key(key,&tmp);
111 idea_set_decrypt_key(&tmp,ctx->cipher_data);
112 memset((unsigned char *)&tmp,0,
113 sizeof(IDEA_KEY_SCHEDULE));
114 }
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
new file mode 100644
index 0000000000..2420d7e5af
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_null.c
@@ -0,0 +1,101 @@
1/* crypto/evp/e_null.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 <openssl/evp.h>
62#include <openssl/objects.h>
63
64static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
65 const unsigned char *iv,int enc);
66static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
67 const unsigned char *in, unsigned int inl);
68static const EVP_CIPHER n_cipher=
69 {
70 NID_undef,
71 1,0,0,
72 0,
73 null_init_key,
74 null_cipher,
75 NULL,
76 0,
77 NULL,
78 NULL,
79 NULL
80 };
81
82const EVP_CIPHER *EVP_enc_null(void)
83 {
84 return(&n_cipher);
85 }
86
87static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
88 const unsigned char *iv, int enc)
89 {
90 /* memset(&(ctx->c),0,sizeof(ctx->c));*/
91 return 1;
92 }
93
94static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
95 const unsigned char *in, unsigned int inl)
96 {
97 if (in != out)
98 memcpy((char *)out,(char *)in,(int)inl);
99 return 1;
100 }
101
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
new file mode 100644
index 0000000000..4685198e2e
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -0,0 +1,229 @@
1/* crypto/evp/e_rc2.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#ifndef OPENSSL_NO_RC2
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc2.h>
67
68static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx);
71static int rc2_magic_to_meth(int i);
72static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
73static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
75
76typedef struct
77 {
78 int key_bits; /* effective key bits */
79 RC2_KEY ks; /* key schedule */
80 } EVP_RC2_KEY;
81
82#define data(ctx) ((EVP_RC2_KEY *)(ctx)->cipher_data)
83
84IMPLEMENT_BLOCK_CIPHER(rc2, ks, RC2, EVP_RC2_KEY, NID_rc2,
85 8,
86 RC2_KEY_LENGTH, 8, 64,
87 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
88 rc2_init_key, NULL,
89 rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv,
90 rc2_ctrl)
91
92#define RC2_40_MAGIC 0xa0
93#define RC2_64_MAGIC 0x78
94#define RC2_128_MAGIC 0x3a
95
96static const EVP_CIPHER r2_64_cbc_cipher=
97 {
98 NID_rc2_64_cbc,
99 8,8 /* 64 bit */,8,
100 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
101 rc2_init_key,
102 rc2_cbc_cipher,
103 NULL,
104 sizeof(EVP_RC2_KEY),
105 rc2_set_asn1_type_and_iv,
106 rc2_get_asn1_type_and_iv,
107 rc2_ctrl,
108 NULL
109 };
110
111static const EVP_CIPHER r2_40_cbc_cipher=
112 {
113 NID_rc2_40_cbc,
114 8,5 /* 40 bit */,8,
115 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
116 rc2_init_key,
117 rc2_cbc_cipher,
118 NULL,
119 sizeof(EVP_RC2_KEY),
120 rc2_set_asn1_type_and_iv,
121 rc2_get_asn1_type_and_iv,
122 rc2_ctrl,
123 NULL
124 };
125
126const EVP_CIPHER *EVP_rc2_64_cbc(void)
127 {
128 return(&r2_64_cbc_cipher);
129 }
130
131const EVP_CIPHER *EVP_rc2_40_cbc(void)
132 {
133 return(&r2_40_cbc_cipher);
134 }
135
136static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
137 const unsigned char *iv, int enc)
138 {
139 RC2_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
140 key,data(ctx)->key_bits);
141 return 1;
142 }
143
144static int rc2_meth_to_magic(EVP_CIPHER_CTX *e)
145 {
146 int i;
147
148 EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
149 if (i == 128) return(RC2_128_MAGIC);
150 else if (i == 64) return(RC2_64_MAGIC);
151 else if (i == 40) return(RC2_40_MAGIC);
152 else return(0);
153 }
154
155static int rc2_magic_to_meth(int i)
156 {
157 if (i == RC2_128_MAGIC) return 128;
158 else if (i == RC2_64_MAGIC) return 64;
159 else if (i == RC2_40_MAGIC) return 40;
160 else
161 {
162 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
163 return(0);
164 }
165 }
166
167static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
168 {
169 long num=0;
170 int i=0,l;
171 int key_bits;
172 unsigned char iv[EVP_MAX_IV_LENGTH];
173
174 if (type != NULL)
175 {
176 l=EVP_CIPHER_CTX_iv_length(c);
177 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
178 if (i != l)
179 return(-1);
180 key_bits =rc2_magic_to_meth((int)num);
181 if (!key_bits)
182 return(-1);
183 if(i > 0) EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1);
184 EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
185 EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
186 }
187 return(i);
188 }
189
190static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
191 {
192 long num;
193 int i=0,j;
194
195 if (type != NULL)
196 {
197 num=rc2_meth_to_magic(c);
198 j=EVP_CIPHER_CTX_iv_length(c);
199 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
200 }
201 return(i);
202 }
203
204static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
205 {
206 switch(type)
207 {
208 case EVP_CTRL_INIT:
209 data(c)->key_bits = EVP_CIPHER_CTX_key_length(c) * 8;
210 return 1;
211
212 case EVP_CTRL_GET_RC2_KEY_BITS:
213 *(int *)ptr = data(c)->key_bits;
214 return 1;
215
216 case EVP_CTRL_SET_RC2_KEY_BITS:
217 if(arg > 0)
218 {
219 data(c)->key_bits = arg;
220 return 1;
221 }
222 return 0;
223
224 default:
225 return -1;
226 }
227 }
228
229#endif
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
new file mode 100644
index 0000000000..4064cc5fa0
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc4.c
@@ -0,0 +1,136 @@
1/* crypto/evp/e_rc4.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#ifndef OPENSSL_NO_RC4
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/rc4.h>
66
67/* FIXME: surely this is available elsewhere? */
68#define EVP_RC4_KEY_SIZE 16
69
70typedef struct
71 {
72 /* FIXME: what is the key for? */
73 unsigned char key[EVP_RC4_KEY_SIZE];
74 RC4_KEY ks; /* working key */
75 } EVP_RC4_KEY;
76
77#define data(ctx) ((EVP_RC4_KEY *)(ctx)->cipher_data)
78
79static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
80 const unsigned char *iv,int enc);
81static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
82 const unsigned char *in, unsigned int inl);
83static const EVP_CIPHER r4_cipher=
84 {
85 NID_rc4,
86 1,EVP_RC4_KEY_SIZE,0,
87 EVP_CIPH_VARIABLE_LENGTH,
88 rc4_init_key,
89 rc4_cipher,
90 NULL,
91 sizeof(EVP_RC4_KEY),
92 NULL,
93 NULL,
94 NULL
95 };
96
97static const EVP_CIPHER r4_40_cipher=
98 {
99 NID_rc4_40,
100 1,5 /* 40 bit */,0,
101 EVP_CIPH_VARIABLE_LENGTH,
102 rc4_init_key,
103 rc4_cipher,
104 NULL,
105 sizeof(EVP_RC4_KEY),
106 NULL,
107 NULL,
108 NULL
109 };
110
111const EVP_CIPHER *EVP_rc4(void)
112 {
113 return(&r4_cipher);
114 }
115
116const EVP_CIPHER *EVP_rc4_40(void)
117 {
118 return(&r4_40_cipher);
119 }
120
121static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
122 const unsigned char *iv, int enc)
123 {
124 memcpy(&data(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx));
125 RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
126 data(ctx)->key);
127 return 1;
128 }
129
130static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
131 const unsigned char *in, unsigned int inl)
132 {
133 RC4(&data(ctx)->ks,inl,in,out);
134 return 1;
135 }
136#endif
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
new file mode 100644
index 0000000000..a6f849e93d
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -0,0 +1,122 @@
1/* crypto/evp/e_xcbc_d.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#ifndef OPENSSL_NO_DES
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/des.h>
65
66static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
67 const unsigned char *iv,int enc);
68static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
69 const unsigned char *in, unsigned int inl);
70
71
72typedef struct
73 {
74 DES_key_schedule ks;/* key schedule */
75 DES_cblock inw;
76 DES_cblock outw;
77 } DESX_CBC_KEY;
78
79#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data)
80
81static const EVP_CIPHER d_xcbc_cipher=
82 {
83 NID_desx_cbc,
84 8,24,8,
85 EVP_CIPH_CBC_MODE,
86 desx_cbc_init_key,
87 desx_cbc_cipher,
88 NULL,
89 sizeof(DESX_CBC_KEY),
90 EVP_CIPHER_set_asn1_iv,
91 EVP_CIPHER_get_asn1_iv,
92 NULL
93 };
94
95const EVP_CIPHER *EVP_desx_cbc(void)
96 {
97 return(&d_xcbc_cipher);
98 }
99
100static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
101 const unsigned char *iv, int enc)
102 {
103 DES_cblock *deskey = (DES_cblock *)key;
104
105 DES_set_key_unchecked(deskey,&data(ctx)->ks);
106 memcpy(&data(ctx)->inw[0],&key[8],8);
107 memcpy(&data(ctx)->outw[0],&key[16],8);
108
109 return 1;
110 }
111
112static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
113 const unsigned char *in, unsigned int inl)
114 {
115 DES_xcbc_encrypt(in,out,inl,&data(ctx)->ks,
116 (DES_cblock *)&(ctx->iv[0]),
117 &data(ctx)->inw,
118 &data(ctx)->outw,
119 ctx->encrypt);
120 return 1;
121 }
122#endif
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
new file mode 100644
index 0000000000..12c6379df1
--- /dev/null
+++ b/src/lib/libcrypto/evp/encode.c
@@ -0,0 +1,444 @@
1/* crypto/evp/encode.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 <openssl/evp.h>
62
63#ifndef CHARSET_EBCDIC
64#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
65#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
66#else
67/* We assume that PEM encoded files are EBCDIC files
68 * (i.e., printable text files). Convert them here while decoding.
69 * When encoding, output is EBCDIC (text) format again.
70 * (No need for conversion in the conv_bin2ascii macro, as the
71 * underlying textstring data_bin2ascii[] is already EBCDIC)
72 */
73#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
74#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f])
75#endif
76
77/* 64 char lines
78 * pad input with 0
79 * left over chars are set to =
80 * 1 byte => xx==
81 * 2 bytes => xxx=
82 * 3 bytes => xxxx
83 */
84#define BIN_PER_LINE (64/4*3)
85#define CHUNKS_PER_LINE (64/4)
86#define CHAR_PER_LINE (64+1)
87
88static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
89abcdefghijklmnopqrstuvwxyz0123456789+/";
90
91/* 0xF0 is a EOLN
92 * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
93 * 0xF2 is EOF
94 * 0xE0 is ignore at start of line.
95 * 0xFF is error
96 */
97
98#define B64_EOLN 0xF0
99#define B64_CR 0xF1
100#define B64_EOF 0xF2
101#define B64_WS 0xE0
102#define B64_ERROR 0xFF
103#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
104
105static unsigned char data_ascii2bin[128]={
106 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
107 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
108 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
109 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
110 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
111 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F,
112 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,
113 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,
114 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06,
115 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
116 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
117 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF,
118 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,
119 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
120 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,
121 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
122 };
123
124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
125 {
126 ctx->length=48;
127 ctx->num=0;
128 ctx->line_num=0;
129 }
130
131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
132 unsigned char *in, int inl)
133 {
134 int i,j;
135 unsigned int total=0;
136
137 *outl=0;
138 if (inl == 0) return;
139 if ((ctx->num+inl) < ctx->length)
140 {
141 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
142 ctx->num+=inl;
143 return;
144 }
145 if (ctx->num != 0)
146 {
147 i=ctx->length-ctx->num;
148 memcpy(&(ctx->enc_data[ctx->num]),in,i);
149 in+=i;
150 inl-=i;
151 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
152 ctx->num=0;
153 out+=j;
154 *(out++)='\n';
155 *out='\0';
156 total=j+1;
157 }
158 while (inl >= ctx->length)
159 {
160 j=EVP_EncodeBlock(out,in,ctx->length);
161 in+=ctx->length;
162 inl-=ctx->length;
163 out+=j;
164 *(out++)='\n';
165 *out='\0';
166 total+=j+1;
167 }
168 if (inl != 0)
169 memcpy(&(ctx->enc_data[0]),in,inl);
170 ctx->num=inl;
171 *outl=total;
172 }
173
174void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
175 {
176 unsigned int ret=0;
177
178 if (ctx->num != 0)
179 {
180 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
181 out[ret++]='\n';
182 out[ret]='\0';
183 ctx->num=0;
184 }
185 *outl=ret;
186 }
187
188int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
189 {
190 int i,ret=0;
191 unsigned long l;
192
193 for (i=dlen; i > 0; i-=3)
194 {
195 if (i >= 3)
196 {
197 l= (((unsigned long)f[0])<<16L)|
198 (((unsigned long)f[1])<< 8L)|f[2];
199 *(t++)=conv_bin2ascii(l>>18L);
200 *(t++)=conv_bin2ascii(l>>12L);
201 *(t++)=conv_bin2ascii(l>> 6L);
202 *(t++)=conv_bin2ascii(l );
203 }
204 else
205 {
206 l=((unsigned long)f[0])<<16L;
207 if (i == 2) l|=((unsigned long)f[1]<<8L);
208
209 *(t++)=conv_bin2ascii(l>>18L);
210 *(t++)=conv_bin2ascii(l>>12L);
211 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
212 *(t++)='=';
213 }
214 ret+=4;
215 f+=3;
216 }
217
218 *t='\0';
219 return(ret);
220 }
221
222void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
223 {
224 ctx->length=30;
225 ctx->num=0;
226 ctx->line_num=0;
227 ctx->expect_nl=0;
228 }
229
230/* -1 for error
231 * 0 for last line
232 * 1 for full line
233 */
234int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
235 unsigned char *in, int inl)
236 {
237 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
238 unsigned char *d;
239
240 n=ctx->num;
241 d=ctx->enc_data;
242 ln=ctx->line_num;
243 exp_nl=ctx->expect_nl;
244
245 /* last line of input. */
246 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
247 { rv=0; goto end; }
248
249 /* We parse the input data */
250 for (i=0; i<inl; i++)
251 {
252 /* If the current line is > 80 characters, scream alot */
253 if (ln >= 80) { rv= -1; goto end; }
254
255 /* Get char and put it into the buffer */
256 tmp= *(in++);
257 v=conv_ascii2bin(tmp);
258 /* only save the good data :-) */
259 if (!B64_NOT_BASE64(v))
260 {
261 d[n++]=tmp;
262 ln++;
263 }
264 else if (v == B64_ERROR)
265 {
266 rv= -1;
267 goto end;
268 }
269
270 /* have we seen a '=' which is 'definitly' the last
271 * input line. seof will point to the character that
272 * holds it. and eof will hold how many characters to
273 * chop off. */
274 if (tmp == '=')
275 {
276 if (seof == -1) seof=n;
277 eof++;
278 }
279
280 if (v == B64_CR)
281 {
282 ln = 0;
283 if (exp_nl)
284 continue;
285 }
286
287 /* eoln */
288 if (v == B64_EOLN)
289 {
290 ln=0;
291 if (exp_nl)
292 {
293 exp_nl=0;
294 continue;
295 }
296 }
297 exp_nl=0;
298
299 /* If we are at the end of input and it looks like a
300 * line, process it. */
301 if (((i+1) == inl) && (((n&3) == 0) || eof))
302 {
303 v=B64_EOF;
304 /* In case things were given us in really small
305 records (so two '=' were given in separate
306 updates), eof may contain the incorrect number
307 of ending bytes to skip, so let's redo the count */
308 eof = 0;
309 if (d[n-1] == '=') eof++;
310 if (d[n-2] == '=') eof++;
311 /* There will never be more than two '=' */
312 }
313
314 if ((v == B64_EOF) || (n >= 64))
315 {
316 /* This is needed to work correctly on 64 byte input
317 * lines. We process the line and then need to
318 * accept the '\n' */
319 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
320 tmp2=v;
321 if (n > 0)
322 {
323 v=EVP_DecodeBlock(out,d,n);
324 if (v < 0) { rv=0; goto end; }
325 n=0;
326 ret+=(v-eof);
327 }
328 else
329 {
330 eof=1;
331 v=0;
332 }
333
334 /* This is the case where we have had a short
335 * but valid input line */
336 if ((v < ctx->length) && eof)
337 {
338 rv=0;
339 goto end;
340 }
341 else
342 ctx->length=v;
343
344 if (seof >= 0) { rv=0; goto end; }
345 out+=v;
346 }
347 }
348 rv=1;
349end:
350 *outl=ret;
351 ctx->num=n;
352 ctx->line_num=ln;
353 ctx->expect_nl=exp_nl;
354 return(rv);
355 }
356
357int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
358 {
359 int i,ret=0,a,b,c,d;
360 unsigned long l;
361
362 /* trim white space from the start of the line. */
363 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
364 {
365 f++;
366 n--;
367 }
368
369 /* strip off stuff at the end of the line
370 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
371 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
372 n--;
373
374 if (n%4 != 0) return(-1);
375
376 for (i=0; i<n; i+=4)
377 {
378 a=conv_ascii2bin(*(f++));
379 b=conv_ascii2bin(*(f++));
380 c=conv_ascii2bin(*(f++));
381 d=conv_ascii2bin(*(f++));
382 if ( (a & 0x80) || (b & 0x80) ||
383 (c & 0x80) || (d & 0x80))
384 return(-1);
385 l=( (((unsigned long)a)<<18L)|
386 (((unsigned long)b)<<12L)|
387 (((unsigned long)c)<< 6L)|
388 (((unsigned long)d) ));
389 *(t++)=(unsigned char)(l>>16L)&0xff;
390 *(t++)=(unsigned char)(l>> 8L)&0xff;
391 *(t++)=(unsigned char)(l )&0xff;
392 ret+=3;
393 }
394 return(ret);
395 }
396
397int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
398 {
399 int i;
400
401 *outl=0;
402 if (ctx->num != 0)
403 {
404 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
405 if (i < 0) return(-1);
406 ctx->num=0;
407 *outl=i;
408 return(1);
409 }
410 else
411 return(1);
412 }
413
414#ifdef undef
415int EVP_DecodeValid(unsigned char *buf, int len)
416 {
417 int i,num=0,bad=0;
418
419 if (len == 0) return(-1);
420 while (conv_ascii2bin(*buf) == B64_WS)
421 {
422 buf++;
423 len--;
424 if (len == 0) return(-1);
425 }
426
427 for (i=len; i >= 4; i-=4)
428 {
429 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
430 (conv_ascii2bin(buf[1]) >= 0x40) ||
431 (conv_ascii2bin(buf[2]) >= 0x40) ||
432 (conv_ascii2bin(buf[3]) >= 0x40))
433 return(-1);
434 buf+=4;
435 num+=1+(buf[2] != '=')+(buf[3] != '=');
436 }
437 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
438 return(num);
439 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
440 (conv_ascii2bin(buf[0]) == B64_EOLN))
441 return(num);
442 return(1);
443 }
444#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
new file mode 100644
index 0000000000..fb16de6852
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp.h
@@ -0,0 +1,844 @@
1/* crypto/evp/evp.h */
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#ifndef HEADER_ENVELOPE_H
60#define HEADER_ENVELOPE_H
61
62#ifdef OPENSSL_ALGORITHM_DEFINES
63# include <openssl/opensslconf.h>
64#else
65# define OPENSSL_ALGORITHM_DEFINES
66# include <openssl/opensslconf.h>
67# undef OPENSSL_ALGORITHM_DEFINES
68#endif
69
70#include <openssl/ossl_typ.h>
71
72#include <openssl/symhacks.h>
73
74#ifndef OPENSSL_NO_BIO
75#include <openssl/bio.h>
76#endif
77
78/*
79#define EVP_RC2_KEY_SIZE 16
80#define EVP_RC4_KEY_SIZE 16
81#define EVP_BLOWFISH_KEY_SIZE 16
82#define EVP_CAST5_KEY_SIZE 16
83#define EVP_RC5_32_12_16_KEY_SIZE 16
84*/
85#define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */
86#define EVP_MAX_KEY_LENGTH 32
87#define EVP_MAX_IV_LENGTH 16
88#define EVP_MAX_BLOCK_LENGTH 32
89
90#define PKCS5_SALT_LEN 8
91/* Default PKCS#5 iteration count */
92#define PKCS5_DEFAULT_ITER 2048
93
94#include <openssl/objects.h>
95
96#define EVP_PK_RSA 0x0001
97#define EVP_PK_DSA 0x0002
98#define EVP_PK_DH 0x0004
99#define EVP_PKT_SIGN 0x0010
100#define EVP_PKT_ENC 0x0020
101#define EVP_PKT_EXCH 0x0040
102#define EVP_PKS_RSA 0x0100
103#define EVP_PKS_DSA 0x0200
104#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
105
106#define EVP_PKEY_NONE NID_undef
107#define EVP_PKEY_RSA NID_rsaEncryption
108#define EVP_PKEY_RSA2 NID_rsa
109#define EVP_PKEY_DSA NID_dsa
110#define EVP_PKEY_DSA1 NID_dsa_2
111#define EVP_PKEY_DSA2 NID_dsaWithSHA
112#define EVP_PKEY_DSA3 NID_dsaWithSHA1
113#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
114#define EVP_PKEY_DH NID_dhKeyAgreement
115
116#ifdef __cplusplus
117extern "C" {
118#endif
119
120/* Type needs to be a bit field
121 * Sub-type needs to be for variations on the method, as in, can it do
122 * arbitrary encryption.... */
123struct evp_pkey_st
124 {
125 int type;
126 int save_type;
127 int references;
128 union {
129 char *ptr;
130#ifndef OPENSSL_NO_RSA
131 struct rsa_st *rsa; /* RSA */
132#endif
133#ifndef OPENSSL_NO_DSA
134 struct dsa_st *dsa; /* DSA */
135#endif
136#ifndef OPENSSL_NO_DH
137 struct dh_st *dh; /* DH */
138#endif
139 } pkey;
140 int save_parameters;
141 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
142 } /* EVP_PKEY */;
143
144#define EVP_PKEY_MO_SIGN 0x0001
145#define EVP_PKEY_MO_VERIFY 0x0002
146#define EVP_PKEY_MO_ENCRYPT 0x0004
147#define EVP_PKEY_MO_DECRYPT 0x0008
148
149#if 0
150/* This structure is required to tie the message digest and signing together.
151 * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
152 * oid, md and pkey.
153 * This is required because for various smart-card perform the digest and
154 * signing/verification on-board. To handle this case, the specific
155 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
156 * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
157 * This can either be software or a token to provide the required low level
158 * routines.
159 */
160typedef struct evp_pkey_md_st
161 {
162 int oid;
163 EVP_MD *md;
164 EVP_PKEY_METHOD *pkey;
165 } EVP_PKEY_MD;
166
167#define EVP_rsa_md2() \
168 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
169 EVP_rsa_pkcs1(),EVP_md2())
170#define EVP_rsa_md5() \
171 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
172 EVP_rsa_pkcs1(),EVP_md5())
173#define EVP_rsa_sha0() \
174 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
175 EVP_rsa_pkcs1(),EVP_sha())
176#define EVP_rsa_sha1() \
177 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
178 EVP_rsa_pkcs1(),EVP_sha1())
179#define EVP_rsa_ripemd160() \
180 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
181 EVP_rsa_pkcs1(),EVP_ripemd160())
182#define EVP_rsa_mdc2() \
183 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
184 EVP_rsa_octet_string(),EVP_mdc2())
185#define EVP_dsa_sha() \
186 EVP_PKEY_MD_add(NID_dsaWithSHA,\
187 EVP_dsa(),EVP_sha())
188#define EVP_dsa_sha1() \
189 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
190 EVP_dsa(),EVP_sha1())
191
192typedef struct evp_pkey_method_st
193 {
194 char *name;
195 int flags;
196 int type; /* RSA, DSA, an SSLeay specific constant */
197 int oid; /* For the pub-key type */
198 int encrypt_oid; /* pub/priv key encryption */
199
200 int (*sign)();
201 int (*verify)();
202 struct {
203 int (*set)(); /* get and/or set the underlying type */
204 int (*get)();
205 int (*encrypt)();
206 int (*decrypt)();
207 int (*i2d)();
208 int (*d2i)();
209 int (*dup)();
210 } pub,priv;
211 int (*set_asn1_parameters)();
212 int (*get_asn1_parameters)();
213 } EVP_PKEY_METHOD;
214#endif
215
216#ifndef EVP_MD
217struct env_md_st
218 {
219 int type;
220 int pkey_type;
221 int md_size;
222 unsigned long flags;
223 int (*init)(EVP_MD_CTX *ctx);
224 int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
225 int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
226 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
227 int (*cleanup)(EVP_MD_CTX *ctx);
228
229 /* FIXME: prototype these some day */
230 int (*sign)();
231 int (*verify)();
232 int required_pkey_type[5]; /*EVP_PKEY_xxx */
233 int block_size;
234 int ctx_size; /* how big does the ctx->md_data need to be */
235 } /* EVP_MD */;
236
237#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
238 * block */
239
240#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
241
242#ifndef OPENSSL_NO_DSA
243#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
244 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
245 EVP_PKEY_DSA4,0}
246#else
247#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
248#endif
249
250#ifndef OPENSSL_NO_RSA
251#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
252 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
253#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
254 RSA_sign_ASN1_OCTET_STRING, \
255 RSA_verify_ASN1_OCTET_STRING, \
256 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
257#else
258#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
259#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
260#endif
261
262#endif /* !EVP_MD */
263
264struct env_md_ctx_st
265 {
266 const EVP_MD *digest;
267 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
268 unsigned long flags;
269 void *md_data;
270 } /* EVP_MD_CTX */;
271
272/* values for EVP_MD_CTX flags */
273
274#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
275 * once only */
276#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been
277 * cleaned */
278
279struct evp_cipher_st
280 {
281 int nid;
282 int block_size;
283 int key_len; /* Default value for variable length ciphers */
284 int iv_len;
285 unsigned long flags; /* Various flags */
286 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
287 const unsigned char *iv, int enc); /* init key */
288 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
289 const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
290 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
291 int ctx_size; /* how big ctx->cipher_data needs to be */
292 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
293 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
294 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
295 void *app_data; /* Application data */
296 } /* EVP_CIPHER */;
297
298/* Values for cipher flags */
299
300/* Modes for ciphers */
301
302#define EVP_CIPH_STREAM_CIPHER 0x0
303#define EVP_CIPH_ECB_MODE 0x1
304#define EVP_CIPH_CBC_MODE 0x2
305#define EVP_CIPH_CFB_MODE 0x3
306#define EVP_CIPH_OFB_MODE 0x4
307#define EVP_CIPH_MODE 0x7
308/* Set if variable length cipher */
309#define EVP_CIPH_VARIABLE_LENGTH 0x8
310/* Set if the iv handling should be done by the cipher itself */
311#define EVP_CIPH_CUSTOM_IV 0x10
312/* Set if the cipher's init() function should be called if key is NULL */
313#define EVP_CIPH_ALWAYS_CALL_INIT 0x20
314/* Call ctrl() to init cipher parameters */
315#define EVP_CIPH_CTRL_INIT 0x40
316/* Don't use standard key length function */
317#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
318/* Don't use standard block padding */
319#define EVP_CIPH_NO_PADDING 0x100
320
321/* ctrl() values */
322
323#define EVP_CTRL_INIT 0x0
324#define EVP_CTRL_SET_KEY_LENGTH 0x1
325#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
326#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
327#define EVP_CTRL_GET_RC5_ROUNDS 0x4
328#define EVP_CTRL_SET_RC5_ROUNDS 0x5
329
330typedef struct evp_cipher_info_st
331 {
332 const EVP_CIPHER *cipher;
333 unsigned char iv[EVP_MAX_IV_LENGTH];
334 } EVP_CIPHER_INFO;
335
336struct evp_cipher_ctx_st
337 {
338 const EVP_CIPHER *cipher;
339 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
340 int encrypt; /* encrypt or decrypt */
341 int buf_len; /* number we have left */
342
343 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
344 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
345 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
346 int num; /* used by cfb/ofb mode */
347
348 void *app_data; /* application stuff */
349 int key_len; /* May change for variable length cipher */
350 unsigned long flags; /* Various flags */
351 void *cipher_data; /* per EVP data */
352 int final_used;
353 int block_mask;
354 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
355 } /* EVP_CIPHER_CTX */;
356
357typedef struct evp_Encode_Ctx_st
358 {
359 int num; /* number saved in a partial encode/decode */
360 int length; /* The length is either the output line length
361 * (in input bytes) or the shortest input line
362 * length that is ok. Once decoding begins,
363 * the length is adjusted up each time a longer
364 * line is decoded */
365 unsigned char enc_data[80]; /* data to encode */
366 int line_num; /* number read on current line */
367 int expect_nl;
368 } EVP_ENCODE_CTX;
369
370/* Password based encryption function */
371typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
372 ASN1_TYPE *param, const EVP_CIPHER *cipher,
373 const EVP_MD *md, int en_de);
374
375#ifndef OPENSSL_NO_RSA
376#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
377 (char *)(rsa))
378#endif
379
380#ifndef OPENSSL_NO_DSA
381#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
382 (char *)(dsa))
383#endif
384
385#ifndef OPENSSL_NO_DH
386#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
387 (char *)(dh))
388#endif
389
390/* Add some extra combinations */
391#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
392#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
393#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
394#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
395
396#define EVP_MD_type(e) ((e)->type)
397#define EVP_MD_nid(e) EVP_MD_type(e)
398#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e))
399#define EVP_MD_pkey_type(e) ((e)->pkey_type)
400#define EVP_MD_size(e) ((e)->md_size)
401#define EVP_MD_block_size(e) ((e)->block_size)
402
403#define EVP_MD_CTX_md(e) ((e)->digest)
404#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
405#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
406#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
407
408#define EVP_CIPHER_nid(e) ((e)->nid)
409#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e))
410#define EVP_CIPHER_block_size(e) ((e)->block_size)
411#define EVP_CIPHER_key_length(e) ((e)->key_len)
412#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
413#define EVP_CIPHER_flags(e) ((e)->flags)
414#define EVP_CIPHER_mode(e) (((e)->flags) & EVP_CIPH_MODE)
415
416#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
417#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
418#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
419#define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
420#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
421#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
422#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
423#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
424#define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
425#define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
426
427#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
428#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
429
430#define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
431#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
432#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
433#define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
434#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
435#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
436#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
437#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
438
439#ifdef CONST_STRICT
440void BIO_set_md(BIO *,const EVP_MD *md);
441#else
442# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
443#endif
444#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
445#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
446#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
447#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
448
449#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
450
451#define EVP_add_cipher_alias(n,alias) \
452 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
453#define EVP_add_digest_alias(n,alias) \
454 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
455#define EVP_delete_cipher_alias(alias) \
456 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
457#define EVP_delete_digest_alias(alias) \
458 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
459
460void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
461int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
462EVP_MD_CTX *EVP_MD_CTX_create(void);
463void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
464int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
465#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
466#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
467#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
468int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
469int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
470 unsigned int cnt);
471int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
472int EVP_Digest(void *data, unsigned int count,
473 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);
474
475int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
476int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
477int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
478
479int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
480void EVP_set_pw_prompt(char *prompt);
481char * EVP_get_pw_prompt(void);
482
483int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
484 const unsigned char *salt, const unsigned char *data,
485 int datal, int count, unsigned char *key,unsigned char *iv);
486
487int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
488 const unsigned char *key, const unsigned char *iv);
489int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
490 const unsigned char *key, const unsigned char *iv);
491int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
492 int *outl, const unsigned char *in, int inl);
493int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
494int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
495
496int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
497 const unsigned char *key, const unsigned char *iv);
498int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
499 const unsigned char *key, const unsigned char *iv);
500int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
501 int *outl, const unsigned char *in, int inl);
502int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
503int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
504
505int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
506 const unsigned char *key,const unsigned char *iv,
507 int enc);
508int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
509 const unsigned char *key,const unsigned char *iv,
510 int enc);
511int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
512 int *outl, const unsigned char *in, int inl);
513int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
514int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
515
516int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
517 EVP_PKEY *pkey);
518
519int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
520 unsigned int siglen,EVP_PKEY *pkey);
521
522int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,unsigned char *ek,
523 int ekl,unsigned char *iv,EVP_PKEY *priv);
524int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
525
526int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
527 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
528int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
529
530void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
531void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
532 int *outl,unsigned char *in,int inl);
533void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
534int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
535
536void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
537int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
538 unsigned char *in, int inl);
539int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
540 char *out, int *outl);
541int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
542
543void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
544int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
545int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
546int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
547int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
548
549#ifndef OPENSSL_NO_BIO
550BIO_METHOD *BIO_f_md(void);
551BIO_METHOD *BIO_f_base64(void);
552BIO_METHOD *BIO_f_cipher(void);
553BIO_METHOD *BIO_f_reliable(void);
554void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
555 unsigned char *i, int enc);
556#endif
557
558const EVP_MD *EVP_md_null(void);
559#ifndef OPENSSL_NO_MD2
560const EVP_MD *EVP_md2(void);
561#endif
562#ifndef OPENSSL_NO_MD4
563const EVP_MD *EVP_md4(void);
564#endif
565#ifndef OPENSSL_NO_MD5
566const EVP_MD *EVP_md5(void);
567#endif
568#ifndef OPENSSL_NO_SHA
569const EVP_MD *EVP_sha(void);
570const EVP_MD *EVP_sha1(void);
571const EVP_MD *EVP_dss(void);
572const EVP_MD *EVP_dss1(void);
573#endif
574#ifndef OPENSSL_NO_MDC2
575const EVP_MD *EVP_mdc2(void);
576#endif
577#ifndef OPENSSL_NO_RIPEMD
578const EVP_MD *EVP_ripemd160(void);
579#endif
580const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
581#ifndef OPENSSL_NO_DES
582const EVP_CIPHER *EVP_des_ecb(void);
583const EVP_CIPHER *EVP_des_ede(void);
584const EVP_CIPHER *EVP_des_ede3(void);
585const EVP_CIPHER *EVP_des_cfb(void);
586const EVP_CIPHER *EVP_des_ede_cfb(void);
587const EVP_CIPHER *EVP_des_ede3_cfb(void);
588const EVP_CIPHER *EVP_des_ofb(void);
589const EVP_CIPHER *EVP_des_ede_ofb(void);
590const EVP_CIPHER *EVP_des_ede3_ofb(void);
591const EVP_CIPHER *EVP_des_cbc(void);
592const EVP_CIPHER *EVP_des_ede_cbc(void);
593const EVP_CIPHER *EVP_des_ede3_cbc(void);
594const EVP_CIPHER *EVP_desx_cbc(void);
595/* This should now be supported through the dev_crypto ENGINE. But also, why are
596 * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */
597#if 0
598# ifdef OPENSSL_OPENBSD_DEV_CRYPTO
599const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
600const EVP_CIPHER *EVP_dev_crypto_rc4(void);
601const EVP_MD *EVP_dev_crypto_md5(void);
602# endif
603#endif
604#endif
605#ifndef OPENSSL_NO_RC4
606const EVP_CIPHER *EVP_rc4(void);
607const EVP_CIPHER *EVP_rc4_40(void);
608#endif
609#ifndef OPENSSL_NO_IDEA
610const EVP_CIPHER *EVP_idea_ecb(void);
611const EVP_CIPHER *EVP_idea_cfb(void);
612const EVP_CIPHER *EVP_idea_ofb(void);
613const EVP_CIPHER *EVP_idea_cbc(void);
614#endif
615#ifndef OPENSSL_NO_RC2
616const EVP_CIPHER *EVP_rc2_ecb(void);
617const EVP_CIPHER *EVP_rc2_cbc(void);
618const EVP_CIPHER *EVP_rc2_40_cbc(void);
619const EVP_CIPHER *EVP_rc2_64_cbc(void);
620const EVP_CIPHER *EVP_rc2_cfb(void);
621const EVP_CIPHER *EVP_rc2_ofb(void);
622#endif
623#ifndef OPENSSL_NO_BF
624const EVP_CIPHER *EVP_bf_ecb(void);
625const EVP_CIPHER *EVP_bf_cbc(void);
626const EVP_CIPHER *EVP_bf_cfb(void);
627const EVP_CIPHER *EVP_bf_ofb(void);
628#endif
629#ifndef OPENSSL_NO_CAST
630const EVP_CIPHER *EVP_cast5_ecb(void);
631const EVP_CIPHER *EVP_cast5_cbc(void);
632const EVP_CIPHER *EVP_cast5_cfb(void);
633const EVP_CIPHER *EVP_cast5_ofb(void);
634#endif
635#ifndef OPENSSL_NO_RC5
636const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
637const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
638const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
639const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
640#endif
641#ifndef OPENSSL_NO_AES
642const EVP_CIPHER *EVP_aes_128_ecb(void);
643const EVP_CIPHER *EVP_aes_128_cbc(void);
644const EVP_CIPHER *EVP_aes_128_cfb(void);
645const EVP_CIPHER *EVP_aes_128_ofb(void);
646#if 0
647const EVP_CIPHER *EVP_aes_128_ctr(void);
648#endif
649const EVP_CIPHER *EVP_aes_192_ecb(void);
650const EVP_CIPHER *EVP_aes_192_cbc(void);
651const EVP_CIPHER *EVP_aes_192_cfb(void);
652const EVP_CIPHER *EVP_aes_192_ofb(void);
653#if 0
654const EVP_CIPHER *EVP_aes_192_ctr(void);
655#endif
656const EVP_CIPHER *EVP_aes_256_ecb(void);
657const EVP_CIPHER *EVP_aes_256_cbc(void);
658const EVP_CIPHER *EVP_aes_256_cfb(void);
659const EVP_CIPHER *EVP_aes_256_ofb(void);
660#if 0
661const EVP_CIPHER *EVP_aes_256_ctr(void);
662#endif
663#endif
664
665void OPENSSL_add_all_algorithms_noconf(void);
666void OPENSSL_add_all_algorithms_conf(void);
667
668#ifdef OPENSSL_LOAD_CONF
669#define OpenSSL_add_all_algorithms() \
670 OPENSSL_add_all_algorithms_conf()
671#else
672#define OpenSSL_add_all_algorithms() \
673 OPENSSL_add_all_algorithms_noconf()
674#endif
675
676void OpenSSL_add_all_ciphers(void);
677void OpenSSL_add_all_digests(void);
678#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
679#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
680#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
681
682int EVP_add_cipher(const EVP_CIPHER *cipher);
683int EVP_add_digest(const EVP_MD *digest);
684
685const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
686const EVP_MD *EVP_get_digestbyname(const char *name);
687void EVP_cleanup(void);
688
689int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
690 int enc_key_len,EVP_PKEY *private_key);
691int EVP_PKEY_encrypt(unsigned char *enc_key,
692 unsigned char *key,int key_len,EVP_PKEY *pub_key);
693int EVP_PKEY_type(int type);
694int EVP_PKEY_bits(EVP_PKEY *pkey);
695int EVP_PKEY_size(EVP_PKEY *pkey);
696int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
697
698#ifndef OPENSSL_NO_RSA
699struct rsa_st;
700int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);
701struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
702#endif
703#ifndef OPENSSL_NO_DSA
704struct dsa_st;
705int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);
706struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
707#endif
708#ifndef OPENSSL_NO_DH
709struct dh_st;
710int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
711struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
712#endif
713
714
715EVP_PKEY * EVP_PKEY_new(void);
716void EVP_PKEY_free(EVP_PKEY *pkey);
717EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
718 long length);
719int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
720
721EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
722 long length);
723EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
724 long length);
725int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
726
727int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
728int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
729int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
730int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
731
732int EVP_CIPHER_type(const EVP_CIPHER *ctx);
733
734/* calls methods */
735int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
736int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
737
738/* These are used by EVP_CIPHER methods */
739int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
740int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
741
742/* PKCS5 password based encryption */
743int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
744 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
745 int en_de);
746int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
747 unsigned char *salt, int saltlen, int iter,
748 int keylen, unsigned char *out);
749int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
750 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
751 int en_de);
752
753void PKCS5_PBE_add(void);
754
755int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
756 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
757int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
758 EVP_PBE_KEYGEN *keygen);
759void EVP_PBE_cleanup(void);
760
761/* BEGIN ERROR CODES */
762/* The following lines are auto generated by the script mkerr.pl. Any changes
763 * made after this point may be overwritten when the script is next run.
764 */
765void ERR_load_EVP_strings(void);
766
767/* Error codes for the EVP functions. */
768
769/* Function codes. */
770#define EVP_F_D2I_PKEY 100
771#define EVP_F_EVP_CIPHERINIT 123
772#define EVP_F_EVP_CIPHER_CTX_CTRL 124
773#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
774#define EVP_F_EVP_DECRYPTFINAL 101
775#define EVP_F_EVP_DIGESTINIT 128
776#define EVP_F_EVP_ENCRYPTFINAL 127
777#define EVP_F_EVP_MD_CTX_COPY 110
778#define EVP_F_EVP_OPENINIT 102
779#define EVP_F_EVP_PBE_ALG_ADD 115
780#define EVP_F_EVP_PBE_CIPHERINIT 116
781#define EVP_F_EVP_PKCS82PKEY 111
782#define EVP_F_EVP_PKCS8_SET_BROKEN 112
783#define EVP_F_EVP_PKEY2PKCS8 113
784#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
785#define EVP_F_EVP_PKEY_DECRYPT 104
786#define EVP_F_EVP_PKEY_ENCRYPT 105
787#define EVP_F_EVP_PKEY_GET1_DH 119
788#define EVP_F_EVP_PKEY_GET1_DSA 120
789#define EVP_F_EVP_PKEY_GET1_RSA 121
790#define EVP_F_EVP_PKEY_NEW 106
791#define EVP_F_EVP_RIJNDAEL 126
792#define EVP_F_EVP_SIGNFINAL 107
793#define EVP_F_EVP_VERIFYFINAL 108
794#define EVP_F_PKCS5_PBE_KEYIVGEN 117
795#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
796#define EVP_F_RC2_MAGIC_TO_METH 109
797#define EVP_F_RC5_CTRL 125
798
799/* Reason codes. */
800#define EVP_R_BAD_BLOCK_LENGTH 136
801#define EVP_R_BAD_DECRYPT 100
802#define EVP_R_BAD_KEY_LENGTH 137
803#define EVP_R_BN_DECODE_ERROR 112
804#define EVP_R_BN_PUBKEY_ERROR 113
805#define EVP_R_CIPHER_PARAMETER_ERROR 122
806#define EVP_R_CTRL_NOT_IMPLEMENTED 132
807#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
808#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138
809#define EVP_R_DECODE_ERROR 114
810#define EVP_R_DIFFERENT_KEY_TYPES 101
811#define EVP_R_ENCODE_ERROR 115
812#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
813#define EVP_R_EXPECTING_AN_RSA_KEY 127
814#define EVP_R_EXPECTING_A_DH_KEY 128
815#define EVP_R_EXPECTING_A_DSA_KEY 129
816#define EVP_R_INITIALIZATION_ERROR 134
817#define EVP_R_INPUT_NOT_INITIALIZED 111
818#define EVP_R_INVALID_KEY_LENGTH 130
819#define EVP_R_IV_TOO_LARGE 102
820#define EVP_R_KEYGEN_FAILURE 120
821#define EVP_R_MISSING_PARAMETERS 103
822#define EVP_R_NO_CIPHER_SET 131
823#define EVP_R_NO_DIGEST_SET 139
824#define EVP_R_NO_DSA_PARAMETERS 116
825#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
826#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
827#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
828#define EVP_R_PUBLIC_KEY_NOT_RSA 106
829#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
830#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135
831#define EVP_R_UNSUPPORTED_CIPHER 107
832#define EVP_R_UNSUPPORTED_KEYLENGTH 123
833#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
834#define EVP_R_UNSUPPORTED_KEY_SIZE 108
835#define EVP_R_UNSUPPORTED_PRF 125
836#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
837#define EVP_R_UNSUPPORTED_SALT_TYPE 126
838#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
839#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
840
841#ifdef __cplusplus
842}
843#endif
844#endif
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
new file mode 100644
index 0000000000..32a1c7a2e9
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -0,0 +1,507 @@
1/* crypto/evp/evp_enc.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 <openssl/evp.h>
62#include <openssl/err.h>
63#include <openssl/engine.h>
64#include "evp_locl.h"
65
66#include <assert.h>
67
68const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
69
70void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
71 {
72 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
73 /* ctx->cipher=NULL; */
74 }
75
76
77int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
78 const unsigned char *key, const unsigned char *iv, int enc)
79 {
80 if (cipher)
81 EVP_CIPHER_CTX_init(ctx);
82 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
83 }
84
85int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
86 const unsigned char *key, const unsigned char *iv, int enc)
87 {
88 if (enc == -1)
89 enc = ctx->encrypt;
90 else
91 {
92 if (enc)
93 enc = 1;
94 ctx->encrypt = enc;
95 }
96 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
97 * so this context may already have an ENGINE! Try to avoid releasing
98 * the previous handle, re-querying for an ENGINE, and having a
99 * reinitialisation, when it may all be unecessary. */
100 if (ctx->engine && ctx->cipher && (!cipher ||
101 (cipher && (cipher->nid == ctx->cipher->nid))))
102 goto skip_to_init;
103 if (cipher)
104 {
105 /* Ensure a context left lying around from last time is cleared
106 * (the previous check attempted to avoid this if the same
107 * ENGINE and EVP_CIPHER could be used). */
108 EVP_CIPHER_CTX_cleanup(ctx);
109
110 /* Restore encrypt field: it is zeroed by cleanup */
111 ctx->encrypt = enc;
112 if(impl)
113 {
114 if (!ENGINE_init(impl))
115 {
116 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
117 return 0;
118 }
119 }
120 else
121 /* Ask if an ENGINE is reserved for this job */
122 impl = ENGINE_get_cipher_engine(cipher->nid);
123 if(impl)
124 {
125 /* There's an ENGINE for this job ... (apparently) */
126 const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);
127 if(!c)
128 {
129 /* One positive side-effect of US's export
130 * control history, is that we should at least
131 * be able to avoid using US mispellings of
132 * "initialisation"? */
133 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
134 return 0;
135 }
136 /* We'll use the ENGINE's private cipher definition */
137 cipher = c;
138 /* Store the ENGINE functional reference so we know
139 * 'cipher' came from an ENGINE and we need to release
140 * it when done. */
141 ctx->engine = impl;
142 }
143 else
144 ctx->engine = NULL;
145
146 ctx->cipher=cipher;
147 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
148 ctx->key_len = cipher->key_len;
149 ctx->flags = 0;
150 if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
151 {
152 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
153 {
154 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
155 return 0;
156 }
157 }
158 }
159 else if(!ctx->cipher)
160 {
161 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);
162 return 0;
163 }
164skip_to_init:
165 /* we assume block size is a power of 2 in *cryptUpdate */
166 assert(ctx->cipher->block_size == 1
167 || ctx->cipher->block_size == 8
168 || ctx->cipher->block_size == 16);
169
170 if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
171 switch(EVP_CIPHER_CTX_mode(ctx)) {
172
173 case EVP_CIPH_STREAM_CIPHER:
174 case EVP_CIPH_ECB_MODE:
175 break;
176
177 case EVP_CIPH_CFB_MODE:
178 case EVP_CIPH_OFB_MODE:
179
180 ctx->num = 0;
181
182 case EVP_CIPH_CBC_MODE:
183
184 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
185 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
186 break;
187
188 default:
189 return 0;
190 break;
191 }
192 }
193
194 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
195 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
196 }
197 ctx->buf_len=0;
198 ctx->final_used=0;
199 ctx->block_mask=ctx->cipher->block_size-1;
200 return 1;
201 }
202
203int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
204 const unsigned char *in, int inl)
205 {
206 if (ctx->encrypt)
207 return EVP_EncryptUpdate(ctx,out,outl,in,inl);
208 else return EVP_DecryptUpdate(ctx,out,outl,in,inl);
209 }
210
211int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
212 {
213 if (ctx->encrypt)
214 return EVP_EncryptFinal_ex(ctx,out,outl);
215 else return EVP_DecryptFinal_ex(ctx,out,outl);
216 }
217
218int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
219 {
220 if (ctx->encrypt)
221 return EVP_EncryptFinal(ctx,out,outl);
222 else return EVP_DecryptFinal(ctx,out,outl);
223 }
224
225int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
226 const unsigned char *key, const unsigned char *iv)
227 {
228 return EVP_CipherInit(ctx, cipher, key, iv, 1);
229 }
230
231int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
232 const unsigned char *key, const unsigned char *iv)
233 {
234 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
235 }
236
237int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
238 const unsigned char *key, const unsigned char *iv)
239 {
240 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0);
241 }
242
243int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
244 const unsigned char *key, const unsigned char *iv)
245 {
246 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
247 }
248
249int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
250 const unsigned char *in, int inl)
251 {
252 int i,j,bl;
253
254 if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
255 {
256 if(ctx->cipher->do_cipher(ctx,out,in,inl))
257 {
258 *outl=inl;
259 return 1;
260 }
261 else
262 {
263 *outl=0;
264 return 0;
265 }
266 }
267 i=ctx->buf_len;
268 bl=ctx->cipher->block_size;
269 if (i != 0)
270 {
271 if (i+inl < bl)
272 {
273 memcpy(&(ctx->buf[i]),in,inl);
274 ctx->buf_len+=inl;
275 *outl=0;
276 return 1;
277 }
278 else
279 {
280 j=bl-i;
281 memcpy(&(ctx->buf[i]),in,j);
282 if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;
283 inl-=j;
284 in+=j;
285 out+=bl;
286 *outl=bl;
287 }
288 }
289 else
290 *outl = 0;
291 i=inl&(bl-1);
292 inl-=i;
293 if (inl > 0)
294 {
295 if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;
296 *outl+=inl;
297 }
298
299 if (i != 0)
300 memcpy(ctx->buf,&(in[inl]),i);
301 ctx->buf_len=i;
302 return 1;
303 }
304
305int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
306 {
307 int ret;
308 ret = EVP_EncryptFinal_ex(ctx, out, outl);
309 return ret;
310 }
311
312int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
313 {
314 int i,n,b,bl,ret;
315
316 b=ctx->cipher->block_size;
317 if (b == 1)
318 {
319 *outl=0;
320 return 1;
321 }
322 bl=ctx->buf_len;
323 if (ctx->flags & EVP_CIPH_NO_PADDING)
324 {
325 if(bl)
326 {
327 EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
328 return 0;
329 }
330 *outl = 0;
331 return 1;
332 }
333
334 n=b-bl;
335 for (i=bl; i<b; i++)
336 ctx->buf[i]=n;
337 ret=ctx->cipher->do_cipher(ctx,out,ctx->buf,b);
338
339
340 if(ret)
341 *outl=b;
342
343 return ret;
344 }
345
346int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
347 const unsigned char *in, int inl)
348 {
349 int b, fix_len;
350
351 if (inl == 0)
352 {
353 *outl=0;
354 return 1;
355 }
356
357 if (ctx->flags & EVP_CIPH_NO_PADDING)
358 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
359
360 b=ctx->cipher->block_size;
361
362 if(ctx->final_used)
363 {
364 memcpy(out,ctx->final,b);
365 out+=b;
366 fix_len = 1;
367 }
368 else
369 fix_len = 0;
370
371
372 if(!EVP_EncryptUpdate(ctx,out,outl,in,inl))
373 return 0;
374
375 /* if we have 'decrypted' a multiple of block size, make sure
376 * we have a copy of this last block */
377 if (b > 1 && !ctx->buf_len)
378 {
379 *outl-=b;
380 ctx->final_used=1;
381 memcpy(ctx->final,&out[*outl],b);
382 }
383 else
384 ctx->final_used = 0;
385
386 if (fix_len)
387 *outl += b;
388
389 return 1;
390 }
391
392int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
393 {
394 int ret;
395 ret = EVP_DecryptFinal_ex(ctx, out, outl);
396 return ret;
397 }
398
399int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
400 {
401 int i,b;
402 int n;
403
404 *outl=0;
405 b=ctx->cipher->block_size;
406 if (ctx->flags & EVP_CIPH_NO_PADDING)
407 {
408 if(ctx->buf_len)
409 {
410 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
411 return 0;
412 }
413 *outl = 0;
414 return 1;
415 }
416 if (b > 1)
417 {
418 if (ctx->buf_len || !ctx->final_used)
419 {
420 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
421 return(0);
422 }
423 n=ctx->final[b-1];
424 if (n > b)
425 {
426 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
427 return(0);
428 }
429 for (i=0; i<n; i++)
430 {
431 if (ctx->final[--b] != n)
432 {
433 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
434 return(0);
435 }
436 }
437 n=ctx->cipher->block_size-n;
438 for (i=0; i<n; i++)
439 out[i]=ctx->final[i];
440 *outl=n;
441 }
442 else
443 *outl=0;
444 return(1);
445 }
446
447int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
448 {
449 if (c->cipher != NULL)
450 {
451 if(c->cipher->cleanup && !c->cipher->cleanup(c))
452 return 0;
453 /* Zero cipher context data */
454 if (c->cipher_data)
455 memset(c->cipher_data, 0, c->cipher->ctx_size);
456 }
457 if (c->cipher_data)
458 OPENSSL_free(c->cipher_data);
459 if (c->engine)
460 /* The EVP_CIPHER we used belongs to an ENGINE, release the
461 * functional reference we held for this reason. */
462 ENGINE_finish(c->engine);
463 memset(c,0,sizeof(EVP_CIPHER_CTX));
464 return 1;
465 }
466
467int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
468 {
469 if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
470 return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
471 if(c->key_len == keylen) return 1;
472 if((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH))
473 {
474 c->key_len = keylen;
475 return 1;
476 }
477 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,EVP_R_INVALID_KEY_LENGTH);
478 return 0;
479 }
480
481int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
482 {
483 if (pad) ctx->flags &= ~EVP_CIPH_NO_PADDING;
484 else ctx->flags |= EVP_CIPH_NO_PADDING;
485 return 1;
486 }
487
488int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
489{
490 int ret;
491 if(!ctx->cipher) {
492 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
493 return 0;
494 }
495
496 if(!ctx->cipher->ctrl) {
497 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
498 return 0;
499 }
500
501 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
502 if(ret == -1) {
503 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
504 return 0;
505 }
506 return ret;
507}
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
new file mode 100644
index 0000000000..3a23d21c21
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -0,0 +1,160 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
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 *
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 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/evp.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA EVP_str_functs[]=
68 {
69{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
70{ERR_PACK(0,EVP_F_EVP_CIPHERINIT,0), "EVP_CipherInit"},
71{ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_CTRL,0), "EVP_CIPHER_CTX_ctrl"},
72{ERR_PACK(0,EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,0), "EVP_CIPHER_CTX_set_key_length"},
73{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
74{ERR_PACK(0,EVP_F_EVP_DIGESTINIT,0), "EVP_DigestInit"},
75{ERR_PACK(0,EVP_F_EVP_ENCRYPTFINAL,0), "EVP_EncryptFinal"},
76{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
77{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
78{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
79{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
80{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
81{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
82{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
83{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
84{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
85{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
86{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DH,0), "EVP_PKEY_get1_DH"},
87{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_DSA,0), "EVP_PKEY_get1_DSA"},
88{ERR_PACK(0,EVP_F_EVP_PKEY_GET1_RSA,0), "EVP_PKEY_get1_RSA"},
89{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
90{ERR_PACK(0,EVP_F_EVP_RIJNDAEL,0), "EVP_RIJNDAEL"},
91{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
92{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
93{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
94{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
95{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
96{ERR_PACK(0,EVP_F_RC5_CTRL,0), "RC5_CTRL"},
97{0,NULL}
98 };
99
100static ERR_STRING_DATA EVP_str_reasons[]=
101 {
102{EVP_R_BAD_BLOCK_LENGTH ,"bad block length"},
103{EVP_R_BAD_DECRYPT ,"bad decrypt"},
104{EVP_R_BAD_KEY_LENGTH ,"bad key length"},
105{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
106{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
107{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
108{EVP_R_CTRL_NOT_IMPLEMENTED ,"ctrl not implemented"},
109{EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED ,"ctrl operation not implemented"},
110{EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH ,"data not multiple of block length"},
111{EVP_R_DECODE_ERROR ,"decode error"},
112{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
113{EVP_R_ENCODE_ERROR ,"encode error"},
114{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
115{EVP_R_EXPECTING_AN_RSA_KEY ,"expecting an rsa key"},
116{EVP_R_EXPECTING_A_DH_KEY ,"expecting a dh key"},
117{EVP_R_EXPECTING_A_DSA_KEY ,"expecting a dsa key"},
118{EVP_R_INITIALIZATION_ERROR ,"initialization error"},
119{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
120{EVP_R_INVALID_KEY_LENGTH ,"invalid key length"},
121{EVP_R_IV_TOO_LARGE ,"iv too large"},
122{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
123{EVP_R_MISSING_PARAMETERS ,"missing parameters"},
124{EVP_R_NO_CIPHER_SET ,"no cipher set"},
125{EVP_R_NO_DIGEST_SET ,"no digest set"},
126{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
127{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
128{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
129{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
130{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
131{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
132{EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS ,"unsuported number of rounds"},
133{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
134{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
135{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
136{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
137{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
138{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
139{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
140{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
141{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
142{0,NULL}
143 };
144
145#endif
146
147void ERR_load_EVP_strings(void)
148 {
149 static int init=1;
150
151 if (init)
152 {
153 init=0;
154#ifndef OPENSSL_NO_ERR
155 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs);
156 ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons);
157#endif
158
159 }
160 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
new file mode 100644
index 0000000000..4271393069
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -0,0 +1,172 @@
1/* crypto/evp/evp_key.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 <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/ui.h>
65
66/* should be init to zeros. */
67static char prompt_string[80];
68
69void EVP_set_pw_prompt(char *prompt)
70 {
71 if (prompt == NULL)
72 prompt_string[0]='\0';
73 else
74 {
75 strncpy(prompt_string,prompt,79);
76 prompt_string[79]='\0';
77 }
78 }
79
80char *EVP_get_pw_prompt(void)
81 {
82 if (prompt_string[0] == '\0')
83 return(NULL);
84 else
85 return(prompt_string);
86 }
87
88/* For historical reasons, the standard function for reading passwords is
89 * in the DES library -- if someone ever wants to disable DES,
90 * this function will fail */
91int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
92 {
93 int ret;
94 char buff[BUFSIZ];
95 UI *ui;
96
97 if ((prompt == NULL) && (prompt_string[0] != '\0'))
98 prompt=prompt_string;
99 ui = UI_new();
100 UI_add_input_string(ui,prompt,0,buf,0,(len>=BUFSIZ)?BUFSIZ-1:len);
101 if (verify)
102 UI_add_verify_string(ui,prompt,0,
103 buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf);
104 ret = UI_process(ui);
105 UI_free(ui);
106 memset(buff,0,BUFSIZ);
107 return ret;
108 }
109
110int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
111 const unsigned char *salt, const unsigned char *data, int datal,
112 int count, unsigned char *key, unsigned char *iv)
113 {
114 EVP_MD_CTX c;
115 unsigned char md_buf[EVP_MAX_MD_SIZE];
116 int niv,nkey,addmd=0;
117 unsigned int mds=0,i;
118
119 nkey=type->key_len;
120 niv=type->iv_len;
121
122 if (data == NULL) return(nkey);
123
124 EVP_MD_CTX_init(&c);
125 for (;;)
126 {
127 EVP_DigestInit_ex(&c,md, NULL);
128 if (addmd++)
129 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
130 EVP_DigestUpdate(&c,data,datal);
131 if (salt != NULL)
132 EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);
133 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
134
135 for (i=1; i<(unsigned int)count; i++)
136 {
137 EVP_DigestInit_ex(&c,md, NULL);
138 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
139 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
140 }
141 i=0;
142 if (nkey)
143 {
144 for (;;)
145 {
146 if (nkey == 0) break;
147 if (i == mds) break;
148 if (key != NULL)
149 *(key++)=md_buf[i];
150 nkey--;
151 i++;
152 }
153 }
154 if (niv && (i != mds))
155 {
156 for (;;)
157 {
158 if (niv == 0) break;
159 if (i == mds) break;
160 if (iv != NULL)
161 *(iv++)=md_buf[i];
162 niv--;
163 i++;
164 }
165 }
166 if ((nkey == 0) && (niv == 0)) break;
167 }
168 EVP_MD_CTX_cleanup(&c);
169 memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE);
170 return(type->key_len);
171 }
172
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
new file mode 100644
index 0000000000..a431945ef5
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -0,0 +1,142 @@
1/* crypto/evp/evp_lib.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 <openssl/evp.h>
62#include <openssl/objects.h>
63
64int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
65 {
66 int ret;
67
68 if (c->cipher->set_asn1_parameters != NULL)
69 ret=c->cipher->set_asn1_parameters(c,type);
70 else
71 ret=1;
72 return(ret);
73 }
74
75int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
76 {
77 int ret;
78
79 if (c->cipher->get_asn1_parameters != NULL)
80 ret=c->cipher->get_asn1_parameters(c,type);
81 else
82 ret=1;
83 return(ret);
84 }
85
86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
87 {
88 int i=0,l;
89
90 if (type != NULL)
91 {
92 l=EVP_CIPHER_CTX_iv_length(c);
93 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
94 if (i != l)
95 return(-1);
96 else if (i > 0)
97 memcpy(c->iv,c->oiv,l);
98 }
99 return(i);
100 }
101
102int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
103 {
104 int i=0,j;
105
106 if (type != NULL)
107 {
108 j=EVP_CIPHER_CTX_iv_length(c);
109 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
110 }
111 return(i);
112 }
113
114/* Convert the various cipher NIDs and dummies to a proper OID NID */
115int EVP_CIPHER_type(const EVP_CIPHER *ctx)
116{
117 int nid;
118 ASN1_OBJECT *otmp;
119 nid = EVP_CIPHER_nid(ctx);
120
121 switch(nid) {
122
123 case NID_rc2_cbc:
124 case NID_rc2_64_cbc:
125 case NID_rc2_40_cbc:
126
127 return NID_rc2_cbc;
128
129 case NID_rc4:
130 case NID_rc4_40:
131
132 return NID_rc4;
133
134 default:
135 /* Check it has an OID and it is valid */
136 otmp = OBJ_nid2obj(nid);
137 if(!otmp || !otmp->data) nid = NID_undef;
138 ASN1_OBJECT_free(otmp);
139 return nid;
140 }
141}
142
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
new file mode 100644
index 0000000000..7b088b4848
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -0,0 +1,227 @@
1/* evp_locl.h */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Macros to code block cipher wrappers */
60
61/* Wrapper functions for each cipher mode */
62
63#define BLOCK_CIPHER_ecb_loop() \
64 unsigned int i, bl; \
65 bl = ctx->cipher->block_size;\
66 if(inl < bl) return 1;\
67 inl -= bl; \
68 for(i=0; i <= inl; i+=bl) \
69
70#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
71static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
72{\
73 BLOCK_CIPHER_ecb_loop() \
74 cprefix##_ecb_encrypt(in + i, out + i, &((kstruct *)ctx->cipher_data)->ksched, ctx->encrypt);\
75 return 1;\
76}
77
78#define BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched) \
79static int cname##_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
80{\
81 cprefix##_ofb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num);\
82 return 1;\
83}
84
85#define BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
86static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
87{\
88 cprefix##_cbc_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, ctx->encrypt);\
89 return 1;\
90}
91
92#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
93static int cname##_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
94{\
95 cprefix##_cfb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
96 return 1;\
97}
98
99#define BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
100 BLOCK_CIPHER_func_cbc(cname, cprefix, kstruct, ksched) \
101 BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
102 BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
103 BLOCK_CIPHER_func_ofb(cname, cprefix, cbits, kstruct, ksched)
104
105#define BLOCK_CIPHER_def1(cname, nmode, mode, MODE, kstruct, nid, block_size, \
106 key_len, iv_len, flags, init_key, cleanup, \
107 set_asn1, get_asn1, ctrl) \
108static const EVP_CIPHER cname##_##mode = { \
109 nid##_##nmode, block_size, key_len, iv_len, \
110 flags | EVP_CIPH_##MODE##_MODE, \
111 init_key, \
112 cname##_##mode##_cipher, \
113 cleanup, \
114 sizeof(kstruct), \
115 set_asn1, get_asn1,\
116 ctrl, \
117 NULL \
118}; \
119const EVP_CIPHER *EVP_##cname##_##mode(void) { return &cname##_##mode; }
120
121#define BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, \
122 iv_len, flags, init_key, cleanup, set_asn1, \
123 get_asn1, ctrl) \
124BLOCK_CIPHER_def1(cname, cbc, cbc, CBC, kstruct, nid, block_size, key_len, \
125 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
126
127#define BLOCK_CIPHER_def_cfb(cname, kstruct, nid, block_size, key_len, \
128 iv_len, cbits, flags, init_key, cleanup, \
129 set_asn1, get_asn1, ctrl) \
130BLOCK_CIPHER_def1(cname, cfb##cbits, cfb, CFB, kstruct, nid, block_size, \
131 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
132 get_asn1, ctrl)
133
134#define BLOCK_CIPHER_def_ofb(cname, kstruct, nid, block_size, key_len, \
135 iv_len, cbits, flags, init_key, cleanup, \
136 set_asn1, get_asn1, ctrl) \
137BLOCK_CIPHER_def1(cname, ofb##cbits, ofb, OFB, kstruct, nid, block_size, \
138 key_len, iv_len, flags, init_key, cleanup, set_asn1, \
139 get_asn1, ctrl)
140
141#define BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, \
142 iv_len, flags, init_key, cleanup, set_asn1, \
143 get_asn1, ctrl) \
144BLOCK_CIPHER_def1(cname, ecb, ecb, ECB, kstruct, nid, block_size, key_len, \
145 iv_len, flags, init_key, cleanup, set_asn1, get_asn1, ctrl)
146
147#define BLOCK_CIPHER_defs(cname, kstruct, \
148 nid, block_size, key_len, iv_len, cbits, flags, \
149 init_key, cleanup, set_asn1, get_asn1, ctrl) \
150BLOCK_CIPHER_def_cbc(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
151 init_key, cleanup, set_asn1, get_asn1, ctrl) \
152BLOCK_CIPHER_def_cfb(cname, kstruct, nid, block_size, key_len, iv_len, cbits, \
153 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
154BLOCK_CIPHER_def_ofb(cname, kstruct, nid, block_size, key_len, iv_len, cbits, \
155 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
156BLOCK_CIPHER_def_ecb(cname, kstruct, nid, block_size, key_len, iv_len, flags, \
157 init_key, cleanup, set_asn1, get_asn1, ctrl)
158
159
160/*
161#define BLOCK_CIPHER_defs(cname, kstruct, \
162 nid, block_size, key_len, iv_len, flags,\
163 init_key, cleanup, set_asn1, get_asn1, ctrl)\
164static const EVP_CIPHER cname##_cbc = {\
165 nid##_cbc, block_size, key_len, iv_len, \
166 flags | EVP_CIPH_CBC_MODE,\
167 init_key,\
168 cname##_cbc_cipher,\
169 cleanup,\
170 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
171 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
172 set_asn1, get_asn1,\
173 ctrl, \
174 NULL \
175};\
176const EVP_CIPHER *EVP_##cname##_cbc(void) { return &cname##_cbc; }\
177static const EVP_CIPHER cname##_cfb = {\
178 nid##_cfb64, 1, key_len, iv_len, \
179 flags | EVP_CIPH_CFB_MODE,\
180 init_key,\
181 cname##_cfb_cipher,\
182 cleanup,\
183 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
184 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
185 set_asn1, get_asn1,\
186 ctrl,\
187 NULL \
188};\
189const EVP_CIPHER *EVP_##cname##_cfb(void) { return &cname##_cfb; }\
190static const EVP_CIPHER cname##_ofb = {\
191 nid##_ofb64, 1, key_len, iv_len, \
192 flags | EVP_CIPH_OFB_MODE,\
193 init_key,\
194 cname##_ofb_cipher,\
195 cleanup,\
196 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
197 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
198 set_asn1, get_asn1,\
199 ctrl,\
200 NULL \
201};\
202const EVP_CIPHER *EVP_##cname##_ofb(void) { return &cname##_ofb; }\
203static const EVP_CIPHER cname##_ecb = {\
204 nid##_ecb, block_size, key_len, iv_len, \
205 flags | EVP_CIPH_ECB_MODE,\
206 init_key,\
207 cname##_ecb_cipher,\
208 cleanup,\
209 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+\
210 sizeof((((EVP_CIPHER_CTX *)NULL)->c.kstruct)),\
211 set_asn1, get_asn1,\
212 ctrl,\
213 NULL \
214};\
215const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
216*/
217
218#define IMPLEMENT_BLOCK_CIPHER(cname, ksched, cprefix, kstruct, nid, \
219 block_size, key_len, iv_len, cbits, \
220 flags, init_key, \
221 cleanup, set_asn1, get_asn1, ctrl) \
222 BLOCK_CIPHER_all_funcs(cname, cprefix, cbits, kstruct, ksched) \
223 BLOCK_CIPHER_defs(cname, kstruct, nid, block_size, key_len, iv_len, \
224 cbits, flags, init_key, cleanup, set_asn1, \
225 get_asn1, ctrl)
226
227#define EVP_C_DATA(kstruct, ctx) ((kstruct *)(ctx)->cipher_data)
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
new file mode 100644
index 0000000000..06afb9d152
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -0,0 +1,136 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/evp.h>
61#include <openssl/x509.h>
62#include "cryptlib.h"
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72const EVP_CIPHER *cipher;
73const EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) strcpy (obj_tmp, "NULL");
91 else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if(!pass) passlen = 0;
96 else if (passlen == -1) passlen = strlen(pass);
97 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
98 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
99 pbetmp->md, en_de);
100 if (!i) {
101 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
102 return 0;
103 }
104 return 1;
105}
106
107static int pbe_cmp(const char * const *a, const char * const *b)
108{
109 EVP_PBE_CTL **pbe1 = (EVP_PBE_CTL **) a, **pbe2 = (EVP_PBE_CTL **)b;
110 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
111}
112
113/* Add a PBE algorithm */
114
115int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
116 EVP_PBE_KEYGEN *keygen)
117{
118 EVP_PBE_CTL *pbe_tmp;
119 if (!pbe_algs) pbe_algs = sk_new(pbe_cmp);
120 if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) {
121 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124 pbe_tmp->pbe_nid = nid;
125 pbe_tmp->cipher = cipher;
126 pbe_tmp->md = md;
127 pbe_tmp->keygen = keygen;
128 sk_push (pbe_algs, (char *)pbe_tmp);
129 return 1;
130}
131
132void EVP_PBE_cleanup(void)
133{
134 sk_pop_free(pbe_algs, OPENSSL_freeFunc);
135 pbe_algs = NULL;
136}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
new file mode 100644
index 0000000000..34b5b1d21c
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -0,0 +1,412 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65#ifndef OPENSSL_NO_DSA
66static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
67#endif
68
69/* Extract a private key from a PKCS8 structure */
70
71EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
72{
73 EVP_PKEY *pkey = NULL;
74#ifndef OPENSSL_NO_RSA
75 RSA *rsa = NULL;
76#endif
77#ifndef OPENSSL_NO_DSA
78 DSA *dsa = NULL;
79 ASN1_INTEGER *privkey;
80 ASN1_TYPE *t1, *t2, *param = NULL;
81 STACK_OF(ASN1_TYPE) *ndsa = NULL;
82 BN_CTX *ctx = NULL;
83 int plen;
84#endif
85 X509_ALGOR *a;
86 unsigned char *p;
87 const unsigned char *cp;
88 int pkeylen;
89 char obj_tmp[80];
90
91 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
92 p8->broken = PKCS8_OK;
93 p = p8->pkey->value.octet_string->data;
94 pkeylen = p8->pkey->value.octet_string->length;
95 } else {
96 p8->broken = PKCS8_NO_OCTET;
97 p = p8->pkey->value.sequence->data;
98 pkeylen = p8->pkey->value.sequence->length;
99 }
100 if (!(pkey = EVP_PKEY_new())) {
101 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
102 return NULL;
103 }
104 a = p8->pkeyalg;
105 switch (OBJ_obj2nid(a->algorithm))
106 {
107#ifndef OPENSSL_NO_RSA
108 case NID_rsaEncryption:
109 cp = p;
110 if (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef OPENSSL_NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,
127 d2i_ASN1_TYPE,
128 ASN1_TYPE_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 goto dsaerr;
131 }
132 if(sk_ASN1_TYPE_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 goto dsaerr;
135 }
136 /* Handle Two broken types:
137 * SEQUENCE {parameters, priv_key}
138 * SEQUENCE {pub_key, priv_key}
139 */
140
141 t1 = sk_ASN1_TYPE_value(ndsa, 0);
142 t2 = sk_ASN1_TYPE_value(ndsa, 1);
143 if(t1->type == V_ASN1_SEQUENCE) {
144 p8->broken = PKCS8_EMBEDDED_PARAM;
145 param = t1;
146 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
147 p8->broken = PKCS8_NS_DB;
148 param = a->parameter;
149 } else {
150 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
151 goto dsaerr;
152 }
153
154 if(t2->type != V_ASN1_INTEGER) {
155 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
156 goto dsaerr;
157 }
158 privkey = t2->value.integer;
159 } else {
160 if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
161 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
162 goto dsaerr;
163 }
164 param = p8->pkeyalg->parameter;
165 }
166 if (!param || (param->type != V_ASN1_SEQUENCE)) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
168 goto dsaerr;
169 }
170 cp = p = param->value.sequence->data;
171 plen = param->value.sequence->length;
172 if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {
173 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
174 goto dsaerr;
175 }
176 /* We have parameters now set private key */
177 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
178 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
179 goto dsaerr;
180 }
181 /* Calculate public key (ouch!) */
182 if (!(dsa->pub_key = BN_new())) {
183 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
184 goto dsaerr;
185 }
186 if (!(ctx = BN_CTX_new())) {
187 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
188 goto dsaerr;
189 }
190
191 if (!BN_mod_exp(dsa->pub_key, dsa->g,
192 dsa->priv_key, dsa->p, ctx)) {
193
194 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
195 goto dsaerr;
196 }
197
198 EVP_PKEY_assign_DSA(pkey, dsa);
199 BN_CTX_free (ctx);
200 if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
201 else ASN1_INTEGER_free(privkey);
202 break;
203 dsaerr:
204 BN_CTX_free (ctx);
205 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
206 DSA_free(dsa);
207 EVP_PKEY_free(pkey);
208 return NULL;
209 break;
210#endif
211 default:
212 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
213 if (!a->algorithm) strcpy (obj_tmp, "NULL");
214 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
215 ERR_add_error_data(2, "TYPE=", obj_tmp);
216 EVP_PKEY_free (pkey);
217 return NULL;
218 }
219 return pkey;
220}
221
222PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
223{
224 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
225}
226
227/* Turn a private key into a PKCS8 structure */
228
229PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
230{
231 PKCS8_PRIV_KEY_INFO *p8;
232
233 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
234 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
235 return NULL;
236 }
237 p8->broken = broken;
238 ASN1_INTEGER_set (p8->version, 0);
239 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
240 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
241 PKCS8_PRIV_KEY_INFO_free (p8);
242 return NULL;
243 }
244 p8->pkey->type = V_ASN1_OCTET_STRING;
245 switch (EVP_PKEY_type(pkey->type)) {
246#ifndef OPENSSL_NO_RSA
247 case EVP_PKEY_RSA:
248
249 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
250
251 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
252 p8->pkeyalg->parameter->type = V_ASN1_NULL;
253 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
254 &p8->pkey->value.octet_string)) {
255 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
256 PKCS8_PRIV_KEY_INFO_free (p8);
257 return NULL;
258 }
259 break;
260#endif
261#ifndef OPENSSL_NO_DSA
262 case EVP_PKEY_DSA:
263 if(!dsa_pkey2pkcs8(p8, pkey)) {
264 PKCS8_PRIV_KEY_INFO_free (p8);
265 return NULL;
266 }
267
268 break;
269#endif
270 default:
271 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
272 PKCS8_PRIV_KEY_INFO_free (p8);
273 return NULL;
274 }
275 RAND_add(p8->pkey->value.octet_string->data,
276 p8->pkey->value.octet_string->length, 0);
277 return p8;
278}
279
280PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
281{
282 switch (broken) {
283
284 case PKCS8_OK:
285 p8->broken = PKCS8_OK;
286 return p8;
287 break;
288
289 case PKCS8_NO_OCTET:
290 p8->broken = PKCS8_NO_OCTET;
291 p8->pkey->type = V_ASN1_SEQUENCE;
292 return p8;
293 break;
294
295 default:
296 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
297 return NULL;
298 break;
299
300 }
301}
302
303#ifndef OPENSSL_NO_DSA
304static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
305{
306 ASN1_STRING *params;
307 ASN1_INTEGER *prkey;
308 ASN1_TYPE *ttmp;
309 STACK_OF(ASN1_TYPE) *ndsa;
310 unsigned char *p, *q;
311 int len;
312
313 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
314 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
315 if (!(p = OPENSSL_malloc(len))) {
316 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
317 PKCS8_PRIV_KEY_INFO_free (p8);
318 return 0;
319 }
320 q = p;
321 i2d_DSAparams (pkey->pkey.dsa, &q);
322 params = ASN1_STRING_new();
323 ASN1_STRING_set(params, p, len);
324 OPENSSL_free(p);
325 /* Get private key into integer */
326 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
327 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
328 return 0;
329 }
330
331 switch(p8->broken) {
332
333 case PKCS8_OK:
334 case PKCS8_NO_OCTET:
335
336 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
337 &p8->pkey->value.octet_string)) {
338 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
339 M_ASN1_INTEGER_free (prkey);
340 return 0;
341 }
342
343 M_ASN1_INTEGER_free (prkey);
344 p8->pkeyalg->parameter->value.sequence = params;
345 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
346
347 break;
348
349 case PKCS8_NS_DB:
350
351 p8->pkeyalg->parameter->value.sequence = params;
352 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
353 ndsa = sk_ASN1_TYPE_new_null();
354 ttmp = ASN1_TYPE_new();
355 if (!(ttmp->value.integer = BN_to_ASN1_INTEGER (pkey->pkey.dsa->pub_key, NULL))) {
356 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
357 PKCS8_PRIV_KEY_INFO_free(p8);
358 return 0;
359 }
360 ttmp->type = V_ASN1_INTEGER;
361 sk_ASN1_TYPE_push(ndsa, ttmp);
362
363 ttmp = ASN1_TYPE_new();
364 ttmp->value.integer = prkey;
365 ttmp->type = V_ASN1_INTEGER;
366 sk_ASN1_TYPE_push(ndsa, ttmp);
367
368 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
369
370 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
371 &p8->pkey->value.octet_string->data,
372 &p8->pkey->value.octet_string->length)) {
373
374 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
375 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
376 M_ASN1_INTEGER_free(prkey);
377 return 0;
378 }
379 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
380 break;
381
382 case PKCS8_EMBEDDED_PARAM:
383
384 p8->pkeyalg->parameter->type = V_ASN1_NULL;
385 ndsa = sk_ASN1_TYPE_new_null();
386 ttmp = ASN1_TYPE_new();
387 ttmp->value.sequence = params;
388 ttmp->type = V_ASN1_SEQUENCE;
389 sk_ASN1_TYPE_push(ndsa, ttmp);
390
391 ttmp = ASN1_TYPE_new();
392 ttmp->value.integer = prkey;
393 ttmp->type = V_ASN1_INTEGER;
394 sk_ASN1_TYPE_push(ndsa, ttmp);
395
396 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
397
398 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
399 &p8->pkey->value.octet_string->data,
400 &p8->pkey->value.octet_string->length)) {
401
402 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
403 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
404 M_ASN1_INTEGER_free (prkey);
405 return 0;
406 }
407 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
408 break;
409 }
410 return 1;
411}
412#endif
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c
index 1bfffb34cf..90294ef686 100644
--- a/src/lib/libcrypto/evp/evp_test.c
+++ b/src/lib/libcrypto/evp/evp_test.c
@@ -118,7 +118,7 @@ static char *sstrsep(char **string, const char *delim)
118 } 118 }
119 119
120static unsigned char *ustrsep(char **p,const char *sep) 120static unsigned char *ustrsep(char **p,const char *sep)
121 { return (unsigned char *)sstrsep((char **)p,sep); } 121 { return (unsigned char *)sstrsep(p,sep); }
122 122
123static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, 123static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
124 const unsigned char *iv,int in, 124 const unsigned char *iv,int in,
@@ -358,7 +358,7 @@ int main(int argc,char **argv)
358 p[-1] = '\0'; 358 p[-1] = '\0';
359 encdec = -1; 359 encdec = -1;
360 } else { 360 } else {
361 encdec = atoi(strsep(&p,"\n")); 361 encdec = atoi(sstrsep(&p,"\n"));
362 } 362 }
363 363
364 364
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
new file mode 100644
index 0000000000..beb8d7fc5c
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_dss.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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifndef OPENSSL_NO_SHA
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD dsa_md=
76 {
77 NID_dsaWithSHA,
78 NID_dsaWithSHA,
79 SHA_DIGEST_LENGTH,
80 0,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_DSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_dss(void)
92 {
93 return(&dsa_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
new file mode 100644
index 0000000000..f5668ebda0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss1.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_dss1.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#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD dss1_md=
76 {
77 NID_dsa,
78 NID_dsaWithSHA1,
79 SHA_DIGEST_LENGTH,
80 0,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_DSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_dss1(void)
92 {
93 return(&dss1_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/m_md4.c b/src/lib/libcrypto/evp/m_md4.c
new file mode 100644
index 0000000000..e19b663754
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md4.c
@@ -0,0 +1,96 @@
1/* crypto/evp/m_md4.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#ifndef OPENSSL_NO_MD4
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/md4.h>
66
67static int init(EVP_MD_CTX *ctx)
68 { return MD4_Init(ctx->md_data); }
69
70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
71 { return MD4_Update(ctx->md_data,data,count); }
72
73static int final(EVP_MD_CTX *ctx,unsigned char *md)
74 { return MD4_Final(md,ctx->md_data); }
75
76static const EVP_MD md4_md=
77 {
78 NID_md4,
79 NID_md4WithRSAEncryption,
80 MD4_DIGEST_LENGTH,
81 0,
82 init,
83 update,
84 final,
85 NULL,
86 NULL,
87 EVP_PKEY_RSA_method,
88 MD4_CBLOCK,
89 sizeof(EVP_MD *)+sizeof(MD4_CTX),
90 };
91
92const EVP_MD *EVP_md4(void)
93 {
94 return(&md4_md);
95 }
96#endif
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
new file mode 100644
index 0000000000..b00a03e048
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md5.c
@@ -0,0 +1,96 @@
1/* crypto/evp/m_md5.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#ifndef OPENSSL_NO_MD5
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/md5.h>
66
67static int init(EVP_MD_CTX *ctx)
68 { return MD5_Init(ctx->md_data); }
69
70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
71 { return MD5_Update(ctx->md_data,data,count); }
72
73static int final(EVP_MD_CTX *ctx,unsigned char *md)
74 { return MD5_Final(md,ctx->md_data); }
75
76static const EVP_MD md5_md=
77 {
78 NID_md5,
79 NID_md5WithRSAEncryption,
80 MD5_DIGEST_LENGTH,
81 0,
82 init,
83 update,
84 final,
85 NULL,
86 NULL,
87 EVP_PKEY_RSA_method,
88 MD5_CBLOCK,
89 sizeof(EVP_MD *)+sizeof(MD5_CTX),
90 };
91
92const EVP_MD *EVP_md5(void)
93 {
94 return(&md5_md);
95 }
96#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
new file mode 100644
index 0000000000..f6f0a1d2c0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_null.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_null.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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static int init(EVP_MD_CTX *ctx)
66 { return 1; }
67
68static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
69 { return 1; }
70
71static int final(EVP_MD_CTX *ctx,unsigned char *md)
72 { return 1; }
73
74static const EVP_MD null_md=
75 {
76 NID_undef,
77 NID_undef,
78 0,
79 0,
80 init,
81 update,
82 final,
83 NULL,
84 NULL,
85 EVP_PKEY_NULL_method,
86 0,
87 sizeof(EVP_MD *),
88 };
89
90const EVP_MD *EVP_md_null(void)
91 {
92 return(&null_md);
93 }
94
95
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
new file mode 100644
index 0000000000..64725528dc
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_ripemd.c
@@ -0,0 +1,96 @@
1/* crypto/evp/m_ripemd.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#ifndef OPENSSL_NO_RIPEMD
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/ripemd.h>
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67static int init(EVP_MD_CTX *ctx)
68 { return RIPEMD160_Init(ctx->md_data); }
69
70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
71 { return RIPEMD160_Update(ctx->md_data,data,count); }
72
73static int final(EVP_MD_CTX *ctx,unsigned char *md)
74 { return RIPEMD160_Final(md,ctx->md_data); }
75
76static const EVP_MD ripemd160_md=
77 {
78 NID_ripemd160,
79 NID_ripemd160WithRSA,
80 RIPEMD160_DIGEST_LENGTH,
81 0,
82 init,
83 update,
84 final,
85 NULL,
86 NULL,
87 EVP_PKEY_RSA_method,
88 RIPEMD160_CBLOCK,
89 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
90 };
91
92const EVP_MD *EVP_ripemd160(void)
93 {
94 return(&ripemd160_md);
95 }
96#endif
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
new file mode 100644
index 0000000000..d6be3502f0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -0,0 +1,95 @@
1/* crypto/evp/m_sha1.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#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66static int init(EVP_MD_CTX *ctx)
67 { return SHA1_Init(ctx->md_data); }
68
69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70 { return SHA1_Update(ctx->md_data,data,count); }
71
72static int final(EVP_MD_CTX *ctx,unsigned char *md)
73 { return SHA1_Final(md,ctx->md_data); }
74
75static const EVP_MD sha1_md=
76 {
77 NID_sha1,
78 NID_sha1WithRSAEncryption,
79 SHA_DIGEST_LENGTH,
80 0,
81 init,
82 update,
83 final,
84 NULL,
85 NULL,
86 EVP_PKEY_RSA_method,
87 SHA_CBLOCK,
88 sizeof(EVP_MD *)+sizeof(SHA_CTX),
89 };
90
91const EVP_MD *EVP_sha1(void)
92 {
93 return(&sha1_md);
94 }
95#endif
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
new file mode 100644
index 0000000000..eb9f4329cd
--- /dev/null
+++ b/src/lib/libcrypto/evp/names.c
@@ -0,0 +1,123 @@
1/* crypto/evp/names.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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_add_cipher(const EVP_CIPHER *c)
66 {
67 int r;
68
69 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
70 if (r == 0) return(0);
71 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
72 return(r);
73 }
74
75int EVP_add_digest(const EVP_MD *md)
76 {
77 int r;
78 const char *name;
79
80 name=OBJ_nid2sn(md->type);
81 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
82 if (r == 0) return(0);
83 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
84 if (r == 0) return(0);
85
86 if (md->type != md->pkey_type)
87 {
88 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
89 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
90 if (r == 0) return(0);
91 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
93 }
94 return(r);
95 }
96
97const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
98 {
99 const EVP_CIPHER *cp;
100
101 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
102 return(cp);
103 }
104
105const EVP_MD *EVP_get_digestbyname(const char *name)
106 {
107 const EVP_MD *cp;
108
109 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
110 return(cp);
111 }
112
113void EVP_cleanup(void)
114 {
115 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
116 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
117 /* The above calls will only clean out the contents of the name
118 hash table, but not the hash table itself. The following line
119 does that part. -- Richard Levitte */
120 OBJ_NAME_cleanup(-1);
121
122 EVP_PBE_cleanup();
123 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
new file mode 100644
index 0000000000..113c60fedb
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -0,0 +1,151 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include "cryptlib.h"
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef OPENSSL_NO_DES
71# ifndef OPENSSL_NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef OPENSSL_NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef OPENSSL_NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef OPENSSL_NO_RC2
85# ifndef OPENSSL_NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef OPENSSL_NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef OPENSSL_NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef OPENSSL_NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 if(!pass) passlen = 0;
129 else if(passlen == -1) passlen = strlen(pass);
130
131 EVP_MD_CTX_init(&ctx);
132 EVP_DigestInit_ex(&ctx, md, NULL);
133 EVP_DigestUpdate(&ctx, pass, passlen);
134 EVP_DigestUpdate(&ctx, salt, saltlen);
135 PBEPARAM_free(pbe);
136 EVP_DigestFinal_ex(&ctx, md_tmp, NULL);
137 for (i = 1; i < iter; i++) {
138 EVP_DigestInit_ex(&ctx, md, NULL);
139 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
140 EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
141 }
142 EVP_MD_CTX_cleanup(&ctx);
143 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
144 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
145 EVP_CIPHER_iv_length(cipher));
146 EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de);
147 memset(md_tmp, 0, EVP_MAX_MD_SIZE);
148 memset(key, 0, EVP_MAX_KEY_LENGTH);
149 memset(iv, 0, EVP_MAX_IV_LENGTH);
150 return 1;
151}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
new file mode 100644
index 0000000000..7881860b53
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -0,0 +1,250 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include "cryptlib.h"
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87
88 HMAC_CTX_init(&hctx);
89 p = out;
90 tkeylen = keylen;
91 if(!pass) passlen = 0;
92 else if(passlen == -1) passlen = strlen(pass);
93 while(tkeylen) {
94 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
95 else cplen = tkeylen;
96 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
97 * but just in case...
98 */
99 itmp[0] = (unsigned char)((i >> 24) & 0xff);
100 itmp[1] = (unsigned char)((i >> 16) & 0xff);
101 itmp[2] = (unsigned char)((i >> 8) & 0xff);
102 itmp[3] = (unsigned char)(i & 0xff);
103 HMAC_Init_ex(&hctx, pass, passlen, EVP_sha1(), NULL);
104 HMAC_Update(&hctx, salt, saltlen);
105 HMAC_Update(&hctx, itmp, 4);
106 HMAC_Final(&hctx, digtmp, NULL);
107 memcpy(p, digtmp, cplen);
108 for(j = 1; j < iter; j++) {
109 HMAC(EVP_sha1(), pass, passlen,
110 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
111 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
112 }
113 tkeylen-= cplen;
114 i++;
115 p+= cplen;
116 }
117 HMAC_CTX_cleanup(&hctx);
118#ifdef DEBUG_PKCS5V2
119 fprintf(stderr, "Password:\n");
120 h__dump (pass, passlen);
121 fprintf(stderr, "Salt:\n");
122 h__dump (salt, saltlen);
123 fprintf(stderr, "Iteration count %d\n", iter);
124 fprintf(stderr, "Key:\n");
125 h__dump (out, keylen);
126#endif
127 return 1;
128}
129
130#ifdef DO_TEST
131main()
132{
133 unsigned char out[4];
134 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
135 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
136 fprintf(stderr, "Out %02X %02X %02X %02X\n",
137 out[0], out[1], out[2], out[3]);
138}
139
140#endif
141
142/* Now the key derivation function itself. This is a bit evil because
143 * it has to check the ASN1 parameters are valid: and there are quite a
144 * few of them...
145 */
146
147int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
148 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md,
149 int en_de)
150{
151 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
152 int saltlen, keylen, iter, plen;
153 PBE2PARAM *pbe2 = NULL;
154 const EVP_CIPHER *cipher;
155 PBKDF2PARAM *kdf = NULL;
156
157 pbuf = param->value.sequence->data;
158 plen = param->value.sequence->length;
159 if(!param || (param->type != V_ASN1_SEQUENCE) ||
160 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
162 return 0;
163 }
164
165 /* See if we recognise the key derivation function */
166
167 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
168 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
169 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
170 goto err;
171 }
172
173 /* lets see if we recognise the encryption algorithm.
174 */
175
176 cipher = EVP_get_cipherbyname(
177 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
178
179 if(!cipher) {
180 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
181 EVP_R_UNSUPPORTED_CIPHER);
182 goto err;
183 }
184
185 /* Fixup cipher based on AlgorithmIdentifier */
186 EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de);
187 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
188 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
189 EVP_R_CIPHER_PARAMETER_ERROR);
190 goto err;
191 }
192 keylen = EVP_CIPHER_CTX_key_length(ctx);
193
194 /* Now decode key derivation function */
195
196 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
197 plen = pbe2->keyfunc->parameter->value.sequence->length;
198 if(!pbe2->keyfunc->parameter ||
199 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
200 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
201 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
202 goto err;
203 }
204
205 PBE2PARAM_free(pbe2);
206 pbe2 = NULL;
207
208 /* Now check the parameters of the kdf */
209
210 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
211 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
212 EVP_R_UNSUPPORTED_KEYLENGTH);
213 goto err;
214 }
215
216 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
217 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
218 goto err;
219 }
220
221 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
222 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
223 EVP_R_UNSUPPORTED_SALT_TYPE);
224 goto err;
225 }
226
227 /* it seems that its all OK */
228 salt = kdf->salt->value.octet_string->data;
229 saltlen = kdf->salt->value.octet_string->length;
230 iter = ASN1_INTEGER_get(kdf->iter);
231 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
232 EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
233 memset(key, 0, keylen);
234 PBKDF2PARAM_free(kdf);
235 return 1;
236
237 err:
238 PBE2PARAM_free(pbe2);
239 PBKDF2PARAM_free(kdf);
240 return 0;
241}
242
243#ifdef DEBUG_PKCS5V2
244static void h__dump (const unsigned char *p, int len)
245{
246 for (; len --; p++) fprintf(stderr, "%02X ", *p);
247 fprintf(stderr, "\n");
248}
249#endif
250#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
new file mode 100644
index 0000000000..8af620400e
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_dec.c
@@ -0,0 +1,87 @@
1/* crypto/evp/p_dec.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 <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
70 EVP_PKEY *priv)
71 {
72 int ret= -1;
73
74#ifndef OPENSSL_NO_RSA
75 if (priv->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef OPENSSL_NO_RSA
80 goto err;
81 }
82
83 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
84err:
85#endif
86 return(ret);
87 }
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
new file mode 100644
index 0000000000..656883b996
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_enc.c
@@ -0,0 +1,86 @@
1/* crypto/evp/p_enc.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 <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
70 EVP_PKEY *pubk)
71 {
72 int ret=0;
73
74#ifndef OPENSSL_NO_RSA
75 if (pubk->type != EVP_PKEY_RSA)
76 {
77#endif
78 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef OPENSSL_NO_RSA
80 goto err;
81 }
82 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
83err:
84#endif
85 return(ret);
86 }
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
new file mode 100644
index 0000000000..215b94292a
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -0,0 +1,337 @@
1/* crypto/evp/p_lib.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 <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509.h>
65
66static void EVP_PKEY_free_it(EVP_PKEY *x);
67
68int EVP_PKEY_bits(EVP_PKEY *pkey)
69 {
70#ifndef OPENSSL_NO_RSA
71 if (pkey->type == EVP_PKEY_RSA)
72 return(BN_num_bits(pkey->pkey.rsa->n));
73 else
74#endif
75#ifndef OPENSSL_NO_DSA
76 if (pkey->type == EVP_PKEY_DSA)
77 return(BN_num_bits(pkey->pkey.dsa->p));
78#endif
79 return(0);
80 }
81
82int EVP_PKEY_size(EVP_PKEY *pkey)
83 {
84 if (pkey == NULL)
85 return(0);
86#ifndef OPENSSL_NO_RSA
87 if (pkey->type == EVP_PKEY_RSA)
88 return(RSA_size(pkey->pkey.rsa));
89 else
90#endif
91#ifndef OPENSSL_NO_DSA
92 if (pkey->type == EVP_PKEY_DSA)
93 return(DSA_size(pkey->pkey.dsa));
94#endif
95 return(0);
96 }
97
98int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
99 {
100#ifndef OPENSSL_NO_DSA
101 if (pkey->type == EVP_PKEY_DSA)
102 {
103 int ret=pkey->save_parameters;
104
105 if (mode >= 0)
106 pkey->save_parameters=mode;
107 return(ret);
108 }
109#endif
110 return(0);
111 }
112
113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
114 {
115 if (to->type != from->type)
116 {
117 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
118 goto err;
119 }
120
121 if (EVP_PKEY_missing_parameters(from))
122 {
123 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
124 goto err;
125 }
126#ifndef OPENSSL_NO_DSA
127 if (to->type == EVP_PKEY_DSA)
128 {
129 BIGNUM *a;
130
131 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
132 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
133 to->pkey.dsa->p=a;
134
135 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
136 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
137 to->pkey.dsa->q=a;
138
139 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
140 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
141 to->pkey.dsa->g=a;
142 }
143#endif
144 return(1);
145err:
146 return(0);
147 }
148
149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
150 {
151#ifndef OPENSSL_NO_DSA
152 if (pkey->type == EVP_PKEY_DSA)
153 {
154 DSA *dsa;
155
156 dsa=pkey->pkey.dsa;
157 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
158 return(1);
159 }
160#endif
161 return(0);
162 }
163
164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
165 {
166#ifndef OPENSSL_NO_DSA
167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
168 {
169 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
170 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
171 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
172 return(0);
173 else
174 return(1);
175 }
176#endif
177 return(-1);
178 }
179
180EVP_PKEY *EVP_PKEY_new(void)
181 {
182 EVP_PKEY *ret;
183
184 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
185 if (ret == NULL)
186 {
187 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
188 return(NULL);
189 }
190 ret->type=EVP_PKEY_NONE;
191 ret->references=1;
192 ret->pkey.ptr=NULL;
193 ret->attributes=NULL;
194 ret->save_parameters=1;
195 return(ret);
196 }
197
198int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
199 {
200 if (pkey == NULL) return(0);
201 if (pkey->pkey.ptr != NULL)
202 EVP_PKEY_free_it(pkey);
203 pkey->type=EVP_PKEY_type(type);
204 pkey->save_type=type;
205 pkey->pkey.ptr=key;
206 return(key != NULL);
207 }
208
209#ifndef OPENSSL_NO_RSA
210int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
211{
212 int ret = EVP_PKEY_assign_RSA(pkey, key);
213 if(ret)
214 RSA_up_ref(key);
215 return ret;
216}
217
218RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
219 {
220 if(pkey->type != EVP_PKEY_RSA) {
221 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
222 return NULL;
223 }
224 RSA_up_ref(pkey->pkey.rsa);
225 return pkey->pkey.rsa;
226}
227#endif
228
229#ifndef OPENSSL_NO_DSA
230int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
231{
232 int ret = EVP_PKEY_assign_DSA(pkey, key);
233 if(ret)
234 DSA_up_ref(key);
235 return ret;
236}
237
238DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
239 {
240 if(pkey->type != EVP_PKEY_DSA) {
241 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
242 return NULL;
243 }
244 DSA_up_ref(pkey->pkey.dsa);
245 return pkey->pkey.dsa;
246}
247#endif
248
249#ifndef OPENSSL_NO_DH
250
251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
252{
253 int ret = EVP_PKEY_assign_DH(pkey, key);
254 if(ret)
255 DH_up_ref(key);
256 return ret;
257}
258
259DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
260 {
261 if(pkey->type != EVP_PKEY_DH) {
262 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
263 return NULL;
264 }
265 DH_up_ref(pkey->pkey.dh);
266 return pkey->pkey.dh;
267}
268#endif
269
270int EVP_PKEY_type(int type)
271 {
272 switch (type)
273 {
274 case EVP_PKEY_RSA:
275 case EVP_PKEY_RSA2:
276 return(EVP_PKEY_RSA);
277 case EVP_PKEY_DSA:
278 case EVP_PKEY_DSA1:
279 case EVP_PKEY_DSA2:
280 case EVP_PKEY_DSA3:
281 case EVP_PKEY_DSA4:
282 return(EVP_PKEY_DSA);
283 case EVP_PKEY_DH:
284 return(EVP_PKEY_DH);
285 default:
286 return(NID_undef);
287 }
288 }
289
290void EVP_PKEY_free(EVP_PKEY *x)
291 {
292 int i;
293
294 if (x == NULL) return;
295
296 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
297#ifdef REF_PRINT
298 REF_PRINT("EVP_PKEY",x);
299#endif
300 if (i > 0) return;
301#ifdef REF_CHECK
302 if (i < 0)
303 {
304 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
305 abort();
306 }
307#endif
308 EVP_PKEY_free_it(x);
309 OPENSSL_free(x);
310 }
311
312static void EVP_PKEY_free_it(EVP_PKEY *x)
313 {
314 switch (x->type)
315 {
316#ifndef OPENSSL_NO_RSA
317 case EVP_PKEY_RSA:
318 case EVP_PKEY_RSA2:
319 RSA_free(x->pkey.rsa);
320 break;
321#endif
322#ifndef OPENSSL_NO_DSA
323 case EVP_PKEY_DSA:
324 case EVP_PKEY_DSA2:
325 case EVP_PKEY_DSA3:
326 case EVP_PKEY_DSA4:
327 DSA_free(x->pkey.dsa);
328 break;
329#endif
330#ifndef OPENSSL_NO_DH
331 case EVP_PKEY_DH:
332 DH_free(x->pkey.dh);
333 break;
334#endif
335 }
336 }
337
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
new file mode 100644
index 0000000000..6976f2a867
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -0,0 +1,123 @@
1/* crypto/evp/p_open.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#ifndef OPENSSL_NO_RSA
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek,
67 int ekl, unsigned char *iv, EVP_PKEY *priv)
68 {
69 unsigned char *key=NULL;
70 int i,size=0,ret=0;
71
72 if(type) {
73 EVP_CIPHER_CTX_init(ctx);
74 if(!EVP_DecryptInit_ex(ctx,type,NULL, NULL,NULL)) return 0;
75 }
76
77 if(!priv) return 1;
78
79 if (priv->type != EVP_PKEY_RSA)
80 {
81 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
82 goto err;
83 }
84
85 size=RSA_size(priv->pkey.rsa);
86 key=(unsigned char *)OPENSSL_malloc(size+2);
87 if (key == NULL)
88 {
89 /* ERROR */
90 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
91 goto err;
92 }
93
94 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
95 if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
96 {
97 /* ERROR */
98 goto err;
99 }
100 if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv)) goto err;
101
102 ret=1;
103err:
104 if (key != NULL) memset(key,0,size);
105 OPENSSL_free(key);
106 return(ret);
107 }
108
109int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112
113 i=EVP_DecryptFinal_ex(ctx,out,outl);
114 EVP_DecryptInit_ex(ctx,NULL,NULL,NULL,NULL);
115 return(i);
116 }
117#else /* !OPENSSL_NO_RSA */
118
119# ifdef PEDANTIC
120static void *dummy=&dummy;
121# endif
122
123#endif
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
new file mode 100644
index 0000000000..37e547fe72
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_seal.c
@@ -0,0 +1,115 @@
1/* crypto/evp/p_seal.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 <openssl/rand.h>
62#ifndef OPENSSL_NO_RSA
63#include <openssl/rsa.h>
64#endif
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68
69int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
70 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
71 {
72 unsigned char key[EVP_MAX_KEY_LENGTH];
73 int i;
74
75 if(type) {
76 EVP_CIPHER_CTX_init(ctx);
77 if(!EVP_EncryptInit_ex(ctx,type,NULL,NULL,NULL)) return 0;
78 }
79 if ((npubk <= 0) || !pubk)
80 return 1;
81 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
82 return 0;
83 if (EVP_CIPHER_CTX_iv_length(ctx))
84 RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx));
85
86 if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv)) return 0;
87
88 for (i=0; i<npubk; i++)
89 {
90 ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_CTX_key_length(ctx),
91 pubk[i]);
92 if (ekl[i] <= 0) return(-1);
93 }
94 return(npubk);
95 }
96
97/* MACRO
98void EVP_SealUpdate(ctx,out,outl,in,inl)
99EVP_CIPHER_CTX *ctx;
100unsigned char *out;
101int *outl;
102unsigned char *in;
103int inl;
104 {
105 EVP_EncryptUpdate(ctx,out,outl,in,inl);
106 }
107*/
108
109int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110 {
111 int i;
112 i = EVP_EncryptFinal_ex(ctx,out,outl);
113 EVP_EncryptInit_ex(ctx,NULL,NULL,NULL,NULL);
114 return i;
115 }
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
new file mode 100644
index 0000000000..e4ae5906f5
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_sign.c
@@ -0,0 +1,114 @@
1/* crypto/evp/p_sign.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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65#ifdef undef
66void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
67 {
68 EVP_DigestInit_ex(ctx,type);
69 }
70
71void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
72 unsigned int count)
73 {
74 EVP_DigestUpdate(ctx,data,count);
75 }
76#endif
77
78int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
79 EVP_PKEY *pkey)
80 {
81 unsigned char m[EVP_MAX_MD_SIZE];
82 unsigned int m_len;
83 int i,ok=0,v;
84 MS_STATIC EVP_MD_CTX tmp_ctx;
85
86 *siglen=0;
87 EVP_MD_CTX_init(&tmp_ctx);
88 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
89 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
90 EVP_MD_CTX_cleanup(&tmp_ctx);
91 for (i=0; i<4; i++)
92 {
93 v=ctx->digest->required_pkey_type[i];
94 if (v == 0) break;
95 if (pkey->type == v)
96 {
97 ok=1;
98 break;
99 }
100 }
101 if (!ok)
102 {
103 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
104 return(0);
105 }
106 if (ctx->digest->sign == NULL)
107 {
108 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
109 return(0);
110 }
111 return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
112 pkey->pkey.ptr));
113 }
114
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
new file mode 100644
index 0000000000..d854d743a5
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -0,0 +1,101 @@
1/* crypto/evp/p_verify.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 <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66 unsigned int siglen, EVP_PKEY *pkey)
67 {
68 unsigned char m[EVP_MAX_MD_SIZE];
69 unsigned int m_len;
70 int i,ok=0,v;
71 MS_STATIC EVP_MD_CTX tmp_ctx;
72
73 for (i=0; i<4; i++)
74 {
75 v=ctx->digest->required_pkey_type[i];
76 if (v == 0) break;
77 if (pkey->type == v)
78 {
79 ok=1;
80 break;
81 }
82 }
83 if (!ok)
84 {
85 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
86 return(-1);
87 }
88 EVP_MD_CTX_init(&tmp_ctx);
89 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
90 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
91 EVP_MD_CTX_cleanup(&tmp_ctx);
92 if (ctx->digest->verify == NULL)
93 {
94 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
95 return(0);
96 }
97
98 return(ctx->digest->verify(ctx->digest->type,m,m_len,
99 sigbuf,siglen,pkey->pkey.ptr));
100 }
101