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/Makefile727
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c567
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c426
-rw-r--r--src/lib/libcrypto/evp/bio_md.c264
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c575
-rw-r--r--src/lib/libcrypto/evp/c_all.c90
-rw-r--r--src/lib/libcrypto/evp/c_allc.c225
-rw-r--r--src/lib/libcrypto/evp/c_alld.c114
-rw-r--r--src/lib/libcrypto/evp/dig_eng.c180
-rw-r--r--src/lib/libcrypto/evp/digest.c440
-rw-r--r--src/lib/libcrypto/evp/e_acss.c85
-rw-r--r--src/lib/libcrypto/evp/e_aes.c117
-rw-r--r--src/lib/libcrypto/evp/e_bf.c88
-rw-r--r--src/lib/libcrypto/evp/e_camellia.c131
-rw-r--r--src/lib/libcrypto/evp/e_cast.c90
-rw-r--r--src/lib/libcrypto/evp/e_des.c179
-rw-r--r--src/lib/libcrypto/evp/e_des3.c270
-rw-r--r--src/lib/libcrypto/evp/e_dsa.c71
-rw-r--r--src/lib/libcrypto/evp/e_idea.c118
-rw-r--r--src/lib/libcrypto/evp/e_null.c102
-rw-r--r--src/lib/libcrypto/evp/e_old.c125
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c232
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c137
-rw-r--r--src/lib/libcrypto/evp/e_rc5.c126
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c125
-rw-r--r--src/lib/libcrypto/evp/enc_min.c390
-rw-r--r--src/lib/libcrypto/evp/encode.c446
-rw-r--r--src/lib/libcrypto/evp/evp.h1064
-rw-r--r--src/lib/libcrypto/evp/evp_acnf.c73
-rw-r--r--src/lib/libcrypto/evp/evp_cnf.c125
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c440
-rw-r--r--src/lib/libcrypto/evp/evp_err.c189
-rw-r--r--src/lib/libcrypto/evp/evp_key.c175
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c278
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h252
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c137
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c794
-rw-r--r--src/lib/libcrypto/evp/evp_test.c449
-rw-r--r--src/lib/libcrypto/evp/evptests.txt321
-rw-r--r--src/lib/libcrypto/evp/m_dss.c99
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c103
-rw-r--r--src/lib/libcrypto/evp/m_ecdsa.c148
-rw-r--r--src/lib/libcrypto/evp/m_md2.c102
-rw-r--r--src/lib/libcrypto/evp/m_md4.c102
-rw-r--r--src/lib/libcrypto/evp/m_md5.c102
-rw-r--r--src/lib/libcrypto/evp/m_mdc2.c100
-rw-r--r--src/lib/libcrypto/evp/m_null.c95
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c101
-rw-r--r--src/lib/libcrypto/evp/m_sha.c101
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c209
-rw-r--r--src/lib/libcrypto/evp/names.c130
-rw-r--r--src/lib/libcrypto/evp/openbsd_hw.c446
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c159
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c263
-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.c502
-rw-r--r--src/lib/libcrypto/evp/p_open.c127
-rw-r--r--src/lib/libcrypto/evp/p_seal.c115
-rw-r--r--src/lib/libcrypto/evp/p_sign.c126
-rw-r--r--src/lib/libcrypto/evp/p_verify.c113
61 files changed, 14153 insertions, 0 deletions
diff --git a/src/lib/libcrypto/evp/Makefile b/src/lib/libcrypto/evp/Makefile
new file mode 100644
index 0000000000..c204f84c1d
--- /dev/null
+++ b/src/lib/libcrypto/evp/Makefile
@@ -0,0 +1,727 @@
1#
2# OpenSSL/crypto/evp/Makefile
3#
4
5DIR= evp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=evp_test.c
17TESTDATA=evptests.txt
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC= encode.c digest.c dig_eng.c evp_enc.c evp_key.c evp_acnf.c evp_cnf.c \
22 e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\
23 e_rc4.c e_aes.c names.c e_seed.c \
24 e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c enc_min.c \
25 m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
26 m_dss.c m_dss1.c m_mdc2.c m_ripemd.c m_ecdsa.c\
27 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
28 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
29 c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
30 evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c \
31 e_old.c
32
33LIBOBJ= encode.o digest.o dig_eng.o evp_enc.o evp_key.o evp_acnf.o evp_cnf.o \
34 e_des.o e_bf.o e_idea.o e_des3.o e_camellia.o\
35 e_rc4.o e_aes.o names.o e_seed.o \
36 e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o enc_min.o \
37 m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
38 m_dss.o m_dss1.o m_mdc2.o m_ripemd.o m_ecdsa.o\
39 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
40 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
41 c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
42 evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o \
43 e_old.o
44
45SRC= $(LIBSRC)
46
47EXHEADER= evp.h
48HEADER= $(EXHEADER)
49
50ALL= $(GENERAL) $(SRC) $(HEADER)
51
52top:
53 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
54
55all: lib
56
57lib: $(LIBOBJ)
58 $(ARX) $(LIB) $(LIBOBJ)
59 $(RANLIB) $(LIB) || echo Never mind.
60 @touch lib
61
62files:
63 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
64
65links:
66 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
67 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
68 cp $(TESTDATA) ../../test
69 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
70
71install:
72 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
73 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
74 do \
75 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
76 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
77 done;
78
79tags:
80 ctags $(SRC)
81
82tests:
83
84lint:
85 lint -DLINT $(INCLUDES) $(SRC)>fluff
86
87depend:
88 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
89 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
90
91dclean:
92 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
93 mv -f Makefile.new $(MAKEFILE)
94
95clean:
96 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
97
98# DO NOT DELETE THIS LINE -- make depend depends on it.
99
100bio_b64.o: ../../e_os.h ../../include/openssl/asn1.h
101bio_b64.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
102bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
103bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h
104bio_b64.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
105bio_b64.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
106bio_b64.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
107bio_b64.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
108bio_b64.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
109bio_b64.o: ../cryptlib.h bio_b64.c
110bio_enc.o: ../../e_os.h ../../include/openssl/asn1.h
111bio_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
112bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
113bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
114bio_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
115bio_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
116bio_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
117bio_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
118bio_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119bio_enc.o: ../cryptlib.h bio_enc.c
120bio_md.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
121bio_md.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
122bio_md.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
123bio_md.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
124bio_md.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
125bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
126bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
127bio_md.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
128bio_md.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_md.c
129bio_ok.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
130bio_ok.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
131bio_ok.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
132bio_ok.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
133bio_ok.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
134bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
135bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
136bio_ok.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
137bio_ok.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
138bio_ok.o: ../cryptlib.h bio_ok.c
139c_all.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
140c_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
141c_all.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
142c_all.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
143c_all.o: ../../include/openssl/engine.h ../../include/openssl/err.h
144c_all.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
145c_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
146c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
147c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
148c_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
149c_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
150c_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
151c_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_all.c
152c_allc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
153c_allc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
154c_allc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
155c_allc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
156c_allc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
157c_allc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
158c_allc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
159c_allc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
160c_allc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
161c_allc.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
162c_allc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
163c_allc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
164c_allc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_allc.c
165c_alld.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
166c_alld.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
167c_alld.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
168c_alld.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
169c_alld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
170c_alld.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
171c_alld.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
172c_alld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
173c_alld.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
174c_alld.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
175c_alld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
176c_alld.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
177c_alld.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_alld.c
178dig_eng.o: ../../e_os.h ../../include/openssl/asn1.h
179dig_eng.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
180dig_eng.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
181dig_eng.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
182dig_eng.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
183dig_eng.o: ../../include/openssl/err.h ../../include/openssl/evp.h
184dig_eng.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
185dig_eng.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
186dig_eng.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
187dig_eng.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
188dig_eng.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
189dig_eng.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
190dig_eng.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
191dig_eng.o: ../cryptlib.h dig_eng.c evp_locl.h
192digest.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
193digest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
194digest.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
195digest.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
196digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h
197digest.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
198digest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
199digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
200digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
201digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
202digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
203digest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
204digest.o: ../../include/openssl/x509_vfy.h ../cryptlib.h digest.c evp_locl.h
205e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
206e_aes.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
207e_aes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
208e_aes.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
209e_aes.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
210e_aes.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
211e_aes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
212e_aes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
213e_aes.o: ../../include/openssl/symhacks.h e_aes.c evp_locl.h
214e_bf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
215e_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/buffer.h
216e_bf.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
217e_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
218e_bf.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
219e_bf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
220e_bf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
221e_bf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
222e_bf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
223e_bf.o: ../cryptlib.h e_bf.c evp_locl.h
224e_camellia.o: ../../include/openssl/opensslconf.h e_camellia.c
225e_cast.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
226e_cast.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
227e_cast.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
228e_cast.o: ../../include/openssl/err.h ../../include/openssl/evp.h
229e_cast.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
230e_cast.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
231e_cast.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
232e_cast.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
233e_cast.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
234e_cast.o: ../cryptlib.h e_cast.c evp_locl.h
235e_des.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
236e_des.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
237e_des.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
238e_des.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
239e_des.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
240e_des.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
241e_des.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
242e_des.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
243e_des.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
244e_des.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
245e_des.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
246e_des.o: ../cryptlib.h e_des.c evp_locl.h
247e_des3.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
248e_des3.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
249e_des3.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
250e_des3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
251e_des3.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
252e_des3.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
253e_des3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
254e_des3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
255e_des3.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
256e_des3.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
257e_des3.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
258e_des3.o: ../cryptlib.h e_des3.c evp_locl.h
259e_idea.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
260e_idea.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
261e_idea.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
262e_idea.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
263e_idea.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
264e_idea.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
265e_idea.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
266e_idea.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
267e_idea.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
268e_idea.o: ../cryptlib.h e_idea.c evp_locl.h
269e_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
270e_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
271e_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
272e_null.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
273e_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
274e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
275e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
276e_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
277e_null.o: ../../include/openssl/symhacks.h ../cryptlib.h e_null.c
278e_old.o: e_old.c
279e_rc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
280e_rc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
281e_rc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
282e_rc2.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
283e_rc2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
284e_rc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
285e_rc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
286e_rc2.o: ../../include/openssl/rc2.h ../../include/openssl/safestack.h
287e_rc2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
288e_rc2.o: ../cryptlib.h e_rc2.c evp_locl.h
289e_rc4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
290e_rc4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
291e_rc4.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
292e_rc4.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
293e_rc4.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
294e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
295e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
296e_rc4.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
297e_rc4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
298e_rc4.o: ../cryptlib.h e_rc4.c evp_locl.h
299e_rc5.o: ../../e_os.h ../../include/openssl/bio.h
300e_rc5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
301e_rc5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
302e_rc5.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
303e_rc5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
304e_rc5.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
305e_rc5.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc5.c
306e_seed.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
307e_seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
308e_seed.o: ../../include/openssl/err.h ../../include/openssl/evp.h
309e_seed.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
310e_seed.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
311e_seed.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
312e_seed.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
313e_seed.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
314e_seed.o: e_seed.c
315e_xcbc_d.o: ../../e_os.h ../../include/openssl/asn1.h
316e_xcbc_d.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
317e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
318e_xcbc_d.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
319e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
320e_xcbc_d.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
321e_xcbc_d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
322e_xcbc_d.o: ../../include/openssl/opensslconf.h
323e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
324e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
325e_xcbc_d.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
326e_xcbc_d.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_xcbc_d.c
327enc_min.o: ../../e_os.h ../../include/openssl/asn1.h
328enc_min.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
329enc_min.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
330enc_min.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
331enc_min.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
332enc_min.o: ../../include/openssl/err.h ../../include/openssl/evp.h
333enc_min.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
334enc_min.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
335enc_min.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
336enc_min.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
337enc_min.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
338enc_min.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
339enc_min.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
340enc_min.o: ../../include/openssl/x509_vfy.h ../cryptlib.h enc_min.c evp_locl.h
341encode.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
342encode.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
343encode.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
344encode.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
345encode.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
346encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
347encode.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
348encode.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
349encode.o: ../../include/openssl/symhacks.h ../cryptlib.h encode.c
350evp_acnf.o: ../../e_os.h ../../include/openssl/asn1.h
351evp_acnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
352evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
353evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
354evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
355evp_acnf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
356evp_acnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
357evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
358evp_acnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
359evp_acnf.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_acnf.c
360evp_cnf.o: ../../e_os.h ../../include/openssl/asn1.h
361evp_cnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
362evp_cnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
363evp_cnf.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
364evp_cnf.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
365evp_cnf.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
366evp_cnf.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
367evp_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
368evp_cnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
369evp_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
370evp_cnf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
371evp_cnf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
372evp_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
373evp_cnf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
374evp_cnf.o: ../cryptlib.h evp_cnf.c
375evp_enc.o: ../../e_os.h ../../include/openssl/asn1.h
376evp_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
377evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
378evp_enc.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
379evp_enc.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
380evp_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
381evp_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
382evp_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
383evp_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
384evp_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
385evp_enc.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
386evp_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
387evp_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
388evp_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_enc.c evp_locl.h
389evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
390evp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
391evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
392evp_err.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
393evp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
394evp_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
395evp_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
396evp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
397evp_err.o: evp_err.c
398evp_key.o: ../../e_os.h ../../include/openssl/asn1.h
399evp_key.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
400evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
401evp_key.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
402evp_key.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
403evp_key.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
404evp_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
405evp_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
406evp_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
407evp_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
408evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
409evp_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
410evp_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
411evp_key.o: ../cryptlib.h evp_key.c
412evp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
413evp_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
414evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
415evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
416evp_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
417evp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
418evp_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
419evp_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
420evp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
421evp_lib.o: ../cryptlib.h evp_lib.c
422evp_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
423evp_pbe.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
424evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
425evp_pbe.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
426evp_pbe.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
427evp_pbe.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
428evp_pbe.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
429evp_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
430evp_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
431evp_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
432evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
433evp_pbe.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
434evp_pbe.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pbe.c
435evp_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
436evp_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
437evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
438evp_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
439evp_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
440evp_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
441evp_pkey.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
442evp_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
443evp_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
444evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
445evp_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
446evp_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
447evp_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
448evp_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
449evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pkey.c
450m_dss.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
451m_dss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
452m_dss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
453m_dss.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
454m_dss.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
455m_dss.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
456m_dss.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
457m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
458m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
459m_dss.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
460m_dss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
461m_dss.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
462m_dss.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_dss.c
463m_dss1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
464m_dss1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
465m_dss1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
466m_dss1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
467m_dss1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
468m_dss1.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
469m_dss1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
470m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
471m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
472m_dss1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
473m_dss1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
474m_dss1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
475m_dss1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_dss1.c
476m_ecdsa.o: ../../e_os.h ../../include/openssl/asn1.h
477m_ecdsa.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
478m_ecdsa.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
479m_ecdsa.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
480m_ecdsa.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
481m_ecdsa.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
482m_ecdsa.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
483m_ecdsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
484m_ecdsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
485m_ecdsa.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
486m_ecdsa.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
487m_ecdsa.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
488m_ecdsa.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_ecdsa.c
489m_md2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
490m_md2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
491m_md2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
492m_md2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
493m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
494m_md2.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
495m_md2.o: ../../include/openssl/md2.h ../../include/openssl/obj_mac.h
496m_md2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
497m_md2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
498m_md2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
499m_md2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
500m_md2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
501m_md2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
502m_md2.o: ../cryptlib.h evp_locl.h m_md2.c
503m_md4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
504m_md4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
505m_md4.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
506m_md4.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
507m_md4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
508m_md4.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
509m_md4.o: ../../include/openssl/md4.h ../../include/openssl/obj_mac.h
510m_md4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
511m_md4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
512m_md4.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
513m_md4.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
514m_md4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
515m_md4.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
516m_md4.o: ../cryptlib.h evp_locl.h m_md4.c
517m_md5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
518m_md5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
519m_md5.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
520m_md5.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
521m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
522m_md5.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
523m_md5.o: ../../include/openssl/md5.h ../../include/openssl/obj_mac.h
524m_md5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
525m_md5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
526m_md5.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
527m_md5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
528m_md5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
529m_md5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
530m_md5.o: ../cryptlib.h evp_locl.h m_md5.c
531m_mdc2.o: ../../e_os.h ../../include/openssl/bio.h
532m_mdc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
533m_mdc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
534m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
535m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
536m_mdc2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
537m_mdc2.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_locl.h m_mdc2.c
538m_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
539m_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
540m_null.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
541m_null.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
542m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
543m_null.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
544m_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
545m_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
546m_null.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
547m_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
548m_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
549m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
550m_null.o: ../cryptlib.h m_null.c
551m_ripemd.o: ../../e_os.h ../../include/openssl/asn1.h
552m_ripemd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
553m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
554m_ripemd.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
555m_ripemd.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
556m_ripemd.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
557m_ripemd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
558m_ripemd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
559m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
560m_ripemd.o: ../../include/openssl/pkcs7.h ../../include/openssl/ripemd.h
561m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
562m_ripemd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
563m_ripemd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
564m_ripemd.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_ripemd.c
565m_sha.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
566m_sha.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
567m_sha.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
568m_sha.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
569m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h
570m_sha.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
571m_sha.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
572m_sha.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
573m_sha.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
574m_sha.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
575m_sha.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
576m_sha.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
577m_sha.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_locl.h m_sha.c
578m_sha1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
579m_sha1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
580m_sha1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
581m_sha1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
582m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
583m_sha1.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
584m_sha1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
585m_sha1.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
586m_sha1.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
587m_sha1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
588m_sha1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
589m_sha1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
590m_sha1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_sha1.c
591names.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
592names.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
593names.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
594names.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
595names.o: ../../include/openssl/err.h ../../include/openssl/evp.h
596names.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
597names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
598names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
599names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
600names.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
601names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
602names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
603names.o: ../cryptlib.h names.c
604p5_crpt.o: ../../e_os.h ../../include/openssl/asn1.h
605p5_crpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
606p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
607p5_crpt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
608p5_crpt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
609p5_crpt.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
610p5_crpt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
611p5_crpt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
612p5_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
613p5_crpt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
614p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
615p5_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
616p5_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt.c
617p5_crpt2.o: ../../e_os.h ../../include/openssl/asn1.h
618p5_crpt2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
619p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
620p5_crpt2.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
621p5_crpt2.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
622p5_crpt2.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
623p5_crpt2.o: ../../include/openssl/hmac.h ../../include/openssl/lhash.h
624p5_crpt2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
625p5_crpt2.o: ../../include/openssl/opensslconf.h
626p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
627p5_crpt2.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
628p5_crpt2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
629p5_crpt2.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
630p5_crpt2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt2.c
631p_dec.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
632p_dec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
633p_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
634p_dec.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
635p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h
636p_dec.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
637p_dec.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
638p_dec.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
639p_dec.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
640p_dec.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
641p_dec.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
642p_dec.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
643p_dec.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
644p_dec.o: ../cryptlib.h p_dec.c
645p_enc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
646p_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
647p_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
648p_enc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
649p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
650p_enc.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
651p_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
652p_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
653p_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
654p_enc.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
655p_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
656p_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
657p_enc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
658p_enc.o: ../cryptlib.h p_enc.c
659p_lib.o: ../../e_os.h ../../include/openssl/asn1.h
660p_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
661p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
662p_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
663p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
664p_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
665p_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
666p_lib.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
667p_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
668p_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
669p_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
670p_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
671p_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
672p_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
673p_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
674p_lib.o: ../cryptlib.h p_lib.c
675p_open.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
676p_open.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
677p_open.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
678p_open.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
679p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h
680p_open.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
681p_open.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
682p_open.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
683p_open.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
684p_open.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
685p_open.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
686p_open.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
687p_open.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_open.c
688p_seal.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
689p_seal.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
690p_seal.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
691p_seal.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
692p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
693p_seal.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
694p_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
695p_seal.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
696p_seal.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
697p_seal.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
698p_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
699p_seal.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
700p_seal.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
701p_seal.o: ../cryptlib.h p_seal.c
702p_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
703p_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
704p_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
705p_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
706p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
707p_sign.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
708p_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
709p_sign.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
710p_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
711p_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
712p_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
713p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
714p_sign.o: ../cryptlib.h p_sign.c
715p_verify.o: ../../e_os.h ../../include/openssl/asn1.h
716p_verify.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
717p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
718p_verify.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
719p_verify.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
720p_verify.o: ../../include/openssl/evp.h ../../include/openssl/fips.h
721p_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
722p_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
723p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
724p_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
725p_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
726p_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
727p_verify.o: ../../include/openssl/x509_vfy.h ../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..fa5cbc7eb1
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -0,0 +1,567 @@
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 OPENSSL_assert(ctx->buf_off+i < (int)sizeof(ctx->buf));
169 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
170 ret=i;
171 out+=i;
172 outl-=i;
173 ctx->buf_off+=i;
174 if (ctx->buf_len == ctx->buf_off)
175 {
176 ctx->buf_len=0;
177 ctx->buf_off=0;
178 }
179 }
180
181 /* At this point, we have room of outl bytes and an empty
182 * buffer, so we should read in some more. */
183
184 ret_code=0;
185 while (outl > 0)
186 {
187
188 if (ctx->cont <= 0)
189 break;
190
191 i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]),
192 B64_BLOCK_SIZE-ctx->tmp_len);
193
194 if (i <= 0)
195 {
196 ret_code=i;
197
198 /* Should be continue next time we are called? */
199 if (!BIO_should_retry(b->next_bio))
200 {
201 ctx->cont=i;
202 /* If buffer empty break */
203 if(ctx->tmp_len == 0)
204 break;
205 /* Fall through and process what we have */
206 else
207 i = 0;
208 }
209 /* else we retry and add more data to buffer */
210 else
211 break;
212 }
213 i+=ctx->tmp_len;
214 ctx->tmp_len = i;
215
216 /* We need to scan, a line at a time until we
217 * have a valid line if we are starting. */
218 if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL))
219 {
220 /* ctx->start=1; */
221 ctx->tmp_len=0;
222 }
223 else if (ctx->start)
224 {
225 q=p=(unsigned char *)ctx->tmp;
226 for (j=0; j<i; j++)
227 {
228 if (*(q++) != '\n') continue;
229
230 /* due to a previous very long line,
231 * we need to keep on scanning for a '\n'
232 * before we even start looking for
233 * base64 encoded stuff. */
234 if (ctx->tmp_nl)
235 {
236 p=q;
237 ctx->tmp_nl=0;
238 continue;
239 }
240
241 k=EVP_DecodeUpdate(&(ctx->base64),
242 (unsigned char *)ctx->buf,
243 &num,p,q-p);
244 if ((k <= 0) && (num == 0) && (ctx->start))
245 EVP_DecodeInit(&ctx->base64);
246 else
247 {
248 if (p != (unsigned char *)
249 &(ctx->tmp[0]))
250 {
251 i-=(p- (unsigned char *)
252 &(ctx->tmp[0]));
253 for (x=0; x < i; x++)
254 ctx->tmp[x]=p[x];
255 }
256 EVP_DecodeInit(&ctx->base64);
257 ctx->start=0;
258 break;
259 }
260 p=q;
261 }
262
263 /* we fell off the end without starting */
264 if (j == i)
265 {
266 /* Is this is one long chunk?, if so, keep on
267 * reading until a new line. */
268 if (p == (unsigned char *)&(ctx->tmp[0]))
269 {
270 /* Check buffer full */
271 if (i == B64_BLOCK_SIZE)
272 {
273 ctx->tmp_nl=1;
274 ctx->tmp_len=0;
275 }
276 }
277 else if (p != q) /* finished on a '\n' */
278 {
279 n=q-p;
280 for (ii=0; ii<n; ii++)
281 ctx->tmp[ii]=p[ii];
282 ctx->tmp_len=n;
283 }
284 /* else finished on a '\n' */
285 continue;
286 }
287 else
288 ctx->tmp_len=0;
289 }
290 /* If buffer isn't full and we can retry then
291 * restart to read in more data.
292 */
293 else if ((i < B64_BLOCK_SIZE) && (ctx->cont > 0))
294 continue;
295
296 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
297 {
298 int z,jj;
299
300 jj=(i>>2)<<2;
301 z=EVP_DecodeBlock((unsigned char *)ctx->buf,
302 (unsigned char *)ctx->tmp,jj);
303 if (jj > 2)
304 {
305 if (ctx->tmp[jj-1] == '=')
306 {
307 z--;
308 if (ctx->tmp[jj-2] == '=')
309 z--;
310 }
311 }
312 /* z is now number of output bytes and jj is the
313 * number consumed */
314 if (jj != i)
315 {
316 memcpy((unsigned char *)ctx->tmp,
317 (unsigned char *)&(ctx->tmp[jj]),i-jj);
318 ctx->tmp_len=i-jj;
319 }
320 ctx->buf_len=0;
321 if (z > 0)
322 {
323 ctx->buf_len=z;
324 i=1;
325 }
326 else
327 i=z;
328 }
329 else
330 {
331 i=EVP_DecodeUpdate(&(ctx->base64),
332 (unsigned char *)ctx->buf,&ctx->buf_len,
333 (unsigned char *)ctx->tmp,i);
334 ctx->tmp_len = 0;
335 }
336 ctx->buf_off=0;
337 if (i < 0)
338 {
339 ret_code=0;
340 ctx->buf_len=0;
341 break;
342 }
343
344 if (ctx->buf_len <= outl)
345 i=ctx->buf_len;
346 else
347 i=outl;
348
349 memcpy(out,ctx->buf,i);
350 ret+=i;
351 ctx->buf_off=i;
352 if (ctx->buf_off == ctx->buf_len)
353 {
354 ctx->buf_len=0;
355 ctx->buf_off=0;
356 }
357 outl-=i;
358 out+=i;
359 }
360 BIO_clear_retry_flags(b);
361 BIO_copy_next_retry(b);
362 return((ret == 0)?ret_code:ret);
363 }
364
365static int b64_write(BIO *b, const char *in, int inl)
366 {
367 int ret=inl,n,i;
368 BIO_B64_CTX *ctx;
369
370 ctx=(BIO_B64_CTX *)b->ptr;
371 BIO_clear_retry_flags(b);
372
373 if (ctx->encode != B64_ENCODE)
374 {
375 ctx->encode=B64_ENCODE;
376 ctx->buf_len=0;
377 ctx->buf_off=0;
378 ctx->tmp_len=0;
379 EVP_EncodeInit(&(ctx->base64));
380 }
381
382 n=ctx->buf_len-ctx->buf_off;
383 while (n > 0)
384 {
385 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
386 if (i <= 0)
387 {
388 BIO_copy_next_retry(b);
389 return(i);
390 }
391 ctx->buf_off+=i;
392 n-=i;
393 }
394 /* at this point all pending data has been written */
395 ctx->buf_off=0;
396 ctx->buf_len=0;
397
398 if ((in == NULL) || (inl <= 0)) return(0);
399
400 while (inl > 0)
401 {
402 n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl;
403
404 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
405 {
406 if (ctx->tmp_len > 0)
407 {
408 n=3-ctx->tmp_len;
409 /* There's a teoretical possibility for this */
410 if (n > inl)
411 n=inl;
412 memcpy(&(ctx->tmp[ctx->tmp_len]),in,n);
413 ctx->tmp_len+=n;
414 if (ctx->tmp_len < 3)
415 break;
416 ctx->buf_len=EVP_EncodeBlock(
417 (unsigned char *)ctx->buf,
418 (unsigned char *)ctx->tmp,
419 ctx->tmp_len);
420 /* Since we're now done using the temporary
421 buffer, the length should be 0'd */
422 ctx->tmp_len=0;
423 }
424 else
425 {
426 if (n < 3)
427 {
428 memcpy(&(ctx->tmp[0]),in,n);
429 ctx->tmp_len=n;
430 break;
431 }
432 n-=n%3;
433 ctx->buf_len=EVP_EncodeBlock(
434 (unsigned char *)ctx->buf,
435 (unsigned char *)in,n);
436 }
437 }
438 else
439 {
440 EVP_EncodeUpdate(&(ctx->base64),
441 (unsigned char *)ctx->buf,&ctx->buf_len,
442 (unsigned char *)in,n);
443 }
444 inl-=n;
445 in+=n;
446
447 ctx->buf_off=0;
448 n=ctx->buf_len;
449 while (n > 0)
450 {
451 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
452 if (i <= 0)
453 {
454 BIO_copy_next_retry(b);
455 return((ret == 0)?i:ret);
456 }
457 n-=i;
458 ctx->buf_off+=i;
459 }
460 ctx->buf_len=0;
461 ctx->buf_off=0;
462 }
463 return(ret);
464 }
465
466static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
467 {
468 BIO_B64_CTX *ctx;
469 long ret=1;
470 int i;
471
472 ctx=(BIO_B64_CTX *)b->ptr;
473
474 switch (cmd)
475 {
476 case BIO_CTRL_RESET:
477 ctx->cont=1;
478 ctx->start=1;
479 ctx->encode=B64_NONE;
480 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
481 break;
482 case BIO_CTRL_EOF: /* More to read */
483 if (ctx->cont <= 0)
484 ret=1;
485 else
486 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
487 break;
488 case BIO_CTRL_WPENDING: /* More to write in buffer */
489 ret=ctx->buf_len-ctx->buf_off;
490 if ((ret == 0) && (ctx->encode != B64_NONE)
491 && (ctx->base64.num != 0))
492 ret=1;
493 else if (ret <= 0)
494 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
495 break;
496 case BIO_CTRL_PENDING: /* More to read in buffer */
497 ret=ctx->buf_len-ctx->buf_off;
498 if (ret <= 0)
499 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
500 break;
501 case BIO_CTRL_FLUSH:
502 /* do a final write */
503again:
504 while (ctx->buf_len != ctx->buf_off)
505 {
506 i=b64_write(b,NULL,0);
507 if (i < 0)
508 return i;
509 }
510 if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)
511 {
512 if (ctx->tmp_len != 0)
513 {
514 ctx->buf_len=EVP_EncodeBlock(
515 (unsigned char *)ctx->buf,
516 (unsigned char *)ctx->tmp,
517 ctx->tmp_len);
518 ctx->buf_off=0;
519 ctx->tmp_len=0;
520 goto again;
521 }
522 }
523 else if (ctx->encode != B64_NONE && ctx->base64.num != 0)
524 {
525 ctx->buf_off=0;
526 EVP_EncodeFinal(&(ctx->base64),
527 (unsigned char *)ctx->buf,
528 &(ctx->buf_len));
529 /* push out the bytes */
530 goto again;
531 }
532 /* Finally flush the underlying BIO */
533 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
534 break;
535
536 case BIO_C_DO_STATE_MACHINE:
537 BIO_clear_retry_flags(b);
538 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
539 BIO_copy_next_retry(b);
540 break;
541
542 case BIO_CTRL_DUP:
543 break;
544 case BIO_CTRL_INFO:
545 case BIO_CTRL_GET:
546 case BIO_CTRL_SET:
547 default:
548 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
549 break;
550 }
551 return(ret);
552 }
553
554static long b64_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
555 {
556 long ret=1;
557
558 if (b->next_bio == NULL) return(0);
559 switch (cmd)
560 {
561 default:
562 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
563 break;
564 }
565 return(ret);
566 }
567
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
new file mode 100644
index 0000000000..f6ac94c6e1
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -0,0 +1,426 @@
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*2)
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 OPENSSL_cleanse(a->ptr,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 (ret == inl) ? i : ret - inl;
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 return i;
329 }
330
331 if (!ctx->finished)
332 {
333 ctx->finished=1;
334 ctx->buf_off=0;
335 ret=EVP_CipherFinal_ex(&(ctx->cipher),
336 (unsigned char *)ctx->buf,
337 &(ctx->buf_len));
338 ctx->ok=(int)ret;
339 if (ret <= 0) break;
340
341 /* push out the bytes */
342 goto again;
343 }
344
345 /* Finally flush the underlying BIO */
346 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
347 break;
348 case BIO_C_GET_CIPHER_STATUS:
349 ret=(long)ctx->ok;
350 break;
351 case BIO_C_DO_STATE_MACHINE:
352 BIO_clear_retry_flags(b);
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 BIO_copy_next_retry(b);
355 break;
356 case BIO_C_GET_CIPHER_CTX:
357 c_ctx=(EVP_CIPHER_CTX **)ptr;
358 (*c_ctx)= &(ctx->cipher);
359 b->init=1;
360 break;
361 case BIO_CTRL_DUP:
362 dbio=(BIO *)ptr;
363 dctx=(BIO_ENC_CTX *)dbio->ptr;
364 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
365 dbio->init=1;
366 break;
367 default:
368 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
369 break;
370 }
371 return(ret);
372 }
373
374static long enc_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
375 {
376 long ret=1;
377
378 if (b->next_bio == NULL) return(0);
379 switch (cmd)
380 {
381 default:
382 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
383 break;
384 }
385 return(ret);
386 }
387
388/*
389void BIO_set_cipher_ctx(b,c)
390BIO *b;
391EVP_CIPHER_ctx *c;
392 {
393 if (b == NULL) return;
394
395 if ((b->callback != NULL) &&
396 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
397 return;
398
399 b->init=1;
400 ctx=(BIO_ENC_CTX *)b->ptr;
401 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
402
403 if (b->callback != NULL)
404 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
405 }
406*/
407
408void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
409 const unsigned char *i, int e)
410 {
411 BIO_ENC_CTX *ctx;
412
413 if (b == NULL) return;
414
415 if ((b->callback != NULL) &&
416 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
417 return;
418
419 b->init=1;
420 ctx=(BIO_ENC_CTX *)b->ptr;
421 EVP_CipherInit_ex(&(ctx->cipher),c,NULL, k,i,e);
422
423 if (b->callback != NULL)
424 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
425 }
426
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
new file mode 100644
index 0000000000..ed5c1135fd
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -0,0 +1,264 @@
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,(const 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 ret = EVP_DigestInit_ex(ctx,ctx->digest, NULL);
180 else
181 ret=0;
182 if (ret > 0)
183 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
184 break;
185 case BIO_C_GET_MD:
186 if (b->init)
187 {
188 ppmd=ptr;
189 *ppmd=ctx->digest;
190 }
191 else
192 ret=0;
193 break;
194 case BIO_C_GET_MD_CTX:
195 pctx=ptr;
196 *pctx=ctx;
197 break;
198 case BIO_C_SET_MD_CTX:
199 if (b->init)
200 b->ptr=ptr;
201 else
202 ret=0;
203 break;
204 case BIO_C_DO_STATE_MACHINE:
205 BIO_clear_retry_flags(b);
206 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
207 BIO_copy_next_retry(b);
208 break;
209
210 case BIO_C_SET_MD:
211 md=ptr;
212 ret = EVP_DigestInit_ex(ctx,md, NULL);
213 if (ret > 0)
214 b->init=1;
215 break;
216 case BIO_CTRL_DUP:
217 dbio=ptr;
218 dctx=dbio->ptr;
219 EVP_MD_CTX_copy_ex(dctx,ctx);
220 b->init=1;
221 break;
222 default:
223 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
224 break;
225 }
226 return(ret);
227 }
228
229static long md_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
230 {
231 long ret=1;
232
233 if (b->next_bio == NULL) return(0);
234 switch (cmd)
235 {
236 default:
237 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
238 break;
239 }
240 return(ret);
241 }
242
243static int md_gets(BIO *bp, char *buf, int size)
244 {
245 EVP_MD_CTX *ctx;
246 unsigned int ret;
247
248
249 ctx=bp->ptr;
250 if (size < ctx->digest->md_size)
251 return(0);
252 EVP_DigestFinal_ex(ctx,(unsigned char *)buf,&ret);
253 return((int)ret);
254 }
255
256/*
257static int md_puts(bp,str)
258BIO *bp;
259char *str;
260 {
261 return(-1);
262 }
263*/
264
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c
new file mode 100644
index 0000000000..98bc1ab409
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_ok.c
@@ -0,0 +1,575 @@
1/* crypto/evp/bio_ok.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/*
60 From: Arne Ansper <arne@cyber.ee>
61
62 Why BIO_f_reliable?
63
64 I wrote function which took BIO* as argument, read data from it
65 and processed it. Then I wanted to store the input file in
66 encrypted form. OK I pushed BIO_f_cipher to the BIO stack
67 and everything was OK. BUT if user types wrong password
68 BIO_f_cipher outputs only garbage and my function crashes. Yes
69 I can and I should fix my function, but BIO_f_cipher is
70 easy way to add encryption support to many existing applications
71 and it's hard to debug and fix them all.
72
73 So I wanted another BIO which would catch the incorrect passwords and
74 file damages which cause garbage on BIO_f_cipher's output.
75
76 The easy way is to push the BIO_f_md and save the checksum at
77 the end of the file. However there are several problems with this
78 approach:
79
80 1) you must somehow separate checksum from actual data.
81 2) you need lot's of memory when reading the file, because you
82 must read to the end of the file and verify the checksum before
83 letting the application to read the data.
84
85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitrary long streams using only fixed amount
87 of memory.
88
89 BIO_f_reliable splits data stream into blocks. Each block is prefixed
90 with it's length and suffixed with it's digest. So you need only
91 several Kbytes of memory to buffer single block before verifying
92 it's digest.
93
94 BIO_f_reliable goes further and adds several important capabilities:
95
96 1) the digest of the block is computed over the whole stream
97 -- so nobody can rearrange the blocks or remove or replace them.
98
99 2) to detect invalid passwords right at the start BIO_f_reliable
100 adds special prefix to the stream. In order to avoid known plain-text
101 attacks this prefix is generated as follows:
102
103 *) digest is initialized with random seed instead of
104 standardized one.
105 *) same seed is written to output
106 *) well-known text is then hashed and the output
107 of the digest is also written to output.
108
109 reader can now read the seed from stream, hash the same string
110 and then compare the digest output.
111
112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
113 initially wrote and tested this code on x86 machine and wrote the
114 digests out in machine-dependent order :( There are people using
115 this code and I cannot change this easily without making existing
116 data files unreadable.
117
118*/
119
120#include <stdio.h>
121#include <errno.h>
122#include <assert.h>
123#include "cryptlib.h"
124#include <openssl/buffer.h>
125#include <openssl/bio.h>
126#include <openssl/evp.h>
127#include <openssl/rand.h>
128
129static int ok_write(BIO *h, const char *buf, int num);
130static int ok_read(BIO *h, char *buf, int size);
131static long ok_ctrl(BIO *h, int cmd, long arg1, void *arg2);
132static int ok_new(BIO *h);
133static int ok_free(BIO *data);
134static long ok_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
135
136static void sig_out(BIO* b);
137static void sig_in(BIO* b);
138static void block_out(BIO* b);
139static void block_in(BIO* b);
140#define OK_BLOCK_SIZE (1024*4)
141#define OK_BLOCK_BLOCK 4
142#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
143#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
144
145typedef struct ok_struct
146 {
147 size_t buf_len;
148 size_t buf_off;
149 size_t buf_len_save;
150 size_t buf_off_save;
151 int cont; /* <= 0 when finished */
152 int finished;
153 EVP_MD_CTX md;
154 int blockout; /* output block is ready */
155 int sigio; /* must process signature */
156 unsigned char buf[IOBS];
157 } BIO_OK_CTX;
158
159static BIO_METHOD methods_ok=
160 {
161 BIO_TYPE_CIPHER,"reliable",
162 ok_write,
163 ok_read,
164 NULL, /* ok_puts, */
165 NULL, /* ok_gets, */
166 ok_ctrl,
167 ok_new,
168 ok_free,
169 ok_callback_ctrl,
170 };
171
172BIO_METHOD *BIO_f_reliable(void)
173 {
174 return(&methods_ok);
175 }
176
177static int ok_new(BIO *bi)
178 {
179 BIO_OK_CTX *ctx;
180
181 ctx=(BIO_OK_CTX *)OPENSSL_malloc(sizeof(BIO_OK_CTX));
182 if (ctx == NULL) return(0);
183
184 ctx->buf_len=0;
185 ctx->buf_off=0;
186 ctx->buf_len_save=0;
187 ctx->buf_off_save=0;
188 ctx->cont=1;
189 ctx->finished=0;
190 ctx->blockout= 0;
191 ctx->sigio=1;
192
193 EVP_MD_CTX_init(&ctx->md);
194
195 bi->init=0;
196 bi->ptr=(char *)ctx;
197 bi->flags=0;
198 return(1);
199 }
200
201static int ok_free(BIO *a)
202 {
203 if (a == NULL) return(0);
204 EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md);
205 OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX));
206 OPENSSL_free(a->ptr);
207 a->ptr=NULL;
208 a->init=0;
209 a->flags=0;
210 return(1);
211 }
212
213static int ok_read(BIO *b, char *out, int outl)
214 {
215 int ret=0,i,n;
216 BIO_OK_CTX *ctx;
217
218 if (out == NULL) return(0);
219 ctx=(BIO_OK_CTX *)b->ptr;
220
221 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
222
223 while(outl > 0)
224 {
225
226 /* copy clean bytes to output buffer */
227 if (ctx->blockout)
228 {
229 i=ctx->buf_len-ctx->buf_off;
230 if (i > outl) i=outl;
231 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
232 ret+=i;
233 out+=i;
234 outl-=i;
235 ctx->buf_off+=i;
236
237 /* all clean bytes are out */
238 if (ctx->buf_len == ctx->buf_off)
239 {
240 ctx->buf_off=0;
241
242 /* copy start of the next block into proper place */
243 if(ctx->buf_len_save- ctx->buf_off_save > 0)
244 {
245 ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
246 memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
247 ctx->buf_len);
248 }
249 else
250 {
251 ctx->buf_len=0;
252 }
253 ctx->blockout= 0;
254 }
255 }
256
257 /* output buffer full -- cancel */
258 if (outl == 0) break;
259
260 /* no clean bytes in buffer -- fill it */
261 n=IOBS- ctx->buf_len;
262 i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
263
264 if (i <= 0) break; /* nothing new */
265
266 ctx->buf_len+= i;
267
268 /* no signature yet -- check if we got one */
269 if (ctx->sigio == 1) sig_in(b);
270
271 /* signature ok -- check if we got block */
272 if (ctx->sigio == 0) block_in(b);
273
274 /* invalid block -- cancel */
275 if (ctx->cont <= 0) break;
276
277 }
278
279 BIO_clear_retry_flags(b);
280 BIO_copy_next_retry(b);
281 return(ret);
282 }
283
284static int ok_write(BIO *b, const char *in, int inl)
285 {
286 int ret=0,n,i;
287 BIO_OK_CTX *ctx;
288
289 if (inl <= 0) return inl;
290
291 ctx=(BIO_OK_CTX *)b->ptr;
292 ret=inl;
293
294 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
295
296 if(ctx->sigio) sig_out(b);
297
298 do{
299 BIO_clear_retry_flags(b);
300 n=ctx->buf_len-ctx->buf_off;
301 while (ctx->blockout && n > 0)
302 {
303 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
304 if (i <= 0)
305 {
306 BIO_copy_next_retry(b);
307 if(!BIO_should_retry(b))
308 ctx->cont= 0;
309 return(i);
310 }
311 ctx->buf_off+=i;
312 n-=i;
313 }
314
315 /* at this point all pending data has been written */
316 ctx->blockout= 0;
317 if (ctx->buf_len == ctx->buf_off)
318 {
319 ctx->buf_len=OK_BLOCK_BLOCK;
320 ctx->buf_off=0;
321 }
322
323 if ((in == NULL) || (inl <= 0)) return(0);
324
325 n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
326 (int)(OK_BLOCK_SIZE+OK_BLOCK_BLOCK-ctx->buf_len) : inl;
327
328 memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
329 ctx->buf_len+= n;
330 inl-=n;
331 in+=n;
332
333 if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
334 {
335 block_out(b);
336 }
337 }while(inl > 0);
338
339 BIO_clear_retry_flags(b);
340 BIO_copy_next_retry(b);
341 return(ret);
342 }
343
344static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
345 {
346 BIO_OK_CTX *ctx;
347 EVP_MD *md;
348 const EVP_MD **ppmd;
349 long ret=1;
350 int i;
351
352 ctx=b->ptr;
353
354 switch (cmd)
355 {
356 case BIO_CTRL_RESET:
357 ctx->buf_len=0;
358 ctx->buf_off=0;
359 ctx->buf_len_save=0;
360 ctx->buf_off_save=0;
361 ctx->cont=1;
362 ctx->finished=0;
363 ctx->blockout= 0;
364 ctx->sigio=1;
365 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
366 break;
367 case BIO_CTRL_EOF: /* More to read */
368 if (ctx->cont <= 0)
369 ret=1;
370 else
371 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
372 break;
373 case BIO_CTRL_PENDING: /* More to read in buffer */
374 case BIO_CTRL_WPENDING: /* More to read in buffer */
375 ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
376 if (ret <= 0)
377 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
378 break;
379 case BIO_CTRL_FLUSH:
380 /* do a final write */
381 if(ctx->blockout == 0)
382 block_out(b);
383
384 while (ctx->blockout)
385 {
386 i=ok_write(b,NULL,0);
387 if (i < 0)
388 {
389 ret=i;
390 break;
391 }
392 }
393
394 ctx->finished=1;
395 ctx->buf_off=ctx->buf_len=0;
396 ctx->cont=(int)ret;
397
398 /* Finally flush the underlying BIO */
399 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
400 break;
401 case BIO_C_DO_STATE_MACHINE:
402 BIO_clear_retry_flags(b);
403 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
404 BIO_copy_next_retry(b);
405 break;
406 case BIO_CTRL_INFO:
407 ret=(long)ctx->cont;
408 break;
409 case BIO_C_SET_MD:
410 md=ptr;
411 EVP_DigestInit_ex(&ctx->md, md, NULL);
412 b->init=1;
413 break;
414 case BIO_C_GET_MD:
415 if (b->init)
416 {
417 ppmd=ptr;
418 *ppmd=ctx->md.digest;
419 }
420 else
421 ret=0;
422 break;
423 default:
424 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
425 break;
426 }
427 return(ret);
428 }
429
430static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
431 {
432 long ret=1;
433
434 if (b->next_bio == NULL) return(0);
435 switch (cmd)
436 {
437 default:
438 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
439 break;
440 }
441 return(ret);
442 }
443
444static void longswap(void *_ptr, size_t len)
445{ const union { long one; char little; } is_endian = {1};
446
447 if (is_endian.little) {
448 size_t i;
449 unsigned char *p=_ptr,c;
450
451 for(i= 0;i < len;i+= 4) {
452 c=p[0],p[0]=p[3],p[3]=c;
453 c=p[1],p[1]=p[2],p[2]=c;
454 }
455 }
456}
457
458static void sig_out(BIO* b)
459 {
460 BIO_OK_CTX *ctx;
461 EVP_MD_CTX *md;
462
463 ctx=b->ptr;
464 md=&ctx->md;
465
466 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
467
468 EVP_DigestInit_ex(md, md->digest, NULL);
469 /* FIXME: there's absolutely no guarantee this makes any sense at all,
470 * particularly now EVP_MD_CTX has been restructured.
471 */
472 RAND_pseudo_bytes(md->md_data, md->digest->md_size);
473 memcpy(&(ctx->buf[ctx->buf_len]), md->md_data, md->digest->md_size);
474 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
475 ctx->buf_len+= md->digest->md_size;
476
477 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
478 EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
479 ctx->buf_len+= md->digest->md_size;
480 ctx->blockout= 1;
481 ctx->sigio= 0;
482 }
483
484static void sig_in(BIO* b)
485 {
486 BIO_OK_CTX *ctx;
487 EVP_MD_CTX *md;
488 unsigned char tmp[EVP_MAX_MD_SIZE];
489 int ret= 0;
490
491 ctx=b->ptr;
492 md=&ctx->md;
493
494 if((int)(ctx->buf_len-ctx->buf_off) < 2*md->digest->md_size) return;
495
496 EVP_DigestInit_ex(md, md->digest, NULL);
497 memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
498 longswap(md->md_data, md->digest->md_size);
499 ctx->buf_off+= md->digest->md_size;
500
501 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
502 EVP_DigestFinal_ex(md, tmp, NULL);
503 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
504 ctx->buf_off+= md->digest->md_size;
505 if(ret == 1)
506 {
507 ctx->sigio= 0;
508 if(ctx->buf_len != ctx->buf_off)
509 {
510 memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
511 }
512 ctx->buf_len-= ctx->buf_off;
513 ctx->buf_off= 0;
514 }
515 else
516 {
517 ctx->cont= 0;
518 }
519 }
520
521static void block_out(BIO* b)
522 {
523 BIO_OK_CTX *ctx;
524 EVP_MD_CTX *md;
525 unsigned long tl;
526
527 ctx=b->ptr;
528 md=&ctx->md;
529
530 tl= ctx->buf_len- OK_BLOCK_BLOCK;
531 ctx->buf[0]=(unsigned char)(tl>>24);
532 ctx->buf[1]=(unsigned char)(tl>>16);
533 ctx->buf[2]=(unsigned char)(tl>>8);
534 ctx->buf[3]=(unsigned char)(tl);
535 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
536 EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
537 ctx->buf_len+= md->digest->md_size;
538 ctx->blockout= 1;
539 }
540
541static void block_in(BIO* b)
542 {
543 BIO_OK_CTX *ctx;
544 EVP_MD_CTX *md;
545 unsigned long tl= 0;
546 unsigned char tmp[EVP_MAX_MD_SIZE];
547
548 ctx=b->ptr;
549 md=&ctx->md;
550
551 assert(sizeof(tl)>=OK_BLOCK_BLOCK); /* always true */
552 tl =ctx->buf[0]; tl<<=8;
553 tl|=ctx->buf[1]; tl<<=8;
554 tl|=ctx->buf[2]; tl<<=8;
555 tl|=ctx->buf[3];
556
557 if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return;
558
559 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
560 EVP_DigestFinal_ex(md, tmp, NULL);
561 if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
562 {
563 /* there might be parts from next block lurking around ! */
564 ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
565 ctx->buf_len_save= ctx->buf_len;
566 ctx->buf_off= OK_BLOCK_BLOCK;
567 ctx->buf_len= tl+ OK_BLOCK_BLOCK;
568 ctx->blockout= 1;
569 }
570 else
571 {
572 ctx->cont= 0;
573 }
574 }
575
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
new file mode 100644
index 0000000000..a5da52e62d
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_all.c
@@ -0,0 +1,90 @@
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#ifndef OPENSSL_NO_ENGINE
63#include <openssl/engine.h>
64#endif
65
66#if 0
67#undef OpenSSL_add_all_algorithms
68
69void OpenSSL_add_all_algorithms(void)
70 {
71 OPENSSL_add_all_algorithms_noconf();
72 }
73#endif
74
75void OPENSSL_add_all_algorithms_noconf(void)
76 {
77 /*
78 * For the moment OPENSSL_cpuid_setup does something
79 * only on IA-32, but we reserve the option for all
80 * platforms...
81 */
82 OPENSSL_cpuid_setup();
83 OpenSSL_add_all_ciphers();
84 OpenSSL_add_all_digests();
85#ifndef OPENSSL_NO_ENGINE
86# if defined(__OpenBSD__) || defined(__FreeBSD__)
87 ENGINE_setup_bsd_cryptodev();
88# endif
89#endif
90 }
diff --git a/src/lib/libcrypto/evp/c_allc.c b/src/lib/libcrypto/evp/c_allc.c
new file mode 100644
index 0000000000..7054d8125d
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_allc.c
@@ -0,0 +1,225 @@
1/* crypto/evp/c_allc.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/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_ciphers(void)
66 {
67
68#ifndef OPENSSL_NO_DES
69 EVP_add_cipher(EVP_des_cfb());
70 EVP_add_cipher(EVP_des_cfb1());
71 EVP_add_cipher(EVP_des_cfb8());
72 EVP_add_cipher(EVP_des_ede_cfb());
73 EVP_add_cipher(EVP_des_ede3_cfb());
74
75 EVP_add_cipher(EVP_des_ofb());
76 EVP_add_cipher(EVP_des_ede_ofb());
77 EVP_add_cipher(EVP_des_ede3_ofb());
78
79 EVP_add_cipher(EVP_desx_cbc());
80 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
81 EVP_add_cipher_alias(SN_desx_cbc,"desx");
82
83 EVP_add_cipher(EVP_des_cbc());
84 EVP_add_cipher_alias(SN_des_cbc,"DES");
85 EVP_add_cipher_alias(SN_des_cbc,"des");
86 EVP_add_cipher(EVP_des_ede_cbc());
87 EVP_add_cipher(EVP_des_ede3_cbc());
88 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
89 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
90
91 EVP_add_cipher(EVP_des_ecb());
92 EVP_add_cipher(EVP_des_ede());
93 EVP_add_cipher(EVP_des_ede3());
94#endif
95
96#ifndef OPENSSL_NO_RC4
97 EVP_add_cipher(EVP_rc4());
98 EVP_add_cipher(EVP_rc4_40());
99#endif
100
101#ifndef OPENSSL_NO_IDEA
102 EVP_add_cipher(EVP_idea_ecb());
103 EVP_add_cipher(EVP_idea_cfb());
104 EVP_add_cipher(EVP_idea_ofb());
105 EVP_add_cipher(EVP_idea_cbc());
106 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
107 EVP_add_cipher_alias(SN_idea_cbc,"idea");
108#endif
109
110#ifndef OPENSSL_NO_SEED
111 EVP_add_cipher(EVP_seed_ecb());
112 EVP_add_cipher(EVP_seed_cfb());
113 EVP_add_cipher(EVP_seed_ofb());
114 EVP_add_cipher(EVP_seed_cbc());
115 EVP_add_cipher_alias(SN_seed_cbc,"SEED");
116 EVP_add_cipher_alias(SN_seed_cbc,"seed");
117#endif
118
119#ifndef OPENSSL_NO_RC2
120 EVP_add_cipher(EVP_rc2_ecb());
121 EVP_add_cipher(EVP_rc2_cfb());
122 EVP_add_cipher(EVP_rc2_ofb());
123 EVP_add_cipher(EVP_rc2_cbc());
124 EVP_add_cipher(EVP_rc2_40_cbc());
125 EVP_add_cipher(EVP_rc2_64_cbc());
126 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
127 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
128#endif
129
130#ifndef OPENSSL_NO_BF
131 EVP_add_cipher(EVP_bf_ecb());
132 EVP_add_cipher(EVP_bf_cfb());
133 EVP_add_cipher(EVP_bf_ofb());
134 EVP_add_cipher(EVP_bf_cbc());
135 EVP_add_cipher_alias(SN_bf_cbc,"BF");
136 EVP_add_cipher_alias(SN_bf_cbc,"bf");
137 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
138#endif
139
140#ifndef OPENSSL_NO_CAST
141 EVP_add_cipher(EVP_cast5_ecb());
142 EVP_add_cipher(EVP_cast5_cfb());
143 EVP_add_cipher(EVP_cast5_ofb());
144 EVP_add_cipher(EVP_cast5_cbc());
145 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
146 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
147 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
148 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
149#endif
150
151#ifndef OPENSSL_NO_RC5
152 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
153 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
154 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
155 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
156 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
157 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
158#endif
159
160#ifndef OPENSSL_NO_AES
161 EVP_add_cipher(EVP_aes_128_ecb());
162 EVP_add_cipher(EVP_aes_128_cbc());
163 EVP_add_cipher(EVP_aes_128_cfb());
164 EVP_add_cipher(EVP_aes_128_cfb1());
165 EVP_add_cipher(EVP_aes_128_cfb8());
166 EVP_add_cipher(EVP_aes_128_ofb());
167#if 0
168 EVP_add_cipher(EVP_aes_128_ctr());
169#endif
170 EVP_add_cipher_alias(SN_aes_128_cbc,"AES128");
171 EVP_add_cipher_alias(SN_aes_128_cbc,"aes128");
172 EVP_add_cipher(EVP_aes_192_ecb());
173 EVP_add_cipher(EVP_aes_192_cbc());
174 EVP_add_cipher(EVP_aes_192_cfb());
175 EVP_add_cipher(EVP_aes_192_cfb1());
176 EVP_add_cipher(EVP_aes_192_cfb8());
177 EVP_add_cipher(EVP_aes_192_ofb());
178#if 0
179 EVP_add_cipher(EVP_aes_192_ctr());
180#endif
181 EVP_add_cipher_alias(SN_aes_192_cbc,"AES192");
182 EVP_add_cipher_alias(SN_aes_192_cbc,"aes192");
183 EVP_add_cipher(EVP_aes_256_ecb());
184 EVP_add_cipher(EVP_aes_256_cbc());
185 EVP_add_cipher(EVP_aes_256_cfb());
186 EVP_add_cipher(EVP_aes_256_cfb1());
187 EVP_add_cipher(EVP_aes_256_cfb8());
188 EVP_add_cipher(EVP_aes_256_ofb());
189#if 0
190 EVP_add_cipher(EVP_aes_256_ctr());
191#endif
192 EVP_add_cipher_alias(SN_aes_256_cbc,"AES256");
193 EVP_add_cipher_alias(SN_aes_256_cbc,"aes256");
194#endif
195
196#ifndef OPENSSL_NO_CAMELLIA
197 EVP_add_cipher(EVP_camellia_128_ecb());
198 EVP_add_cipher(EVP_camellia_128_cbc());
199 EVP_add_cipher(EVP_camellia_128_cfb());
200 EVP_add_cipher(EVP_camellia_128_cfb1());
201 EVP_add_cipher(EVP_camellia_128_cfb8());
202 EVP_add_cipher(EVP_camellia_128_ofb());
203 EVP_add_cipher_alias(SN_camellia_128_cbc,"CAMELLIA128");
204 EVP_add_cipher_alias(SN_camellia_128_cbc,"camellia128");
205 EVP_add_cipher(EVP_camellia_192_ecb());
206 EVP_add_cipher(EVP_camellia_192_cbc());
207 EVP_add_cipher(EVP_camellia_192_cfb());
208 EVP_add_cipher(EVP_camellia_192_cfb1());
209 EVP_add_cipher(EVP_camellia_192_cfb8());
210 EVP_add_cipher(EVP_camellia_192_ofb());
211 EVP_add_cipher_alias(SN_camellia_192_cbc,"CAMELLIA192");
212 EVP_add_cipher_alias(SN_camellia_192_cbc,"camellia192");
213 EVP_add_cipher(EVP_camellia_256_ecb());
214 EVP_add_cipher(EVP_camellia_256_cbc());
215 EVP_add_cipher(EVP_camellia_256_cfb());
216 EVP_add_cipher(EVP_camellia_256_cfb1());
217 EVP_add_cipher(EVP_camellia_256_cfb8());
218 EVP_add_cipher(EVP_camellia_256_ofb());
219 EVP_add_cipher_alias(SN_camellia_256_cbc,"CAMELLIA256");
220 EVP_add_cipher_alias(SN_camellia_256_cbc,"camellia256");
221#endif
222
223 PKCS12_PBE_add();
224 PKCS5_PBE_add();
225 }
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c
new file mode 100644
index 0000000000..d270b0ee03
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_alld.c
@@ -0,0 +1,114 @@
1/* crypto/evp/c_alld.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/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_digests(void)
66 {
67#ifndef OPENSSL_NO_MD2
68 EVP_add_digest(EVP_md2());
69#endif
70#ifndef OPENSSL_NO_MD4
71 EVP_add_digest(EVP_md4());
72#endif
73#ifndef OPENSSL_NO_MD5
74 EVP_add_digest(EVP_md5());
75 EVP_add_digest_alias(SN_md5,"ssl2-md5");
76 EVP_add_digest_alias(SN_md5,"ssl3-md5");
77#endif
78#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
79 EVP_add_digest(EVP_sha());
80#ifndef OPENSSL_NO_DSA
81 EVP_add_digest(EVP_dss());
82#endif
83#endif
84#ifndef OPENSSL_NO_SHA
85 EVP_add_digest(EVP_sha1());
86 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
87 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
88#ifndef OPENSSL_NO_DSA
89 EVP_add_digest(EVP_dss1());
90 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
91 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
92 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
93#endif
94#ifndef OPENSSL_NO_ECDSA
95 EVP_add_digest(EVP_ecdsa());
96#endif
97#endif
98#if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
99 EVP_add_digest(EVP_mdc2());
100#endif
101#ifndef OPENSSL_NO_RIPEMD
102 EVP_add_digest(EVP_ripemd160());
103 EVP_add_digest_alias(SN_ripemd160,"ripemd");
104 EVP_add_digest_alias(SN_ripemd160,"rmd160");
105#endif
106#ifndef OPENSSL_NO_SHA256
107 EVP_add_digest(EVP_sha224());
108 EVP_add_digest(EVP_sha256());
109#endif
110#ifndef OPENSSL_NO_SHA512
111 EVP_add_digest(EVP_sha384());
112 EVP_add_digest(EVP_sha512());
113#endif
114 }
diff --git a/src/lib/libcrypto/evp/dig_eng.c b/src/lib/libcrypto/evp/dig_eng.c
new file mode 100644
index 0000000000..64cdf9366c
--- /dev/null
+++ b/src/lib/libcrypto/evp/dig_eng.c
@@ -0,0 +1,180 @@
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#ifndef OPENSSL_NO_ENGINE
117#include <openssl/engine.h>
118#endif
119#include "evp_locl.h"
120
121#ifndef OPENSSL_NO_ENGINE
122
123#ifdef OPENSSL_FIPS
124
125static int do_evp_md_engine_full(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
126 {
127 if (*ptype)
128 {
129 /* Ensure an ENGINE left lying around from last time is cleared
130 * (the previous check attempted to avoid this if the same
131 * ENGINE and EVP_MD could be used). */
132 if(ctx->engine)
133 ENGINE_finish(ctx->engine);
134 if(impl)
135 {
136 if (!ENGINE_init(impl))
137 {
138 EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR);
139 return 0;
140 }
141 }
142 else
143 /* Ask if an ENGINE is reserved for this job */
144 impl = ENGINE_get_digest_engine((*ptype)->type);
145 if(impl)
146 {
147 /* There's an ENGINE for this job ... (apparently) */
148 const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type);
149 if(!d)
150 {
151 /* Same comment from evp_enc.c */
152 EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_INITIALIZATION_ERROR);
153 return 0;
154 }
155 /* We'll use the ENGINE's private digest definition */
156 *ptype = d;
157 /* Store the ENGINE functional reference so we know
158 * 'type' came from an ENGINE and we need to release
159 * it when done. */
160 ctx->engine = impl;
161 }
162 else
163 ctx->engine = NULL;
164 }
165 else
166 if(!ctx->digest)
167 {
168 EVPerr(EVP_F_DO_EVP_MD_ENGINE_FULL,EVP_R_NO_DIGEST_SET);
169 return 0;
170 }
171 return 1;
172 }
173
174void int_EVP_MD_init_engine_callbacks(void)
175 {
176 int_EVP_MD_set_engine_callbacks(
177 ENGINE_init, ENGINE_finish, do_evp_md_engine_full);
178 }
179#endif
180#endif
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
new file mode 100644
index 0000000000..3bc2d1295c
--- /dev/null
+++ b/src/lib/libcrypto/evp/digest.c
@@ -0,0 +1,440 @@
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#ifndef OPENSSL_NO_ENGINE
117#include <openssl/engine.h>
118#endif
119#include "evp_locl.h"
120
121void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
122 {
123 memset(ctx,'\0',sizeof *ctx);
124 }
125
126EVP_MD_CTX *EVP_MD_CTX_create(void)
127 {
128 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
129
130 EVP_MD_CTX_init(ctx);
131
132 return ctx;
133 }
134
135int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
136 {
137 EVP_MD_CTX_init(ctx);
138 return EVP_DigestInit_ex(ctx, type, NULL);
139 }
140
141#ifdef OPENSSL_FIPS
142
143/* The purpose of these is to trap programs that attempt to use non FIPS
144 * algorithms in FIPS mode and ignore the errors.
145 */
146
147static int bad_init(EVP_MD_CTX *ctx)
148 { FIPS_ERROR_IGNORED("Digest init"); return 0;}
149
150static int bad_update(EVP_MD_CTX *ctx,const void *data,size_t count)
151 { FIPS_ERROR_IGNORED("Digest update"); return 0;}
152
153static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
154 { FIPS_ERROR_IGNORED("Digest Final"); return 0;}
155
156static const EVP_MD bad_md =
157 {
158 0,
159 0,
160 0,
161 0,
162 bad_init,
163 bad_update,
164 bad_final,
165 NULL,
166 NULL,
167 NULL,
168 0,
169 {0,0,0,0},
170 };
171
172#endif
173
174#ifndef OPENSSL_NO_ENGINE
175
176#ifdef OPENSSL_FIPS
177
178static int do_engine_null(ENGINE *impl) { return 0;}
179static int do_evp_md_engine_null(EVP_MD_CTX *ctx,
180 const EVP_MD **ptype, ENGINE *impl)
181 { return 1; }
182
183static int (*do_engine_init)(ENGINE *impl)
184 = do_engine_null;
185
186static int (*do_engine_finish)(ENGINE *impl)
187 = do_engine_null;
188
189static int (*do_evp_md_engine)
190 (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
191 = do_evp_md_engine_null;
192
193void int_EVP_MD_set_engine_callbacks(
194 int (*eng_md_init)(ENGINE *impl),
195 int (*eng_md_fin)(ENGINE *impl),
196 int (*eng_md_evp)
197 (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl))
198 {
199 do_engine_init = eng_md_init;
200 do_engine_finish = eng_md_fin;
201 do_evp_md_engine = eng_md_evp;
202 }
203
204#else
205
206#define do_engine_init ENGINE_init
207#define do_engine_finish ENGINE_finish
208
209static int do_evp_md_engine(EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl)
210 {
211 if (*ptype)
212 {
213 /* Ensure an ENGINE left lying around from last time is cleared
214 * (the previous check attempted to avoid this if the same
215 * ENGINE and EVP_MD could be used). */
216 if(ctx->engine)
217 ENGINE_finish(ctx->engine);
218 if(impl)
219 {
220 if (!ENGINE_init(impl))
221 {
222 EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_INITIALIZATION_ERROR);
223 return 0;
224 }
225 }
226 else
227 /* Ask if an ENGINE is reserved for this job */
228 impl = ENGINE_get_digest_engine((*ptype)->type);
229 if(impl)
230 {
231 /* There's an ENGINE for this job ... (apparently) */
232 const EVP_MD *d = ENGINE_get_digest(impl, (*ptype)->type);
233 if(!d)
234 {
235 /* Same comment from evp_enc.c */
236 EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_INITIALIZATION_ERROR);
237 return 0;
238 }
239 /* We'll use the ENGINE's private digest definition */
240 *ptype = d;
241 /* Store the ENGINE functional reference so we know
242 * 'type' came from an ENGINE and we need to release
243 * it when done. */
244 ctx->engine = impl;
245 }
246 else
247 ctx->engine = NULL;
248 }
249 else
250 if(!ctx->digest)
251 {
252 EVPerr(EVP_F_DO_EVP_MD_ENGINE,EVP_R_NO_DIGEST_SET);
253 return 0;
254 }
255 return 1;
256 }
257
258#endif
259
260#endif
261
262int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
263 {
264 M_EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
265#ifdef OPENSSL_FIPS
266 if(FIPS_selftest_failed())
267 {
268 FIPSerr(FIPS_F_EVP_DIGESTINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
269 ctx->digest = &bad_md;
270 return 0;
271 }
272#endif
273#ifndef OPENSSL_NO_ENGINE
274 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
275 * so this context may already have an ENGINE! Try to avoid releasing
276 * the previous handle, re-querying for an ENGINE, and having a
277 * reinitialisation, when it may all be unecessary. */
278 if (ctx->engine && ctx->digest && (!type ||
279 (type && (type->type == ctx->digest->type))))
280 goto skip_to_init;
281 if (!do_evp_md_engine(ctx, &type, impl))
282 return 0;
283#endif
284 if (ctx->digest != type)
285 {
286#ifdef OPENSSL_FIPS
287 if (FIPS_mode())
288 {
289 if (!(type->flags & EVP_MD_FLAG_FIPS)
290 && !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
291 {
292 EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_DISABLED_FOR_FIPS);
293 ctx->digest = &bad_md;
294 return 0;
295 }
296 }
297#endif
298 if (ctx->digest && ctx->digest->ctx_size)
299 OPENSSL_free(ctx->md_data);
300 ctx->digest=type;
301 if (type->ctx_size)
302 ctx->md_data=OPENSSL_malloc(type->ctx_size);
303 }
304#ifndef OPENSSL_NO_ENGINE
305 skip_to_init:
306#endif
307 return ctx->digest->init(ctx);
308 }
309
310int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
311 size_t count)
312 {
313#ifdef OPENSSL_FIPS
314 FIPS_selftest_check();
315#endif
316 return ctx->digest->update(ctx,data,count);
317 }
318
319/* The caller can assume that this removes any secret data from the context */
320int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
321 {
322 int ret;
323 ret = EVP_DigestFinal_ex(ctx, md, size);
324 EVP_MD_CTX_cleanup(ctx);
325 return ret;
326 }
327
328/* The caller can assume that this removes any secret data from the context */
329int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
330 {
331 int ret;
332#ifdef OPENSSL_FIPS
333 FIPS_selftest_check();
334#endif
335
336 OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE);
337 ret=ctx->digest->final(ctx,md);
338 if (size != NULL)
339 *size=ctx->digest->md_size;
340 if (ctx->digest->cleanup)
341 {
342 ctx->digest->cleanup(ctx);
343 M_EVP_MD_CTX_set_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
344 }
345 memset(ctx->md_data,0,ctx->digest->ctx_size);
346 return ret;
347 }
348
349int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)
350 {
351 EVP_MD_CTX_init(out);
352 return EVP_MD_CTX_copy_ex(out, in);
353 }
354
355int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
356 {
357 unsigned char *tmp_buf;
358 if ((in == NULL) || (in->digest == NULL))
359 {
360 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,EVP_R_INPUT_NOT_INITIALIZED);
361 return 0;
362 }
363#ifndef OPENSSL_NO_ENGINE
364 /* Make sure it's safe to copy a digest context using an ENGINE */
365 if (in->engine && !do_engine_init(in->engine))
366 {
367 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_ENGINE_LIB);
368 return 0;
369 }
370#endif
371
372 if (out->digest == in->digest)
373 {
374 tmp_buf = out->md_data;
375 M_EVP_MD_CTX_set_flags(out,EVP_MD_CTX_FLAG_REUSE);
376 }
377 else tmp_buf = NULL;
378 EVP_MD_CTX_cleanup(out);
379 memcpy(out,in,sizeof *out);
380
381 if (out->digest->ctx_size)
382 {
383 if (tmp_buf) out->md_data = tmp_buf;
384 else out->md_data=OPENSSL_malloc(out->digest->ctx_size);
385 memcpy(out->md_data,in->md_data,out->digest->ctx_size);
386 }
387
388 if (out->digest->copy)
389 return out->digest->copy(out,in);
390
391 return 1;
392 }
393
394int EVP_Digest(const void *data, size_t count,
395 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl)
396 {
397 EVP_MD_CTX ctx;
398 int ret;
399
400 EVP_MD_CTX_init(&ctx);
401 M_EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT);
402 ret=EVP_DigestInit_ex(&ctx, type, impl)
403 && EVP_DigestUpdate(&ctx, data, count)
404 && EVP_DigestFinal_ex(&ctx, md, size);
405 EVP_MD_CTX_cleanup(&ctx);
406
407 return ret;
408 }
409
410void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
411 {
412 EVP_MD_CTX_cleanup(ctx);
413 OPENSSL_free(ctx);
414 }
415
416/* This call frees resources associated with the context */
417int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
418 {
419 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
420 * because sometimes only copies of the context are ever finalised.
421 */
422 if (ctx->digest && ctx->digest->cleanup
423 && !M_EVP_MD_CTX_test_flags(ctx,EVP_MD_CTX_FLAG_CLEANED))
424 ctx->digest->cleanup(ctx);
425 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
426 && !M_EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
427 {
428 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
429 OPENSSL_free(ctx->md_data);
430 }
431#ifndef OPENSSL_NO_ENGINE
432 if(ctx->engine)
433 /* The EVP_MD we used belongs to an ENGINE, release the
434 * functional reference we held for this reason. */
435 do_engine_finish(ctx->engine);
436#endif
437 memset(ctx,'\0',sizeof *ctx);
438
439 return 1;
440 }
diff --git a/src/lib/libcrypto/evp/e_acss.c b/src/lib/libcrypto/evp/e_acss.c
new file mode 100644
index 0000000000..a16b85c627
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_acss.c
@@ -0,0 +1,85 @@
1/* $Id: e_acss.c,v 1.2 2004/02/13 10:05:44 hshoexer Exp $ */
2/*
3 * Copyright (c) 2004 The OpenBSD project
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef OPENSSL_NO_ACSS
19
20#include "cryptlib.h"
21#include <openssl/evp.h>
22#include <openssl/objects.h>
23#include "evp_locl.h"
24#include <openssl/acss.h>
25
26typedef struct {
27 ACSS_KEY ks;
28} EVP_ACSS_KEY;
29
30#define data(ctx) EVP_C_DATA(EVP_ACSS_KEY,ctx)
31
32static int acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
33 const unsigned char *iv, int enc);
34static int acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out,
35 const unsigned char *in, unsigned int inl);
36static int acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
37static const EVP_CIPHER acss_cipher = {
38 NID_undef,
39 1,5,0,
40 0,
41 acss_init_key,
42 acss_ciph,
43 NULL,
44 sizeof(EVP_ACSS_KEY),
45 NULL,
46 NULL,
47 acss_ctrl,
48 NULL
49};
50
51const
52EVP_CIPHER *EVP_acss(void)
53{
54 return(&acss_cipher);
55}
56
57static int
58acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
59 const unsigned char *iv, int enc)
60{
61 acss_setkey(&data(ctx)->ks,key,enc,ACSS_MODE1);
62 return 1;
63}
64
65static int
66acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in,
67 unsigned int inl)
68{
69 acss(&data(ctx)->ks,inl,in,out);
70 return 1;
71}
72
73static int
74acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
75{
76 switch(type) {
77 case EVP_CTRL_SET_ACSS_MODE:
78 data(ctx)->ks.mode = arg;
79 return 1;
80
81 default:
82 return -1;
83 }
84}
85#endif
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
new file mode 100644
index 0000000000..c9a5ee8d75
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -0,0 +1,117 @@
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#include <openssl/opensslconf.h>
52#ifndef OPENSSL_NO_AES
53#include <openssl/evp.h>
54#include <openssl/err.h>
55#include <string.h>
56#include <assert.h>
57#include <openssl/aes.h>
58#include "evp_locl.h"
59
60static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
61 const unsigned char *iv, int enc);
62
63typedef struct
64 {
65 AES_KEY ks;
66 } EVP_AES_KEY;
67
68#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
69
70IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
71 NID_aes_128, 16, 16, 16, 128,
72 EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
73 aes_init_key,
74 NULL, NULL, NULL, NULL)
75IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
76 NID_aes_192, 16, 24, 16, 128,
77 EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
78 aes_init_key,
79 NULL, NULL, NULL, NULL)
80IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
81 NID_aes_256, 16, 32, 16, 128,
82 EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
83 aes_init_key,
84 NULL, NULL, NULL, NULL)
85
86#define IMPLEMENT_AES_CFBR(ksize,cbits,flags) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16,flags)
87
88IMPLEMENT_AES_CFBR(128,1,EVP_CIPH_FLAG_FIPS)
89IMPLEMENT_AES_CFBR(192,1,EVP_CIPH_FLAG_FIPS)
90IMPLEMENT_AES_CFBR(256,1,EVP_CIPH_FLAG_FIPS)
91
92IMPLEMENT_AES_CFBR(128,8,EVP_CIPH_FLAG_FIPS)
93IMPLEMENT_AES_CFBR(192,8,EVP_CIPH_FLAG_FIPS)
94IMPLEMENT_AES_CFBR(256,8,EVP_CIPH_FLAG_FIPS)
95
96static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
97 const unsigned char *iv, int enc)
98 {
99 int ret;
100
101 if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
102 || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
103 || enc)
104 ret=AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
105 else
106 ret=AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
107
108 if(ret < 0)
109 {
110 EVPerr(EVP_F_AES_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
111 return 0;
112 }
113
114 return 1;
115 }
116
117#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..cc224e5363
--- /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#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_BF
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_camellia.c b/src/lib/libcrypto/evp/e_camellia.c
new file mode 100644
index 0000000000..365d397164
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_camellia.c
@@ -0,0 +1,131 @@
1/* crypto/evp/e_camellia.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2006 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#include <openssl/opensslconf.h>
57#ifndef OPENSSL_NO_CAMELLIA
58#include <openssl/evp.h>
59#include <openssl/err.h>
60#include <string.h>
61#include <assert.h>
62#include <openssl/camellia.h>
63#include "evp_locl.h"
64
65static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
66 const unsigned char *iv, int enc);
67
68/* Camellia subkey Structure */
69typedef struct
70 {
71 CAMELLIA_KEY ks;
72 } EVP_CAMELLIA_KEY;
73
74/* Attribute operation for Camellia */
75#define data(ctx) EVP_C_DATA(EVP_CAMELLIA_KEY,ctx)
76
77IMPLEMENT_BLOCK_CIPHER(camellia_128, ks, Camellia, EVP_CAMELLIA_KEY,
78 NID_camellia_128, 16, 16, 16, 128,
79 0, camellia_init_key, NULL,
80 EVP_CIPHER_set_asn1_iv,
81 EVP_CIPHER_get_asn1_iv,
82 NULL)
83IMPLEMENT_BLOCK_CIPHER(camellia_192, ks, Camellia, EVP_CAMELLIA_KEY,
84 NID_camellia_192, 16, 24, 16, 128,
85 0, camellia_init_key, NULL,
86 EVP_CIPHER_set_asn1_iv,
87 EVP_CIPHER_get_asn1_iv,
88 NULL)
89IMPLEMENT_BLOCK_CIPHER(camellia_256, ks, Camellia, EVP_CAMELLIA_KEY,
90 NID_camellia_256, 16, 32, 16, 128,
91 0, camellia_init_key, NULL,
92 EVP_CIPHER_set_asn1_iv,
93 EVP_CIPHER_get_asn1_iv,
94 NULL)
95
96#define IMPLEMENT_CAMELLIA_CFBR(ksize,cbits) IMPLEMENT_CFBR(camellia,Camellia,EVP_CAMELLIA_KEY,ks,ksize,cbits,16,0)
97
98IMPLEMENT_CAMELLIA_CFBR(128,1)
99IMPLEMENT_CAMELLIA_CFBR(192,1)
100IMPLEMENT_CAMELLIA_CFBR(256,1)
101
102IMPLEMENT_CAMELLIA_CFBR(128,8)
103IMPLEMENT_CAMELLIA_CFBR(192,8)
104IMPLEMENT_CAMELLIA_CFBR(256,8)
105
106
107
108/* The subkey for Camellia is generated. */
109static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
110 const unsigned char *iv, int enc)
111 {
112 int ret;
113
114 ret=Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data);
115
116 if(ret < 0)
117 {
118 EVPerr(EVP_F_CAMELLIA_INIT_KEY,EVP_R_CAMELLIA_KEY_SETUP_FAILED);
119 return 0;
120 }
121
122 return 1;
123 }
124
125#else
126
127# ifdef PEDANTIC
128static void *dummy=&dummy;
129# endif
130
131#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..d77bcd9298
--- /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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_CAST
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..04376df232
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des.c
@@ -0,0 +1,179 @@
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#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66#include <openssl/rand.h>
67
68static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv, int enc);
70static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
71
72/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
73
74static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
75 const unsigned char *in, unsigned int inl)
76{
77 BLOCK_CIPHER_ecb_loop()
78 DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), ctx->cipher_data, ctx->encrypt);
79 return 1;
80}
81
82static int des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
83 const unsigned char *in, unsigned int inl)
84{
85 DES_ofb64_encrypt(in, out, (long)inl, ctx->cipher_data, (DES_cblock *)ctx->iv, &ctx->num);
86 return 1;
87}
88
89static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
90 const unsigned char *in, unsigned int inl)
91{
92 DES_ncbc_encrypt(in, out, (long)inl, ctx->cipher_data,
93 (DES_cblock *)ctx->iv, ctx->encrypt);
94 return 1;
95}
96
97static int des_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
98 const unsigned char *in, unsigned int inl)
99{
100 DES_cfb64_encrypt(in, out, (long)inl, ctx->cipher_data,
101 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
102 return 1;
103}
104
105/* Although we have a CFB-r implementation for DES, it doesn't pack the right
106 way, so wrap it here */
107static int des_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
108 const unsigned char *in, unsigned int inl)
109 {
110 unsigned int n;
111 unsigned char c[1],d[1];
112
113 for(n=0 ; n < inl ; ++n)
114 {
115 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
116 DES_cfb_encrypt(c,d,1,1,ctx->cipher_data,(DES_cblock *)ctx->iv,
117 ctx->encrypt);
118 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
119 }
120 return 1;
121 }
122
123static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
124 const unsigned char *in, unsigned int inl)
125 {
126 DES_cfb_encrypt(in,out,8,inl,ctx->cipher_data,(DES_cblock *)ctx->iv,
127 ctx->encrypt);
128 return 1;
129 }
130
131BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
132 EVP_CIPH_RAND_KEY,
133 des_init_key, NULL,
134 EVP_CIPHER_set_asn1_iv,
135 EVP_CIPHER_get_asn1_iv,
136 des_ctrl)
137
138BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
139 EVP_CIPH_RAND_KEY,
140 des_init_key, NULL,
141 EVP_CIPHER_set_asn1_iv,
142 EVP_CIPHER_get_asn1_iv,des_ctrl)
143
144BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
145 EVP_CIPH_RAND_KEY,
146 des_init_key,NULL,
147 EVP_CIPHER_set_asn1_iv,
148 EVP_CIPHER_get_asn1_iv,des_ctrl)
149
150static int des_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#ifdef EVP_CHECK_DES_KEY
155 if(DES_set_key_checked(deskey,ctx->cipher_data) != 0)
156 return 0;
157#else
158 DES_set_key_unchecked(deskey,ctx->cipher_data);
159#endif
160 return 1;
161 }
162
163static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
164 {
165
166 switch(type)
167 {
168 case EVP_CTRL_RAND_KEY:
169 if (RAND_bytes(ptr, 8) <= 0)
170 return 0;
171 DES_set_odd_parity((DES_cblock *)ptr);
172 return 1;
173
174 default:
175 return -1;
176 }
177 }
178
179#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..f910af19b1
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_des3.c
@@ -0,0 +1,270 @@
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#include <stdio.h>
60#include "cryptlib.h"
61#ifndef OPENSSL_NO_DES
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include "evp_locl.h"
65#include <openssl/des.h>
66#include <openssl/rand.h>
67
68static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70
71static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
72 const unsigned char *iv,int enc);
73
74static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
75
76typedef struct
77 {
78 DES_key_schedule ks1;/* key schedule */
79 DES_key_schedule ks2;/* key schedule (for ede) */
80 DES_key_schedule ks3;/* key schedule (for ede3) */
81 } DES_EDE_KEY;
82
83#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data)
84
85/* Because of various casts and different args can't use IMPLEMENT_BLOCK_CIPHER */
86
87static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
88 const unsigned char *in, unsigned int inl)
89{
90 BLOCK_CIPHER_ecb_loop()
91 DES_ecb3_encrypt((const_DES_cblock *)(in + i),
92 (DES_cblock *)(out + i),
93 &data(ctx)->ks1, &data(ctx)->ks2,
94 &data(ctx)->ks3,
95 ctx->encrypt);
96 return 1;
97}
98
99static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
100 const unsigned char *in, unsigned int inl)
101{
102 DES_ede3_ofb64_encrypt(in, out, (long)inl,
103 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
104 (DES_cblock *)ctx->iv, &ctx->num);
105 return 1;
106}
107
108static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
109 const unsigned char *in, unsigned int inl)
110{
111#ifdef KSSL_DEBUG
112 {
113 int i;
114 printf("des_ede_cbc_cipher(ctx=%lx, buflen=%d)\n", (unsigned long)ctx, ctx->buf_len);
115 printf("\t iv= ");
116 for(i=0;i<8;i++)
117 printf("%02X",ctx->iv[i]);
118 printf("\n");
119 }
120#endif /* KSSL_DEBUG */
121 DES_ede3_cbc_encrypt(in, out, (long)inl,
122 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
123 (DES_cblock *)ctx->iv, ctx->encrypt);
124 return 1;
125}
126
127static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
128 const unsigned char *in, unsigned int inl)
129{
130 DES_ede3_cfb64_encrypt(in, out, (long)inl,
131 &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3,
132 (DES_cblock *)ctx->iv, &ctx->num, ctx->encrypt);
133 return 1;
134}
135
136/* Although we have a CFB-r implementation for 3-DES, it doesn't pack the right
137 way, so wrap it here */
138static int des_ede3_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
139 const unsigned char *in, unsigned int inl)
140 {
141 unsigned int n;
142 unsigned char c[1],d[1];
143
144 for(n=0 ; n < inl ; ++n)
145 {
146 c[0]=(in[n/8]&(1 << (7-n%8))) ? 0x80 : 0;
147 DES_ede3_cfb_encrypt(c,d,1,1,
148 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
149 (DES_cblock *)ctx->iv,ctx->encrypt);
150 out[n/8]=(out[n/8]&~(0x80 >> (n%8)))|((d[0]&0x80) >> (n%8));
151 }
152
153 return 1;
154 }
155
156static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
157 const unsigned char *in, unsigned int inl)
158 {
159 DES_ede3_cfb_encrypt(in,out,8,inl,
160 &data(ctx)->ks1,&data(ctx)->ks2,&data(ctx)->ks3,
161 (DES_cblock *)ctx->iv,ctx->encrypt);
162 return 1;
163 }
164
165BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
166 EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
167 des_ede_init_key,
168 NULL, NULL, NULL,
169 des3_ctrl)
170
171#define des_ede3_cfb64_cipher des_ede_cfb64_cipher
172#define des_ede3_ofb_cipher des_ede_ofb_cipher
173#define des_ede3_cbc_cipher des_ede_cbc_cipher
174#define des_ede3_ecb_cipher des_ede_ecb_cipher
175
176BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
177 EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
178 des_ede3_init_key,
179 NULL, NULL, NULL,
180 des3_ctrl)
181
182BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,
183 EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
184 des_ede3_init_key,
185 NULL, NULL, NULL,
186 des3_ctrl)
187
188BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,
189 EVP_CIPH_RAND_KEY|EVP_CIPH_FLAG_FIPS|EVP_CIPH_FLAG_DEFAULT_ASN1,
190 des_ede3_init_key,
191 NULL, NULL, NULL,
192 des3_ctrl)
193
194static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
195 const unsigned char *iv, int enc)
196 {
197 DES_cblock *deskey = (DES_cblock *)key;
198#ifdef EVP_CHECK_DES_KEY
199 if (DES_set_key_checked(&deskey[0],&data(ctx)->ks1)
200 !! DES_set_key_checked(&deskey[1],&data(ctx)->ks2))
201 return 0;
202#else
203 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
204 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
205#endif
206 memcpy(&data(ctx)->ks3,&data(ctx)->ks1,
207 sizeof(data(ctx)->ks1));
208 return 1;
209 }
210
211static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
212 const unsigned char *iv, int enc)
213 {
214 DES_cblock *deskey = (DES_cblock *)key;
215#ifdef KSSL_DEBUG
216 {
217 int i;
218 printf("des_ede3_init_key(ctx=%lx)\n", (unsigned long)ctx);
219 printf("\tKEY= ");
220 for(i=0;i<24;i++) printf("%02X",key[i]); printf("\n");
221 printf("\t IV= ");
222 for(i=0;i<8;i++) printf("%02X",iv[i]); printf("\n");
223 }
224#endif /* KSSL_DEBUG */
225
226#ifdef EVP_CHECK_DES_KEY
227 if (DES_set_key_checked(&deskey[0],&data(ctx)->ks1)
228 || DES_set_key_checked(&deskey[1],&data(ctx)->ks2)
229 || DES_set_key_checked(&deskey[2],&data(ctx)->ks3))
230 return 0;
231#else
232 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
233 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
234 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3);
235#endif
236 return 1;
237 }
238
239static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
240 {
241
242 DES_cblock *deskey = ptr;
243
244 switch(type)
245 {
246 case EVP_CTRL_RAND_KEY:
247 if (RAND_bytes(ptr, c->key_len) <= 0)
248 return 0;
249 DES_set_odd_parity(deskey);
250 if (c->key_len >= 16)
251 DES_set_odd_parity(deskey + 1);
252 if (c->key_len >= 24)
253 DES_set_odd_parity(deskey + 2);
254 return 1;
255
256 default:
257 return -1;
258 }
259 }
260
261const EVP_CIPHER *EVP_des_ede(void)
262{
263 return &des_ede_ecb;
264}
265
266const EVP_CIPHER *EVP_des_ede3(void)
267{
268 return &des_ede3_ecb;
269}
270#endif
diff --git a/src/lib/libcrypto/evp/e_dsa.c b/src/lib/libcrypto/evp/e_dsa.c
new file mode 100644
index 0000000000..b96f2738b3
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_dsa.c
@@ -0,0 +1,71 @@
1/* crypto/evp/e_dsa.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 EVP_PKEY_METHOD dss_method=
66 {
67 DSA_sign,
68 DSA_verify,
69 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3,NULL},
70 };
71
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
new file mode 100644
index 0000000000..48c33a774a
--- /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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_IDEA
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 OPENSSL_cleanse((unsigned char *)&tmp,
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..0872d733e4
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_null.c
@@ -0,0 +1,102 @@
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 EVP_CIPH_FLAG_FIPS,
73 null_init_key,
74 null_cipher,
75 NULL,
76 0,
77 NULL,
78 NULL,
79 NULL,
80 NULL
81 };
82
83const EVP_CIPHER *EVP_enc_null(void)
84 {
85 return(&n_cipher);
86 }
87
88static int null_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
89 const unsigned char *iv, int enc)
90 {
91 /* memset(&(ctx->c),0,sizeof(ctx->c));*/
92 return 1;
93 }
94
95static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97 {
98 if (in != out)
99 memcpy((char *)out,(const char *)in,(size_t)inl);
100 return 1;
101 }
102
diff --git a/src/lib/libcrypto/evp/e_old.c b/src/lib/libcrypto/evp/e_old.c
new file mode 100644
index 0000000000..1642af4869
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_old.c
@@ -0,0 +1,125 @@
1/* crypto/evp/e_old.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2004.
4 */
5/* ====================================================================
6 * Copyright (c) 2004 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 * openssl-core@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#ifdef OPENSSL_NO_DEPRECATED
60static void *dummy = &dummy;
61#else
62
63#include <openssl/evp.h>
64
65/* Define some deprecated functions, so older programs
66 don't crash and burn too quickly. On Windows and VMS,
67 these will never be used, since functions and variables
68 in shared libraries are selected by entry point location,
69 not by name. */
70
71#ifndef OPENSSL_NO_BF
72#undef EVP_bf_cfb
73const EVP_CIPHER *EVP_bf_cfb(void);
74const EVP_CIPHER *EVP_bf_cfb(void) { return EVP_bf_cfb64(); }
75#endif
76
77#ifndef OPENSSL_NO_DES
78#undef EVP_des_cfb
79const EVP_CIPHER *EVP_des_cfb(void);
80const EVP_CIPHER *EVP_des_cfb(void) { return EVP_des_cfb64(); }
81#undef EVP_des_ede3_cfb
82const EVP_CIPHER *EVP_des_ede3_cfb(void);
83const EVP_CIPHER *EVP_des_ede3_cfb(void) { return EVP_des_ede3_cfb64(); }
84#undef EVP_des_ede_cfb
85const EVP_CIPHER *EVP_des_ede_cfb(void);
86const EVP_CIPHER *EVP_des_ede_cfb(void) { return EVP_des_ede_cfb64(); }
87#endif
88
89#ifndef OPENSSL_NO_IDEA
90#undef EVP_idea_cfb
91const EVP_CIPHER *EVP_idea_cfb(void);
92const EVP_CIPHER *EVP_idea_cfb(void) { return EVP_idea_cfb64(); }
93#endif
94
95#ifndef OPENSSL_NO_RC2
96#undef EVP_rc2_cfb
97const EVP_CIPHER *EVP_rc2_cfb(void);
98const EVP_CIPHER *EVP_rc2_cfb(void) { return EVP_rc2_cfb64(); }
99#endif
100
101#ifndef OPENSSL_NO_CAST
102#undef EVP_cast5_cfb
103const EVP_CIPHER *EVP_cast5_cfb(void);
104const EVP_CIPHER *EVP_cast5_cfb(void) { return EVP_cast5_cfb64(); }
105#endif
106
107#ifndef OPENSSL_NO_RC5
108#undef EVP_rc5_32_12_16_cfb
109const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void);
110const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) { return EVP_rc5_32_12_16_cfb64(); }
111#endif
112
113#ifndef OPENSSL_NO_AES
114#undef EVP_aes_128_cfb
115const EVP_CIPHER *EVP_aes_128_cfb(void);
116const EVP_CIPHER *EVP_aes_128_cfb(void) { return EVP_aes_128_cfb128(); }
117#undef EVP_aes_192_cfb
118const EVP_CIPHER *EVP_aes_192_cfb(void);
119const EVP_CIPHER *EVP_aes_192_cfb(void) { return EVP_aes_192_cfb128(); }
120#undef EVP_aes_256_cfb
121const EVP_CIPHER *EVP_aes_256_cfb(void);
122const EVP_CIPHER *EVP_aes_256_cfb(void) { return EVP_aes_256_cfb128(); }
123#endif
124
125#endif
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
new file mode 100644
index 0000000000..d37726ffae
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -0,0 +1,232 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RC2
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include "evp_locl.h"
67#include <openssl/rc2.h>
68
69static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
70 const unsigned char *iv,int enc);
71static int rc2_meth_to_magic(EVP_CIPHER_CTX *ctx);
72static int rc2_magic_to_meth(int i);
73static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
75static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
76
77typedef struct
78 {
79 int key_bits; /* effective key bits */
80 RC2_KEY ks; /* key schedule */
81 } EVP_RC2_KEY;
82
83#define data(ctx) ((EVP_RC2_KEY *)(ctx)->cipher_data)
84
85IMPLEMENT_BLOCK_CIPHER(rc2, ks, RC2, EVP_RC2_KEY, NID_rc2,
86 8,
87 RC2_KEY_LENGTH, 8, 64,
88 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
89 rc2_init_key, NULL,
90 rc2_set_asn1_type_and_iv, rc2_get_asn1_type_and_iv,
91 rc2_ctrl)
92
93#define RC2_40_MAGIC 0xa0
94#define RC2_64_MAGIC 0x78
95#define RC2_128_MAGIC 0x3a
96
97static const EVP_CIPHER r2_64_cbc_cipher=
98 {
99 NID_rc2_64_cbc,
100 8,8 /* 64 bit */,8,
101 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
102 rc2_init_key,
103 rc2_cbc_cipher,
104 NULL,
105 sizeof(EVP_RC2_KEY),
106 rc2_set_asn1_type_and_iv,
107 rc2_get_asn1_type_and_iv,
108 rc2_ctrl,
109 NULL
110 };
111
112static const EVP_CIPHER r2_40_cbc_cipher=
113 {
114 NID_rc2_40_cbc,
115 8,5 /* 40 bit */,8,
116 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
117 rc2_init_key,
118 rc2_cbc_cipher,
119 NULL,
120 sizeof(EVP_RC2_KEY),
121 rc2_set_asn1_type_and_iv,
122 rc2_get_asn1_type_and_iv,
123 rc2_ctrl,
124 NULL
125 };
126
127const EVP_CIPHER *EVP_rc2_64_cbc(void)
128 {
129 return(&r2_64_cbc_cipher);
130 }
131
132const EVP_CIPHER *EVP_rc2_40_cbc(void)
133 {
134 return(&r2_40_cbc_cipher);
135 }
136
137static int rc2_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
138 const unsigned char *iv, int enc)
139 {
140 RC2_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
141 key,data(ctx)->key_bits);
142 return 1;
143 }
144
145static int rc2_meth_to_magic(EVP_CIPHER_CTX *e)
146 {
147 int i;
148
149 EVP_CIPHER_CTX_ctrl(e, EVP_CTRL_GET_RC2_KEY_BITS, 0, &i);
150 if (i == 128) return(RC2_128_MAGIC);
151 else if (i == 64) return(RC2_64_MAGIC);
152 else if (i == 40) return(RC2_40_MAGIC);
153 else return(0);
154 }
155
156static int rc2_magic_to_meth(int i)
157 {
158 if (i == RC2_128_MAGIC) return 128;
159 else if (i == RC2_64_MAGIC) return 64;
160 else if (i == RC2_40_MAGIC) return 40;
161 else
162 {
163 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
164 return(0);
165 }
166 }
167
168static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
169 {
170 long num=0;
171 int i=0;
172 int key_bits;
173 unsigned int l;
174 unsigned char iv[EVP_MAX_IV_LENGTH];
175
176 if (type != NULL)
177 {
178 l=EVP_CIPHER_CTX_iv_length(c);
179 OPENSSL_assert(l <= sizeof(iv));
180 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
181 if (i != (int)l)
182 return(-1);
183 key_bits =rc2_magic_to_meth((int)num);
184 if (!key_bits)
185 return(-1);
186 if(i > 0) EVP_CipherInit_ex(c, NULL, NULL, NULL, iv, -1);
187 EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_RC2_KEY_BITS, key_bits, NULL);
188 EVP_CIPHER_CTX_set_key_length(c, key_bits / 8);
189 }
190 return(i);
191 }
192
193static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
194 {
195 long num;
196 int i=0,j;
197
198 if (type != NULL)
199 {
200 num=rc2_meth_to_magic(c);
201 j=EVP_CIPHER_CTX_iv_length(c);
202 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
203 }
204 return(i);
205 }
206
207static int rc2_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
208 {
209 switch(type)
210 {
211 case EVP_CTRL_INIT:
212 data(c)->key_bits = EVP_CIPHER_CTX_key_length(c) * 8;
213 return 1;
214
215 case EVP_CTRL_GET_RC2_KEY_BITS:
216 *(int *)ptr = data(c)->key_bits;
217 return 1;
218
219 case EVP_CTRL_SET_RC2_KEY_BITS:
220 if(arg > 0)
221 {
222 data(c)->key_bits = arg;
223 return 1;
224 }
225 return 0;
226
227 default:
228 return -1;
229 }
230 }
231
232#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..55baad7446
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc4.c
@@ -0,0 +1,137 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RC4
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/rc4.h>
67#include "evp_locl.h"
68
69/* FIXME: surely this is available elsewhere? */
70#define EVP_RC4_KEY_SIZE 16
71
72typedef struct
73 {
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 NULL
96 };
97
98static const EVP_CIPHER r4_40_cipher=
99 {
100 NID_rc4_40,
101 1,5 /* 40 bit */,0,
102 EVP_CIPH_VARIABLE_LENGTH,
103 rc4_init_key,
104 rc4_cipher,
105 NULL,
106 sizeof(EVP_RC4_KEY),
107 NULL,
108 NULL,
109 NULL,
110 NULL
111 };
112
113const EVP_CIPHER *EVP_rc4(void)
114 {
115 return(&r4_cipher);
116 }
117
118const EVP_CIPHER *EVP_rc4_40(void)
119 {
120 return(&r4_40_cipher);
121 }
122
123static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
124 const unsigned char *iv, int enc)
125 {
126 RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
127 key);
128 return 1;
129 }
130
131static int rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
132 const unsigned char *in, unsigned int inl)
133 {
134 RC4(&data(ctx)->ks,inl,in,out);
135 return 1;
136 }
137#endif
diff --git a/src/lib/libcrypto/evp/e_rc5.c b/src/lib/libcrypto/evp/e_rc5.c
new file mode 100644
index 0000000000..19a10c6402
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc5.c
@@ -0,0 +1,126 @@
1/* crypto/evp/e_rc5.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
62#ifndef OPENSSL_NO_RC5
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include "evp_locl.h"
67#include <openssl/rc5.h>
68
69static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
70 const unsigned char *iv,int enc);
71static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
72
73typedef struct
74 {
75 int rounds; /* number of rounds */
76 RC5_32_KEY ks; /* key schedule */
77 } EVP_RC5_KEY;
78
79#define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx)
80
81IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5,
82 8, RC5_32_KEY_LENGTH, 8, 64,
83 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
84 r_32_12_16_init_key, NULL,
85 NULL, NULL, rc5_ctrl)
86
87static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
88 {
89 switch(type)
90 {
91 case EVP_CTRL_INIT:
92 data(c)->rounds = RC5_12_ROUNDS;
93 return 1;
94
95 case EVP_CTRL_GET_RC5_ROUNDS:
96 *(int *)ptr = data(c)->rounds;
97 return 1;
98
99 case EVP_CTRL_SET_RC5_ROUNDS:
100 switch(arg)
101 {
102 case RC5_8_ROUNDS:
103 case RC5_12_ROUNDS:
104 case RC5_16_ROUNDS:
105 data(c)->rounds = arg;
106 return 1;
107
108 default:
109 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
110 return 0;
111 }
112
113 default:
114 return -1;
115 }
116 }
117
118static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
119 const unsigned char *iv, int enc)
120 {
121 RC5_32_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
122 key,data(ctx)->rounds);
123 return 1;
124 }
125
126#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..8832da2433
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -0,0 +1,125 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_DES
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/des.h>
67
68static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
71 const unsigned char *in, unsigned int inl);
72
73
74typedef struct
75 {
76 DES_key_schedule ks;/* key schedule */
77 DES_cblock inw;
78 DES_cblock outw;
79 } DESX_CBC_KEY;
80
81#define data(ctx) ((DESX_CBC_KEY *)(ctx)->cipher_data)
82
83static const EVP_CIPHER d_xcbc_cipher=
84 {
85 NID_desx_cbc,
86 8,24,8,
87 EVP_CIPH_CBC_MODE,
88 desx_cbc_init_key,
89 desx_cbc_cipher,
90 NULL,
91 sizeof(DESX_CBC_KEY),
92 EVP_CIPHER_set_asn1_iv,
93 EVP_CIPHER_get_asn1_iv,
94 NULL,
95 NULL
96 };
97
98const EVP_CIPHER *EVP_desx_cbc(void)
99 {
100 return(&d_xcbc_cipher);
101 }
102
103static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
104 const unsigned char *iv, int enc)
105 {
106 DES_cblock *deskey = (DES_cblock *)key;
107
108 DES_set_key_unchecked(deskey,&data(ctx)->ks);
109 memcpy(&data(ctx)->inw[0],&key[8],8);
110 memcpy(&data(ctx)->outw[0],&key[16],8);
111
112 return 1;
113 }
114
115static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
116 const unsigned char *in, unsigned int inl)
117 {
118 DES_xcbc_encrypt(in,out,inl,&data(ctx)->ks,
119 (DES_cblock *)&(ctx->iv[0]),
120 &data(ctx)->inw,
121 &data(ctx)->outw,
122 ctx->encrypt);
123 return 1;
124 }
125#endif
diff --git a/src/lib/libcrypto/evp/enc_min.c b/src/lib/libcrypto/evp/enc_min.c
new file mode 100644
index 0000000000..7fba38ee24
--- /dev/null
+++ b/src/lib/libcrypto/evp/enc_min.c
@@ -0,0 +1,390 @@
1/* crypto/evp/enc_min.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/rand.h>
64#ifndef OPENSSL_NO_ENGINE
65#include <openssl/engine.h>
66#endif
67#include "evp_locl.h"
68
69void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
70 {
71#ifdef OPENSSL_FIPS
72 FIPS_selftest_check();
73#endif
74 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
75 /* ctx->cipher=NULL; */
76 }
77
78#ifdef OPENSSL_FIPS
79
80/* The purpose of these is to trap programs that attempt to use non FIPS
81 * algorithms in FIPS mode and ignore the errors.
82 */
83
84static int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
85 const unsigned char *iv, int enc)
86 { FIPS_ERROR_IGNORED("Cipher init"); return 0;}
87
88static int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
89 const unsigned char *in, unsigned int inl)
90 { FIPS_ERROR_IGNORED("Cipher update"); return 0;}
91
92/* NB: no cleanup because it is allowed after failed init */
93
94static int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
95 { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;}
96static int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
97 { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;}
98static int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
99 { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;}
100
101static const EVP_CIPHER bad_cipher =
102 {
103 0,
104 0,
105 0,
106 0,
107 0,
108 bad_init,
109 bad_do_cipher,
110 NULL,
111 0,
112 bad_set_asn1,
113 bad_get_asn1,
114 bad_ctrl,
115 NULL
116 };
117
118#endif
119
120#ifndef OPENSSL_NO_ENGINE
121
122#ifdef OPENSSL_FIPS
123
124static int do_engine_null(ENGINE *impl) { return 0;}
125static int do_evp_enc_engine_null(EVP_CIPHER_CTX *ctx,
126 const EVP_CIPHER **pciph, ENGINE *impl)
127 { return 1; }
128
129static int (*do_engine_finish)(ENGINE *impl)
130 = do_engine_null;
131
132static int (*do_evp_enc_engine)
133 (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl)
134 = do_evp_enc_engine_null;
135
136void int_EVP_CIPHER_set_engine_callbacks(
137 int (*eng_ciph_fin)(ENGINE *impl),
138 int (*eng_ciph_evp)
139 (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl))
140 {
141 do_engine_finish = eng_ciph_fin;
142 do_evp_enc_engine = eng_ciph_evp;
143 }
144
145#else
146
147#define do_engine_finish ENGINE_finish
148
149static int do_evp_enc_engine(EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pcipher, ENGINE *impl)
150 {
151 if(impl)
152 {
153 if (!ENGINE_init(impl))
154 {
155 EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR);
156 return 0;
157 }
158 }
159 else
160 /* Ask if an ENGINE is reserved for this job */
161 impl = ENGINE_get_cipher_engine((*pcipher)->nid);
162 if(impl)
163 {
164 /* There's an ENGINE for this job ... (apparently) */
165 const EVP_CIPHER *c = ENGINE_get_cipher(impl, (*pcipher)->nid);
166 if(!c)
167 {
168 /* One positive side-effect of US's export
169 * control history, is that we should at least
170 * be able to avoid using US mispellings of
171 * "initialisation"? */
172 EVPerr(EVP_F_DO_EVP_ENC_ENGINE, EVP_R_INITIALIZATION_ERROR);
173 return 0;
174 }
175 /* We'll use the ENGINE's private cipher definition */
176 *pcipher = c;
177 /* Store the ENGINE functional reference so we know
178 * 'cipher' came from an ENGINE and we need to release
179 * it when done. */
180 ctx->engine = impl;
181 }
182 else
183 ctx->engine = NULL;
184 return 1;
185 }
186
187#endif
188
189#endif
190
191int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
192 const unsigned char *key, const unsigned char *iv, int enc)
193 {
194 if (enc == -1)
195 enc = ctx->encrypt;
196 else
197 {
198 if (enc)
199 enc = 1;
200 ctx->encrypt = enc;
201 }
202#ifdef OPENSSL_FIPS
203 if(FIPS_selftest_failed())
204 {
205 FIPSerr(FIPS_F_EVP_CIPHERINIT_EX,FIPS_R_FIPS_SELFTEST_FAILED);
206 ctx->cipher = &bad_cipher;
207 return 0;
208 }
209#endif
210#ifndef OPENSSL_NO_ENGINE
211 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
212 * so this context may already have an ENGINE! Try to avoid releasing
213 * the previous handle, re-querying for an ENGINE, and having a
214 * reinitialisation, when it may all be unecessary. */
215 if (ctx->engine && ctx->cipher && (!cipher ||
216 (cipher && (cipher->nid == ctx->cipher->nid))))
217 goto skip_to_init;
218#endif
219 if (cipher)
220 {
221 /* Ensure a context left lying around from last time is cleared
222 * (the previous check attempted to avoid this if the same
223 * ENGINE and EVP_CIPHER could be used). */
224 EVP_CIPHER_CTX_cleanup(ctx);
225
226 /* Restore encrypt field: it is zeroed by cleanup */
227 ctx->encrypt = enc;
228#ifndef OPENSSL_NO_ENGINE
229 if (!do_evp_enc_engine(ctx, &cipher, impl))
230 return 0;
231#endif
232
233 ctx->cipher=cipher;
234 if (ctx->cipher->ctx_size)
235 {
236 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
237 if (!ctx->cipher_data)
238 {
239 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);
240 return 0;
241 }
242 }
243 else
244 {
245 ctx->cipher_data = NULL;
246 }
247 ctx->key_len = cipher->key_len;
248 ctx->flags = 0;
249 if(ctx->cipher->flags & EVP_CIPH_CTRL_INIT)
250 {
251 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
252 {
253 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
254 return 0;
255 }
256 }
257 }
258 else if(!ctx->cipher)
259 {
260 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET);
261 return 0;
262 }
263#ifndef OPENSSL_NO_ENGINE
264skip_to_init:
265#endif
266 /* we assume block size is a power of 2 in *cryptUpdate */
267 OPENSSL_assert(ctx->cipher->block_size == 1
268 || ctx->cipher->block_size == 8
269 || ctx->cipher->block_size == 16);
270
271 if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) {
272 switch(EVP_CIPHER_CTX_mode(ctx)) {
273
274 case EVP_CIPH_STREAM_CIPHER:
275 case EVP_CIPH_ECB_MODE:
276 break;
277
278 case EVP_CIPH_CFB_MODE:
279 case EVP_CIPH_OFB_MODE:
280
281 ctx->num = 0;
282
283 case EVP_CIPH_CBC_MODE:
284
285 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <=
286 (int)sizeof(ctx->iv));
287 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
288 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
289 break;
290
291 default:
292 return 0;
293 break;
294 }
295 }
296
297#ifdef OPENSSL_FIPS
298 /* After 'key' is set no further parameters changes are permissible.
299 * So only check for non FIPS enabling at this point.
300 */
301 if (key && FIPS_mode())
302 {
303 if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS)
304 & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
305 {
306 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_DISABLED_FOR_FIPS);
307#if 0
308 ERR_add_error_data(2, "cipher=",
309 EVP_CIPHER_name(ctx->cipher));
310#endif
311 ctx->cipher = &bad_cipher;
312 return 0;
313 }
314 }
315#endif
316
317 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
318 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
319 }
320 ctx->buf_len=0;
321 ctx->final_used=0;
322 ctx->block_mask=ctx->cipher->block_size-1;
323 return 1;
324 }
325
326int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
327 {
328 if (c->cipher != NULL)
329 {
330 if(c->cipher->cleanup && !c->cipher->cleanup(c))
331 return 0;
332 /* Cleanse cipher context data */
333 if (c->cipher_data)
334 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
335 }
336 if (c->cipher_data)
337 OPENSSL_free(c->cipher_data);
338#ifndef OPENSSL_NO_ENGINE
339 if (c->engine)
340 /* The EVP_CIPHER we used belongs to an ENGINE, release the
341 * functional reference we held for this reason. */
342 do_engine_finish(c->engine);
343#endif
344 memset(c,0,sizeof(EVP_CIPHER_CTX));
345 return 1;
346 }
347
348int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
349 {
350#ifdef OPENSSL_FIPS
351 FIPS_selftest_check();
352#endif
353 return ctx->cipher->do_cipher(ctx,out,in,inl);
354 }
355
356int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
357{
358 int ret;
359 if(!ctx->cipher) {
360 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
361 return 0;
362 }
363
364 if(!ctx->cipher->ctrl) {
365 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
366 return 0;
367 }
368
369 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
370 if(ret == -1) {
371 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
372 return 0;
373 }
374 return ret;
375}
376
377unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
378 {
379 return ctx->cipher->flags;
380 }
381
382int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
383 {
384 return ctx->cipher->iv_len;
385 }
386
387int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
388 {
389 return cipher->nid;
390 }
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
new file mode 100644
index 0000000000..5921f0d710
--- /dev/null
+++ b/src/lib/libcrypto/evp/encode.c
@@ -0,0 +1,446 @@
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 const 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 OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data));
140 if ((ctx->num+inl) < ctx->length)
141 {
142 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
143 ctx->num+=inl;
144 return;
145 }
146 if (ctx->num != 0)
147 {
148 i=ctx->length-ctx->num;
149 memcpy(&(ctx->enc_data[ctx->num]),in,i);
150 in+=i;
151 inl-=i;
152 j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
153 ctx->num=0;
154 out+=j;
155 *(out++)='\n';
156 *out='\0';
157 total=j+1;
158 }
159 while (inl >= ctx->length)
160 {
161 j=EVP_EncodeBlock(out,in,ctx->length);
162 in+=ctx->length;
163 inl-=ctx->length;
164 out+=j;
165 *(out++)='\n';
166 *out='\0';
167 total+=j+1;
168 }
169 if (inl != 0)
170 memcpy(&(ctx->enc_data[0]),in,inl);
171 ctx->num=inl;
172 *outl=total;
173 }
174
175void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
176 {
177 unsigned int ret=0;
178
179 if (ctx->num != 0)
180 {
181 ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
182 out[ret++]='\n';
183 out[ret]='\0';
184 ctx->num=0;
185 }
186 *outl=ret;
187 }
188
189int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
190 {
191 int i,ret=0;
192 unsigned long l;
193
194 for (i=dlen; i > 0; i-=3)
195 {
196 if (i >= 3)
197 {
198 l= (((unsigned long)f[0])<<16L)|
199 (((unsigned long)f[1])<< 8L)|f[2];
200 *(t++)=conv_bin2ascii(l>>18L);
201 *(t++)=conv_bin2ascii(l>>12L);
202 *(t++)=conv_bin2ascii(l>> 6L);
203 *(t++)=conv_bin2ascii(l );
204 }
205 else
206 {
207 l=((unsigned long)f[0])<<16L;
208 if (i == 2) l|=((unsigned long)f[1]<<8L);
209
210 *(t++)=conv_bin2ascii(l>>18L);
211 *(t++)=conv_bin2ascii(l>>12L);
212 *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L);
213 *(t++)='=';
214 }
215 ret+=4;
216 f+=3;
217 }
218
219 *t='\0';
220 return(ret);
221 }
222
223void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
224 {
225 ctx->length=30;
226 ctx->num=0;
227 ctx->line_num=0;
228 ctx->expect_nl=0;
229 }
230
231/* -1 for error
232 * 0 for last line
233 * 1 for full line
234 */
235int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
236 const unsigned char *in, int inl)
237 {
238 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
239 unsigned char *d;
240
241 n=ctx->num;
242 d=ctx->enc_data;
243 ln=ctx->line_num;
244 exp_nl=ctx->expect_nl;
245
246 /* last line of input. */
247 if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF)))
248 { rv=0; goto end; }
249
250 /* We parse the input data */
251 for (i=0; i<inl; i++)
252 {
253 /* If the current line is > 80 characters, scream alot */
254 if (ln >= 80) { rv= -1; goto end; }
255
256 /* Get char and put it into the buffer */
257 tmp= *(in++);
258 v=conv_ascii2bin(tmp);
259 /* only save the good data :-) */
260 if (!B64_NOT_BASE64(v))
261 {
262 OPENSSL_assert(n < (int)sizeof(ctx->enc_data));
263 d[n++]=tmp;
264 ln++;
265 }
266 else if (v == B64_ERROR)
267 {
268 rv= -1;
269 goto end;
270 }
271
272 /* have we seen a '=' which is 'definitly' the last
273 * input line. seof will point to the character that
274 * holds it. and eof will hold how many characters to
275 * chop off. */
276 if (tmp == '=')
277 {
278 if (seof == -1) seof=n;
279 eof++;
280 }
281
282 if (v == B64_CR)
283 {
284 ln = 0;
285 if (exp_nl)
286 continue;
287 }
288
289 /* eoln */
290 if (v == B64_EOLN)
291 {
292 ln=0;
293 if (exp_nl)
294 {
295 exp_nl=0;
296 continue;
297 }
298 }
299 exp_nl=0;
300
301 /* If we are at the end of input and it looks like a
302 * line, process it. */
303 if (((i+1) == inl) && (((n&3) == 0) || eof))
304 {
305 v=B64_EOF;
306 /* In case things were given us in really small
307 records (so two '=' were given in separate
308 updates), eof may contain the incorrect number
309 of ending bytes to skip, so let's redo the count */
310 eof = 0;
311 if (d[n-1] == '=') eof++;
312 if (d[n-2] == '=') eof++;
313 /* There will never be more than two '=' */
314 }
315
316 if ((v == B64_EOF && (n&3) == 0) || (n >= 64))
317 {
318 /* This is needed to work correctly on 64 byte input
319 * lines. We process the line and then need to
320 * accept the '\n' */
321 if ((v != B64_EOF) && (n >= 64)) exp_nl=1;
322 tmp2=v;
323 if (n > 0)
324 {
325 v=EVP_DecodeBlock(out,d,n);
326 n=0;
327 if (v < 0) { rv=0; goto end; }
328 ret+=(v-eof);
329 }
330 else
331 {
332 eof=1;
333 v=0;
334 }
335
336 /* This is the case where we have had a short
337 * but valid input line */
338 if ((v < ctx->length) && eof)
339 {
340 rv=0;
341 goto end;
342 }
343 else
344 ctx->length=v;
345
346 if (seof >= 0) { rv=0; goto end; }
347 out+=v;
348 }
349 }
350 rv=1;
351end:
352 *outl=ret;
353 ctx->num=n;
354 ctx->line_num=ln;
355 ctx->expect_nl=exp_nl;
356 return(rv);
357 }
358
359int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n)
360 {
361 int i,ret=0,a,b,c,d;
362 unsigned long l;
363
364 /* trim white space from the start of the line. */
365 while ((conv_ascii2bin(*f) == B64_WS) && (n > 0))
366 {
367 f++;
368 n--;
369 }
370
371 /* strip off stuff at the end of the line
372 * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */
373 while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1]))))
374 n--;
375
376 if (n%4 != 0) return(-1);
377
378 for (i=0; i<n; i+=4)
379 {
380 a=conv_ascii2bin(*(f++));
381 b=conv_ascii2bin(*(f++));
382 c=conv_ascii2bin(*(f++));
383 d=conv_ascii2bin(*(f++));
384 if ( (a & 0x80) || (b & 0x80) ||
385 (c & 0x80) || (d & 0x80))
386 return(-1);
387 l=( (((unsigned long)a)<<18L)|
388 (((unsigned long)b)<<12L)|
389 (((unsigned long)c)<< 6L)|
390 (((unsigned long)d) ));
391 *(t++)=(unsigned char)(l>>16L)&0xff;
392 *(t++)=(unsigned char)(l>> 8L)&0xff;
393 *(t++)=(unsigned char)(l )&0xff;
394 ret+=3;
395 }
396 return(ret);
397 }
398
399int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
400 {
401 int i;
402
403 *outl=0;
404 if (ctx->num != 0)
405 {
406 i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num);
407 if (i < 0) return(-1);
408 ctx->num=0;
409 *outl=i;
410 return(1);
411 }
412 else
413 return(1);
414 }
415
416#ifdef undef
417int EVP_DecodeValid(unsigned char *buf, int len)
418 {
419 int i,num=0,bad=0;
420
421 if (len == 0) return(-1);
422 while (conv_ascii2bin(*buf) == B64_WS)
423 {
424 buf++;
425 len--;
426 if (len == 0) return(-1);
427 }
428
429 for (i=len; i >= 4; i-=4)
430 {
431 if ( (conv_ascii2bin(buf[0]) >= 0x40) ||
432 (conv_ascii2bin(buf[1]) >= 0x40) ||
433 (conv_ascii2bin(buf[2]) >= 0x40) ||
434 (conv_ascii2bin(buf[3]) >= 0x40))
435 return(-1);
436 buf+=4;
437 num+=1+(buf[2] != '=')+(buf[3] != '=');
438 }
439 if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN))
440 return(num);
441 if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) &&
442 (conv_ascii2bin(buf[0]) == B64_EOLN))
443 return(num);
444 return(1);
445 }
446#endif
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
new file mode 100644
index 0000000000..82b5862ce7
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp.h
@@ -0,0 +1,1064 @@
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#ifdef OPENSSL_FIPS
79#include <openssl/fips.h>
80#endif
81
82/*
83#define EVP_RC2_KEY_SIZE 16
84#define EVP_RC4_KEY_SIZE 16
85#define EVP_BLOWFISH_KEY_SIZE 16
86#define EVP_CAST5_KEY_SIZE 16
87#define EVP_RC5_32_12_16_KEY_SIZE 16
88*/
89#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */
90#define EVP_MAX_KEY_LENGTH 32
91#define EVP_MAX_IV_LENGTH 16
92#define EVP_MAX_BLOCK_LENGTH 32
93
94#define PKCS5_SALT_LEN 8
95/* Default PKCS#5 iteration count */
96#define PKCS5_DEFAULT_ITER 2048
97
98#include <openssl/objects.h>
99
100#define EVP_PK_RSA 0x0001
101#define EVP_PK_DSA 0x0002
102#define EVP_PK_DH 0x0004
103#define EVP_PK_EC 0x0008
104#define EVP_PKT_SIGN 0x0010
105#define EVP_PKT_ENC 0x0020
106#define EVP_PKT_EXCH 0x0040
107#define EVP_PKS_RSA 0x0100
108#define EVP_PKS_DSA 0x0200
109#define EVP_PKS_EC 0x0400
110#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
111
112#define EVP_PKEY_NONE NID_undef
113#define EVP_PKEY_RSA NID_rsaEncryption
114#define EVP_PKEY_RSA2 NID_rsa
115#define EVP_PKEY_DSA NID_dsa
116#define EVP_PKEY_DSA1 NID_dsa_2
117#define EVP_PKEY_DSA2 NID_dsaWithSHA
118#define EVP_PKEY_DSA3 NID_dsaWithSHA1
119#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
120#define EVP_PKEY_DH NID_dhKeyAgreement
121#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey
122
123#ifdef __cplusplus
124extern "C" {
125#endif
126
127/* Type needs to be a bit field
128 * Sub-type needs to be for variations on the method, as in, can it do
129 * arbitrary encryption.... */
130struct evp_pkey_st
131 {
132 int type;
133 int save_type;
134 int references;
135 union {
136 char *ptr;
137#ifndef OPENSSL_NO_RSA
138 struct rsa_st *rsa; /* RSA */
139#endif
140#ifndef OPENSSL_NO_DSA
141 struct dsa_st *dsa; /* DSA */
142#endif
143#ifndef OPENSSL_NO_DH
144 struct dh_st *dh; /* DH */
145#endif
146#ifndef OPENSSL_NO_EC
147 struct ec_key_st *ec; /* ECC */
148#endif
149 } pkey;
150 int save_parameters;
151 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
152 } /* EVP_PKEY */;
153
154#define EVP_PKEY_MO_SIGN 0x0001
155#define EVP_PKEY_MO_VERIFY 0x0002
156#define EVP_PKEY_MO_ENCRYPT 0x0004
157#define EVP_PKEY_MO_DECRYPT 0x0008
158
159#if 0
160/* This structure is required to tie the message digest and signing together.
161 * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or
162 * oid, md and pkey.
163 * This is required because for various smart-card perform the digest and
164 * signing/verification on-board. To handle this case, the specific
165 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
166 * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
167 * This can either be software or a token to provide the required low level
168 * routines.
169 */
170typedef struct evp_pkey_md_st
171 {
172 int oid;
173 EVP_MD *md;
174 EVP_PKEY_METHOD *pkey;
175 } EVP_PKEY_MD;
176
177#define EVP_rsa_md2() \
178 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
179 EVP_rsa_pkcs1(),EVP_md2())
180#define EVP_rsa_md5() \
181 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
182 EVP_rsa_pkcs1(),EVP_md5())
183#define EVP_rsa_sha0() \
184 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
185 EVP_rsa_pkcs1(),EVP_sha())
186#define EVP_rsa_sha1() \
187 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
188 EVP_rsa_pkcs1(),EVP_sha1())
189#define EVP_rsa_ripemd160() \
190 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
191 EVP_rsa_pkcs1(),EVP_ripemd160())
192#define EVP_rsa_mdc2() \
193 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
194 EVP_rsa_octet_string(),EVP_mdc2())
195#define EVP_dsa_sha() \
196 EVP_PKEY_MD_add(NID_dsaWithSHA,\
197 EVP_dsa(),EVP_sha())
198#define EVP_dsa_sha1() \
199 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
200 EVP_dsa(),EVP_sha1())
201
202typedef struct evp_pkey_method_st
203 {
204 char *name;
205 int flags;
206 int type; /* RSA, DSA, an SSLeay specific constant */
207 int oid; /* For the pub-key type */
208 int encrypt_oid; /* pub/priv key encryption */
209
210 int (*sign)();
211 int (*verify)();
212 struct {
213 int (*set)(); /* get and/or set the underlying type */
214 int (*get)();
215 int (*encrypt)();
216 int (*decrypt)();
217 int (*i2d)();
218 int (*d2i)();
219 int (*dup)();
220 } pub,priv;
221 int (*set_asn1_parameters)();
222 int (*get_asn1_parameters)();
223 } EVP_PKEY_METHOD;
224#endif
225
226#ifndef EVP_MD
227struct env_md_st
228 {
229 int type;
230 int pkey_type;
231 int md_size;
232 unsigned long flags;
233 int (*init)(EVP_MD_CTX *ctx);
234 int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count);
235 int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
236 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
237 int (*cleanup)(EVP_MD_CTX *ctx);
238
239 /* FIXME: prototype these some day */
240 int (*sign)(int type, const unsigned char *m, unsigned int m_length,
241 unsigned char *sigret, unsigned int *siglen, void *key);
242 int (*verify)(int type, const unsigned char *m, unsigned int m_length,
243 const unsigned char *sigbuf, unsigned int siglen,
244 void *key);
245 int required_pkey_type[5]; /*EVP_PKEY_xxx */
246 int block_size;
247 int ctx_size; /* how big does the ctx->md_data need to be */
248 } /* EVP_MD */;
249
250typedef int evp_sign_method(int type,const unsigned char *m,
251 unsigned int m_length,unsigned char *sigret,
252 unsigned int *siglen, void *key);
253typedef int evp_verify_method(int type,const unsigned char *m,
254 unsigned int m_length,const unsigned char *sigbuf,
255 unsigned int siglen, void *key);
256
257typedef struct
258 {
259 EVP_MD_CTX *mctx;
260 void *key;
261 } EVP_MD_SVCTX;
262
263#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
264 * block */
265
266#define EVP_MD_FLAG_FIPS 0x0400 /* Note if suitable for use in FIPS mode */
267
268#define EVP_MD_FLAG_SVCTX 0x0800 /* pass EVP_MD_SVCTX to sign/verify */
269
270#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
271
272#ifndef OPENSSL_NO_DSA
273#define EVP_PKEY_DSA_method (evp_sign_method *)DSA_sign, \
274 (evp_verify_method *)DSA_verify, \
275 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
276 EVP_PKEY_DSA4,0}
277#else
278#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
279#endif
280
281#ifndef OPENSSL_NO_ECDSA
282#define EVP_PKEY_ECDSA_method (evp_sign_method *)ECDSA_sign, \
283 (evp_verify_method *)ECDSA_verify, \
284 {EVP_PKEY_EC,0,0,0}
285#else
286#define EVP_PKEY_ECDSA_method EVP_PKEY_NULL_method
287#endif
288
289#ifndef OPENSSL_NO_RSA
290#define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \
291 (evp_verify_method *)RSA_verify, \
292 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
293#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
294 (evp_sign_method *)RSA_sign_ASN1_OCTET_STRING, \
295 (evp_verify_method *)RSA_verify_ASN1_OCTET_STRING, \
296 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
297#else
298#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
299#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method
300#endif
301
302#endif /* !EVP_MD */
303
304struct env_md_ctx_st
305 {
306 const EVP_MD *digest;
307 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
308 unsigned long flags;
309 void *md_data;
310 } /* EVP_MD_CTX */;
311
312/* values for EVP_MD_CTX flags */
313
314#define EVP_MD_CTX_FLAG_ONESHOT 0x0001 /* digest update will be called
315 * once only */
316#define EVP_MD_CTX_FLAG_CLEANED 0x0002 /* context has already been
317 * cleaned */
318#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data
319 * in EVP_MD_CTX_cleanup */
320#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest
321 * in FIPS mode */
322
323#define EVP_MD_CTX_FLAG_PAD_MASK 0xF0 /* RSA mode to use */
324#define EVP_MD_CTX_FLAG_PAD_PKCS1 0x00 /* PKCS#1 v1.5 mode */
325#define EVP_MD_CTX_FLAG_PAD_X931 0x10 /* X9.31 mode */
326#define EVP_MD_CTX_FLAG_PAD_PSS 0x20 /* PSS mode */
327#define M_EVP_MD_CTX_FLAG_PSS_SALT(ctx) \
328 ((ctx->flags>>16) &0xFFFF) /* seed length */
329#define EVP_MD_CTX_FLAG_PSS_MDLEN 0xFFFF /* salt len same as digest */
330#define EVP_MD_CTX_FLAG_PSS_MREC 0xFFFE /* salt max or auto recovered */
331
332struct evp_cipher_st
333 {
334 int nid;
335 int block_size;
336 int key_len; /* Default value for variable length ciphers */
337 int iv_len;
338 unsigned long flags; /* Various flags */
339 int (*init)(EVP_CIPHER_CTX *ctx, const unsigned char *key,
340 const unsigned char *iv, int enc); /* init key */
341 int (*do_cipher)(EVP_CIPHER_CTX *ctx, unsigned char *out,
342 const unsigned char *in, unsigned int inl);/* encrypt/decrypt data */
343 int (*cleanup)(EVP_CIPHER_CTX *); /* cleanup ctx */
344 int ctx_size; /* how big ctx->cipher_data needs to be */
345 int (*set_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Populate a ASN1_TYPE with parameters */
346 int (*get_asn1_parameters)(EVP_CIPHER_CTX *, ASN1_TYPE *); /* Get parameters from a ASN1_TYPE */
347 int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr); /* Miscellaneous operations */
348 void *app_data; /* Application data */
349 } /* EVP_CIPHER */;
350
351/* Values for cipher flags */
352
353/* Modes for ciphers */
354
355#define EVP_CIPH_STREAM_CIPHER 0x0
356#define EVP_CIPH_ECB_MODE 0x1
357#define EVP_CIPH_CBC_MODE 0x2
358#define EVP_CIPH_CFB_MODE 0x3
359#define EVP_CIPH_OFB_MODE 0x4
360#define EVP_CIPH_MODE 0x7
361/* Set if variable length cipher */
362#define EVP_CIPH_VARIABLE_LENGTH 0x8
363/* Set if the iv handling should be done by the cipher itself */
364#define EVP_CIPH_CUSTOM_IV 0x10
365/* Set if the cipher's init() function should be called if key is NULL */
366#define EVP_CIPH_ALWAYS_CALL_INIT 0x20
367/* Call ctrl() to init cipher parameters */
368#define EVP_CIPH_CTRL_INIT 0x40
369/* Don't use standard key length function */
370#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
371/* Don't use standard block padding */
372#define EVP_CIPH_NO_PADDING 0x100
373/* cipher handles random key generation */
374#define EVP_CIPH_RAND_KEY 0x200
375/* Note if suitable for use in FIPS mode */
376#define EVP_CIPH_FLAG_FIPS 0x400
377/* Allow non FIPS cipher in FIPS mode */
378#define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800
379/* Allow use default ASN1 get/set iv */
380#define EVP_CIPH_FLAG_DEFAULT_ASN1 0x1000
381/* Buffer length in bits not bytes: CFB1 mode only */
382#define EVP_CIPH_FLAG_LENGTH_BITS 0x2000
383
384/* ctrl() values */
385
386#define EVP_CTRL_INIT 0x0
387#define EVP_CTRL_SET_KEY_LENGTH 0x1
388#define EVP_CTRL_GET_RC2_KEY_BITS 0x2
389#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
390#define EVP_CTRL_GET_RC5_ROUNDS 0x4
391#define EVP_CTRL_SET_RC5_ROUNDS 0x5
392#define EVP_CTRL_SET_ACSS_MODE 0x6
393#define EVP_CTRL_RAND_KEY 0x7
394
395typedef struct evp_cipher_info_st
396 {
397 const EVP_CIPHER *cipher;
398 unsigned char iv[EVP_MAX_IV_LENGTH];
399 } EVP_CIPHER_INFO;
400
401struct evp_cipher_ctx_st
402 {
403 const EVP_CIPHER *cipher;
404 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
405 int encrypt; /* encrypt or decrypt */
406 int buf_len; /* number we have left */
407
408 unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
409 unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
410 unsigned char buf[EVP_MAX_BLOCK_LENGTH];/* saved partial block */
411 int num; /* used by cfb/ofb mode */
412
413 void *app_data; /* application stuff */
414 int key_len; /* May change for variable length cipher */
415 unsigned long flags; /* Various flags */
416 void *cipher_data; /* per EVP data */
417 int final_used;
418 int block_mask;
419 unsigned char final[EVP_MAX_BLOCK_LENGTH];/* possible final block */
420 } /* EVP_CIPHER_CTX */;
421
422typedef struct evp_Encode_Ctx_st
423 {
424 int num; /* number saved in a partial encode/decode */
425 int length; /* The length is either the output line length
426 * (in input bytes) or the shortest input line
427 * length that is ok. Once decoding begins,
428 * the length is adjusted up each time a longer
429 * line is decoded */
430 unsigned char enc_data[80]; /* data to encode */
431 int line_num; /* number read on current line */
432 int expect_nl;
433 } EVP_ENCODE_CTX;
434
435/* Password based encryption function */
436typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
437 ASN1_TYPE *param, const EVP_CIPHER *cipher,
438 const EVP_MD *md, int en_de);
439
440#ifndef OPENSSL_NO_RSA
441#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
442 (char *)(rsa))
443#endif
444
445#ifndef OPENSSL_NO_DSA
446#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
447 (char *)(dsa))
448#endif
449
450#ifndef OPENSSL_NO_DH
451#define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\
452 (char *)(dh))
453#endif
454
455#ifndef OPENSSL_NO_EC
456#define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\
457 (char *)(eckey))
458#endif
459
460/* Add some extra combinations */
461#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
462#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
463#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
464#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
465
466/* Macros to reduce FIPS dependencies: do NOT use in applications */
467#define M_EVP_MD_size(e) ((e)->md_size)
468#define M_EVP_MD_block_size(e) ((e)->block_size)
469#define M_EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
470#define M_EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
471#define M_EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
472#define M_EVP_MD_type(e) ((e)->type)
473#define M_EVP_MD_CTX_type(e) M_EVP_MD_type(M_EVP_MD_CTX_md(e))
474#define M_EVP_MD_CTX_md(e) ((e)->digest)
475
476#define M_EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
477
478int EVP_MD_type(const EVP_MD *md);
479#define EVP_MD_nid(e) EVP_MD_type(e)
480#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e))
481int EVP_MD_pkey_type(const EVP_MD *md);
482int EVP_MD_size(const EVP_MD *md);
483int EVP_MD_block_size(const EVP_MD *md);
484
485const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
486#define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e))
487#define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e))
488#define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e))
489
490int EVP_CIPHER_nid(const EVP_CIPHER *cipher);
491#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e))
492int EVP_CIPHER_block_size(const EVP_CIPHER *cipher);
493int EVP_CIPHER_key_length(const EVP_CIPHER *cipher);
494int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher);
495unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher);
496#define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE)
497
498const EVP_CIPHER * EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx);
499int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx);
500int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx);
501int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx);
502int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx);
503void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
504void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data);
505#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
506unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx);
507#define EVP_CIPHER_CTX_mode(e) (EVP_CIPHER_CTX_flags(e) & EVP_CIPH_MODE)
508
509#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
510#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
511
512#define EVP_SignInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
513#define EVP_SignInit(a,b) EVP_DigestInit(a,b)
514#define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
515#define EVP_VerifyInit_ex(a,b,c) EVP_DigestInit_ex(a,b,c)
516#define EVP_VerifyInit(a,b) EVP_DigestInit(a,b)
517#define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c)
518#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
519#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
520
521#ifdef CONST_STRICT
522void BIO_set_md(BIO *,const EVP_MD *md);
523#else
524# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
525#endif
526#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
527#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
528#define BIO_set_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_SET_MD_CTX,0,(char *)mdcp)
529#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
530#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
531
532int EVP_Cipher(EVP_CIPHER_CTX *c,
533 unsigned char *out,
534 const unsigned char *in,
535 unsigned int inl);
536
537#define EVP_add_cipher_alias(n,alias) \
538 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
539#define EVP_add_digest_alias(n,alias) \
540 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
541#define EVP_delete_cipher_alias(alias) \
542 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
543#define EVP_delete_digest_alias(alias) \
544 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
545
546void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
547int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
548EVP_MD_CTX *EVP_MD_CTX_create(void);
549void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
550int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
551void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
552void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
553int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx,int flags);
554int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
555int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
556 size_t cnt);
557int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
558int EVP_Digest(const void *data, size_t count,
559 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);
560
561int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
562int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
563int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
564
565int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
566void EVP_set_pw_prompt(const char *prompt);
567char * EVP_get_pw_prompt(void);
568
569int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
570 const unsigned char *salt, const unsigned char *data,
571 int datal, int count, unsigned char *key,unsigned char *iv);
572
573void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags);
574void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags);
575int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx,int flags);
576
577int EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
578 const unsigned char *key, const unsigned char *iv);
579int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
580 const unsigned char *key, const unsigned char *iv);
581int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
582 int *outl, const unsigned char *in, int inl);
583int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
584int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
585
586int EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
587 const unsigned char *key, const unsigned char *iv);
588int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
589 const unsigned char *key, const unsigned char *iv);
590int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
591 int *outl, const unsigned char *in, int inl);
592int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
593int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
594
595int EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher,
596 const unsigned char *key,const unsigned char *iv,
597 int enc);
598int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
599 const unsigned char *key,const unsigned char *iv,
600 int enc);
601int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
602 int *outl, const unsigned char *in, int inl);
603int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
604int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
605
606int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
607 EVP_PKEY *pkey);
608
609int EVP_VerifyFinal(EVP_MD_CTX *ctx,const unsigned char *sigbuf,
610 unsigned int siglen,EVP_PKEY *pkey);
611
612int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
613 const unsigned char *ek, int ekl, const unsigned char *iv,
614 EVP_PKEY *priv);
615int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
616
617int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
618 unsigned char **ek, int *ekl, unsigned char *iv,
619 EVP_PKEY **pubk, int npubk);
620int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
621
622void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
623void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
624 const unsigned char *in,int inl);
625void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
626int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
627
628void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
629int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
630 const unsigned char *in, int inl);
631int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
632 char *out, int *outl);
633int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
634
635void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
636int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
637EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
638void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a);
639int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
640int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
641int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
642int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
643
644#ifndef OPENSSL_NO_BIO
645BIO_METHOD *BIO_f_md(void);
646BIO_METHOD *BIO_f_base64(void);
647BIO_METHOD *BIO_f_cipher(void);
648BIO_METHOD *BIO_f_reliable(void);
649void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,const unsigned char *k,
650 const unsigned char *i, int enc);
651#endif
652
653const EVP_MD *EVP_md_null(void);
654#ifndef OPENSSL_NO_MD2
655const EVP_MD *EVP_md2(void);
656#endif
657#ifndef OPENSSL_NO_MD4
658const EVP_MD *EVP_md4(void);
659#endif
660#ifndef OPENSSL_NO_MD5
661const EVP_MD *EVP_md5(void);
662#endif
663#ifndef OPENSSL_NO_SHA
664const EVP_MD *EVP_sha(void);
665const EVP_MD *EVP_sha1(void);
666const EVP_MD *EVP_dss(void);
667const EVP_MD *EVP_dss1(void);
668const EVP_MD *EVP_ecdsa(void);
669#endif
670#ifndef OPENSSL_NO_SHA256
671const EVP_MD *EVP_sha224(void);
672const EVP_MD *EVP_sha256(void);
673#endif
674#ifndef OPENSSL_NO_SHA512
675const EVP_MD *EVP_sha384(void);
676const EVP_MD *EVP_sha512(void);
677#endif
678#ifndef OPENSSL_NO_MDC2
679const EVP_MD *EVP_mdc2(void);
680#endif
681#ifndef OPENSSL_NO_RIPEMD
682const EVP_MD *EVP_ripemd160(void);
683#endif
684const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */
685#ifndef OPENSSL_NO_DES
686const EVP_CIPHER *EVP_des_ecb(void);
687const EVP_CIPHER *EVP_des_ede(void);
688const EVP_CIPHER *EVP_des_ede3(void);
689const EVP_CIPHER *EVP_des_ede_ecb(void);
690const EVP_CIPHER *EVP_des_ede3_ecb(void);
691const EVP_CIPHER *EVP_des_cfb64(void);
692# define EVP_des_cfb EVP_des_cfb64
693const EVP_CIPHER *EVP_des_cfb1(void);
694const EVP_CIPHER *EVP_des_cfb8(void);
695const EVP_CIPHER *EVP_des_ede_cfb64(void);
696# define EVP_des_ede_cfb EVP_des_ede_cfb64
697#if 0
698const EVP_CIPHER *EVP_des_ede_cfb1(void);
699const EVP_CIPHER *EVP_des_ede_cfb8(void);
700#endif
701const EVP_CIPHER *EVP_des_ede3_cfb64(void);
702# define EVP_des_ede3_cfb EVP_des_ede3_cfb64
703const EVP_CIPHER *EVP_des_ede3_cfb1(void);
704const EVP_CIPHER *EVP_des_ede3_cfb8(void);
705const EVP_CIPHER *EVP_des_ofb(void);
706const EVP_CIPHER *EVP_des_ede_ofb(void);
707const EVP_CIPHER *EVP_des_ede3_ofb(void);
708const EVP_CIPHER *EVP_des_cbc(void);
709const EVP_CIPHER *EVP_des_ede_cbc(void);
710const EVP_CIPHER *EVP_des_ede3_cbc(void);
711const EVP_CIPHER *EVP_desx_cbc(void);
712/* This should now be supported through the dev_crypto ENGINE. But also, why are
713 * rc4 and md5 declarations made here inside a "NO_DES" precompiler branch? */
714#if 0
715# ifdef OPENSSL_OPENBSD_DEV_CRYPTO
716const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
717const EVP_CIPHER *EVP_dev_crypto_rc4(void);
718const EVP_MD *EVP_dev_crypto_md5(void);
719# endif
720#endif
721#endif
722#ifndef OPENSSL_NO_RC4
723const EVP_CIPHER *EVP_rc4(void);
724const EVP_CIPHER *EVP_rc4_40(void);
725#endif
726#ifndef OPENSSL_NO_IDEA
727const EVP_CIPHER *EVP_idea_ecb(void);
728const EVP_CIPHER *EVP_idea_cfb64(void);
729# define EVP_idea_cfb EVP_idea_cfb64
730const EVP_CIPHER *EVP_idea_ofb(void);
731const EVP_CIPHER *EVP_idea_cbc(void);
732#endif
733#ifndef OPENSSL_NO_RC2
734const EVP_CIPHER *EVP_rc2_ecb(void);
735const EVP_CIPHER *EVP_rc2_cbc(void);
736const EVP_CIPHER *EVP_rc2_40_cbc(void);
737const EVP_CIPHER *EVP_rc2_64_cbc(void);
738const EVP_CIPHER *EVP_rc2_cfb64(void);
739# define EVP_rc2_cfb EVP_rc2_cfb64
740const EVP_CIPHER *EVP_rc2_ofb(void);
741#endif
742#ifndef OPENSSL_NO_BF
743const EVP_CIPHER *EVP_bf_ecb(void);
744const EVP_CIPHER *EVP_bf_cbc(void);
745const EVP_CIPHER *EVP_bf_cfb64(void);
746# define EVP_bf_cfb EVP_bf_cfb64
747const EVP_CIPHER *EVP_bf_ofb(void);
748#endif
749#ifndef OPENSSL_NO_CAST
750const EVP_CIPHER *EVP_cast5_ecb(void);
751const EVP_CIPHER *EVP_cast5_cbc(void);
752const EVP_CIPHER *EVP_cast5_cfb64(void);
753# define EVP_cast5_cfb EVP_cast5_cfb64
754const EVP_CIPHER *EVP_cast5_ofb(void);
755#endif
756#ifndef OPENSSL_NO_RC5
757const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
758const EVP_CIPHER *EVP_rc5_32_12_16_ecb(void);
759const EVP_CIPHER *EVP_rc5_32_12_16_cfb64(void);
760# define EVP_rc5_32_12_16_cfb EVP_rc5_32_12_16_cfb64
761const EVP_CIPHER *EVP_rc5_32_12_16_ofb(void);
762#endif
763#ifndef OPENSSL_NO_AES
764const EVP_CIPHER *EVP_aes_128_ecb(void);
765const EVP_CIPHER *EVP_aes_128_cbc(void);
766const EVP_CIPHER *EVP_aes_128_cfb1(void);
767const EVP_CIPHER *EVP_aes_128_cfb8(void);
768const EVP_CIPHER *EVP_aes_128_cfb128(void);
769# define EVP_aes_128_cfb EVP_aes_128_cfb128
770const EVP_CIPHER *EVP_aes_128_ofb(void);
771#if 0
772const EVP_CIPHER *EVP_aes_128_ctr(void);
773#endif
774const EVP_CIPHER *EVP_aes_192_ecb(void);
775const EVP_CIPHER *EVP_aes_192_cbc(void);
776const EVP_CIPHER *EVP_aes_192_cfb1(void);
777const EVP_CIPHER *EVP_aes_192_cfb8(void);
778const EVP_CIPHER *EVP_aes_192_cfb128(void);
779# define EVP_aes_192_cfb EVP_aes_192_cfb128
780const EVP_CIPHER *EVP_aes_192_ofb(void);
781#if 0
782const EVP_CIPHER *EVP_aes_192_ctr(void);
783#endif
784const EVP_CIPHER *EVP_aes_256_ecb(void);
785const EVP_CIPHER *EVP_aes_256_cbc(void);
786const EVP_CIPHER *EVP_aes_256_cfb1(void);
787const EVP_CIPHER *EVP_aes_256_cfb8(void);
788const EVP_CIPHER *EVP_aes_256_cfb128(void);
789# define EVP_aes_256_cfb EVP_aes_256_cfb128
790const EVP_CIPHER *EVP_aes_256_ofb(void);
791#if 0
792const EVP_CIPHER *EVP_aes_256_ctr(void);
793#endif
794#endif
795#ifndef OPENSSL_NO_ACSS
796const EVP_CIPHER *EVP_acss(void);
797#endif
798#ifndef OPENSSL_NO_CAMELLIA
799const EVP_CIPHER *EVP_camellia_128_ecb(void);
800const EVP_CIPHER *EVP_camellia_128_cbc(void);
801const EVP_CIPHER *EVP_camellia_128_cfb1(void);
802const EVP_CIPHER *EVP_camellia_128_cfb8(void);
803const EVP_CIPHER *EVP_camellia_128_cfb128(void);
804# define EVP_camellia_128_cfb EVP_camellia_128_cfb128
805const EVP_CIPHER *EVP_camellia_128_ofb(void);
806const EVP_CIPHER *EVP_camellia_192_ecb(void);
807const EVP_CIPHER *EVP_camellia_192_cbc(void);
808const EVP_CIPHER *EVP_camellia_192_cfb1(void);
809const EVP_CIPHER *EVP_camellia_192_cfb8(void);
810const EVP_CIPHER *EVP_camellia_192_cfb128(void);
811# define EVP_camellia_192_cfb EVP_camellia_192_cfb128
812const EVP_CIPHER *EVP_camellia_192_ofb(void);
813const EVP_CIPHER *EVP_camellia_256_ecb(void);
814const EVP_CIPHER *EVP_camellia_256_cbc(void);
815const EVP_CIPHER *EVP_camellia_256_cfb1(void);
816const EVP_CIPHER *EVP_camellia_256_cfb8(void);
817const EVP_CIPHER *EVP_camellia_256_cfb128(void);
818# define EVP_camellia_256_cfb EVP_camellia_256_cfb128
819const EVP_CIPHER *EVP_camellia_256_ofb(void);
820#endif
821
822#ifndef OPENSSL_NO_SEED
823const EVP_CIPHER *EVP_seed_ecb(void);
824const EVP_CIPHER *EVP_seed_cbc(void);
825const EVP_CIPHER *EVP_seed_cfb128(void);
826# define EVP_seed_cfb EVP_seed_cfb128
827const EVP_CIPHER *EVP_seed_ofb(void);
828#endif
829
830void OPENSSL_add_all_algorithms_noconf(void);
831void OPENSSL_add_all_algorithms_conf(void);
832
833#ifdef OPENSSL_LOAD_CONF
834#define OpenSSL_add_all_algorithms() \
835 OPENSSL_add_all_algorithms_conf()
836#else
837#define OpenSSL_add_all_algorithms() \
838 OPENSSL_add_all_algorithms_noconf()
839#endif
840
841void OpenSSL_add_all_ciphers(void);
842void OpenSSL_add_all_digests(void);
843#define SSLeay_add_all_algorithms() OpenSSL_add_all_algorithms()
844#define SSLeay_add_all_ciphers() OpenSSL_add_all_ciphers()
845#define SSLeay_add_all_digests() OpenSSL_add_all_digests()
846
847int EVP_add_cipher(const EVP_CIPHER *cipher);
848int EVP_add_digest(const EVP_MD *digest);
849
850const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
851const EVP_MD *EVP_get_digestbyname(const char *name);
852void EVP_cleanup(void);
853
854int EVP_PKEY_decrypt(unsigned char *dec_key,
855 const unsigned char *enc_key,int enc_key_len,
856 EVP_PKEY *private_key);
857int EVP_PKEY_encrypt(unsigned char *enc_key,
858 const unsigned char *key,int key_len,
859 EVP_PKEY *pub_key);
860int EVP_PKEY_type(int type);
861int EVP_PKEY_bits(EVP_PKEY *pkey);
862int EVP_PKEY_size(EVP_PKEY *pkey);
863int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key);
864
865#ifndef OPENSSL_NO_RSA
866struct rsa_st;
867int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,struct rsa_st *key);
868struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);
869#endif
870#ifndef OPENSSL_NO_DSA
871struct dsa_st;
872int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,struct dsa_st *key);
873struct dsa_st *EVP_PKEY_get1_DSA(EVP_PKEY *pkey);
874#endif
875#ifndef OPENSSL_NO_DH
876struct dh_st;
877int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
878struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
879#endif
880#ifndef OPENSSL_NO_EC
881struct ec_key_st;
882int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,struct ec_key_st *key);
883struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
884#endif
885
886EVP_PKEY * EVP_PKEY_new(void);
887void EVP_PKEY_free(EVP_PKEY *pkey);
888
889EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
890 long length);
891int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
892
893EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, const unsigned char **pp,
894 long length);
895EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
896 long length);
897int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
898
899int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);
900int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
901int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
902int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b);
903
904int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
905
906int EVP_CIPHER_type(const EVP_CIPHER *ctx);
907
908/* calls methods */
909int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
910int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
911
912/* These are used by EVP_CIPHER methods */
913int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
914int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
915
916/* PKCS5 password based encryption */
917int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
918 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
919 int en_de);
920int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
921 const unsigned char *salt, int saltlen, int iter,
922 int keylen, unsigned char *out);
923int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
924 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
925 int en_de);
926
927void PKCS5_PBE_add(void);
928
929int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
930 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
931int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
932 EVP_PBE_KEYGEN *keygen);
933void EVP_PBE_cleanup(void);
934
935#ifdef OPENSSL_FIPS
936#ifndef OPENSSL_NO_ENGINE
937void int_EVP_MD_set_engine_callbacks(
938 int (*eng_md_init)(ENGINE *impl),
939 int (*eng_md_fin)(ENGINE *impl),
940 int (*eng_md_evp)
941 (EVP_MD_CTX *ctx, const EVP_MD **ptype, ENGINE *impl));
942void int_EVP_MD_init_engine_callbacks(void);
943void int_EVP_CIPHER_set_engine_callbacks(
944 int (*eng_ciph_fin)(ENGINE *impl),
945 int (*eng_ciph_evp)
946 (EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pciph, ENGINE *impl));
947void int_EVP_CIPHER_init_engine_callbacks(void);
948#endif
949#endif
950
951void EVP_add_alg_module(void);
952
953/* BEGIN ERROR CODES */
954/* The following lines are auto generated by the script mkerr.pl. Any changes
955 * made after this point may be overwritten when the script is next run.
956 */
957void ERR_load_EVP_strings(void);
958
959/* Error codes for the EVP functions. */
960
961/* Function codes. */
962#define EVP_F_AESNI_INIT_KEY 165
963#define EVP_F_AES_INIT_KEY 133
964#define EVP_F_ALG_MODULE_INIT 138
965#define EVP_F_CAMELLIA_INIT_KEY 159
966#define EVP_F_D2I_PKEY 100
967#define EVP_F_DO_EVP_ENC_ENGINE 140
968#define EVP_F_DO_EVP_ENC_ENGINE_FULL 141
969#define EVP_F_DO_EVP_MD_ENGINE 139
970#define EVP_F_DO_EVP_MD_ENGINE_FULL 142
971#define EVP_F_DSAPKEY2PKCS8 134
972#define EVP_F_DSA_PKEY2PKCS8 135
973#define EVP_F_ECDSA_PKEY2PKCS8 129
974#define EVP_F_ECKEY_PKEY2PKCS8 132
975#define EVP_F_EVP_CIPHERINIT 137
976#define EVP_F_EVP_CIPHERINIT_EX 123
977#define EVP_F_EVP_CIPHER_CTX_CTRL 124
978#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
979#define EVP_F_EVP_DECRYPTFINAL_EX 101
980#define EVP_F_EVP_DIGESTINIT 136
981#define EVP_F_EVP_DIGESTINIT_EX 128
982#define EVP_F_EVP_ENCRYPTFINAL_EX 127
983#define EVP_F_EVP_MD_CTX_COPY_EX 110
984#define EVP_F_EVP_OPENINIT 102
985#define EVP_F_EVP_PBE_ALG_ADD 115
986#define EVP_F_EVP_PBE_CIPHERINIT 116
987#define EVP_F_EVP_PKCS82PKEY 111
988#define EVP_F_EVP_PKEY2PKCS8_BROKEN 113
989#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
990#define EVP_F_EVP_PKEY_DECRYPT 104
991#define EVP_F_EVP_PKEY_ENCRYPT 105
992#define EVP_F_EVP_PKEY_GET1_DH 119
993#define EVP_F_EVP_PKEY_GET1_DSA 120
994#define EVP_F_EVP_PKEY_GET1_ECDSA 130
995#define EVP_F_EVP_PKEY_GET1_EC_KEY 131
996#define EVP_F_EVP_PKEY_GET1_RSA 121
997#define EVP_F_EVP_PKEY_NEW 106
998#define EVP_F_EVP_RIJNDAEL 126
999#define EVP_F_EVP_SIGNFINAL 107
1000#define EVP_F_EVP_VERIFYFINAL 108
1001#define EVP_F_PKCS5_PBE_KEYIVGEN 117
1002#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
1003#define EVP_F_PKCS8_SET_BROKEN 112
1004#define EVP_F_RC2_MAGIC_TO_METH 109
1005#define EVP_F_RC5_CTRL 125
1006
1007/* Reason codes. */
1008#define EVP_R_AES_KEY_SETUP_FAILED 143
1009#define EVP_R_ASN1_LIB 140
1010#define EVP_R_BAD_BLOCK_LENGTH 136
1011#define EVP_R_BAD_DECRYPT 100
1012#define EVP_R_BAD_KEY_LENGTH 137
1013#define EVP_R_BN_DECODE_ERROR 112
1014#define EVP_R_BN_PUBKEY_ERROR 113
1015#define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157
1016#define EVP_R_CIPHER_PARAMETER_ERROR 122
1017#define EVP_R_CTRL_NOT_IMPLEMENTED 132
1018#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
1019#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138
1020#define EVP_R_DECODE_ERROR 114
1021#define EVP_R_DIFFERENT_KEY_TYPES 101
1022#define EVP_R_DISABLED_FOR_FIPS 144
1023#define EVP_R_ENCODE_ERROR 115
1024#define EVP_R_ERROR_LOADING_SECTION 145
1025#define EVP_R_ERROR_SETTING_FIPS_MODE 146
1026#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
1027#define EVP_R_EXPECTING_AN_RSA_KEY 127
1028#define EVP_R_EXPECTING_A_DH_KEY 128
1029#define EVP_R_EXPECTING_A_DSA_KEY 129
1030#define EVP_R_EXPECTING_A_ECDSA_KEY 141
1031#define EVP_R_EXPECTING_A_EC_KEY 142
1032#define EVP_R_FIPS_MODE_NOT_SUPPORTED 147
1033#define EVP_R_INITIALIZATION_ERROR 134
1034#define EVP_R_INPUT_NOT_INITIALIZED 111
1035#define EVP_R_INVALID_FIPS_MODE 148
1036#define EVP_R_INVALID_KEY_LENGTH 130
1037#define EVP_R_IV_TOO_LARGE 102
1038#define EVP_R_KEYGEN_FAILURE 120
1039#define EVP_R_MISSING_PARAMETERS 103
1040#define EVP_R_NO_CIPHER_SET 131
1041#define EVP_R_NO_DIGEST_SET 139
1042#define EVP_R_NO_DSA_PARAMETERS 116
1043#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
1044#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
1045#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
1046#define EVP_R_PUBLIC_KEY_NOT_RSA 106
1047#define EVP_R_UNKNOWN_OPTION 149
1048#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
1049#define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135
1050#define EVP_R_UNSUPPORTED_CIPHER 107
1051#define EVP_R_UNSUPPORTED_KEYLENGTH 123
1052#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
1053#define EVP_R_UNSUPPORTED_KEY_SIZE 108
1054#define EVP_R_UNSUPPORTED_PRF 125
1055#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
1056#define EVP_R_UNSUPPORTED_SALT_TYPE 126
1057#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
1058#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
1059#define EVP_R_SEED_KEY_SETUP_FAILED 162
1060
1061#ifdef __cplusplus
1062}
1063#endif
1064#endif
diff --git a/src/lib/libcrypto/evp/evp_acnf.c b/src/lib/libcrypto/evp/evp_acnf.c
new file mode 100644
index 0000000000..643a1864e8
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_acnf.c
@@ -0,0 +1,73 @@
1/* evp_acnf.c */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 "cryptlib.h"
60#include <openssl/evp.h>
61#include <openssl/conf.h>
62
63
64/* Load all algorithms and configure OpenSSL.
65 * This function is called automatically when
66 * OPENSSL_LOAD_CONF is set.
67 */
68
69void OPENSSL_add_all_algorithms_conf(void)
70 {
71 OPENSSL_add_all_algorithms_noconf();
72 OPENSSL_config(NULL);
73 }
diff --git a/src/lib/libcrypto/evp/evp_cnf.c b/src/lib/libcrypto/evp/evp_cnf.c
new file mode 100644
index 0000000000..2e4db30235
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_cnf.c
@@ -0,0 +1,125 @@
1/* evp_cnf.c */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2007.
4 */
5/* ====================================================================
6 * Copyright (c) 2007 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 <ctype.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/conf.h>
64#include <openssl/dso.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67#ifdef OPENSSL_FIPS
68#include <openssl/fips.h>
69#endif
70
71
72/* Algorithm configuration module. */
73
74static int alg_module_init(CONF_IMODULE *md, const CONF *cnf)
75 {
76 int i;
77 const char *oid_section;
78 STACK_OF(CONF_VALUE) *sktmp;
79 CONF_VALUE *oval;
80 oid_section = CONF_imodule_get_value(md);
81 if(!(sktmp = NCONF_get_section(cnf, oid_section)))
82 {
83 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION);
84 return 0;
85 }
86 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
87 {
88 oval = sk_CONF_VALUE_value(sktmp, i);
89 if (!strcmp(oval->name, "fips_mode"))
90 {
91 int m;
92 if (!X509V3_get_value_bool(oval, &m))
93 {
94 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE);
95 return 0;
96 }
97 if (m > 0)
98 {
99#ifdef OPENSSL_FIPS
100 if (!FIPS_mode() && !FIPS_mode_set(1))
101 {
102 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_SETTING_FIPS_MODE);
103 return 0;
104 }
105#else
106 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_FIPS_MODE_NOT_SUPPORTED);
107 return 0;
108#endif
109 }
110 }
111 else
112 {
113 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION);
114 ERR_add_error_data(4, "name=", oval->name,
115 ", value=", oval->value);
116 }
117
118 }
119 return 1;
120 }
121
122void EVP_add_alg_module(void)
123 {
124 CONF_module_add("alg_section", alg_module_init, 0);
125 }
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
new file mode 100644
index 0000000000..30e0ca4d9f
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -0,0 +1,440 @@
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/rand.h>
64#ifndef OPENSSL_NO_ENGINE
65#include <openssl/engine.h>
66#endif
67#include "evp_locl.h"
68
69#ifdef OPENSSL_FIPS
70 #define M_do_cipher(ctx, out, in, inl) \
71 EVP_Cipher(ctx,out,in,inl)
72#else
73 #define M_do_cipher(ctx, out, in, inl) \
74 ctx->cipher->do_cipher(ctx,out,in,inl)
75#endif
76
77const char EVP_version[]="EVP" OPENSSL_VERSION_PTEXT;
78
79EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
80 {
81 EVP_CIPHER_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
82 if (ctx)
83 EVP_CIPHER_CTX_init(ctx);
84 return ctx;
85 }
86
87int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
88 const unsigned char *key, const unsigned char *iv, int enc)
89 {
90 if (cipher)
91 EVP_CIPHER_CTX_init(ctx);
92 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
93 }
94
95int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
96 const unsigned char *in, int inl)
97 {
98 if (ctx->encrypt)
99 return EVP_EncryptUpdate(ctx,out,outl,in,inl);
100 else return EVP_DecryptUpdate(ctx,out,outl,in,inl);
101 }
102
103int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
104 {
105 if (ctx->encrypt)
106 return EVP_EncryptFinal_ex(ctx,out,outl);
107 else return EVP_DecryptFinal_ex(ctx,out,outl);
108 }
109
110int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
111 {
112 if (ctx->encrypt)
113 return EVP_EncryptFinal(ctx,out,outl);
114 else return EVP_DecryptFinal(ctx,out,outl);
115 }
116
117int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
118 const unsigned char *key, const unsigned char *iv)
119 {
120 return EVP_CipherInit(ctx, cipher, key, iv, 1);
121 }
122
123int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *impl,
124 const unsigned char *key, const unsigned char *iv)
125 {
126 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
127 }
128
129int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
130 const unsigned char *key, const unsigned char *iv)
131 {
132 return EVP_CipherInit(ctx, cipher, key, iv, 0);
133 }
134
135int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
136 const unsigned char *key, const unsigned char *iv)
137 {
138 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
139 }
140
141int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
142 const unsigned char *in, int inl)
143 {
144 int i,j,bl;
145
146 if (inl <= 0)
147 {
148 *outl = 0;
149 return inl == 0;
150 }
151
152 if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)
153 {
154 if(M_do_cipher(ctx,out,in,inl))
155 {
156 *outl=inl;
157 return 1;
158 }
159 else
160 {
161 *outl=0;
162 return 0;
163 }
164 }
165 i=ctx->buf_len;
166 bl=ctx->cipher->block_size;
167 OPENSSL_assert(bl <= (int)sizeof(ctx->buf));
168 if (i != 0)
169 {
170 if (i+inl < bl)
171 {
172 memcpy(&(ctx->buf[i]),in,inl);
173 ctx->buf_len+=inl;
174 *outl=0;
175 return 1;
176 }
177 else
178 {
179 j=bl-i;
180 memcpy(&(ctx->buf[i]),in,j);
181 if(!M_do_cipher(ctx,out,ctx->buf,bl)) return 0;
182 inl-=j;
183 in+=j;
184 out+=bl;
185 *outl=bl;
186 }
187 }
188 else
189 *outl = 0;
190 i=inl&(bl-1);
191 inl-=i;
192 if (inl > 0)
193 {
194 if(!M_do_cipher(ctx,out,in,inl)) return 0;
195 *outl+=inl;
196 }
197
198 if (i != 0)
199 memcpy(ctx->buf,&(in[inl]),i);
200 ctx->buf_len=i;
201 return 1;
202 }
203
204int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
205 {
206 int ret;
207 ret = EVP_EncryptFinal_ex(ctx, out, outl);
208 return ret;
209 }
210
211int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
212 {
213 int n,ret;
214 unsigned int i, b, bl;
215
216 b=ctx->cipher->block_size;
217 OPENSSL_assert(b <= sizeof ctx->buf);
218 if (b == 1)
219 {
220 *outl=0;
221 return 1;
222 }
223 bl=ctx->buf_len;
224 if (ctx->flags & EVP_CIPH_NO_PADDING)
225 {
226 if(bl)
227 {
228 EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
229 return 0;
230 }
231 *outl = 0;
232 return 1;
233 }
234
235 n=b-bl;
236 for (i=bl; i<b; i++)
237 ctx->buf[i]=n;
238 ret=M_do_cipher(ctx,out,ctx->buf,b);
239
240
241 if(ret)
242 *outl=b;
243
244 return ret;
245 }
246
247int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
248 const unsigned char *in, int inl)
249 {
250 int fix_len;
251 unsigned int b;
252
253 if (inl <= 0)
254 {
255 *outl = 0;
256 return inl == 0;
257 }
258
259 if (ctx->flags & EVP_CIPH_NO_PADDING)
260 return EVP_EncryptUpdate(ctx, out, outl, in, inl);
261
262 b=ctx->cipher->block_size;
263 OPENSSL_assert(b <= sizeof ctx->final);
264
265 if(ctx->final_used)
266 {
267 memcpy(out,ctx->final,b);
268 out+=b;
269 fix_len = 1;
270 }
271 else
272 fix_len = 0;
273
274
275 if(!EVP_EncryptUpdate(ctx,out,outl,in,inl))
276 return 0;
277
278 /* if we have 'decrypted' a multiple of block size, make sure
279 * we have a copy of this last block */
280 if (b > 1 && !ctx->buf_len)
281 {
282 *outl-=b;
283 ctx->final_used=1;
284 memcpy(ctx->final,&out[*outl],b);
285 }
286 else
287 ctx->final_used = 0;
288
289 if (fix_len)
290 *outl += b;
291
292 return 1;
293 }
294
295int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
296 {
297 int ret;
298 ret = EVP_DecryptFinal_ex(ctx, out, outl);
299 return ret;
300 }
301
302int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
303 {
304 int i,n;
305 unsigned int b;
306
307 *outl=0;
308 b=ctx->cipher->block_size;
309 if (ctx->flags & EVP_CIPH_NO_PADDING)
310 {
311 if(ctx->buf_len)
312 {
313 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
314 return 0;
315 }
316 *outl = 0;
317 return 1;
318 }
319 if (b > 1)
320 {
321 if (ctx->buf_len || !ctx->final_used)
322 {
323 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
324 return(0);
325 }
326 OPENSSL_assert(b <= sizeof ctx->final);
327 n=ctx->final[b-1];
328 if (n == 0 || n > (int)b)
329 {
330 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
331 return(0);
332 }
333 for (i=0; i<n; i++)
334 {
335 if (ctx->final[--b] != n)
336 {
337 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT);
338 return(0);
339 }
340 }
341 n=ctx->cipher->block_size-n;
342 for (i=0; i<n; i++)
343 out[i]=ctx->final[i];
344 *outl=n;
345 }
346 else
347 *outl=0;
348 return(1);
349 }
350
351void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
352 {
353 if (ctx)
354 {
355 EVP_CIPHER_CTX_cleanup(ctx);
356 OPENSSL_free(ctx);
357 }
358 }
359
360int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
361 {
362 if(c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
363 return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
364 if(c->key_len == keylen) return 1;
365 if((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH))
366 {
367 c->key_len = keylen;
368 return 1;
369 }
370 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH,EVP_R_INVALID_KEY_LENGTH);
371 return 0;
372 }
373
374int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
375 {
376 if (pad) ctx->flags &= ~EVP_CIPH_NO_PADDING;
377 else ctx->flags |= EVP_CIPH_NO_PADDING;
378 return 1;
379 }
380
381int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
382 {
383 if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
384 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key);
385 if (RAND_bytes(key, ctx->key_len) <= 0)
386 return 0;
387 return 1;
388 }
389
390#ifndef OPENSSL_NO_ENGINE
391
392#ifdef OPENSSL_FIPS
393
394static int do_evp_enc_engine_full(EVP_CIPHER_CTX *ctx, const EVP_CIPHER **pcipher, ENGINE *impl)
395 {
396 if(impl)
397 {
398 if (!ENGINE_init(impl))
399 {
400 EVPerr(EVP_F_DO_EVP_ENC_ENGINE_FULL, EVP_R_INITIALIZATION_ERROR);
401 return 0;
402 }
403 }
404 else
405 /* Ask if an ENGINE is reserved for this job */
406 impl = ENGINE_get_cipher_engine((*pcipher)->nid);
407 if(impl)
408 {
409 /* There's an ENGINE for this job ... (apparently) */
410 const EVP_CIPHER *c = ENGINE_get_cipher(impl, (*pcipher)->nid);
411 if(!c)
412 {
413 /* One positive side-effect of US's export
414 * control history, is that we should at least
415 * be able to avoid using US mispellings of
416 * "initialisation"? */
417 EVPerr(EVP_F_DO_EVP_ENC_ENGINE_FULL, EVP_R_INITIALIZATION_ERROR);
418 return 0;
419 }
420 /* We'll use the ENGINE's private cipher definition */
421 *pcipher = c;
422 /* Store the ENGINE functional reference so we know
423 * 'cipher' came from an ENGINE and we need to release
424 * it when done. */
425 ctx->engine = impl;
426 }
427 else
428 ctx->engine = NULL;
429 return 1;
430 }
431
432void int_EVP_CIPHER_init_engine_callbacks(void)
433 {
434 int_EVP_CIPHER_set_engine_callbacks(
435 ENGINE_finish, do_evp_enc_engine_full);
436 }
437
438#endif
439
440#endif
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
new file mode 100644
index 0000000000..ec2d127cd8
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -0,0 +1,189 @@
1/* crypto/evp/evp_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2007 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
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_EVP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EVP,0,reason)
70
71static ERR_STRING_DATA EVP_str_functs[]=
72 {
73{ERR_FUNC(EVP_F_AESNI_INIT_KEY), "AESNI_INIT_KEY"},
74{ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
75{ERR_FUNC(EVP_F_ALG_MODULE_INIT), "ALG_MODULE_INIT"},
76{ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY), "CAMELLIA_INIT_KEY"},
77{ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"},
78{ERR_FUNC(EVP_F_DO_EVP_ENC_ENGINE), "DO_EVP_ENC_ENGINE"},
79{ERR_FUNC(EVP_F_DO_EVP_ENC_ENGINE_FULL), "DO_EVP_ENC_ENGINE_FULL"},
80{ERR_FUNC(EVP_F_DO_EVP_MD_ENGINE), "DO_EVP_MD_ENGINE"},
81{ERR_FUNC(EVP_F_DO_EVP_MD_ENGINE_FULL), "DO_EVP_MD_ENGINE_FULL"},
82{ERR_FUNC(EVP_F_DSAPKEY2PKCS8), "DSAPKEY2PKCS8"},
83{ERR_FUNC(EVP_F_DSA_PKEY2PKCS8), "DSA_PKEY2PKCS8"},
84{ERR_FUNC(EVP_F_ECDSA_PKEY2PKCS8), "ECDSA_PKEY2PKCS8"},
85{ERR_FUNC(EVP_F_ECKEY_PKEY2PKCS8), "ECKEY_PKEY2PKCS8"},
86{ERR_FUNC(EVP_F_EVP_CIPHERINIT), "EVP_CipherInit"},
87{ERR_FUNC(EVP_F_EVP_CIPHERINIT_EX), "EVP_CipherInit_ex"},
88{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL), "EVP_CIPHER_CTX_ctrl"},
89{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH), "EVP_CIPHER_CTX_set_key_length"},
90{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX), "EVP_DecryptFinal_ex"},
91{ERR_FUNC(EVP_F_EVP_DIGESTINIT), "EVP_DigestInit"},
92{ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"},
93{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX), "EVP_EncryptFinal_ex"},
94{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX), "EVP_MD_CTX_copy_ex"},
95{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
96{ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD), "EVP_PBE_alg_add"},
97{ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT), "EVP_PBE_CipherInit"},
98{ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"},
99{ERR_FUNC(EVP_F_EVP_PKEY2PKCS8_BROKEN), "EVP_PKEY2PKCS8_broken"},
100{ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"},
101{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"},
102{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT), "EVP_PKEY_encrypt"},
103{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH), "EVP_PKEY_get1_DH"},
104{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA), "EVP_PKEY_get1_DSA"},
105{ERR_FUNC(EVP_F_EVP_PKEY_GET1_ECDSA), "EVP_PKEY_GET1_ECDSA"},
106{ERR_FUNC(EVP_F_EVP_PKEY_GET1_EC_KEY), "EVP_PKEY_get1_EC_KEY"},
107{ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA), "EVP_PKEY_get1_RSA"},
108{ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"},
109{ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"},
110{ERR_FUNC(EVP_F_EVP_SIGNFINAL), "EVP_SignFinal"},
111{ERR_FUNC(EVP_F_EVP_VERIFYFINAL), "EVP_VerifyFinal"},
112{ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN), "PKCS5_PBE_keyivgen"},
113{ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN), "PKCS5_v2_PBE_keyivgen"},
114{ERR_FUNC(EVP_F_PKCS8_SET_BROKEN), "PKCS8_set_broken"},
115{ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"},
116{ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"},
117{0,NULL}
118 };
119
120static ERR_STRING_DATA EVP_str_reasons[]=
121 {
122{ERR_REASON(EVP_R_AES_KEY_SETUP_FAILED) ,"aes key setup failed"},
123{ERR_REASON(EVP_R_ASN1_LIB) ,"asn1 lib"},
124{ERR_REASON(EVP_R_BAD_BLOCK_LENGTH) ,"bad block length"},
125{ERR_REASON(EVP_R_BAD_DECRYPT) ,"bad decrypt"},
126{ERR_REASON(EVP_R_BAD_KEY_LENGTH) ,"bad key length"},
127{ERR_REASON(EVP_R_BN_DECODE_ERROR) ,"bn decode error"},
128{ERR_REASON(EVP_R_BN_PUBKEY_ERROR) ,"bn pubkey error"},
129{ERR_REASON(EVP_R_CAMELLIA_KEY_SETUP_FAILED),"camellia key setup failed"},
130{ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"},
131{ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED) ,"ctrl not implemented"},
132{ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"},
133{ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"},
134{ERR_REASON(EVP_R_DECODE_ERROR) ,"decode error"},
135{ERR_REASON(EVP_R_DIFFERENT_KEY_TYPES) ,"different key types"},
136{ERR_REASON(EVP_R_DISABLED_FOR_FIPS) ,"disabled for fips"},
137{ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"},
138{ERR_REASON(EVP_R_ERROR_LOADING_SECTION) ,"error loading section"},
139{ERR_REASON(EVP_R_ERROR_SETTING_FIPS_MODE),"error setting fips mode"},
140{ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"},
141{ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"},
142{ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"},
143{ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"},
144{ERR_REASON(EVP_R_EXPECTING_A_ECDSA_KEY) ,"expecting a ecdsa key"},
145{ERR_REASON(EVP_R_EXPECTING_A_EC_KEY) ,"expecting a ec key"},
146{ERR_REASON(EVP_R_FIPS_MODE_NOT_SUPPORTED),"fips mode not supported"},
147{ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"},
148{ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"},
149{ERR_REASON(EVP_R_INVALID_FIPS_MODE) ,"invalid fips mode"},
150{ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"},
151{ERR_REASON(EVP_R_IV_TOO_LARGE) ,"iv too large"},
152{ERR_REASON(EVP_R_KEYGEN_FAILURE) ,"keygen failure"},
153{ERR_REASON(EVP_R_MISSING_PARAMETERS) ,"missing parameters"},
154{ERR_REASON(EVP_R_NO_CIPHER_SET) ,"no cipher set"},
155{ERR_REASON(EVP_R_NO_DIGEST_SET) ,"no digest set"},
156{ERR_REASON(EVP_R_NO_DSA_PARAMETERS) ,"no dsa parameters"},
157{ERR_REASON(EVP_R_NO_SIGN_FUNCTION_CONFIGURED),"no sign function configured"},
158{ERR_REASON(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED),"no verify function configured"},
159{ERR_REASON(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE),"pkcs8 unknown broken type"},
160{ERR_REASON(EVP_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"},
161{ERR_REASON(EVP_R_SEED_KEY_SETUP_FAILED) ,"seed key setup failed"},
162{ERR_REASON(EVP_R_UNKNOWN_OPTION) ,"unknown option"},
163{ERR_REASON(EVP_R_UNKNOWN_PBE_ALGORITHM) ,"unknown pbe algorithm"},
164{ERR_REASON(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS),"unsuported number of rounds"},
165{ERR_REASON(EVP_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
166{ERR_REASON(EVP_R_UNSUPPORTED_KEYLENGTH) ,"unsupported keylength"},
167{ERR_REASON(EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION),"unsupported key derivation function"},
168{ERR_REASON(EVP_R_UNSUPPORTED_KEY_SIZE) ,"unsupported key size"},
169{ERR_REASON(EVP_R_UNSUPPORTED_PRF) ,"unsupported prf"},
170{ERR_REASON(EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM),"unsupported private key algorithm"},
171{ERR_REASON(EVP_R_UNSUPPORTED_SALT_TYPE) ,"unsupported salt type"},
172{ERR_REASON(EVP_R_WRONG_FINAL_BLOCK_LENGTH),"wrong final block length"},
173{ERR_REASON(EVP_R_WRONG_PUBLIC_KEY_TYPE) ,"wrong public key type"},
174{0,NULL}
175 };
176
177#endif
178
179void ERR_load_EVP_strings(void)
180 {
181#ifndef OPENSSL_NO_ERR
182
183 if (ERR_func_error_string(EVP_str_functs[0].error) == NULL)
184 {
185 ERR_load_strings(0,EVP_str_functs);
186 ERR_load_strings(0,EVP_str_reasons);
187 }
188#endif
189 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
new file mode 100644
index 0000000000..361ea69ab6
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -0,0 +1,175 @@
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(const 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 OPENSSL_cleanse(buff,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 OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH);
122 OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH);
123
124 if (data == NULL) return(nkey);
125
126 EVP_MD_CTX_init(&c);
127 for (;;)
128 {
129 if (!EVP_DigestInit_ex(&c,md, NULL))
130 return 0;
131 if (addmd++)
132 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
133 EVP_DigestUpdate(&c,data,datal);
134 if (salt != NULL)
135 EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);
136 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
137
138 for (i=1; i<(unsigned int)count; i++)
139 {
140 EVP_DigestInit_ex(&c,md, NULL);
141 EVP_DigestUpdate(&c,&(md_buf[0]),mds);
142 EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
143 }
144 i=0;
145 if (nkey)
146 {
147 for (;;)
148 {
149 if (nkey == 0) break;
150 if (i == mds) break;
151 if (key != NULL)
152 *(key++)=md_buf[i];
153 nkey--;
154 i++;
155 }
156 }
157 if (niv && (i != mds))
158 {
159 for (;;)
160 {
161 if (niv == 0) break;
162 if (i == mds) break;
163 if (iv != NULL)
164 *(iv++)=md_buf[i];
165 niv--;
166 i++;
167 }
168 }
169 if ((nkey == 0) && (niv == 0)) break;
170 }
171 EVP_MD_CTX_cleanup(&c);
172 OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE);
173 return(type->key_len);
174 }
175
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
new file mode 100644
index 0000000000..174cf6c594
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -0,0 +1,278 @@
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 if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1)
71 ret=EVP_CIPHER_set_asn1_iv(c, type);
72 else
73 ret=-1;
74 return(ret);
75 }
76
77int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
78 {
79 int ret;
80
81 if (c->cipher->get_asn1_parameters != NULL)
82 ret=c->cipher->get_asn1_parameters(c,type);
83 else if (c->cipher->flags & EVP_CIPH_FLAG_DEFAULT_ASN1)
84 ret=EVP_CIPHER_get_asn1_iv(c, type);
85 else
86 ret=-1;
87 return(ret);
88 }
89
90int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
91 {
92 int i=0;
93 unsigned int l;
94
95 if (type != NULL)
96 {
97 l=EVP_CIPHER_CTX_iv_length(c);
98 OPENSSL_assert(l <= sizeof(c->iv));
99 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
100 if (i != (int)l)
101 return(-1);
102 else if (i > 0)
103 memcpy(c->iv,c->oiv,l);
104 }
105 return(i);
106 }
107
108int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
109 {
110 int i=0;
111 unsigned int j;
112
113 if (type != NULL)
114 {
115 j=EVP_CIPHER_CTX_iv_length(c);
116 OPENSSL_assert(j <= sizeof(c->iv));
117 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
118 }
119 return(i);
120 }
121
122/* Convert the various cipher NIDs and dummies to a proper OID NID */
123int EVP_CIPHER_type(const EVP_CIPHER *ctx)
124{
125 int nid;
126 ASN1_OBJECT *otmp;
127 nid = EVP_CIPHER_nid(ctx);
128
129 switch(nid) {
130
131 case NID_rc2_cbc:
132 case NID_rc2_64_cbc:
133 case NID_rc2_40_cbc:
134
135 return NID_rc2_cbc;
136
137 case NID_rc4:
138 case NID_rc4_40:
139
140 return NID_rc4;
141
142 case NID_aes_128_cfb128:
143 case NID_aes_128_cfb8:
144 case NID_aes_128_cfb1:
145
146 return NID_aes_128_cfb128;
147
148 case NID_aes_192_cfb128:
149 case NID_aes_192_cfb8:
150 case NID_aes_192_cfb1:
151
152 return NID_aes_192_cfb128;
153
154 case NID_aes_256_cfb128:
155 case NID_aes_256_cfb8:
156 case NID_aes_256_cfb1:
157
158 return NID_aes_256_cfb128;
159
160 case NID_des_cfb64:
161 case NID_des_cfb8:
162 case NID_des_cfb1:
163
164 return NID_des_cfb64;
165
166 default:
167 /* Check it has an OID and it is valid */
168 otmp = OBJ_nid2obj(nid);
169 if(!otmp || !otmp->data) nid = NID_undef;
170 ASN1_OBJECT_free(otmp);
171 return nid;
172 }
173}
174
175int EVP_CIPHER_block_size(const EVP_CIPHER *e)
176 {
177 return e->block_size;
178 }
179
180int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
181 {
182 return ctx->cipher->block_size;
183 }
184
185const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx)
186 {
187 return ctx->cipher;
188 }
189
190unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher)
191 {
192 return cipher->flags;
193 }
194
195void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
196 {
197 return ctx->app_data;
198 }
199
200void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
201 {
202 ctx->app_data = data;
203 }
204
205int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
206 {
207 return cipher->iv_len;
208 }
209
210int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
211 {
212 return cipher->key_len;
213 }
214
215int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
216 {
217 return ctx->key_len;
218 }
219
220int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
221 {
222 return ctx->cipher->nid;
223 }
224
225int EVP_MD_block_size(const EVP_MD *md)
226 {
227 return md->block_size;
228 }
229
230int EVP_MD_type(const EVP_MD *md)
231 {
232 return md->type;
233 }
234
235int EVP_MD_pkey_type(const EVP_MD *md)
236 {
237 return md->pkey_type;
238 }
239
240int EVP_MD_size(const EVP_MD *md)
241 {
242 return md->md_size;
243 }
244
245const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
246 {
247 return ctx->digest;
248 }
249
250void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
251 {
252 ctx->flags |= flags;
253 }
254
255void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
256 {
257 ctx->flags &= ~flags;
258 }
259
260int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
261 {
262 return (ctx->flags & flags);
263 }
264
265void EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags)
266 {
267 ctx->flags |= flags;
268 }
269
270void EVP_CIPHER_CTX_clear_flags(EVP_CIPHER_CTX *ctx, int flags)
271 {
272 ctx->flags &= ~flags;
273 }
274
275int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
276 {
277 return (ctx->flags & flags);
278 }
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
new file mode 100644
index 0000000000..eabcc96f30
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -0,0 +1,252 @@
1/* evp_locl.h */
2/* Written by Dr Stephen N Henson (steve@openssl.org) 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##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
94{\
95 cprefix##_cfb##cbits##_encrypt(in, out, (long)((cbits==1) && !(ctx->flags & EVP_CIPH_FLAG_LENGTH_BITS) ?inl*8: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, key_len, \
128 iv_len, cbits, flags, init_key, cleanup, \
129 set_asn1, get_asn1, ctrl) \
130BLOCK_CIPHER_def1(cname, cfb##cbits, cfb##cbits, CFB, kstruct, nid, 1, \
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, 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, 1, \
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, key_len, iv_len, cbits, \
153 flags, init_key, cleanup, set_asn1, get_asn1, ctrl) \
154BLOCK_CIPHER_def_ofb(cname, kstruct, nid, 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)
228
229#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,fl) \
230 BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
231 BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
232 NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
233 (fl)|EVP_CIPH_FLAG_DEFAULT_ASN1, \
234 cipher##_init_key, NULL, NULL, NULL, NULL)
235
236#ifdef OPENSSL_FIPS
237#define RC2_set_key private_RC2_set_key
238#define RC4_set_key private_RC4_set_key
239#define CAST_set_key private_CAST_set_key
240#define RC5_32_set_key private_RC5_32_set_key
241#define BF_set_key private_BF_set_key
242#define Camellia_set_key private_Camellia_set_key
243#define idea_set_encrypt_key private_idea_set_encrypt_key
244
245#define MD5_Init private_MD5_Init
246#define MD4_Init private_MD4_Init
247#define MD2_Init private_MD2_Init
248#define MDC2_Init private_MDC2_Init
249#define SHA_Init private_SHA_Init
250
251#endif
252
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
new file mode 100644
index 0000000000..5e830be65f
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -0,0 +1,137 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) 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 "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/x509.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) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
91 else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, 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 const EVP_PBE_CTL * const *pbe1 = (const EVP_PBE_CTL * const *) a,
110 * const *pbe2 = (const EVP_PBE_CTL * const *)b;
111 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
112}
113
114/* Add a PBE algorithm */
115
116int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
117 EVP_PBE_KEYGEN *keygen)
118{
119 EVP_PBE_CTL *pbe_tmp;
120 if (!pbe_algs) pbe_algs = sk_new(pbe_cmp);
121 if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) {
122 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
123 return 0;
124 }
125 pbe_tmp->pbe_nid = nid;
126 pbe_tmp->cipher = cipher;
127 pbe_tmp->md = md;
128 pbe_tmp->keygen = keygen;
129 sk_push (pbe_algs, (char *)pbe_tmp);
130 return 1;
131}
132
133void EVP_PBE_cleanup(void)
134{
135 sk_pop_free(pbe_algs, OPENSSL_freeFunc);
136 pbe_algs = NULL;
137}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
new file mode 100644
index 0000000000..10d9e9e772
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -0,0 +1,794 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2002 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#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70#include <openssl/bn.h>
71
72#ifndef OPENSSL_NO_DSA
73static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
74#endif
75#ifndef OPENSSL_NO_EC
76static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
77#endif
78
79/* Extract a private key from a PKCS8 structure */
80
81EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
82{
83 EVP_PKEY *pkey = NULL;
84#ifndef OPENSSL_NO_RSA
85 RSA *rsa = NULL;
86#endif
87#ifndef OPENSSL_NO_DSA
88 DSA *dsa = NULL;
89 ASN1_TYPE *t1, *t2;
90 ASN1_INTEGER *privkey;
91 STACK_OF(ASN1_TYPE) *ndsa = NULL;
92#endif
93#ifndef OPENSSL_NO_EC
94 EC_KEY *eckey = NULL;
95 const unsigned char *p_tmp;
96#endif
97#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
98 ASN1_TYPE *param = NULL;
99 BN_CTX *ctx = NULL;
100 int plen;
101#endif
102 X509_ALGOR *a;
103 const unsigned char *p;
104 const unsigned char *cp;
105 int pkeylen;
106 int nid;
107 char obj_tmp[80];
108
109 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
110 p8->broken = PKCS8_OK;
111 p = p8->pkey->value.octet_string->data;
112 pkeylen = p8->pkey->value.octet_string->length;
113 } else {
114 p8->broken = PKCS8_NO_OCTET;
115 p = p8->pkey->value.sequence->data;
116 pkeylen = p8->pkey->value.sequence->length;
117 }
118 if (!(pkey = EVP_PKEY_new())) {
119 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
120 return NULL;
121 }
122 a = p8->pkeyalg;
123 nid = OBJ_obj2nid(a->algorithm);
124 switch(nid)
125 {
126#ifndef OPENSSL_NO_RSA
127 case NID_rsaEncryption:
128 cp = p;
129 if (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {
130 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
131 return NULL;
132 }
133 EVP_PKEY_assign_RSA (pkey, rsa);
134 break;
135#endif
136#ifndef OPENSSL_NO_DSA
137 case NID_dsa:
138 /* PKCS#8 DSA is weird: you just get a private key integer
139 * and parameters in the AlgorithmIdentifier the pubkey must
140 * be recalculated.
141 */
142
143 /* Check for broken DSA PKCS#8, UGH! */
144 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
145 if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,
146 d2i_ASN1_TYPE,
147 ASN1_TYPE_free))) {
148 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
149 goto dsaerr;
150 }
151 if(sk_ASN1_TYPE_num(ndsa) != 2 ) {
152 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
153 goto dsaerr;
154 }
155 /* Handle Two broken types:
156 * SEQUENCE {parameters, priv_key}
157 * SEQUENCE {pub_key, priv_key}
158 */
159
160 t1 = sk_ASN1_TYPE_value(ndsa, 0);
161 t2 = sk_ASN1_TYPE_value(ndsa, 1);
162 if(t1->type == V_ASN1_SEQUENCE) {
163 p8->broken = PKCS8_EMBEDDED_PARAM;
164 param = t1;
165 } else if(a->parameter->type == V_ASN1_SEQUENCE) {
166 p8->broken = PKCS8_NS_DB;
167 param = a->parameter;
168 } else {
169 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
170 goto dsaerr;
171 }
172
173 if(t2->type != V_ASN1_INTEGER) {
174 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
175 goto dsaerr;
176 }
177 privkey = t2->value.integer;
178 } else {
179 if (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
180 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
181 goto dsaerr;
182 }
183 param = p8->pkeyalg->parameter;
184 }
185 if (!param || (param->type != V_ASN1_SEQUENCE)) {
186 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
187 goto dsaerr;
188 }
189 cp = p = param->value.sequence->data;
190 plen = param->value.sequence->length;
191 if (!(dsa = d2i_DSAparams (NULL, &cp, plen))) {
192 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
193 goto dsaerr;
194 }
195 /* We have parameters now set private key */
196 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
197 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
198 goto dsaerr;
199 }
200 /* Calculate public key (ouch!) */
201 if (!(dsa->pub_key = BN_new())) {
202 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
203 goto dsaerr;
204 }
205 if (!(ctx = BN_CTX_new())) {
206 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
207 goto dsaerr;
208 }
209
210 if (!BN_mod_exp(dsa->pub_key, dsa->g,
211 dsa->priv_key, dsa->p, ctx)) {
212
213 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
214 goto dsaerr;
215 }
216
217 EVP_PKEY_assign_DSA(pkey, dsa);
218 BN_CTX_free (ctx);
219 if(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
220 else ASN1_INTEGER_free(privkey);
221 break;
222 dsaerr:
223 BN_CTX_free (ctx);
224 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
225 DSA_free(dsa);
226 EVP_PKEY_free(pkey);
227 return NULL;
228 break;
229#endif
230#ifndef OPENSSL_NO_EC
231 case NID_X9_62_id_ecPublicKey:
232 p_tmp = p;
233 /* extract the ec parameters */
234 param = p8->pkeyalg->parameter;
235
236 if (!param || ((param->type != V_ASN1_SEQUENCE) &&
237 (param->type != V_ASN1_OBJECT)))
238 {
239 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
240 goto ecerr;
241 }
242
243 if (param->type == V_ASN1_SEQUENCE)
244 {
245 cp = p = param->value.sequence->data;
246 plen = param->value.sequence->length;
247
248 if (!(eckey = d2i_ECParameters(NULL, &cp, plen)))
249 {
250 EVPerr(EVP_F_EVP_PKCS82PKEY,
251 EVP_R_DECODE_ERROR);
252 goto ecerr;
253 }
254 }
255 else
256 {
257 EC_GROUP *group;
258 cp = p = param->value.object->data;
259 plen = param->value.object->length;
260
261 /* type == V_ASN1_OBJECT => the parameters are given
262 * by an asn1 OID
263 */
264 if ((eckey = EC_KEY_new()) == NULL)
265 {
266 EVPerr(EVP_F_EVP_PKCS82PKEY,
267 ERR_R_MALLOC_FAILURE);
268 goto ecerr;
269 }
270 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object));
271 if (group == NULL)
272 goto ecerr;
273 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
274 if (EC_KEY_set_group(eckey, group) == 0)
275 goto ecerr;
276 EC_GROUP_free(group);
277 }
278
279 /* We have parameters now set private key */
280 if (!d2i_ECPrivateKey(&eckey, &p_tmp, pkeylen))
281 {
282 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
283 goto ecerr;
284 }
285
286 /* calculate public key (if necessary) */
287 if (EC_KEY_get0_public_key(eckey) == NULL)
288 {
289 const BIGNUM *priv_key;
290 const EC_GROUP *group;
291 EC_POINT *pub_key;
292 /* the public key was not included in the SEC1 private
293 * key => calculate the public key */
294 group = EC_KEY_get0_group(eckey);
295 pub_key = EC_POINT_new(group);
296 if (pub_key == NULL)
297 {
298 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
299 goto ecerr;
300 }
301 if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group)))
302 {
303 EC_POINT_free(pub_key);
304 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
305 goto ecerr;
306 }
307 priv_key = EC_KEY_get0_private_key(eckey);
308 if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
309 {
310 EC_POINT_free(pub_key);
311 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
312 goto ecerr;
313 }
314 if (EC_KEY_set_public_key(eckey, pub_key) == 0)
315 {
316 EC_POINT_free(pub_key);
317 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
318 goto ecerr;
319 }
320 EC_POINT_free(pub_key);
321 }
322
323 EVP_PKEY_assign_EC_KEY(pkey, eckey);
324 if (ctx)
325 BN_CTX_free(ctx);
326 break;
327ecerr:
328 if (ctx)
329 BN_CTX_free(ctx);
330 if (eckey)
331 EC_KEY_free(eckey);
332 if (pkey)
333 EVP_PKEY_free(pkey);
334 return NULL;
335#endif
336 default:
337 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
338 if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
339 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
340 ERR_add_error_data(2, "TYPE=", obj_tmp);
341 EVP_PKEY_free (pkey);
342 return NULL;
343 }
344 return pkey;
345}
346
347PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
348{
349 return EVP_PKEY2PKCS8_broken(pkey, PKCS8_OK);
350}
351
352/* Turn a private key into a PKCS8 structure */
353
354PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
355{
356 PKCS8_PRIV_KEY_INFO *p8;
357
358 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
359 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
360 return NULL;
361 }
362 p8->broken = broken;
363 if (!ASN1_INTEGER_set(p8->version, 0)) {
364 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
365 PKCS8_PRIV_KEY_INFO_free (p8);
366 return NULL;
367 }
368 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
369 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
370 PKCS8_PRIV_KEY_INFO_free (p8);
371 return NULL;
372 }
373 p8->pkey->type = V_ASN1_OCTET_STRING;
374 switch (EVP_PKEY_type(pkey->type)) {
375#ifndef OPENSSL_NO_RSA
376 case EVP_PKEY_RSA:
377
378 if(p8->broken == PKCS8_NO_OCTET) p8->pkey->type = V_ASN1_SEQUENCE;
379
380 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
381 p8->pkeyalg->parameter->type = V_ASN1_NULL;
382 if (!ASN1_pack_string_of (EVP_PKEY,pkey, i2d_PrivateKey,
383 &p8->pkey->value.octet_string)) {
384 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
385 PKCS8_PRIV_KEY_INFO_free (p8);
386 return NULL;
387 }
388 break;
389#endif
390#ifndef OPENSSL_NO_DSA
391 case EVP_PKEY_DSA:
392 if(!dsa_pkey2pkcs8(p8, pkey)) {
393 PKCS8_PRIV_KEY_INFO_free (p8);
394 return NULL;
395 }
396
397 break;
398#endif
399#ifndef OPENSSL_NO_EC
400 case EVP_PKEY_EC:
401 if (!eckey_pkey2pkcs8(p8, pkey))
402 {
403 PKCS8_PRIV_KEY_INFO_free(p8);
404 return(NULL);
405 }
406 break;
407#endif
408 default:
409 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
410 PKCS8_PRIV_KEY_INFO_free (p8);
411 return NULL;
412 }
413 RAND_add(p8->pkey->value.octet_string->data,
414 p8->pkey->value.octet_string->length, 0.0);
415 return p8;
416}
417
418PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
419{
420 switch (broken) {
421
422 case PKCS8_OK:
423 p8->broken = PKCS8_OK;
424 return p8;
425 break;
426
427 case PKCS8_NO_OCTET:
428 p8->broken = PKCS8_NO_OCTET;
429 p8->pkey->type = V_ASN1_SEQUENCE;
430 return p8;
431 break;
432
433 default:
434 EVPerr(EVP_F_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
435 return NULL;
436 }
437}
438
439#ifndef OPENSSL_NO_DSA
440static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
441{
442 ASN1_STRING *params = NULL;
443 ASN1_INTEGER *prkey = NULL;
444 ASN1_TYPE *ttmp = NULL;
445 STACK_OF(ASN1_TYPE) *ndsa = NULL;
446 unsigned char *p = NULL, *q;
447 int len;
448
449 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
450 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
451 if (!(p = OPENSSL_malloc(len))) {
452 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
453 goto err;
454 }
455 q = p;
456 i2d_DSAparams (pkey->pkey.dsa, &q);
457 if (!(params = ASN1_STRING_new())) {
458 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
459 goto err;
460 }
461 if (!ASN1_STRING_set(params, p, len)) {
462 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
463 goto err;
464 }
465 OPENSSL_free(p);
466 p = NULL;
467 /* Get private key into integer */
468 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
469 EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
470 goto err;
471 }
472
473 switch(p8->broken) {
474
475 case PKCS8_OK:
476 case PKCS8_NO_OCTET:
477
478 if (!ASN1_pack_string_of(ASN1_INTEGER,prkey, i2d_ASN1_INTEGER,
479 &p8->pkey->value.octet_string)) {
480 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
481 goto err;
482 }
483
484 M_ASN1_INTEGER_free (prkey);
485 prkey = NULL;
486 p8->pkeyalg->parameter->value.sequence = params;
487 params = NULL;
488 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
489
490 break;
491
492 case PKCS8_NS_DB:
493
494 p8->pkeyalg->parameter->value.sequence = params;
495 params = NULL;
496 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
497 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
498 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
499 goto err;
500 }
501 if (!(ttmp = ASN1_TYPE_new())) {
502 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
503 goto err;
504 }
505 if (!(ttmp->value.integer =
506 BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {
507 EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
508 goto err;
509 }
510 ttmp->type = V_ASN1_INTEGER;
511 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
512 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
513 goto err;
514 }
515
516 if (!(ttmp = ASN1_TYPE_new())) {
517 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
518 goto err;
519 }
520 ttmp->value.integer = prkey;
521 prkey = NULL;
522 ttmp->type = V_ASN1_INTEGER;
523 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
524 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
525 goto err;
526 }
527 ttmp = NULL;
528
529 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
530 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
531 goto err;
532 }
533
534 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
535 &p8->pkey->value.octet_string->data,
536 &p8->pkey->value.octet_string->length)) {
537
538 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
539 goto err;
540 }
541 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
542 break;
543
544 case PKCS8_EMBEDDED_PARAM:
545
546 p8->pkeyalg->parameter->type = V_ASN1_NULL;
547 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
548 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
549 goto err;
550 }
551 if (!(ttmp = ASN1_TYPE_new())) {
552 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
553 goto err;
554 }
555 ttmp->value.sequence = params;
556 params = NULL;
557 ttmp->type = V_ASN1_SEQUENCE;
558 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
559 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
560 goto err;
561 }
562
563 if (!(ttmp = ASN1_TYPE_new())) {
564 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
565 goto err;
566 }
567 ttmp->value.integer = prkey;
568 prkey = NULL;
569 ttmp->type = V_ASN1_INTEGER;
570 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
571 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
572 goto err;
573 }
574 ttmp = NULL;
575
576 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
577 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
578 goto err;
579 }
580
581 if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,
582 &p8->pkey->value.octet_string->data,
583 &p8->pkey->value.octet_string->length)) {
584
585 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
586 goto err;
587 }
588 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
589 break;
590 }
591 return 1;
592err:
593 if (p != NULL) OPENSSL_free(p);
594 if (params != NULL) ASN1_STRING_free(params);
595 if (prkey != NULL) M_ASN1_INTEGER_free(prkey);
596 if (ttmp != NULL) ASN1_TYPE_free(ttmp);
597 if (ndsa != NULL) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
598 return 0;
599}
600#endif
601
602#ifndef OPENSSL_NO_EC
603static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
604{
605 EC_KEY *ec_key;
606 const EC_GROUP *group;
607 unsigned char *p, *pp;
608 int nid, i, ret = 0;
609 unsigned int tmp_flags, old_flags;
610
611 ec_key = pkey->pkey.ec;
612 if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL)
613 {
614 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, EVP_R_MISSING_PARAMETERS);
615 return 0;
616 }
617
618 /* set the ec parameters OID */
619 if (p8->pkeyalg->algorithm)
620 ASN1_OBJECT_free(p8->pkeyalg->algorithm);
621
622 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_X9_62_id_ecPublicKey);
623
624 /* set the ec parameters */
625
626 if (p8->pkeyalg->parameter)
627 {
628 ASN1_TYPE_free(p8->pkeyalg->parameter);
629 p8->pkeyalg->parameter = NULL;
630 }
631
632 if ((p8->pkeyalg->parameter = ASN1_TYPE_new()) == NULL)
633 {
634 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
635 return 0;
636 }
637
638 if (EC_GROUP_get_asn1_flag(group)
639 && (nid = EC_GROUP_get_curve_name(group)))
640 {
641 /* we have a 'named curve' => just set the OID */
642 p8->pkeyalg->parameter->type = V_ASN1_OBJECT;
643 p8->pkeyalg->parameter->value.object = OBJ_nid2obj(nid);
644 }
645 else /* explicit parameters */
646 {
647 if ((i = i2d_ECParameters(ec_key, NULL)) == 0)
648 {
649 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
650 return 0;
651 }
652 if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
653 {
654 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
655 return 0;
656 }
657 pp = p;
658 if (!i2d_ECParameters(ec_key, &pp))
659 {
660 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
661 OPENSSL_free(p);
662 return 0;
663 }
664 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
665 if ((p8->pkeyalg->parameter->value.sequence
666 = ASN1_STRING_new()) == NULL)
667 {
668 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_ASN1_LIB);
669 OPENSSL_free(p);
670 return 0;
671 }
672 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, i);
673 OPENSSL_free(p);
674 }
675
676 /* set the private key */
677
678 /* do not include the parameters in the SEC1 private key
679 * see PKCS#11 12.11 */
680 old_flags = EC_KEY_get_enc_flags(pkey->pkey.ec);
681 tmp_flags = old_flags | EC_PKEY_NO_PARAMETERS;
682 EC_KEY_set_enc_flags(pkey->pkey.ec, tmp_flags);
683 i = i2d_ECPrivateKey(pkey->pkey.ec, NULL);
684 if (!i)
685 {
686 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
687 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
688 return 0;
689 }
690 p = (unsigned char *) OPENSSL_malloc(i);
691 if (!p)
692 {
693 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
694 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
695 return 0;
696 }
697 pp = p;
698 if (!i2d_ECPrivateKey(pkey->pkey.ec, &pp))
699 {
700 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
701 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
702 OPENSSL_free(p);
703 return 0;
704 }
705 /* restore old encoding flags */
706 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
707
708 switch(p8->broken) {
709
710 case PKCS8_OK:
711 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
712 if (!p8->pkey->value.octet_string ||
713 !M_ASN1_OCTET_STRING_set(p8->pkey->value.octet_string,
714 (const void *)p, i))
715
716 {
717 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
718 }
719 else
720 ret = 1;
721 break;
722 case PKCS8_NO_OCTET: /* RSA specific */
723 case PKCS8_NS_DB: /* DSA specific */
724 case PKCS8_EMBEDDED_PARAM: /* DSA specific */
725 default:
726 EVPerr(EVP_F_ECKEY_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
727 }
728 OPENSSL_cleanse(p, (size_t)i);
729 OPENSSL_free(p);
730 return ret;
731}
732#endif
733
734/* EVP_PKEY attribute functions */
735
736int EVP_PKEY_get_attr_count(const EVP_PKEY *key)
737{
738 return X509at_get_attr_count(key->attributes);
739}
740
741int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
742 int lastpos)
743{
744 return X509at_get_attr_by_NID(key->attributes, nid, lastpos);
745}
746
747int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
748 int lastpos)
749{
750 return X509at_get_attr_by_OBJ(key->attributes, obj, lastpos);
751}
752
753X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc)
754{
755 return X509at_get_attr(key->attributes, loc);
756}
757
758X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc)
759{
760 return X509at_delete_attr(key->attributes, loc);
761}
762
763int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr)
764{
765 if(X509at_add1_attr(&key->attributes, attr)) return 1;
766 return 0;
767}
768
769int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
770 const ASN1_OBJECT *obj, int type,
771 const unsigned char *bytes, int len)
772{
773 if(X509at_add1_attr_by_OBJ(&key->attributes, obj,
774 type, bytes, len)) return 1;
775 return 0;
776}
777
778int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
779 int nid, int type,
780 const unsigned char *bytes, int len)
781{
782 if(X509at_add1_attr_by_NID(&key->attributes, nid,
783 type, bytes, len)) return 1;
784 return 0;
785}
786
787int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
788 const char *attrname, int type,
789 const unsigned char *bytes, int len)
790{
791 if(X509at_add1_attr_by_txt(&key->attributes, attrname,
792 type, bytes, len)) return 1;
793 return 0;
794}
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c
new file mode 100644
index 0000000000..436be20bf1
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_test.c
@@ -0,0 +1,449 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 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#include <stdio.h>
51#include <string.h>
52
53#include "../e_os.h"
54
55#include <openssl/opensslconf.h>
56#include <openssl/evp.h>
57#ifndef OPENSSL_NO_ENGINE
58#include <openssl/engine.h>
59#endif
60#include <openssl/err.h>
61#include <openssl/conf.h>
62
63static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
64 {
65 int n=0;
66
67 fprintf(f,"%s",title);
68 for( ; n < l ; ++n)
69 {
70 if((n%16) == 0)
71 fprintf(f,"\n%04x",n);
72 fprintf(f," %02x",s[n]);
73 }
74 fprintf(f,"\n");
75 }
76
77static int convert(unsigned char *s)
78 {
79 unsigned char *d;
80
81 for(d=s ; *s ; s+=2,++d)
82 {
83 unsigned int n;
84
85 if(!s[1])
86 {
87 fprintf(stderr,"Odd number of hex digits!");
88 EXIT(4);
89 }
90 sscanf((char *)s,"%2x",&n);
91 *d=(unsigned char)n;
92 }
93 return s-d;
94 }
95
96static char *sstrsep(char **string, const char *delim)
97 {
98 char isdelim[256];
99 char *token = *string;
100
101 if (**string == 0)
102 return NULL;
103
104 memset(isdelim, 0, 256);
105 isdelim[0] = 1;
106
107 while (*delim)
108 {
109 isdelim[(unsigned char)(*delim)] = 1;
110 delim++;
111 }
112
113 while (!isdelim[(unsigned char)(**string)])
114 {
115 (*string)++;
116 }
117
118 if (**string)
119 {
120 **string = 0;
121 (*string)++;
122 }
123
124 return token;
125 }
126
127static unsigned char *ustrsep(char **p,const char *sep)
128 { return (unsigned char *)sstrsep(p,sep); }
129
130static int test1_exit(int ec)
131 {
132 EXIT(ec);
133 return(0); /* To keep some compilers quiet */
134 }
135
136static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
137 const unsigned char *iv,int in,
138 const unsigned char *plaintext,int pn,
139 const unsigned char *ciphertext,int cn,
140 int encdec)
141 {
142 EVP_CIPHER_CTX ctx;
143 unsigned char out[4096];
144 int outl,outl2;
145
146 printf("Testing cipher %s%s\n",EVP_CIPHER_name(c),
147 (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)")));
148 hexdump(stdout,"Key",key,kn);
149 if(in)
150 hexdump(stdout,"IV",iv,in);
151 hexdump(stdout,"Plaintext",plaintext,pn);
152 hexdump(stdout,"Ciphertext",ciphertext,cn);
153
154 if(kn != c->key_len)
155 {
156 fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn,
157 c->key_len);
158 test1_exit(5);
159 }
160 EVP_CIPHER_CTX_init(&ctx);
161 if (encdec != 0)
162 {
163 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
164 {
165 fprintf(stderr,"EncryptInit failed\n");
166 ERR_print_errors_fp(stderr);
167 test1_exit(10);
168 }
169 EVP_CIPHER_CTX_set_padding(&ctx,0);
170
171 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn))
172 {
173 fprintf(stderr,"Encrypt failed\n");
174 ERR_print_errors_fp(stderr);
175 test1_exit(6);
176 }
177 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
178 {
179 fprintf(stderr,"EncryptFinal failed\n");
180 ERR_print_errors_fp(stderr);
181 test1_exit(7);
182 }
183
184 if(outl+outl2 != cn)
185 {
186 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
187 outl+outl2,cn);
188 test1_exit(8);
189 }
190
191 if(memcmp(out,ciphertext,cn))
192 {
193 fprintf(stderr,"Ciphertext mismatch\n");
194 hexdump(stderr,"Got",out,cn);
195 hexdump(stderr,"Expected",ciphertext,cn);
196 test1_exit(9);
197 }
198 }
199
200 if (encdec <= 0)
201 {
202 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
203 {
204 fprintf(stderr,"DecryptInit failed\n");
205 ERR_print_errors_fp(stderr);
206 test1_exit(11);
207 }
208 EVP_CIPHER_CTX_set_padding(&ctx,0);
209
210 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn))
211 {
212 fprintf(stderr,"Decrypt failed\n");
213 ERR_print_errors_fp(stderr);
214 test1_exit(6);
215 }
216 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
217 {
218 fprintf(stderr,"DecryptFinal failed\n");
219 ERR_print_errors_fp(stderr);
220 test1_exit(7);
221 }
222
223 if(outl+outl2 != pn)
224 {
225 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
226 outl+outl2,pn);
227 test1_exit(8);
228 }
229
230 if(memcmp(out,plaintext,pn))
231 {
232 fprintf(stderr,"Plaintext mismatch\n");
233 hexdump(stderr,"Got",out,pn);
234 hexdump(stderr,"Expected",plaintext,pn);
235 test1_exit(9);
236 }
237 }
238
239 EVP_CIPHER_CTX_cleanup(&ctx);
240
241 printf("\n");
242 }
243
244static int test_cipher(const char *cipher,const unsigned char *key,int kn,
245 const unsigned char *iv,int in,
246 const unsigned char *plaintext,int pn,
247 const unsigned char *ciphertext,int cn,
248 int encdec)
249 {
250 const EVP_CIPHER *c;
251
252 c=EVP_get_cipherbyname(cipher);
253 if(!c)
254 return 0;
255
256 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec);
257
258 return 1;
259 }
260
261static int test_digest(const char *digest,
262 const unsigned char *plaintext,int pn,
263 const unsigned char *ciphertext, unsigned int cn)
264 {
265 const EVP_MD *d;
266 EVP_MD_CTX ctx;
267 unsigned char md[EVP_MAX_MD_SIZE];
268 unsigned int mdn;
269
270 d=EVP_get_digestbyname(digest);
271 if(!d)
272 return 0;
273
274 printf("Testing digest %s\n",EVP_MD_name(d));
275 hexdump(stdout,"Plaintext",plaintext,pn);
276 hexdump(stdout,"Digest",ciphertext,cn);
277
278 EVP_MD_CTX_init(&ctx);
279 if(!EVP_DigestInit_ex(&ctx,d, NULL))
280 {
281 fprintf(stderr,"DigestInit failed\n");
282 ERR_print_errors_fp(stderr);
283 EXIT(100);
284 }
285 if(!EVP_DigestUpdate(&ctx,plaintext,pn))
286 {
287 fprintf(stderr,"DigestUpdate failed\n");
288 ERR_print_errors_fp(stderr);
289 EXIT(101);
290 }
291 if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
292 {
293 fprintf(stderr,"DigestFinal failed\n");
294 ERR_print_errors_fp(stderr);
295 EXIT(101);
296 }
297 EVP_MD_CTX_cleanup(&ctx);
298
299 if(mdn != cn)
300 {
301 fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn);
302 EXIT(102);
303 }
304
305 if(memcmp(md,ciphertext,cn))
306 {
307 fprintf(stderr,"Digest mismatch\n");
308 hexdump(stderr,"Got",md,cn);
309 hexdump(stderr,"Expected",ciphertext,cn);
310 EXIT(103);
311 }
312
313 printf("\n");
314
315 EVP_MD_CTX_cleanup(&ctx);
316
317 return 1;
318 }
319
320int main(int argc,char **argv)
321 {
322 const char *szTestFile;
323 FILE *f;
324
325 if(argc != 2)
326 {
327 fprintf(stderr,"%s <test file>\n",argv[0]);
328 EXIT(1);
329 }
330 CRYPTO_malloc_debug_init();
331 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
332 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
333
334 szTestFile=argv[1];
335
336 f=fopen(szTestFile,"r");
337 if(!f)
338 {
339 perror(szTestFile);
340 EXIT(2);
341 }
342
343 /* Load up the software EVP_CIPHER and EVP_MD definitions */
344 OpenSSL_add_all_ciphers();
345 OpenSSL_add_all_digests();
346#ifndef OPENSSL_NO_ENGINE
347 /* Load all compiled-in ENGINEs */
348 ENGINE_load_builtin_engines();
349#endif
350#if 0
351 OPENSSL_config();
352#endif
353#ifndef OPENSSL_NO_ENGINE
354 /* Register all available ENGINE implementations of ciphers and digests.
355 * This could perhaps be changed to "ENGINE_register_all_complete()"? */
356 ENGINE_register_all_ciphers();
357 ENGINE_register_all_digests();
358 /* If we add command-line options, this statement should be switchable.
359 * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if
360 * they weren't already initialised. */
361 /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */
362#endif
363
364 for( ; ; )
365 {
366 char line[4096];
367 char *p;
368 char *cipher;
369 unsigned char *iv,*key,*plaintext,*ciphertext;
370 int encdec;
371 int kn,in,pn,cn;
372
373 if(!fgets((char *)line,sizeof line,f))
374 break;
375 if(line[0] == '#' || line[0] == '\n')
376 continue;
377 p=line;
378 cipher=sstrsep(&p,":");
379 key=ustrsep(&p,":");
380 iv=ustrsep(&p,":");
381 plaintext=ustrsep(&p,":");
382 ciphertext=ustrsep(&p,":");
383 if (p[-1] == '\n') {
384 p[-1] = '\0';
385 encdec = -1;
386 } else {
387 encdec = atoi(sstrsep(&p,"\n"));
388 }
389
390
391 kn=convert(key);
392 in=convert(iv);
393 pn=convert(plaintext);
394 cn=convert(ciphertext);
395
396 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec)
397 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
398 {
399#ifdef OPENSSL_NO_AES
400 if (strstr(cipher, "AES") == cipher)
401 {
402 fprintf(stdout, "Cipher disabled, skipping %s\n", cipher);
403 continue;
404 }
405#endif
406#ifdef OPENSSL_NO_DES
407 if (strstr(cipher, "DES") == cipher)
408 {
409 fprintf(stdout, "Cipher disabled, skipping %s\n", cipher);
410 continue;
411 }
412#endif
413#ifdef OPENSSL_NO_RC4
414 if (strstr(cipher, "RC4") == cipher)
415 {
416 fprintf(stdout, "Cipher disabled, skipping %s\n", cipher);
417 continue;
418 }
419#endif
420#ifdef OPENSSL_NO_CAMELLIA
421 if (strstr(cipher, "CAMELLIA") == cipher)
422 {
423 fprintf(stdout, "Cipher disabled, skipping %s\n", cipher);
424 continue;
425 }
426#endif
427#ifdef OPENSSL_NO_SEED
428 if (strstr(cipher, "SEED") == cipher)
429 {
430 fprintf(stdout, "Cipher disabled, skipping %s\n", cipher);
431 continue;
432 }
433#endif
434 fprintf(stderr,"Can't find %s\n",cipher);
435 EXIT(3);
436 }
437 }
438
439#ifndef OPENSSL_NO_ENGINE
440 ENGINE_cleanup();
441#endif
442 EVP_cleanup();
443 CRYPTO_cleanup_all_ex_data();
444 ERR_remove_state(0);
445 ERR_free_strings();
446 CRYPTO_mem_leaks_fp(stderr);
447
448 return 0;
449 }
diff --git a/src/lib/libcrypto/evp/evptests.txt b/src/lib/libcrypto/evp/evptests.txt
new file mode 100644
index 0000000000..beb12144b6
--- /dev/null
+++ b/src/lib/libcrypto/evp/evptests.txt
@@ -0,0 +1,321 @@
1#cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt)
2#digest:::input:output
3
4# SHA(1) tests (from shatest.c)
5SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d
6
7# MD5 tests (from md5test.c)
8MD5::::d41d8cd98f00b204e9800998ecf8427e
9MD5:::61:0cc175b9c0f1b6a831c399e269772661
10MD5:::616263:900150983cd24fb0d6963f7d28e17f72
11MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0
12MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b
13MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f
14MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a
15
16# AES 128 ECB tests (from FIPS-197 test vectors, encrypt)
17
18AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A:1
19
20# AES 192 ECB tests (from FIPS-197 test vectors, encrypt)
21
22AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191:1
23
24# AES 256 ECB tests (from FIPS-197 test vectors, encrypt)
25
26AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089:1
27
28# AES 128 ECB tests (from NIST test vectors, encrypt)
29
30#AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F:1
31
32# AES 128 ECB tests (from NIST test vectors, decrypt)
33
34#AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000:0
35
36# AES 192 ECB tests (from NIST test vectors, decrypt)
37
38#AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000:0
39
40# AES 256 ECB tests (from NIST test vectors, decrypt)
41
42#AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000:0
43
44# AES 128 CBC tests (from NIST test vectors, encrypt)
45
46#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D:1
47
48# AES 192 CBC tests (from NIST test vectors, encrypt)
49
50#AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104:1
51
52# AES 256 CBC tests (from NIST test vectors, encrypt)
53
54#AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0:1
55
56# AES 128 CBC tests (from NIST test vectors, decrypt)
57
58#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000:0
59
60# AES tests from NIST document SP800-38A
61# For all ECB encrypts and decrypts, the transformed sequence is
62# AES-bits-ECB:key::plaintext:ciphertext:encdec
63# ECB-AES128.Encrypt and ECB-AES128.Decrypt
64AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:3AD77BB40D7A3660A89ECAF32466EF97
65AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:F5D3D58503B9699DE785895A96FDBAAF
66AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:43B1CD7F598ECE23881B00E3ED030688
67AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:7B0C785E27E8AD3F8223207104725DD4
68# ECB-AES192.Encrypt and ECB-AES192.Decrypt
69AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:BD334F1D6E45F25FF712A214571FA5CC
70AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:974104846D0AD3AD7734ECB3ECEE4EEF
71AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:EF7AFD2270E2E60ADCE0BA2FACE6444E
72AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:9A4B41BA738D6C72FB16691603C18E0E
73# ECB-AES256.Encrypt and ECB-AES256.Decrypt
74AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:F3EED1BDB5D2A03C064B5A7E3DB181F8
75AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:591CCB10D410ED26DC5BA74A31362870
76AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:B6ED21B99CA6F4F9F153E7B1BEAFED1D
77AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:23304B7A39F9F3FF067D8D8F9E24ECC7
78# For all CBC encrypts and decrypts, the transformed sequence is
79# AES-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec
80# CBC-AES128.Encrypt and CBC-AES128.Decrypt
81AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:7649ABAC8119B246CEE98E9B12E9197D
82AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:7649ABAC8119B246CEE98E9B12E9197D:AE2D8A571E03AC9C9EB76FAC45AF8E51:5086CB9B507219EE95DB113A917678B2
83AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:5086CB9B507219EE95DB113A917678B2:30C81C46A35CE411E5FBC1191A0A52EF:73BED6B8E3C1743B7116E69E22229516
84AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:73BED6B8E3C1743B7116E69E22229516:F69F2445DF4F9B17AD2B417BE66C3710:3FF1CAA1681FAC09120ECA307586E1A7
85# CBC-AES192.Encrypt and CBC-AES192.Decrypt
86AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:4F021DB243BC633D7178183A9FA071E8
87AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:4F021DB243BC633D7178183A9FA071E8:AE2D8A571E03AC9C9EB76FAC45AF8E51:B4D9ADA9AD7DEDF4E5E738763F69145A
88AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:B4D9ADA9AD7DEDF4E5E738763F69145A:30C81C46A35CE411E5FBC1191A0A52EF:571B242012FB7AE07FA9BAAC3DF102E0
89AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:571B242012FB7AE07FA9BAAC3DF102E0:F69F2445DF4F9B17AD2B417BE66C3710:08B0E27988598881D920A9E64F5615CD
90# CBC-AES256.Encrypt and CBC-AES256.Decrypt
91AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:F58C4C04D6E5F1BA779EABFB5F7BFBD6
92AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:F58C4C04D6E5F1BA779EABFB5F7BFBD6:AE2D8A571E03AC9C9EB76FAC45AF8E51:9CFC4E967EDB808D679F777BC6702C7D
93AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:9CFC4E967EDB808D679F777BC6702C7D:30C81C46A35CE411E5FBC1191A0A52EF:39F23369A9D9BACFA530E26304231461
94AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39F23369A9D9BACFA530E26304231461:F69F2445DF4F9B17AD2B417BE66C3710:B2EB05E2C39BE9FCDA6C19078C6A9D1B
95# We don't support CFB{1,8}-AESxxx.{En,De}crypt
96# For all CFB128 encrypts and decrypts, the transformed sequence is
97# AES-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec
98# CFB128-AES128.Encrypt
99AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1
100AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:1
101AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:1
102AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:1
103# CFB128-AES128.Decrypt
104AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
105AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:0
106AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:0
107AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:0
108# CFB128-AES192.Encrypt
109AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1
110AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:1
111AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:1
112AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:1
113# CFB128-AES192.Decrypt
114AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0
115AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:0
116AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:0
117AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:0
118# CFB128-AES256.Encrypt
119AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
120AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:1
121AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:1
122AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:1
123# CFB128-AES256.Decrypt
124AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
125AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:0
126AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:0
127AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:0
128# For all OFB encrypts and decrypts, the transformed sequence is
129# AES-bits-CFB:key:IV/output':plaintext:ciphertext:encdec
130# OFB-AES128.Encrypt
131AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1
132AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:1
133AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:1
134AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:1
135# OFB-AES128.Decrypt
136AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
137AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:0
138AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:0
139AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:0
140# OFB-AES192.Encrypt
141AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1
142AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:1
143AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:1
144AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:1
145# OFB-AES192.Decrypt
146AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0
147AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:0
148AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:0
149AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:0
150# OFB-AES256.Encrypt
151AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
152AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:1
153AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:1
154AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:1
155# OFB-AES256.Decrypt
156AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
157AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:0
158AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:0
159AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:0
160
161# DES ECB tests (from destest)
162
163DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7
164DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58
165DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B
166DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533
167DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D
168DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD
169DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4
170
171# DESX-CBC tests (from destest)
172DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4
173
174# DES EDE3 CBC tests (from destest)
175DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
176
177# RC4 tests (from rc4test)
178RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596
179RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879
180RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a
181RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858
182RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf
183RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61
184
185
186# Camellia tests from RFC3713
187# For all ECB encrypts and decrypts, the transformed sequence is
188# CAMELLIA-bits-ECB:key::plaintext:ciphertext:encdec
189CAMELLIA-128-ECB:0123456789abcdeffedcba9876543210::0123456789abcdeffedcba9876543210:67673138549669730857065648eabe43
190CAMELLIA-192-ECB:0123456789abcdeffedcba98765432100011223344556677::0123456789abcdeffedcba9876543210:b4993401b3e996f84ee5cee7d79b09b9
191CAMELLIA-256-ECB:0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff::0123456789abcdeffedcba9876543210:9acc237dff16d76c20ef7c919e3a7509
192
193# ECB-CAMELLIA128.Encrypt
194CAMELLIA-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:77CF412067AF8270613529149919546F:1
195CAMELLIA-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:B22F3C36B72D31329EEE8ADDC2906C68:1
196CAMELLIA-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:2EDF1F3418D53B88841FC8985FB1ECF2:1
197
198# ECB-CAMELLIA128.Encrypt and ECB-CAMELLIA128.Decrypt
199CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:432FC5DCD628115B7C388D770B270C96
200CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:0BE1F14023782A22E8384C5ABB7FAB2B
201CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:A0A1ABCD1893AB6FE0FE5B65DF5F8636
202CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:E61925E0D5DFAA9BB29F815B3076E51A
203
204# ECB-CAMELLIA192.Encrypt and ECB-CAMELLIA192.Decrypt
205CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:CCCC6C4E138B45848514D48D0D3439D3
206CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:5713C62C14B2EC0F8393B6AFD6F5785A
207CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:B40ED2B60EB54D09D030CF511FEEF366
208CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:909DBD95799096748CB27357E73E1D26
209
210# ECB-CAMELLIA256.Encrypt and ECB-CAMELLIA256.Decrypt
211CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:BEFD219B112FA00098919CD101C9CCFA
212CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:C91D3A8F1AEA08A9386CF4B66C0169EA
213CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:A623D711DC5F25A51BB8A80D56397D28
214CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:7960109FB6DC42947FCFE59EA3C5EB6B
215
216# For all CBC encrypts and decrypts, the transformed sequence is
217# CAMELLIA-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec
218# CBC-CAMELLIA128.Encrypt and CBC-CAMELLIA128.Decrypt
219CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:1607CF494B36BBF00DAEB0B503C831AB
220CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:1607CF494B36BBF00DAEB0B503C831AB:AE2D8A571E03AC9C9EB76FAC45AF8E51:A2F2CF671629EF7840C5A5DFB5074887
221CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:A2F2CF671629EF7840C5A5DFB5074887:30C81C46A35CE411E5FBC1191A0A52EF:0F06165008CF8B8B5A63586362543E54
222CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:36A84CDAFD5F9A85ADA0F0A993D6D577:F69F2445DF4F9B17AD2B417BE66C3710:74C64268CDB8B8FAF5B34E8AF3732980
223
224# CBC-CAMELLIA192.Encrypt and CBC-CAMELLIA192.Decrypt
225CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:2A4830AB5AC4A1A2405955FD2195CF93
226CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2A4830AB5AC4A1A2405955FD2195CF93:AE2D8A571E03AC9C9EB76FAC45AF8E51:5D5A869BD14CE54264F892A6DD2EC3D5
227CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:5D5A869BD14CE54264F892A6DD2EC3D5:30C81C46A35CE411E5FBC1191A0A52EF:37D359C3349836D884E310ADDF68C449
228CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:37D359C3349836D884E310ADDF68C449:F69F2445DF4F9B17AD2B417BE66C3710:01FAAA930B4AB9916E9668E1428C6B08
229
230# CBC-CAMELLIA256.Encrypt and CBC-CAMELLIA256.Decrypt
231CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:E6CFA35FC02B134A4D2C0B6737AC3EDA
232CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E6CFA35FC02B134A4D2C0B6737AC3EDA:AE2D8A571E03AC9C9EB76FAC45AF8E51:36CBEB73BD504B4070B1B7DE2B21EB50
233CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:36CBEB73BD504B4070B1B7DE2B21EB50:30C81C46A35CE411E5FBC1191A0A52EF:E31A6055297D96CA3330CDF1B1860A83
234CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E31A6055297D96CA3330CDF1B1860A83:F69F2445DF4F9B17AD2B417BE66C3710:5D563F6D1CCCF236051C0C5C1C58F28F
235
236# We don't support CFB{1,8}-CAMELLIAxxx.{En,De}crypt
237# For all CFB128 encrypts and decrypts, the transformed sequence is
238# CAMELLIA-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec
239# CFB128-CAMELLIA128.Encrypt
240CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1
241CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:1
242CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:1
243CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:1
244
245# CFB128-CAMELLIA128.Decrypt
246CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0
247CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:0
248CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:0
249CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:0
250
251# CFB128-CAMELLIA192.Encrypt
252CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1
253CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:1
254CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:1
255CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:1
256
257# CFB128-CAMELLIA192.Decrypt
258CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0
259CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:0
260CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:0
261CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:0
262
263# CFB128-CAMELLIA256.Encrypt
264CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1
265CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:1
266CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:1
267CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:1
268
269# CFB128-CAMELLIA256.Decrypt
270CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0
271CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:0
272CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:0
273CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:0
274
275# For all OFB encrypts and decrypts, the transformed sequence is
276# CAMELLIA-bits-OFB:key:IV/output':plaintext:ciphertext:encdec
277# OFB-CAMELLIA128.Encrypt
278CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1
279CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:1
280CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:1
281CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:1
282
283# OFB-CAMELLIA128.Decrypt
284CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0
285CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:0
286CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:0
287CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:0
288
289# OFB-CAMELLIA192.Encrypt
290CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1
291CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:1
292CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:1
293CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:1
294
295# OFB-CAMELLIA192.Decrypt
296CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0
297CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:0
298CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:0
299CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:0
300
301# OFB-CAMELLIA256.Encrypt
302CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1
303CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:1
304CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:1
305CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:1
306
307# OFB-CAMELLIA256.Decrypt
308CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0
309CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:0
310CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:0
311CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:0
312
313# SEED test vectors from RFC4269
314SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:0
315SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:0
316SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:0
317SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:0
318SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:1
319SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:1
320SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:1
321SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:1
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
new file mode 100644
index 0000000000..6b0c0aa7a3
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss.c
@@ -0,0 +1,99 @@
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#ifndef OPENSSL_NO_DSA
65#include <openssl/dsa.h>
66#endif
67
68#ifndef OPENSSL_NO_SHA
69
70static int init(EVP_MD_CTX *ctx)
71 { return SHA1_Init(ctx->md_data); }
72
73static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
74 { return SHA1_Update(ctx->md_data,data,count); }
75
76static int final(EVP_MD_CTX *ctx,unsigned char *md)
77 { return SHA1_Final(md,ctx->md_data); }
78
79static const EVP_MD dsa_md=
80 {
81 NID_dsaWithSHA,
82 NID_dsaWithSHA,
83 SHA_DIGEST_LENGTH,
84 EVP_MD_FLAG_FIPS,
85 init,
86 update,
87 final,
88 NULL,
89 NULL,
90 EVP_PKEY_DSA_method,
91 SHA_CBLOCK,
92 sizeof(EVP_MD *)+sizeof(SHA_CTX),
93 };
94
95const EVP_MD *EVP_dss(void)
96 {
97 return(&dsa_md);
98 }
99#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..da8babc147
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_dss1.c
@@ -0,0 +1,103 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_SHA
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/x509.h>
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70
71#ifndef OPENSSL_FIPS
72
73static int init(EVP_MD_CTX *ctx)
74 { return SHA1_Init(ctx->md_data); }
75
76static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
77 { return SHA1_Update(ctx->md_data,data,count); }
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return SHA1_Final(md,ctx->md_data); }
81
82static const EVP_MD dss1_md=
83 {
84 NID_dsa,
85 NID_dsaWithSHA1,
86 SHA_DIGEST_LENGTH,
87 0,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_DSA_method,
94 SHA_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(SHA_CTX),
96 };
97
98const EVP_MD *EVP_dss1(void)
99 {
100 return(&dss1_md);
101 }
102#endif
103#endif
diff --git a/src/lib/libcrypto/evp/m_ecdsa.c b/src/lib/libcrypto/evp/m_ecdsa.c
new file mode 100644
index 0000000000..fad270faca
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_ecdsa.c
@@ -0,0 +1,148 @@
1/* crypto/evp/m_ecdsa.c */
2/* ====================================================================
3 * Copyright (c) 1998-2002 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/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved.
57 *
58 * This package is an SSL implementation written
59 * by Eric Young (eay@cryptsoft.com).
60 * The implementation was written so as to conform with Netscapes SSL.
61 *
62 * This library is free for commercial and non-commercial use as long as
63 * the following conditions are aheared to. The following conditions
64 * apply to all code found in this distribution, be it the RC4, RSA,
65 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
66 * included with this distribution is covered by the same copyright terms
67 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
68 *
69 * Copyright remains Eric Young's, and as such any Copyright notices in
70 * the code are not to be removed.
71 * If this package is used in a product, Eric Young should be given attribution
72 * as the author of the parts of the library used.
73 * This can be in the form of a textual message at program startup or
74 * in documentation (online or textual) provided with the package.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 * 1. Redistributions of source code must retain the copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * "This product includes cryptographic software written by
87 * Eric Young (eay@cryptsoft.com)"
88 * The word 'cryptographic' can be left out if the rouines from the library
89 * being used are not cryptographic related :-).
90 * 4. If you include any Windows specific code (or a derivative thereof) from
91 * the apps directory (application code) you must include an acknowledgement:
92 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
95 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 * SUCH DAMAGE.
105 *
106 * The licence and distribution terms for any publically available version or
107 * derivative of this code cannot be changed. i.e. this code cannot simply be
108 * copied and put under another distribution licence
109 * [including the GNU Public Licence.]
110 */
111
112#include <stdio.h>
113#include "cryptlib.h"
114#include <openssl/evp.h>
115#include <openssl/objects.h>
116#include <openssl/x509.h>
117
118#ifndef OPENSSL_NO_SHA
119static int init(EVP_MD_CTX *ctx)
120 { return SHA1_Init(ctx->md_data); }
121
122static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
123 { return SHA1_Update(ctx->md_data,data,count); }
124
125static int final(EVP_MD_CTX *ctx,unsigned char *md)
126 { return SHA1_Final(md,ctx->md_data); }
127
128static const EVP_MD ecdsa_md=
129 {
130 NID_ecdsa_with_SHA1,
131 NID_ecdsa_with_SHA1,
132 SHA_DIGEST_LENGTH,
133 0,
134 init,
135 update,
136 final,
137 NULL,
138 NULL,
139 EVP_PKEY_ECDSA_method,
140 SHA_CBLOCK,
141 sizeof(EVP_MD *)+sizeof(SHA_CTX),
142 };
143
144const EVP_MD *EVP_ecdsa(void)
145 {
146 return(&ecdsa_md);
147 }
148#endif
diff --git a/src/lib/libcrypto/evp/m_md2.c b/src/lib/libcrypto/evp/m_md2.c
new file mode 100644
index 0000000000..8eee6236ba
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md2.c
@@ -0,0 +1,102 @@
1/* crypto/evp/m_md2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "evp_locl.h"
62
63#ifndef OPENSSL_NO_MD2
64
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/md2.h>
69#ifndef OPENSSL_NO_RSA
70#include <openssl/rsa.h>
71#endif
72
73static int init(EVP_MD_CTX *ctx)
74 { return MD2_Init(ctx->md_data); }
75
76static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
77 { return MD2_Update(ctx->md_data,data,count); }
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return MD2_Final(md,ctx->md_data); }
81
82static const EVP_MD md2_md=
83 {
84 NID_md2,
85 NID_md2WithRSAEncryption,
86 MD2_DIGEST_LENGTH,
87 0,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_RSA_method,
94 MD2_BLOCK,
95 sizeof(EVP_MD *)+sizeof(MD2_CTX),
96 };
97
98const EVP_MD *EVP_md2(void)
99 {
100 return(&md2_md);
101 }
102#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..5cd2ab5ade
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md4.c
@@ -0,0 +1,102 @@
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#include <stdio.h>
60#include "cryptlib.h"
61#include "evp_locl.h"
62
63#ifndef OPENSSL_NO_MD4
64
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/md4.h>
69#ifndef OPENSSL_NO_RSA
70#include <openssl/rsa.h>
71#endif
72
73static int init(EVP_MD_CTX *ctx)
74 { return MD4_Init(ctx->md_data); }
75
76static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
77 { return MD4_Update(ctx->md_data,data,count); }
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return MD4_Final(md,ctx->md_data); }
81
82static const EVP_MD md4_md=
83 {
84 NID_md4,
85 NID_md4WithRSAEncryption,
86 MD4_DIGEST_LENGTH,
87 0,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_RSA_method,
94 MD4_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(MD4_CTX),
96 };
97
98const EVP_MD *EVP_md4(void)
99 {
100 return(&md4_md);
101 }
102#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..6455829671
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md5.c
@@ -0,0 +1,102 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_MD5
63
64#include <openssl/evp.h>
65#include "evp_locl.h"
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/md5.h>
69#ifndef OPENSSL_NO_RSA
70#include <openssl/rsa.h>
71#endif
72
73static int init(EVP_MD_CTX *ctx)
74 { return MD5_Init(ctx->md_data); }
75
76static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
77 { return MD5_Update(ctx->md_data,data,count); }
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return MD5_Final(md,ctx->md_data); }
81
82static const EVP_MD md5_md=
83 {
84 NID_md5,
85 NID_md5WithRSAEncryption,
86 MD5_DIGEST_LENGTH,
87 0,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_RSA_method,
94 MD5_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(MD5_CTX),
96 };
97
98const EVP_MD *EVP_md5(void)
99 {
100 return(&md5_md);
101 }
102#endif
diff --git a/src/lib/libcrypto/evp/m_mdc2.c b/src/lib/libcrypto/evp/m_mdc2.c
new file mode 100644
index 0000000000..9f9bcf06ed
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_mdc2.c
@@ -0,0 +1,100 @@
1/* crypto/evp/m_mdc2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "evp_locl.h"
62
63#ifndef OPENSSL_NO_MDC2
64
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#include <openssl/mdc2.h>
69#include <openssl/rsa.h>
70
71static int init(EVP_MD_CTX *ctx)
72 { return MDC2_Init(ctx->md_data); }
73
74static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
75 { return MDC2_Update(ctx->md_data,data,count); }
76
77static int final(EVP_MD_CTX *ctx,unsigned char *md)
78 { return MDC2_Final(md,ctx->md_data); }
79
80static const EVP_MD mdc2_md=
81 {
82 NID_mdc2,
83 NID_mdc2WithRSA,
84 MDC2_DIGEST_LENGTH,
85 0,
86 init,
87 update,
88 final,
89 NULL,
90 NULL,
91 EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
92 MDC2_BLOCK,
93 sizeof(EVP_MD *)+sizeof(MDC2_CTX),
94 };
95
96const EVP_MD *EVP_mdc2(void)
97 {
98 return(&mdc2_md);
99 }
100#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..cb0721699d
--- /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,size_t 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..a1d60ee78d
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_ripemd.c
@@ -0,0 +1,101 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RIPEMD
63
64#include <openssl/ripemd.h>
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#ifndef OPENSSL_NO_RSA
69#include <openssl/rsa.h>
70#endif
71
72static int init(EVP_MD_CTX *ctx)
73 { return RIPEMD160_Init(ctx->md_data); }
74
75static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
76 { return RIPEMD160_Update(ctx->md_data,data,count); }
77
78static int final(EVP_MD_CTX *ctx,unsigned char *md)
79 { return RIPEMD160_Final(md,ctx->md_data); }
80
81static const EVP_MD ripemd160_md=
82 {
83 NID_ripemd160,
84 NID_ripemd160WithRSA,
85 RIPEMD160_DIGEST_LENGTH,
86 0,
87 init,
88 update,
89 final,
90 NULL,
91 NULL,
92 EVP_PKEY_RSA_method,
93 RIPEMD160_CBLOCK,
94 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
95 };
96
97const EVP_MD *EVP_ripemd160(void)
98 {
99 return(&ripemd160_md);
100 }
101#endif
diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c
new file mode 100644
index 0000000000..3f30dfc579
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha.c
@@ -0,0 +1,101 @@
1/* crypto/evp/m_sha.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "evp_locl.h"
62
63#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
64
65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
68#ifndef OPENSSL_NO_RSA
69#include <openssl/rsa.h>
70#endif
71
72static int init(EVP_MD_CTX *ctx)
73 { return SHA_Init(ctx->md_data); }
74
75static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
76 { return SHA_Update(ctx->md_data,data,count); }
77
78static int final(EVP_MD_CTX *ctx,unsigned char *md)
79 { return SHA_Final(md,ctx->md_data); }
80
81static const EVP_MD sha_md=
82 {
83 NID_sha,
84 NID_shaWithRSAEncryption,
85 SHA_DIGEST_LENGTH,
86 0,
87 init,
88 update,
89 final,
90 NULL,
91 NULL,
92 EVP_PKEY_RSA_method,
93 SHA_CBLOCK,
94 sizeof(EVP_MD *)+sizeof(SHA_CTX),
95 };
96
97const EVP_MD *EVP_sha(void)
98 {
99 return(&sha_md);
100 }
101#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..471ec30be0
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -0,0 +1,209 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_SHA
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70
71#ifndef OPENSSL_FIPS
72
73static int init(EVP_MD_CTX *ctx)
74 { return SHA1_Init(ctx->md_data); }
75
76static int update(EVP_MD_CTX *ctx,const void *data,size_t count)
77 { return SHA1_Update(ctx->md_data,data,count); }
78
79static int final(EVP_MD_CTX *ctx,unsigned char *md)
80 { return SHA1_Final(md,ctx->md_data); }
81
82static const EVP_MD sha1_md=
83 {
84 NID_sha1,
85 NID_sha1WithRSAEncryption,
86 SHA_DIGEST_LENGTH,
87 0,
88 init,
89 update,
90 final,
91 NULL,
92 NULL,
93 EVP_PKEY_RSA_method,
94 SHA_CBLOCK,
95 sizeof(EVP_MD *)+sizeof(SHA_CTX),
96 };
97
98const EVP_MD *EVP_sha1(void)
99 {
100 return(&sha1_md);
101 }
102
103#ifndef OPENSSL_NO_SHA256
104static int init224(EVP_MD_CTX *ctx)
105 { return SHA224_Init(ctx->md_data); }
106static int init256(EVP_MD_CTX *ctx)
107 { return SHA256_Init(ctx->md_data); }
108/*
109 * Even though there're separate SHA224_[Update|Final], we call
110 * SHA256 functions even in SHA224 context. This is what happens
111 * there anyway, so we can spare few CPU cycles:-)
112 */
113static int update256(EVP_MD_CTX *ctx,const void *data,size_t count)
114 { return SHA256_Update(ctx->md_data,data,count); }
115static int final256(EVP_MD_CTX *ctx,unsigned char *md)
116 { return SHA256_Final(md,ctx->md_data); }
117
118static const EVP_MD sha224_md=
119 {
120 NID_sha224,
121 NID_sha224WithRSAEncryption,
122 SHA224_DIGEST_LENGTH,
123 0,
124 init224,
125 update256,
126 final256,
127 NULL,
128 NULL,
129 EVP_PKEY_RSA_method,
130 SHA256_CBLOCK,
131 sizeof(EVP_MD *)+sizeof(SHA256_CTX),
132 };
133
134const EVP_MD *EVP_sha224(void)
135 { return(&sha224_md); }
136
137static const EVP_MD sha256_md=
138 {
139 NID_sha256,
140 NID_sha256WithRSAEncryption,
141 SHA256_DIGEST_LENGTH,
142 0,
143 init256,
144 update256,
145 final256,
146 NULL,
147 NULL,
148 EVP_PKEY_RSA_method,
149 SHA256_CBLOCK,
150 sizeof(EVP_MD *)+sizeof(SHA256_CTX),
151 };
152
153const EVP_MD *EVP_sha256(void)
154 { return(&sha256_md); }
155#endif /* ifndef OPENSSL_NO_SHA256 */
156
157#ifndef OPENSSL_NO_SHA512
158static int init384(EVP_MD_CTX *ctx)
159 { return SHA384_Init(ctx->md_data); }
160static int init512(EVP_MD_CTX *ctx)
161 { return SHA512_Init(ctx->md_data); }
162/* See comment in SHA224/256 section */
163static int update512(EVP_MD_CTX *ctx,const void *data,size_t count)
164 { return SHA512_Update(ctx->md_data,data,count); }
165static int final512(EVP_MD_CTX *ctx,unsigned char *md)
166 { return SHA512_Final(md,ctx->md_data); }
167
168static const EVP_MD sha384_md=
169 {
170 NID_sha384,
171 NID_sha384WithRSAEncryption,
172 SHA384_DIGEST_LENGTH,
173 0,
174 init384,
175 update512,
176 final512,
177 NULL,
178 NULL,
179 EVP_PKEY_RSA_method,
180 SHA512_CBLOCK,
181 sizeof(EVP_MD *)+sizeof(SHA512_CTX),
182 };
183
184const EVP_MD *EVP_sha384(void)
185 { return(&sha384_md); }
186
187static const EVP_MD sha512_md=
188 {
189 NID_sha512,
190 NID_sha512WithRSAEncryption,
191 SHA512_DIGEST_LENGTH,
192 0,
193 init512,
194 update512,
195 final512,
196 NULL,
197 NULL,
198 EVP_PKEY_RSA_method,
199 SHA512_CBLOCK,
200 sizeof(EVP_MD *)+sizeof(SHA512_CTX),
201 };
202
203const EVP_MD *EVP_sha512(void)
204 { return(&sha512_md); }
205#endif /* ifndef OPENSSL_NO_SHA512 */
206
207#endif
208
209#endif
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
new file mode 100644
index 0000000000..e2e04c3570
--- /dev/null
+++ b/src/lib/libcrypto/evp/names.c
@@ -0,0 +1,130 @@
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#ifdef OPENSSL_FIPS
70 OPENSSL_init();
71#endif
72
73 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
74 if (r == 0) return(0);
75 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c);
76 return(r);
77 }
78
79int EVP_add_digest(const EVP_MD *md)
80 {
81 int r;
82 const char *name;
83
84#ifdef OPENSSL_FIPS
85 OPENSSL_init();
86#endif
87 name=OBJ_nid2sn(md->type);
88 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(const char *)md);
89 if (r == 0) return(0);
90 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(const char *)md);
91 if (r == 0) return(0);
92
93 if (md->type != md->pkey_type)
94 {
95 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
96 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
97 if (r == 0) return(0);
98 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
99 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
100 }
101 return(r);
102 }
103
104const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
105 {
106 const EVP_CIPHER *cp;
107
108 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
109 return(cp);
110 }
111
112const EVP_MD *EVP_get_digestbyname(const char *name)
113 {
114 const EVP_MD *cp;
115
116 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
117 return(cp);
118 }
119
120void EVP_cleanup(void)
121 {
122 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
123 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
124 /* The above calls will only clean out the contents of the name
125 hash table, but not the hash table itself. The following line
126 does that part. -- Richard Levitte */
127 OBJ_NAME_cleanup(-1);
128
129 EVP_PBE_cleanup();
130 }
diff --git a/src/lib/libcrypto/evp/openbsd_hw.c b/src/lib/libcrypto/evp/openbsd_hw.c
new file mode 100644
index 0000000000..3831a5731e
--- /dev/null
+++ b/src/lib/libcrypto/evp/openbsd_hw.c
@@ -0,0 +1,446 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 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#include <openssl/evp.h>
51#include <openssl/objects.h>
52#include <openssl/rsa.h>
53#include "evp_locl.h"
54
55/* This stuff should now all be supported through
56 * crypto/engine/hw_openbsd_dev_crypto.c unless I botched it up */
57static void *dummy=&dummy;
58
59#if 0
60
61/* check flag after OpenSSL headers to ensure make depend works */
62#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
63
64#include <fcntl.h>
65#include <stdio.h>
66#include <errno.h>
67#include <sys/ioctl.h>
68#include <crypto/cryptodev.h>
69#include <unistd.h>
70#include <assert.h>
71
72/* longest key supported in hardware */
73#define MAX_HW_KEY 24
74#define MAX_HW_IV 8
75
76#define MD5_DIGEST_LENGTH 16
77#define MD5_CBLOCK 64
78
79static int fd;
80static int dev_failed;
81
82typedef struct session_op session_op;
83
84#define CDATA(ctx) EVP_C_DATA(session_op,ctx)
85
86static void err(const char *str)
87 {
88 fprintf(stderr,"%s: errno %d\n",str,errno);
89 }
90
91static int dev_crypto_init(session_op *ses)
92 {
93 if(dev_failed)
94 return 0;
95 if(!fd)
96 {
97 int cryptodev_fd;
98
99 if ((cryptodev_fd=open("/dev/crypto",O_RDWR,0)) < 0)
100 {
101 err("/dev/crypto");
102 dev_failed=1;
103 return 0;
104 }
105 if (ioctl(cryptodev_fd,CRIOGET,&fd) == -1)
106 {
107 err("CRIOGET failed");
108 close(cryptodev_fd);
109 dev_failed=1;
110 return 0;
111 }
112 close(cryptodev_fd);
113 }
114 assert(ses);
115 memset(ses,'\0',sizeof *ses);
116
117 return 1;
118 }
119
120static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
121 {
122 if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
123 err("CIOCFSESSION failed");
124
125 OPENSSL_free(CDATA(ctx)->key);
126
127 return 1;
128 }
129
130static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
131 const unsigned char *key,int klen)
132 {
133 if(!dev_crypto_init(CDATA(ctx)))
134 return 0;
135
136 CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
137
138 assert(ctx->cipher->iv_len <= MAX_HW_IV);
139
140 memcpy(CDATA(ctx)->key,key,klen);
141
142 CDATA(ctx)->cipher=cipher;
143 CDATA(ctx)->keylen=klen;
144
145 if (ioctl(fd,CIOCGSESSION,CDATA(ctx)) == -1)
146 {
147 err("CIOCGSESSION failed");
148 return 0;
149 }
150 return 1;
151 }
152
153static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
154 const unsigned char *in,unsigned int inl)
155 {
156 struct crypt_op cryp;
157 unsigned char lb[MAX_HW_IV];
158
159 if(!inl)
160 return 1;
161
162 assert(CDATA(ctx));
163 assert(!dev_failed);
164
165 memset(&cryp,'\0',sizeof cryp);
166 cryp.ses=CDATA(ctx)->ses;
167 cryp.op=ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
168 cryp.flags=0;
169 cryp.len=inl;
170 assert((inl&(ctx->cipher->block_size-1)) == 0);
171 cryp.src=(caddr_t)in;
172 cryp.dst=(caddr_t)out;
173 cryp.mac=0;
174 if(ctx->cipher->iv_len)
175 cryp.iv=(caddr_t)ctx->iv;
176
177 if(!ctx->encrypt)
178 memcpy(lb,&in[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
179
180 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
181 {
182 if(errno == EINVAL) /* buffers are misaligned */
183 {
184 unsigned int cinl=0;
185 char *cin=NULL;
186 char *cout=NULL;
187
188 /* NB: this can only make cinl != inl with stream ciphers */
189 cinl=(inl+3)/4*4;
190
191 if(((unsigned long)in&3) || cinl != inl)
192 {
193 cin=OPENSSL_malloc(cinl);
194 memcpy(cin,in,inl);
195 cryp.src=cin;
196 }
197
198 if(((unsigned long)out&3) || cinl != inl)
199 {
200 cout=OPENSSL_malloc(cinl);
201 cryp.dst=cout;
202 }
203
204 cryp.len=cinl;
205
206 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
207 {
208 err("CIOCCRYPT(2) failed");
209 printf("src=%p dst=%p\n",cryp.src,cryp.dst);
210 abort();
211 return 0;
212 }
213
214 if(cout)
215 {
216 memcpy(out,cout,inl);
217 OPENSSL_free(cout);
218 }
219 if(cin)
220 OPENSSL_free(cin);
221 }
222 else
223 {
224 err("CIOCCRYPT failed");
225 abort();
226 return 0;
227 }
228 }
229
230 if(ctx->encrypt)
231 memcpy(ctx->iv,&out[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
232 else
233 memcpy(ctx->iv,lb,ctx->cipher->iv_len);
234
235 return 1;
236 }
237
238static int dev_crypto_des_ede3_init_key(EVP_CIPHER_CTX *ctx,
239 const unsigned char *key,
240 const unsigned char *iv, int enc)
241 { return dev_crypto_init_key(ctx,CRYPTO_3DES_CBC,key,24); }
242
243#define dev_crypto_des_ede3_cbc_cipher dev_crypto_cipher
244
245BLOCK_CIPHER_def_cbc(dev_crypto_des_ede3, session_op, NID_des_ede3, 8, 24, 8,
246 0, dev_crypto_des_ede3_init_key,
247 dev_crypto_cleanup,
248 EVP_CIPHER_set_asn1_iv,
249 EVP_CIPHER_get_asn1_iv,
250 NULL)
251
252static int dev_crypto_rc4_init_key(EVP_CIPHER_CTX *ctx,
253 const unsigned char *key,
254 const unsigned char *iv, int enc)
255 { return dev_crypto_init_key(ctx,CRYPTO_ARC4,key,16); }
256
257static const EVP_CIPHER r4_cipher=
258 {
259 NID_rc4,
260 1,16,0, /* FIXME: key should be up to 256 bytes */
261 EVP_CIPH_VARIABLE_LENGTH,
262 dev_crypto_rc4_init_key,
263 dev_crypto_cipher,
264 dev_crypto_cleanup,
265 sizeof(session_op),
266 NULL,
267 NULL,
268 NULL
269 };
270
271const EVP_CIPHER *EVP_dev_crypto_rc4(void)
272 { return &r4_cipher; }
273
274typedef struct
275 {
276 session_op sess;
277 char *data;
278 int len;
279 unsigned char md[EVP_MAX_MD_SIZE];
280 } MD_DATA;
281
282static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
283 {
284 if(!dev_crypto_init(&md_data->sess))
285 return 0;
286
287 md_data->len=0;
288 md_data->data=NULL;
289
290 md_data->sess.mac=mac;
291
292 if (ioctl(fd,CIOCGSESSION,&md_data->sess) == -1)
293 {
294 err("CIOCGSESSION failed");
295 return 0;
296 }
297 return 1;
298 }
299
300static int dev_crypto_cleanup_digest(MD_DATA *md_data)
301 {
302 if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
303 {
304 err("CIOCFSESSION failed");
305 return 0;
306 }
307
308 return 1;
309 }
310
311/* FIXME: if device can do chained MACs, then don't accumulate */
312/* FIXME: move accumulation to the framework */
313static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
314 { return dev_crypto_init_digest(ctx->md_data,CRYPTO_MD5); }
315
316static int do_digest(int ses,unsigned char *md,const void *data,int len)
317 {
318 struct crypt_op cryp;
319 static unsigned char md5zero[16]=
320 {
321 0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,
322 0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e
323 };
324
325 /* some cards can't do zero length */
326 if(!len)
327 {
328 memcpy(md,md5zero,16);
329 return 1;
330 }
331
332 memset(&cryp,'\0',sizeof cryp);
333 cryp.ses=ses;
334 cryp.op=COP_ENCRYPT;/* required to do the MAC rather than check it */
335 cryp.len=len;
336 cryp.src=(caddr_t)data;
337 cryp.dst=(caddr_t)data; // FIXME!!!
338 cryp.mac=(caddr_t)md;
339
340 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
341 {
342 if(errno == EINVAL) /* buffer is misaligned */
343 {
344 char *dcopy;
345
346 dcopy=OPENSSL_malloc(len);
347 memcpy(dcopy,data,len);
348 cryp.src=dcopy;
349 cryp.dst=cryp.src; // FIXME!!!
350
351 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
352 {
353 err("CIOCCRYPT(MAC2) failed");
354 abort();
355 return 0;
356 }
357 OPENSSL_free(dcopy);
358 }
359 else
360 {
361 err("CIOCCRYPT(MAC) failed");
362 abort();
363 return 0;
364 }
365 }
366 // printf("done\n");
367
368 return 1;
369 }
370
371static int dev_crypto_md5_update(EVP_MD_CTX *ctx,const void *data,
372 unsigned long len)
373 {
374 MD_DATA *md_data=ctx->md_data;
375
376 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
377 return do_digest(md_data->sess.ses,md_data->md,data,len);
378
379 md_data->data=OPENSSL_realloc(md_data->data,md_data->len+len);
380 memcpy(md_data->data+md_data->len,data,len);
381 md_data->len+=len;
382
383 return 1;
384 }
385
386static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md)
387 {
388 int ret;
389 MD_DATA *md_data=ctx->md_data;
390
391 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
392 {
393 memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
394 ret=1;
395 }
396 else
397 {
398 ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
399 OPENSSL_free(md_data->data);
400 md_data->data=NULL;
401 md_data->len=0;
402 }
403
404 return ret;
405 }
406
407static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
408 {
409 const MD_DATA *from_md=from->md_data;
410 MD_DATA *to_md=to->md_data;
411
412 // How do we copy sessions?
413 assert(from->digest->flags&EVP_MD_FLAG_ONESHOT);
414
415 to_md->data=OPENSSL_malloc(from_md->len);
416 memcpy(to_md->data,from_md->data,from_md->len);
417
418 return 1;
419 }
420
421static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
422 {
423 return dev_crypto_cleanup_digest(ctx->md_data);
424 }
425
426static const EVP_MD md5_md=
427 {
428 NID_md5,
429 NID_md5WithRSAEncryption,
430 MD5_DIGEST_LENGTH,
431 EVP_MD_FLAG_ONESHOT, // XXX: set according to device info...
432 dev_crypto_md5_init,
433 dev_crypto_md5_update,
434 dev_crypto_md5_final,
435 dev_crypto_md5_copy,
436 dev_crypto_md5_cleanup,
437 EVP_PKEY_RSA_method,
438 MD5_CBLOCK,
439 sizeof(MD_DATA),
440 };
441
442const EVP_MD *EVP_dev_crypto_md5(void)
443 { return &md5_md; }
444
445#endif
446#endif
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
new file mode 100644
index 0000000000..2a265fdee2
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -0,0 +1,159 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) 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/evp.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;
114 const unsigned char *pbuf;
115
116 /* Extract useful info from parameter */
117 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
118 param->value.sequence == NULL) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 pbuf = param->value.sequence->data;
124 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) {
125 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
126 return 0;
127 }
128
129 if (!pbe->iter) iter = 1;
130 else iter = ASN1_INTEGER_get (pbe->iter);
131 salt = pbe->salt->data;
132 saltlen = pbe->salt->length;
133
134 if(!pass) passlen = 0;
135 else if(passlen == -1) passlen = strlen(pass);
136
137 EVP_MD_CTX_init(&ctx);
138 EVP_DigestInit_ex(&ctx, md, NULL);
139 EVP_DigestUpdate(&ctx, pass, passlen);
140 EVP_DigestUpdate(&ctx, salt, saltlen);
141 PBEPARAM_free(pbe);
142 EVP_DigestFinal_ex(&ctx, md_tmp, NULL);
143 for (i = 1; i < iter; i++) {
144 EVP_DigestInit_ex(&ctx, md, NULL);
145 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
146 EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
147 }
148 EVP_MD_CTX_cleanup(&ctx);
149 OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= (int)sizeof(md_tmp));
150 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
151 OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16);
152 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
153 EVP_CIPHER_iv_length(cipher));
154 EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de);
155 OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE);
156 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
157 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH);
158 return 1;
159}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
new file mode 100644
index 0000000000..6bec77baf9
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -0,0 +1,263 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) 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#include <stdio.h>
59#include <stdlib.h>
60#include "cryptlib.h"
61#if !defined(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
62#include <openssl/x509.h>
63#include <openssl/evp.h>
64#include <openssl/hmac.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 const 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 *salt, key[EVP_MAX_KEY_LENGTH];
152 const unsigned char *pbuf;
153 int saltlen, iter, plen;
154 unsigned int keylen;
155 PBE2PARAM *pbe2 = NULL;
156 const EVP_CIPHER *cipher;
157 PBKDF2PARAM *kdf = NULL;
158
159 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
160 param->value.sequence == NULL) {
161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
162 return 0;
163 }
164
165 pbuf = param->value.sequence->data;
166 plen = param->value.sequence->length;
167 if(!(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
168 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
169 return 0;
170 }
171
172 /* See if we recognise the key derivation function */
173
174 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
175 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
176 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
177 goto err;
178 }
179
180 /* lets see if we recognise the encryption algorithm.
181 */
182
183 cipher = EVP_get_cipherbyname(
184 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
185
186 if(!cipher) {
187 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
188 EVP_R_UNSUPPORTED_CIPHER);
189 goto err;
190 }
191
192 /* Fixup cipher based on AlgorithmIdentifier */
193 EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de);
194 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
195 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
196 EVP_R_CIPHER_PARAMETER_ERROR);
197 goto err;
198 }
199 keylen = EVP_CIPHER_CTX_key_length(ctx);
200 OPENSSL_assert(keylen <= sizeof key);
201
202 /* Now decode key derivation function */
203
204 if(!pbe2->keyfunc->parameter ||
205 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE))
206 {
207 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
208 goto err;
209 }
210
211 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
212 plen = pbe2->keyfunc->parameter->value.sequence->length;
213 if(!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
214 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
215 goto err;
216 }
217
218 PBE2PARAM_free(pbe2);
219 pbe2 = NULL;
220
221 /* Now check the parameters of the kdf */
222
223 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)){
224 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
225 EVP_R_UNSUPPORTED_KEYLENGTH);
226 goto err;
227 }
228
229 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
230 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
231 goto err;
232 }
233
234 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
235 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
236 EVP_R_UNSUPPORTED_SALT_TYPE);
237 goto err;
238 }
239
240 /* it seems that its all OK */
241 salt = kdf->salt->value.octet_string->data;
242 saltlen = kdf->salt->value.octet_string->length;
243 iter = ASN1_INTEGER_get(kdf->iter);
244 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
245 EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
246 OPENSSL_cleanse(key, keylen);
247 PBKDF2PARAM_free(kdf);
248 return 1;
249
250 err:
251 PBE2PARAM_free(pbe2);
252 PBKDF2PARAM_free(kdf);
253 return 0;
254}
255
256#ifdef DEBUG_PKCS5V2
257static void h__dump (const unsigned char *p, int len)
258{
259 for (; len --; p++) fprintf(stderr, "%02X ", *p);
260 fprintf(stderr, "\n");
261}
262#endif
263#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..f64901f653
--- /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, const 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..c2dfdc52ad
--- /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, const 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..22155ecf62
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -0,0 +1,502 @@
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/bn.h>
62#include <openssl/err.h>
63#include <openssl/objects.h>
64#include <openssl/evp.h>
65#include <openssl/asn1_mac.h>
66#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DSA
71#include <openssl/dsa.h>
72#endif
73#ifndef OPENSSL_NO_DH
74#include <openssl/dh.h>
75#endif
76
77static void EVP_PKEY_free_it(EVP_PKEY *x);
78
79int EVP_PKEY_bits(EVP_PKEY *pkey)
80 {
81 if (0)
82 return 0;
83#ifndef OPENSSL_NO_RSA
84 else if (pkey->type == EVP_PKEY_RSA)
85 return(BN_num_bits(pkey->pkey.rsa->n));
86#endif
87#ifndef OPENSSL_NO_DSA
88 else if (pkey->type == EVP_PKEY_DSA)
89 return(BN_num_bits(pkey->pkey.dsa->p));
90#endif
91#ifndef OPENSSL_NO_EC
92 else if (pkey->type == EVP_PKEY_EC)
93 {
94 BIGNUM *order = BN_new();
95 const EC_GROUP *group;
96 int ret;
97
98 if (!order)
99 {
100 ERR_clear_error();
101 return 0;
102 }
103 group = EC_KEY_get0_group(pkey->pkey.ec);
104 if (!EC_GROUP_get_order(group, order, NULL))
105 {
106 ERR_clear_error();
107 return 0;
108 }
109
110 ret = BN_num_bits(order);
111 BN_free(order);
112 return ret;
113 }
114#endif
115 return(0);
116 }
117
118int EVP_PKEY_size(EVP_PKEY *pkey)
119 {
120 if (pkey == NULL)
121 return(0);
122#ifndef OPENSSL_NO_RSA
123 if (pkey->type == EVP_PKEY_RSA)
124 return(RSA_size(pkey->pkey.rsa));
125 else
126#endif
127#ifndef OPENSSL_NO_DSA
128 if (pkey->type == EVP_PKEY_DSA)
129 return(DSA_size(pkey->pkey.dsa));
130#endif
131#ifndef OPENSSL_NO_ECDSA
132 if (pkey->type == EVP_PKEY_EC)
133 return(ECDSA_size(pkey->pkey.ec));
134#endif
135
136 return(0);
137 }
138
139int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
140 {
141#ifndef OPENSSL_NO_DSA
142 if (pkey->type == EVP_PKEY_DSA)
143 {
144 int ret=pkey->save_parameters;
145
146 if (mode >= 0)
147 pkey->save_parameters=mode;
148 return(ret);
149 }
150#endif
151#ifndef OPENSSL_NO_EC
152 if (pkey->type == EVP_PKEY_EC)
153 {
154 int ret = pkey->save_parameters;
155
156 if (mode >= 0)
157 pkey->save_parameters = mode;
158 return(ret);
159 }
160#endif
161 return(0);
162 }
163
164int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
165 {
166 if (to->type != from->type)
167 {
168 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);
169 goto err;
170 }
171
172 if (EVP_PKEY_missing_parameters(from))
173 {
174 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);
175 goto err;
176 }
177#ifndef OPENSSL_NO_DSA
178 if (to->type == EVP_PKEY_DSA)
179 {
180 BIGNUM *a;
181
182 if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;
183 if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);
184 to->pkey.dsa->p=a;
185
186 if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;
187 if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);
188 to->pkey.dsa->q=a;
189
190 if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;
191 if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);
192 to->pkey.dsa->g=a;
193 }
194#endif
195#ifndef OPENSSL_NO_EC
196 if (to->type == EVP_PKEY_EC)
197 {
198 EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
199 if (group == NULL)
200 goto err;
201 if (EC_KEY_set_group(to->pkey.ec, group) == 0)
202 goto err;
203 EC_GROUP_free(group);
204 }
205#endif
206 return(1);
207err:
208 return(0);
209 }
210
211int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
212 {
213#ifndef OPENSSL_NO_DSA
214 if (pkey->type == EVP_PKEY_DSA)
215 {
216 DSA *dsa;
217
218 dsa=pkey->pkey.dsa;
219 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
220 return(1);
221 }
222#endif
223#ifndef OPENSSL_NO_EC
224 if (pkey->type == EVP_PKEY_EC)
225 {
226 if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
227 return(1);
228 }
229#endif
230
231 return(0);
232 }
233
234int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
235 {
236#ifndef OPENSSL_NO_DSA
237 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
238 {
239 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
240 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
241 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
242 return(0);
243 else
244 return(1);
245 }
246#endif
247#ifndef OPENSSL_NO_EC
248 if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC)
249 {
250 const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
251 *group_b = EC_KEY_get0_group(b->pkey.ec);
252 if (EC_GROUP_cmp(group_a, group_b, NULL))
253 return 0;
254 else
255 return 1;
256 }
257#endif
258 return(-1);
259 }
260
261int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
262 {
263 if (a->type != b->type)
264 return -1;
265
266 if (EVP_PKEY_cmp_parameters(a, b) == 0)
267 return 0;
268
269 switch (a->type)
270 {
271#ifndef OPENSSL_NO_RSA
272 case EVP_PKEY_RSA:
273 if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0
274 || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0)
275 return 0;
276 break;
277#endif
278#ifndef OPENSSL_NO_DSA
279 case EVP_PKEY_DSA:
280 if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
281 return 0;
282 break;
283#endif
284#ifndef OPENSSL_NO_EC
285 case EVP_PKEY_EC:
286 {
287 int r;
288 const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);
289 const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec),
290 *pb = EC_KEY_get0_public_key(b->pkey.ec);
291 r = EC_POINT_cmp(group, pa, pb, NULL);
292 if (r != 0)
293 {
294 if (r == 1)
295 return 0;
296 else
297 return -2;
298 }
299 }
300 break;
301#endif
302#ifndef OPENSSL_NO_DH
303 case EVP_PKEY_DH:
304 return -2;
305#endif
306 default:
307 return -2;
308 }
309
310 return 1;
311 }
312
313EVP_PKEY *EVP_PKEY_new(void)
314 {
315 EVP_PKEY *ret;
316
317 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));
318 if (ret == NULL)
319 {
320 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
321 return(NULL);
322 }
323 ret->type=EVP_PKEY_NONE;
324 ret->references=1;
325 ret->pkey.ptr=NULL;
326 ret->attributes=NULL;
327 ret->save_parameters=1;
328 return(ret);
329 }
330
331int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
332 {
333 if (pkey == NULL) return(0);
334 if (pkey->pkey.ptr != NULL)
335 EVP_PKEY_free_it(pkey);
336 pkey->type=EVP_PKEY_type(type);
337 pkey->save_type=type;
338 pkey->pkey.ptr=key;
339 return(key != NULL);
340 }
341
342#ifndef OPENSSL_NO_RSA
343int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
344{
345 int ret = EVP_PKEY_assign_RSA(pkey, key);
346 if(ret)
347 RSA_up_ref(key);
348 return ret;
349}
350
351RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
352 {
353 if(pkey->type != EVP_PKEY_RSA) {
354 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
355 return NULL;
356 }
357 RSA_up_ref(pkey->pkey.rsa);
358 return pkey->pkey.rsa;
359}
360#endif
361
362#ifndef OPENSSL_NO_DSA
363int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
364{
365 int ret = EVP_PKEY_assign_DSA(pkey, key);
366 if(ret)
367 DSA_up_ref(key);
368 return ret;
369}
370
371DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
372 {
373 if(pkey->type != EVP_PKEY_DSA) {
374 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY);
375 return NULL;
376 }
377 DSA_up_ref(pkey->pkey.dsa);
378 return pkey->pkey.dsa;
379}
380#endif
381
382#ifndef OPENSSL_NO_EC
383
384int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
385{
386 int ret = EVP_PKEY_assign_EC_KEY(pkey,key);
387 if (ret)
388 EC_KEY_up_ref(key);
389 return ret;
390}
391
392EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
393{
394 if (pkey->type != EVP_PKEY_EC)
395 {
396 EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
397 return NULL;
398 }
399 EC_KEY_up_ref(pkey->pkey.ec);
400 return pkey->pkey.ec;
401}
402#endif
403
404
405#ifndef OPENSSL_NO_DH
406
407int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
408{
409 int ret = EVP_PKEY_assign_DH(pkey, key);
410 if(ret)
411 DH_up_ref(key);
412 return ret;
413}
414
415DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
416 {
417 if(pkey->type != EVP_PKEY_DH) {
418 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY);
419 return NULL;
420 }
421 DH_up_ref(pkey->pkey.dh);
422 return pkey->pkey.dh;
423}
424#endif
425
426int EVP_PKEY_type(int type)
427 {
428 switch (type)
429 {
430 case EVP_PKEY_RSA:
431 case EVP_PKEY_RSA2:
432 return(EVP_PKEY_RSA);
433 case EVP_PKEY_DSA:
434 case EVP_PKEY_DSA1:
435 case EVP_PKEY_DSA2:
436 case EVP_PKEY_DSA3:
437 case EVP_PKEY_DSA4:
438 return(EVP_PKEY_DSA);
439 case EVP_PKEY_DH:
440 return(EVP_PKEY_DH);
441 case EVP_PKEY_EC:
442 return(EVP_PKEY_EC);
443 default:
444 return(NID_undef);
445 }
446 }
447
448void EVP_PKEY_free(EVP_PKEY *x)
449 {
450 int i;
451
452 if (x == NULL) return;
453
454 i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY);
455#ifdef REF_PRINT
456 REF_PRINT("EVP_PKEY",x);
457#endif
458 if (i > 0) return;
459#ifdef REF_CHECK
460 if (i < 0)
461 {
462 fprintf(stderr,"EVP_PKEY_free, bad reference count\n");
463 abort();
464 }
465#endif
466 EVP_PKEY_free_it(x);
467 if (x->attributes)
468 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
469 OPENSSL_free(x);
470 }
471
472static void EVP_PKEY_free_it(EVP_PKEY *x)
473 {
474 switch (x->type)
475 {
476#ifndef OPENSSL_NO_RSA
477 case EVP_PKEY_RSA:
478 case EVP_PKEY_RSA2:
479 RSA_free(x->pkey.rsa);
480 break;
481#endif
482#ifndef OPENSSL_NO_DSA
483 case EVP_PKEY_DSA:
484 case EVP_PKEY_DSA2:
485 case EVP_PKEY_DSA3:
486 case EVP_PKEY_DSA4:
487 DSA_free(x->pkey.dsa);
488 break;
489#endif
490#ifndef OPENSSL_NO_EC
491 case EVP_PKEY_EC:
492 EC_KEY_free(x->pkey.ec);
493 break;
494#endif
495#ifndef OPENSSL_NO_DH
496 case EVP_PKEY_DH:
497 DH_free(x->pkey.dh);
498 break;
499#endif
500 }
501 }
502
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
new file mode 100644
index 0000000000..9935206d0f
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -0,0 +1,127 @@
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#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RSA
63
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/x509.h>
67#include <openssl/rsa.h>
68
69int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
70 const unsigned char *ek, int ekl, const unsigned char *iv,
71 EVP_PKEY *priv)
72 {
73 unsigned char *key=NULL;
74 int i,size=0,ret=0;
75
76 if(type) {
77 EVP_CIPHER_CTX_init(ctx);
78 if(!EVP_DecryptInit_ex(ctx,type,NULL, NULL,NULL)) return 0;
79 }
80
81 if(!priv) return 1;
82
83 if (priv->type != EVP_PKEY_RSA)
84 {
85 EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA);
86 goto err;
87 }
88
89 size=RSA_size(priv->pkey.rsa);
90 key=(unsigned char *)OPENSSL_malloc(size+2);
91 if (key == NULL)
92 {
93 /* ERROR */
94 EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE);
95 goto err;
96 }
97
98 i=EVP_PKEY_decrypt(key,ek,ekl,priv);
99 if ((i <= 0) || !EVP_CIPHER_CTX_set_key_length(ctx, i))
100 {
101 /* ERROR */
102 goto err;
103 }
104 if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv)) goto err;
105
106 ret=1;
107err:
108 if (key != NULL) OPENSSL_cleanse(key,size);
109 OPENSSL_free(key);
110 return(ret);
111 }
112
113int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
114 {
115 int i;
116
117 i=EVP_DecryptFinal_ex(ctx,out,outl);
118 EVP_DecryptInit_ex(ctx,NULL,NULL,NULL,NULL);
119 return(i);
120 }
121#else /* !OPENSSL_NO_RSA */
122
123# ifdef PEDANTIC
124static void *dummy=&dummy;
125# endif
126
127#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..8cc8fcb0bd
--- /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 (EVP_CIPHER_CTX_rand_key(ctx, key) <= 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..bf41a0db68
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_sign.c
@@ -0,0 +1,126 @@
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 for (i=0; i<4; i++)
88 {
89 v=ctx->digest->required_pkey_type[i];
90 if (v == 0) break;
91 if (pkey->type == v)
92 {
93 ok=1;
94 break;
95 }
96 }
97 if (!ok)
98 {
99 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
100 return(0);
101 }
102 if (ctx->digest->sign == NULL)
103 {
104 EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
105 return(0);
106 }
107 EVP_MD_CTX_init(&tmp_ctx);
108 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
109 if (ctx->digest->flags & EVP_MD_FLAG_SVCTX)
110 {
111 EVP_MD_SVCTX sctmp;
112 sctmp.mctx = &tmp_ctx;
113 sctmp.key = pkey->pkey.ptr;
114 i = ctx->digest->sign(ctx->digest->type,
115 NULL, -1, sigret, siglen, &sctmp);
116 }
117 else
118 {
119 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
120 i = ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen,
121 pkey->pkey.ptr);
122 }
123 EVP_MD_CTX_cleanup(&tmp_ctx);
124 return i;
125 }
126
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
new file mode 100644
index 0000000000..2d46dffe7e
--- /dev/null
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -0,0 +1,113 @@
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, const 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 if (ctx->digest->verify == NULL)
89 {
90 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
91 return(0);
92 }
93
94 EVP_MD_CTX_init(&tmp_ctx);
95 EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);
96 if (ctx->digest->flags & EVP_MD_FLAG_SVCTX)
97 {
98 EVP_MD_SVCTX sctmp;
99 sctmp.mctx = &tmp_ctx;
100 sctmp.key = pkey->pkey.ptr;
101 i = ctx->digest->verify(ctx->digest->type,
102 NULL, -1, sigbuf, siglen, &sctmp);
103 }
104 else
105 {
106 EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
107 i = ctx->digest->verify(ctx->digest->type,m,m_len,
108 sigbuf,siglen,pkey->pkey.ptr);
109 }
110 EVP_MD_CTX_cleanup(&tmp_ctx);
111 return i;
112 }
113