diff options
Diffstat (limited to 'src/lib/libcrypto/engine')
39 files changed, 13768 insertions, 83 deletions
diff --git a/src/lib/libcrypto/engine/Makefile b/src/lib/libcrypto/engine/Makefile new file mode 100644 index 0000000000..38f83f1654 --- /dev/null +++ b/src/lib/libcrypto/engine/Makefile | |||
@@ -0,0 +1,536 @@ | |||
1 | # | ||
2 | # OpenSSL/crypto/engine/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= engine | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
12 | INSTALLTOP=/usr/local/ssl | ||
13 | MAKEDEPPROG= makedepend | ||
14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
15 | MAKEFILE= Makefile | ||
16 | AR= ar r | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile | ||
21 | TEST= enginetest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \ | ||
26 | eng_table.c eng_pkey.c eng_fat.c eng_all.c \ | ||
27 | tb_rsa.c tb_dsa.c tb_dh.c tb_rand.c tb_cipher.c tb_digest.c \ | ||
28 | eng_openssl.c eng_dyn.c eng_cnf.c \ | ||
29 | hw_atalla.c hw_cswift.c hw_ncipher.c hw_nuron.c hw_ubsec.c \ | ||
30 | hw_cryptodev.c hw_aep.c hw_sureware.c hw_4758_cca.c | ||
31 | LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \ | ||
32 | eng_table.o eng_pkey.o eng_fat.o eng_all.o \ | ||
33 | tb_rsa.o tb_dsa.o tb_dh.o tb_rand.o tb_cipher.o tb_digest.o \ | ||
34 | eng_openssl.o eng_dyn.o eng_cnf.o \ | ||
35 | hw_atalla.o hw_cswift.o hw_ncipher.o hw_nuron.o hw_ubsec.o \ | ||
36 | hw_cryptodev.o hw_aep.o hw_sureware.o hw_4758_cca.o | ||
37 | |||
38 | SRC= $(LIBSRC) | ||
39 | |||
40 | EXHEADER= engine.h | ||
41 | HEADER= $(EXHEADER) | ||
42 | |||
43 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
44 | |||
45 | top: | ||
46 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
47 | |||
48 | all: lib | ||
49 | |||
50 | lib: $(LIBOBJ) | ||
51 | $(AR) $(LIB) $(LIBOBJ) | ||
52 | $(RANLIB) $(LIB) || echo Never mind. | ||
53 | @touch lib | ||
54 | |||
55 | files: | ||
56 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
57 | |||
58 | links: | ||
59 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
60 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
61 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
62 | |||
63 | install: | ||
64 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
65 | do \ | ||
66 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
67 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
68 | done; | ||
69 | |||
70 | tags: | ||
71 | ctags $(SRC) | ||
72 | |||
73 | errors: | ||
74 | $(PERL) $(TOP)/util/mkerr.pl -conf hw.ec \ | ||
75 | -nostatic -staticloader -write hw_*.c | ||
76 | |||
77 | tests: | ||
78 | |||
79 | lint: | ||
80 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
81 | |||
82 | depend: | ||
83 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
84 | |||
85 | dclean: | ||
86 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
87 | mv -f Makefile.new $(MAKEFILE) | ||
88 | |||
89 | clean: | ||
90 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
91 | |||
92 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
93 | |||
94 | eng_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
95 | eng_all.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
96 | eng_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
97 | eng_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
98 | eng_all.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
99 | eng_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
100 | eng_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
101 | eng_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
102 | eng_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
103 | eng_all.o: ../../include/openssl/ui.h eng_all.c eng_int.h | ||
104 | eng_cnf.o: ../../e_os.h ../../include/openssl/asn1.h | ||
105 | eng_cnf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
106 | eng_cnf.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
107 | eng_cnf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
108 | eng_cnf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
109 | eng_cnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
110 | eng_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
111 | eng_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
112 | eng_cnf.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
113 | eng_cnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
114 | eng_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
115 | eng_cnf.o: ../cryptlib.h eng_cnf.c | ||
116 | eng_ctrl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
117 | eng_ctrl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
118 | eng_ctrl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
119 | eng_ctrl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
120 | eng_ctrl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
121 | eng_ctrl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
122 | eng_ctrl.o: ../../include/openssl/opensslconf.h | ||
123 | eng_ctrl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
124 | eng_ctrl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
125 | eng_ctrl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
126 | eng_ctrl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
127 | eng_ctrl.o: ../cryptlib.h eng_ctrl.c eng_int.h | ||
128 | eng_dyn.o: ../../e_os.h ../../include/openssl/asn1.h | ||
129 | eng_dyn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
130 | eng_dyn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
131 | eng_dyn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
132 | eng_dyn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
133 | eng_dyn.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
134 | eng_dyn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
135 | eng_dyn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
136 | eng_dyn.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
137 | eng_dyn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
138 | eng_dyn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
139 | eng_dyn.o: ../cryptlib.h eng_dyn.c eng_int.h | ||
140 | eng_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
141 | eng_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
142 | eng_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
143 | eng_err.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
144 | eng_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
145 | eng_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
146 | eng_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
147 | eng_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
148 | eng_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
149 | eng_err.o: ../../include/openssl/ui.h eng_err.c | ||
150 | eng_fat.o: ../../e_os.h ../../include/openssl/asn1.h | ||
151 | eng_fat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
152 | eng_fat.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
153 | eng_fat.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
154 | eng_fat.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
155 | eng_fat.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
156 | eng_fat.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
157 | eng_fat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
158 | eng_fat.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
159 | eng_fat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
160 | eng_fat.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
161 | eng_fat.o: ../cryptlib.h eng_fat.c eng_int.h | ||
162 | eng_init.o: ../../e_os.h ../../include/openssl/asn1.h | ||
163 | eng_init.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
164 | eng_init.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
165 | eng_init.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
166 | eng_init.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
167 | eng_init.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
168 | eng_init.o: ../../include/openssl/opensslconf.h | ||
169 | eng_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
170 | eng_init.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
171 | eng_init.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
172 | eng_init.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
173 | eng_init.o: ../cryptlib.h eng_init.c eng_int.h | ||
174 | eng_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
175 | eng_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
176 | eng_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
177 | eng_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
178 | eng_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
179 | eng_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
180 | eng_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
181 | eng_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
182 | eng_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
183 | eng_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
184 | eng_lib.o: ../../include/openssl/ui.h ../cryptlib.h eng_int.h eng_lib.c | ||
185 | eng_list.o: ../../e_os.h ../../include/openssl/asn1.h | ||
186 | eng_list.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
187 | eng_list.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
188 | eng_list.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
189 | eng_list.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
190 | eng_list.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
191 | eng_list.o: ../../include/openssl/opensslconf.h | ||
192 | eng_list.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
193 | eng_list.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
194 | eng_list.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
195 | eng_list.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
196 | eng_list.o: ../cryptlib.h eng_int.h eng_list.c | ||
197 | eng_openssl.o: ../../e_os.h ../../include/openssl/aes.h | ||
198 | eng_openssl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
199 | eng_openssl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
200 | eng_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
201 | eng_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
202 | eng_openssl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
203 | eng_openssl.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
204 | eng_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
205 | eng_openssl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
206 | eng_openssl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
207 | eng_openssl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
208 | eng_openssl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
209 | eng_openssl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
210 | eng_openssl.o: ../../include/openssl/opensslconf.h | ||
211 | eng_openssl.o: ../../include/openssl/opensslv.h | ||
212 | eng_openssl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
213 | eng_openssl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
214 | eng_openssl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
215 | eng_openssl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
216 | eng_openssl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
217 | eng_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
218 | eng_openssl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
219 | eng_openssl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
220 | eng_openssl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
221 | eng_openssl.o: ../cryptlib.h eng_openssl.c | ||
222 | eng_pkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
223 | eng_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
224 | eng_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
225 | eng_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
226 | eng_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
227 | eng_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
228 | eng_pkey.o: ../../include/openssl/opensslconf.h | ||
229 | eng_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
230 | eng_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
231 | eng_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
232 | eng_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
233 | eng_pkey.o: ../cryptlib.h eng_int.h eng_pkey.c | ||
234 | eng_table.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
235 | eng_table.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
236 | eng_table.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
237 | eng_table.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
238 | eng_table.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
239 | eng_table.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
240 | eng_table.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
241 | eng_table.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
242 | eng_table.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
243 | eng_table.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
244 | eng_table.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
245 | eng_table.o: ../../include/openssl/objects.h | ||
246 | eng_table.o: ../../include/openssl/opensslconf.h | ||
247 | eng_table.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
248 | eng_table.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
249 | eng_table.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
250 | eng_table.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
251 | eng_table.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
252 | eng_table.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
253 | eng_table.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
254 | eng_table.o: eng_int.h eng_table.c | ||
255 | hw_4758_cca.o: ../../e_os.h ../../include/openssl/aes.h | ||
256 | hw_4758_cca.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
257 | hw_4758_cca.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
258 | hw_4758_cca.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
259 | hw_4758_cca.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
260 | hw_4758_cca.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
261 | hw_4758_cca.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
262 | hw_4758_cca.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
263 | hw_4758_cca.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
264 | hw_4758_cca.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
265 | hw_4758_cca.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
266 | hw_4758_cca.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
267 | hw_4758_cca.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
268 | hw_4758_cca.o: ../../include/openssl/opensslconf.h | ||
269 | hw_4758_cca.o: ../../include/openssl/opensslv.h | ||
270 | hw_4758_cca.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
271 | hw_4758_cca.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
272 | hw_4758_cca.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
273 | hw_4758_cca.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
274 | hw_4758_cca.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
275 | hw_4758_cca.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
276 | hw_4758_cca.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
277 | hw_4758_cca.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
278 | hw_4758_cca.o: ../cryptlib.h hw_4758_cca.c hw_4758_cca_err.c hw_4758_cca_err.h | ||
279 | hw_4758_cca.o: vendor_defns/hw_4758_cca.h | ||
280 | hw_aep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
281 | hw_aep.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
282 | hw_aep.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
283 | hw_aep.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
284 | hw_aep.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
285 | hw_aep.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
286 | hw_aep.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
287 | hw_aep.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
288 | hw_aep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
289 | hw_aep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
290 | hw_aep.o: ../../include/openssl/ui.h hw_aep.c hw_aep_err.c hw_aep_err.h | ||
291 | hw_aep.o: vendor_defns/aep.h | ||
292 | hw_atalla.o: ../../e_os.h ../../include/openssl/asn1.h | ||
293 | hw_atalla.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
294 | hw_atalla.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
295 | hw_atalla.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
296 | hw_atalla.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
297 | hw_atalla.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
298 | hw_atalla.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
299 | hw_atalla.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
300 | hw_atalla.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
301 | hw_atalla.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
302 | hw_atalla.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
303 | hw_atalla.o: ../cryptlib.h hw_atalla.c hw_atalla_err.c hw_atalla_err.h | ||
304 | hw_atalla.o: vendor_defns/atalla.h | ||
305 | hw_cryptodev.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
306 | hw_cryptodev.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
307 | hw_cryptodev.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
308 | hw_cryptodev.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
309 | hw_cryptodev.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
310 | hw_cryptodev.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
311 | hw_cryptodev.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
312 | hw_cryptodev.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
313 | hw_cryptodev.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
314 | hw_cryptodev.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
315 | hw_cryptodev.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
316 | hw_cryptodev.o: ../../include/openssl/objects.h | ||
317 | hw_cryptodev.o: ../../include/openssl/opensslconf.h | ||
318 | hw_cryptodev.o: ../../include/openssl/opensslv.h | ||
319 | hw_cryptodev.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
320 | hw_cryptodev.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
321 | hw_cryptodev.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
322 | hw_cryptodev.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
323 | hw_cryptodev.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
324 | hw_cryptodev.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
325 | hw_cryptodev.o: ../../include/openssl/ui_compat.h hw_cryptodev.c | ||
326 | hw_cswift.o: ../../e_os.h ../../include/openssl/asn1.h | ||
327 | hw_cswift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
328 | hw_cswift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
329 | hw_cswift.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
330 | hw_cswift.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
331 | hw_cswift.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
332 | hw_cswift.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
333 | hw_cswift.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
334 | hw_cswift.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
335 | hw_cswift.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
336 | hw_cswift.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
337 | hw_cswift.o: ../cryptlib.h hw_cswift.c hw_cswift_err.c hw_cswift_err.h | ||
338 | hw_cswift.o: vendor_defns/cswift.h | ||
339 | hw_ncipher.o: ../../e_os.h ../../include/openssl/aes.h | ||
340 | hw_ncipher.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
341 | hw_ncipher.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
342 | hw_ncipher.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
343 | hw_ncipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
344 | hw_ncipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
345 | hw_ncipher.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
346 | hw_ncipher.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
347 | hw_ncipher.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
348 | hw_ncipher.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
349 | hw_ncipher.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
350 | hw_ncipher.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
351 | hw_ncipher.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
352 | hw_ncipher.o: ../../include/openssl/opensslconf.h | ||
353 | hw_ncipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
354 | hw_ncipher.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
355 | hw_ncipher.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
356 | hw_ncipher.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
357 | hw_ncipher.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
358 | hw_ncipher.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
359 | hw_ncipher.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
360 | hw_ncipher.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
361 | hw_ncipher.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
362 | hw_ncipher.o: ../../include/openssl/x509_vfy.h ../cryptlib.h hw_ncipher.c | ||
363 | hw_ncipher.o: hw_ncipher_err.c hw_ncipher_err.h vendor_defns/hwcryptohook.h | ||
364 | hw_nuron.o: ../../e_os.h ../../include/openssl/asn1.h | ||
365 | hw_nuron.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
366 | hw_nuron.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
367 | hw_nuron.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
368 | hw_nuron.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
369 | hw_nuron.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
370 | hw_nuron.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
371 | hw_nuron.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
372 | hw_nuron.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
373 | hw_nuron.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
374 | hw_nuron.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
375 | hw_nuron.o: ../cryptlib.h hw_nuron.c hw_nuron_err.c hw_nuron_err.h | ||
376 | hw_sureware.o: ../../e_os.h ../../include/openssl/aes.h | ||
377 | hw_sureware.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
378 | hw_sureware.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
379 | hw_sureware.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
380 | hw_sureware.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
381 | hw_sureware.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
382 | hw_sureware.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
383 | hw_sureware.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
384 | hw_sureware.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
385 | hw_sureware.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
386 | hw_sureware.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
387 | hw_sureware.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
388 | hw_sureware.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
389 | hw_sureware.o: ../../include/openssl/opensslconf.h | ||
390 | hw_sureware.o: ../../include/openssl/opensslv.h | ||
391 | hw_sureware.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
392 | hw_sureware.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
393 | hw_sureware.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
394 | hw_sureware.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
395 | hw_sureware.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
396 | hw_sureware.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
397 | hw_sureware.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
398 | hw_sureware.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
399 | hw_sureware.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
400 | hw_sureware.o: ../cryptlib.h eng_int.h engine.h hw_sureware.c hw_sureware_err.c | ||
401 | hw_sureware.o: hw_sureware_err.h vendor_defns/sureware.h | ||
402 | hw_ubsec.o: ../../e_os.h ../../include/openssl/asn1.h | ||
403 | hw_ubsec.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
404 | hw_ubsec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
405 | hw_ubsec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
406 | hw_ubsec.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
407 | hw_ubsec.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
408 | hw_ubsec.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
409 | hw_ubsec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
410 | hw_ubsec.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
411 | hw_ubsec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
412 | hw_ubsec.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
413 | hw_ubsec.o: ../cryptlib.h hw_ubsec.c hw_ubsec_err.c hw_ubsec_err.h | ||
414 | hw_ubsec.o: vendor_defns/hw_ubsec.h | ||
415 | tb_cipher.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
416 | tb_cipher.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
417 | tb_cipher.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
418 | tb_cipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
419 | tb_cipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
420 | tb_cipher.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
421 | tb_cipher.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
422 | tb_cipher.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
423 | tb_cipher.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
424 | tb_cipher.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
425 | tb_cipher.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
426 | tb_cipher.o: ../../include/openssl/objects.h | ||
427 | tb_cipher.o: ../../include/openssl/opensslconf.h | ||
428 | tb_cipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
429 | tb_cipher.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
430 | tb_cipher.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
431 | tb_cipher.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
432 | tb_cipher.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
433 | tb_cipher.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
434 | tb_cipher.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
435 | tb_cipher.o: eng_int.h tb_cipher.c | ||
436 | tb_dh.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
437 | tb_dh.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
438 | tb_dh.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
439 | tb_dh.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
440 | tb_dh.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
441 | tb_dh.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
442 | tb_dh.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
443 | tb_dh.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
444 | tb_dh.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
445 | tb_dh.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
446 | tb_dh.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
447 | tb_dh.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
448 | tb_dh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
449 | tb_dh.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
450 | tb_dh.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
451 | tb_dh.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
452 | tb_dh.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
453 | tb_dh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
454 | tb_dh.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h eng_int.h | ||
455 | tb_dh.o: tb_dh.c | ||
456 | tb_digest.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
457 | tb_digest.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
458 | tb_digest.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
459 | tb_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
460 | tb_digest.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
461 | tb_digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
462 | tb_digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
463 | tb_digest.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
464 | tb_digest.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
465 | tb_digest.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
466 | tb_digest.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
467 | tb_digest.o: ../../include/openssl/objects.h | ||
468 | tb_digest.o: ../../include/openssl/opensslconf.h | ||
469 | tb_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
470 | tb_digest.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
471 | tb_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
472 | tb_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
473 | tb_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
474 | tb_digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
475 | tb_digest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
476 | tb_digest.o: eng_int.h tb_digest.c | ||
477 | tb_dsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
478 | tb_dsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
479 | tb_dsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
480 | tb_dsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
481 | tb_dsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
482 | tb_dsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
483 | tb_dsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
484 | tb_dsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
485 | tb_dsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
486 | tb_dsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
487 | tb_dsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
488 | tb_dsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
489 | tb_dsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
490 | tb_dsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
491 | tb_dsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
492 | tb_dsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
493 | tb_dsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
494 | tb_dsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
495 | tb_dsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
496 | tb_dsa.o: eng_int.h tb_dsa.c | ||
497 | tb_rand.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
498 | tb_rand.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
499 | tb_rand.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
500 | tb_rand.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
501 | tb_rand.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
502 | tb_rand.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
503 | tb_rand.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
504 | tb_rand.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
505 | tb_rand.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
506 | tb_rand.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
507 | tb_rand.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
508 | tb_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
509 | tb_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
510 | tb_rand.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
511 | tb_rand.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
512 | tb_rand.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
513 | tb_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
514 | tb_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
515 | tb_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
516 | tb_rand.o: eng_int.h tb_rand.c | ||
517 | tb_rsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
518 | tb_rsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
519 | tb_rsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
520 | tb_rsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
521 | tb_rsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
522 | tb_rsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
523 | tb_rsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
524 | tb_rsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
525 | tb_rsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
526 | tb_rsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
527 | tb_rsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
528 | tb_rsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
529 | tb_rsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
530 | tb_rsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
531 | tb_rsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
532 | tb_rsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
533 | tb_rsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
534 | tb_rsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
535 | tb_rsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
536 | tb_rsa.o: eng_int.h tb_rsa.c | ||
diff --git a/src/lib/libcrypto/engine/Makefile.ssl b/src/lib/libcrypto/engine/Makefile.ssl new file mode 100644 index 0000000000..30a4446ff9 --- /dev/null +++ b/src/lib/libcrypto/engine/Makefile.ssl | |||
@@ -0,0 +1,538 @@ | |||
1 | # | ||
2 | # OpenSSL/crypto/engine/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= engine | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
9 | CFLAG=-g | ||
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
12 | INSTALLTOP=/usr/local/ssl | ||
13 | MAKE= make -f Makefile.ssl | ||
14 | MAKEDEPPROG= makedepend | ||
15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
16 | MAKEFILE= Makefile.ssl | ||
17 | AR= ar r | ||
18 | |||
19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
20 | |||
21 | GENERAL=Makefile | ||
22 | TEST= enginetest.c | ||
23 | APPS= | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \ | ||
27 | eng_table.c eng_pkey.c eng_fat.c eng_all.c \ | ||
28 | tb_rsa.c tb_dsa.c tb_dh.c tb_rand.c tb_cipher.c tb_digest.c \ | ||
29 | eng_openssl.c eng_dyn.c eng_cnf.c \ | ||
30 | hw_atalla.c hw_cswift.c hw_ncipher.c hw_nuron.c hw_ubsec.c \ | ||
31 | hw_cryptodev.c hw_aep.c hw_sureware.c hw_4758_cca.c | ||
32 | LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \ | ||
33 | eng_table.o eng_pkey.o eng_fat.o eng_all.o \ | ||
34 | tb_rsa.o tb_dsa.o tb_dh.o tb_rand.o tb_cipher.o tb_digest.o \ | ||
35 | eng_openssl.o eng_dyn.o eng_cnf.o \ | ||
36 | hw_atalla.o hw_cswift.o hw_ncipher.o hw_nuron.o hw_ubsec.o \ | ||
37 | hw_cryptodev.o hw_aep.o hw_sureware.o hw_4758_cca.o | ||
38 | |||
39 | SRC= $(LIBSRC) | ||
40 | |||
41 | EXHEADER= engine.h | ||
42 | HEADER= $(EXHEADER) | ||
43 | |||
44 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
45 | |||
46 | top: | ||
47 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
48 | |||
49 | all: lib | ||
50 | |||
51 | lib: $(LIBOBJ) | ||
52 | $(AR) $(LIB) $(LIBOBJ) | ||
53 | $(RANLIB) $(LIB) || echo Never mind. | ||
54 | @touch lib | ||
55 | |||
56 | files: | ||
57 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
58 | |||
59 | links: | ||
60 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
61 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
62 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
63 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
64 | |||
65 | install: | ||
66 | @for i in $(EXHEADER) ; \ | ||
67 | do \ | ||
68 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
69 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
70 | done; | ||
71 | |||
72 | tags: | ||
73 | ctags $(SRC) | ||
74 | |||
75 | errors: | ||
76 | $(PERL) $(TOP)/util/mkerr.pl -conf hw.ec \ | ||
77 | -nostatic -staticloader -write hw_*.c | ||
78 | |||
79 | tests: | ||
80 | |||
81 | lint: | ||
82 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
83 | |||
84 | depend: | ||
85 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
86 | |||
87 | dclean: | ||
88 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
89 | mv -f Makefile.new $(MAKEFILE) | ||
90 | |||
91 | clean: | ||
92 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
93 | |||
94 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
95 | |||
96 | eng_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
97 | eng_all.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
98 | eng_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
99 | eng_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
100 | eng_all.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
101 | eng_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
102 | eng_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
103 | eng_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
104 | eng_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
105 | eng_all.o: ../../include/openssl/ui.h eng_all.c eng_int.h | ||
106 | eng_cnf.o: ../../e_os.h ../../include/openssl/asn1.h | ||
107 | eng_cnf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
108 | eng_cnf.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
109 | eng_cnf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
110 | eng_cnf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
111 | eng_cnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
112 | eng_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
113 | eng_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
114 | eng_cnf.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
115 | eng_cnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
116 | eng_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
117 | eng_cnf.o: ../cryptlib.h eng_cnf.c | ||
118 | eng_ctrl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
119 | eng_ctrl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
120 | eng_ctrl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
121 | eng_ctrl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
122 | eng_ctrl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
123 | eng_ctrl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
124 | eng_ctrl.o: ../../include/openssl/opensslconf.h | ||
125 | eng_ctrl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
126 | eng_ctrl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
127 | eng_ctrl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
128 | eng_ctrl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
129 | eng_ctrl.o: ../cryptlib.h eng_ctrl.c eng_int.h | ||
130 | eng_dyn.o: ../../e_os.h ../../include/openssl/asn1.h | ||
131 | eng_dyn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
132 | eng_dyn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
133 | eng_dyn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
134 | eng_dyn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
135 | eng_dyn.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
136 | eng_dyn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
137 | eng_dyn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
138 | eng_dyn.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
139 | eng_dyn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
140 | eng_dyn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
141 | eng_dyn.o: ../cryptlib.h eng_dyn.c eng_int.h | ||
142 | eng_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
143 | eng_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
144 | eng_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
145 | eng_err.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
146 | eng_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
147 | eng_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
148 | eng_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
149 | eng_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
150 | eng_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
151 | eng_err.o: ../../include/openssl/ui.h eng_err.c | ||
152 | eng_fat.o: ../../e_os.h ../../include/openssl/asn1.h | ||
153 | eng_fat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
154 | eng_fat.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h | ||
155 | eng_fat.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
156 | eng_fat.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
157 | eng_fat.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
158 | eng_fat.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
159 | eng_fat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
160 | eng_fat.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
161 | eng_fat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
162 | eng_fat.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
163 | eng_fat.o: ../cryptlib.h eng_fat.c eng_int.h | ||
164 | eng_init.o: ../../e_os.h ../../include/openssl/asn1.h | ||
165 | eng_init.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
166 | eng_init.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
167 | eng_init.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
168 | eng_init.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
169 | eng_init.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
170 | eng_init.o: ../../include/openssl/opensslconf.h | ||
171 | eng_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
172 | eng_init.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
173 | eng_init.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
174 | eng_init.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
175 | eng_init.o: ../cryptlib.h eng_init.c eng_int.h | ||
176 | eng_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
177 | eng_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
178 | eng_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
179 | eng_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
180 | eng_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
181 | eng_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
182 | eng_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
183 | eng_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
184 | eng_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
185 | eng_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
186 | eng_lib.o: ../../include/openssl/ui.h ../cryptlib.h eng_int.h eng_lib.c | ||
187 | eng_list.o: ../../e_os.h ../../include/openssl/asn1.h | ||
188 | eng_list.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
189 | eng_list.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
190 | eng_list.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
191 | eng_list.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
192 | eng_list.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
193 | eng_list.o: ../../include/openssl/opensslconf.h | ||
194 | eng_list.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
195 | eng_list.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
196 | eng_list.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
197 | eng_list.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
198 | eng_list.o: ../cryptlib.h eng_int.h eng_list.c | ||
199 | eng_openssl.o: ../../e_os.h ../../include/openssl/aes.h | ||
200 | eng_openssl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
201 | eng_openssl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
202 | eng_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
203 | eng_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
204 | eng_openssl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
205 | eng_openssl.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
206 | eng_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
207 | eng_openssl.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
208 | eng_openssl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
209 | eng_openssl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
210 | eng_openssl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
211 | eng_openssl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
212 | eng_openssl.o: ../../include/openssl/opensslconf.h | ||
213 | eng_openssl.o: ../../include/openssl/opensslv.h | ||
214 | eng_openssl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
215 | eng_openssl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
216 | eng_openssl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
217 | eng_openssl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
218 | eng_openssl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
219 | eng_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
220 | eng_openssl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
221 | eng_openssl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
222 | eng_openssl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
223 | eng_openssl.o: ../cryptlib.h eng_openssl.c | ||
224 | eng_pkey.o: ../../e_os.h ../../include/openssl/asn1.h | ||
225 | eng_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
226 | eng_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
227 | eng_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
228 | eng_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
229 | eng_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
230 | eng_pkey.o: ../../include/openssl/opensslconf.h | ||
231 | eng_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
232 | eng_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
233 | eng_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
234 | eng_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
235 | eng_pkey.o: ../cryptlib.h eng_int.h eng_pkey.c | ||
236 | eng_table.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
237 | eng_table.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
238 | eng_table.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
239 | eng_table.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
240 | eng_table.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
241 | eng_table.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
242 | eng_table.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
243 | eng_table.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
244 | eng_table.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
245 | eng_table.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
246 | eng_table.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
247 | eng_table.o: ../../include/openssl/objects.h | ||
248 | eng_table.o: ../../include/openssl/opensslconf.h | ||
249 | eng_table.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
250 | eng_table.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
251 | eng_table.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
252 | eng_table.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
253 | eng_table.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
254 | eng_table.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
255 | eng_table.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
256 | eng_table.o: eng_int.h eng_table.c | ||
257 | hw_4758_cca.o: ../../e_os.h ../../include/openssl/aes.h | ||
258 | hw_4758_cca.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
259 | hw_4758_cca.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
260 | hw_4758_cca.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
261 | hw_4758_cca.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
262 | hw_4758_cca.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
263 | hw_4758_cca.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
264 | hw_4758_cca.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
265 | hw_4758_cca.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
266 | hw_4758_cca.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
267 | hw_4758_cca.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
268 | hw_4758_cca.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
269 | hw_4758_cca.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
270 | hw_4758_cca.o: ../../include/openssl/opensslconf.h | ||
271 | hw_4758_cca.o: ../../include/openssl/opensslv.h | ||
272 | hw_4758_cca.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h | ||
273 | hw_4758_cca.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
274 | hw_4758_cca.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
275 | hw_4758_cca.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
276 | hw_4758_cca.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
277 | hw_4758_cca.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
278 | hw_4758_cca.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
279 | hw_4758_cca.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
280 | hw_4758_cca.o: ../cryptlib.h hw_4758_cca.c hw_4758_cca_err.c hw_4758_cca_err.h | ||
281 | hw_4758_cca.o: vendor_defns/hw_4758_cca.h | ||
282 | hw_aep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
283 | hw_aep.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
284 | hw_aep.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h | ||
285 | hw_aep.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
286 | hw_aep.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
287 | hw_aep.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
288 | hw_aep.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
289 | hw_aep.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
290 | hw_aep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
291 | hw_aep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
292 | hw_aep.o: ../../include/openssl/ui.h hw_aep.c hw_aep_err.c hw_aep_err.h | ||
293 | hw_aep.o: vendor_defns/aep.h | ||
294 | hw_atalla.o: ../../e_os.h ../../include/openssl/asn1.h | ||
295 | hw_atalla.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
296 | hw_atalla.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
297 | hw_atalla.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
298 | hw_atalla.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
299 | hw_atalla.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
300 | hw_atalla.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
301 | hw_atalla.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
302 | hw_atalla.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
303 | hw_atalla.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
304 | hw_atalla.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
305 | hw_atalla.o: ../cryptlib.h hw_atalla.c hw_atalla_err.c hw_atalla_err.h | ||
306 | hw_atalla.o: vendor_defns/atalla.h | ||
307 | hw_cryptodev.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
308 | hw_cryptodev.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
309 | hw_cryptodev.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
310 | hw_cryptodev.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
311 | hw_cryptodev.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
312 | hw_cryptodev.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
313 | hw_cryptodev.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
314 | hw_cryptodev.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
315 | hw_cryptodev.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
316 | hw_cryptodev.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
317 | hw_cryptodev.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
318 | hw_cryptodev.o: ../../include/openssl/objects.h | ||
319 | hw_cryptodev.o: ../../include/openssl/opensslconf.h | ||
320 | hw_cryptodev.o: ../../include/openssl/opensslv.h | ||
321 | hw_cryptodev.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
322 | hw_cryptodev.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
323 | hw_cryptodev.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
324 | hw_cryptodev.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
325 | hw_cryptodev.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
326 | hw_cryptodev.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
327 | hw_cryptodev.o: ../../include/openssl/ui_compat.h hw_cryptodev.c | ||
328 | hw_cswift.o: ../../e_os.h ../../include/openssl/asn1.h | ||
329 | hw_cswift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
330 | hw_cswift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
331 | hw_cswift.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
332 | hw_cswift.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
333 | hw_cswift.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
334 | hw_cswift.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
335 | hw_cswift.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
336 | hw_cswift.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
337 | hw_cswift.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
338 | hw_cswift.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
339 | hw_cswift.o: ../cryptlib.h hw_cswift.c hw_cswift_err.c hw_cswift_err.h | ||
340 | hw_cswift.o: vendor_defns/cswift.h | ||
341 | hw_ncipher.o: ../../e_os.h ../../include/openssl/aes.h | ||
342 | hw_ncipher.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
343 | hw_ncipher.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
344 | hw_ncipher.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
345 | hw_ncipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
346 | hw_ncipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
347 | hw_ncipher.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
348 | hw_ncipher.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
349 | hw_ncipher.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
350 | hw_ncipher.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
351 | hw_ncipher.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
352 | hw_ncipher.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
353 | hw_ncipher.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
354 | hw_ncipher.o: ../../include/openssl/opensslconf.h | ||
355 | hw_ncipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
356 | hw_ncipher.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
357 | hw_ncipher.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
358 | hw_ncipher.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
359 | hw_ncipher.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
360 | hw_ncipher.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
361 | hw_ncipher.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
362 | hw_ncipher.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
363 | hw_ncipher.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h | ||
364 | hw_ncipher.o: ../../include/openssl/x509_vfy.h ../cryptlib.h hw_ncipher.c | ||
365 | hw_ncipher.o: hw_ncipher_err.c hw_ncipher_err.h vendor_defns/hwcryptohook.h | ||
366 | hw_nuron.o: ../../e_os.h ../../include/openssl/asn1.h | ||
367 | hw_nuron.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
368 | hw_nuron.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
369 | hw_nuron.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
370 | hw_nuron.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
371 | hw_nuron.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
372 | hw_nuron.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
373 | hw_nuron.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
374 | hw_nuron.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
375 | hw_nuron.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
376 | hw_nuron.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
377 | hw_nuron.o: ../cryptlib.h hw_nuron.c hw_nuron_err.c hw_nuron_err.h | ||
378 | hw_sureware.o: ../../e_os.h ../../include/openssl/aes.h | ||
379 | hw_sureware.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
380 | hw_sureware.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
381 | hw_sureware.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
382 | hw_sureware.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
383 | hw_sureware.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
384 | hw_sureware.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h | ||
385 | hw_sureware.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
386 | hw_sureware.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
387 | hw_sureware.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
388 | hw_sureware.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
389 | hw_sureware.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
390 | hw_sureware.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
391 | hw_sureware.o: ../../include/openssl/opensslconf.h | ||
392 | hw_sureware.o: ../../include/openssl/opensslv.h | ||
393 | hw_sureware.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h | ||
394 | hw_sureware.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h | ||
395 | hw_sureware.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
396 | hw_sureware.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
397 | hw_sureware.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
398 | hw_sureware.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
399 | hw_sureware.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
400 | hw_sureware.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
401 | hw_sureware.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
402 | hw_sureware.o: ../cryptlib.h eng_int.h engine.h hw_sureware.c hw_sureware_err.c | ||
403 | hw_sureware.o: hw_sureware_err.h vendor_defns/sureware.h | ||
404 | hw_ubsec.o: ../../e_os.h ../../include/openssl/asn1.h | ||
405 | hw_ubsec.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
406 | hw_ubsec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
407 | hw_ubsec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
408 | hw_ubsec.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
409 | hw_ubsec.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
410 | hw_ubsec.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
411 | hw_ubsec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
412 | hw_ubsec.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
413 | hw_ubsec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
414 | hw_ubsec.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
415 | hw_ubsec.o: ../cryptlib.h hw_ubsec.c hw_ubsec_err.c hw_ubsec_err.h | ||
416 | hw_ubsec.o: vendor_defns/hw_ubsec.h | ||
417 | tb_cipher.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
418 | tb_cipher.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
419 | tb_cipher.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
420 | tb_cipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
421 | tb_cipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
422 | tb_cipher.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
423 | tb_cipher.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
424 | tb_cipher.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
425 | tb_cipher.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
426 | tb_cipher.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
427 | tb_cipher.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
428 | tb_cipher.o: ../../include/openssl/objects.h | ||
429 | tb_cipher.o: ../../include/openssl/opensslconf.h | ||
430 | tb_cipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
431 | tb_cipher.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
432 | tb_cipher.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
433 | tb_cipher.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
434 | tb_cipher.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
435 | tb_cipher.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
436 | tb_cipher.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
437 | tb_cipher.o: eng_int.h tb_cipher.c | ||
438 | tb_dh.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
439 | tb_dh.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
440 | tb_dh.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
441 | tb_dh.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
442 | tb_dh.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
443 | tb_dh.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
444 | tb_dh.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
445 | tb_dh.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
446 | tb_dh.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
447 | tb_dh.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
448 | tb_dh.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
449 | tb_dh.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
450 | tb_dh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
451 | tb_dh.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
452 | tb_dh.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
453 | tb_dh.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
454 | tb_dh.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
455 | tb_dh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
456 | tb_dh.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h eng_int.h | ||
457 | tb_dh.o: tb_dh.c | ||
458 | tb_digest.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
459 | tb_digest.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
460 | tb_digest.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
461 | tb_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
462 | tb_digest.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
463 | tb_digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
464 | tb_digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
465 | tb_digest.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
466 | tb_digest.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
467 | tb_digest.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
468 | tb_digest.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
469 | tb_digest.o: ../../include/openssl/objects.h | ||
470 | tb_digest.o: ../../include/openssl/opensslconf.h | ||
471 | tb_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
472 | tb_digest.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
473 | tb_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
474 | tb_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
475 | tb_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
476 | tb_digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
477 | tb_digest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
478 | tb_digest.o: eng_int.h tb_digest.c | ||
479 | tb_dsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
480 | tb_dsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
481 | tb_dsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
482 | tb_dsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
483 | tb_dsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
484 | tb_dsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
485 | tb_dsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
486 | tb_dsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
487 | tb_dsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
488 | tb_dsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
489 | tb_dsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
490 | tb_dsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
491 | tb_dsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
492 | tb_dsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
493 | tb_dsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
494 | tb_dsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
495 | tb_dsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
496 | tb_dsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
497 | tb_dsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
498 | tb_dsa.o: eng_int.h tb_dsa.c | ||
499 | tb_rand.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
500 | tb_rand.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
501 | tb_rand.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
502 | tb_rand.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
503 | tb_rand.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
504 | tb_rand.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
505 | tb_rand.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
506 | tb_rand.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
507 | tb_rand.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
508 | tb_rand.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
509 | tb_rand.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
510 | tb_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
511 | tb_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
512 | tb_rand.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
513 | tb_rand.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
514 | tb_rand.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
515 | tb_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
516 | tb_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
517 | tb_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
518 | tb_rand.o: eng_int.h tb_rand.c | ||
519 | tb_rsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h | ||
520 | tb_rsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h | ||
521 | tb_rsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h | ||
522 | tb_rsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
523 | tb_rsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
524 | tb_rsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
525 | tb_rsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h | ||
526 | tb_rsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
527 | tb_rsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
528 | tb_rsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
529 | tb_rsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
530 | tb_rsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
531 | tb_rsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
532 | tb_rsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
533 | tb_rsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
534 | tb_rsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
535 | tb_rsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
536 | tb_rsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
537 | tb_rsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
538 | tb_rsa.o: eng_int.h tb_rsa.c | ||
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c index 4225760af1..cdf670901a 100644 --- a/src/lib/libcrypto/engine/eng_cnf.c +++ b/src/lib/libcrypto/engine/eng_cnf.c | |||
@@ -158,7 +158,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
158 | */ | 158 | */ |
159 | if (!strcmp(ctrlvalue, "EMPTY")) | 159 | if (!strcmp(ctrlvalue, "EMPTY")) |
160 | ctrlvalue = NULL; | 160 | ctrlvalue = NULL; |
161 | if (!strcmp(ctrlname, "init")) | 161 | else if (!strcmp(ctrlname, "init")) |
162 | { | 162 | { |
163 | if (!NCONF_get_number_e(cnf, value, "init", &do_init)) | 163 | if (!NCONF_get_number_e(cnf, value, "init", &do_init)) |
164 | goto err; | 164 | goto err; |
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c index fdc0e7be0f..814d95ee32 100644 --- a/src/lib/libcrypto/engine/eng_err.c +++ b/src/lib/libcrypto/engine/eng_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/engine/eng_err.c */ | 1 | /* crypto/engine/eng_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -64,91 +64,87 @@ | |||
64 | 64 | ||
65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA ENGINE_str_functs[]= | 67 | static ERR_STRING_DATA ENGINE_str_functs[]= |
72 | { | 68 | { |
73 | {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, | 69 | {ERR_PACK(0,ENGINE_F_DYNAMIC_CTRL,0), "DYNAMIC_CTRL"}, |
74 | {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, | 70 | {ERR_PACK(0,ENGINE_F_DYNAMIC_GET_DATA_CTX,0), "DYNAMIC_GET_DATA_CTX"}, |
75 | {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, | 71 | {ERR_PACK(0,ENGINE_F_DYNAMIC_LOAD,0), "DYNAMIC_LOAD"}, |
76 | {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, | 72 | {ERR_PACK(0,ENGINE_F_ENGINE_ADD,0), "ENGINE_add"}, |
77 | {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, | 73 | {ERR_PACK(0,ENGINE_F_ENGINE_BY_ID,0), "ENGINE_by_id"}, |
78 | {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, | 74 | {ERR_PACK(0,ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,0), "ENGINE_cmd_is_executable"}, |
79 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"}, | 75 | {ERR_PACK(0,ENGINE_F_ENGINE_CTRL,0), "ENGINE_ctrl"}, |
80 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, | 76 | {ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD,0), "ENGINE_ctrl_cmd"}, |
81 | {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, | 77 | {ERR_PACK(0,ENGINE_F_ENGINE_CTRL_CMD_STRING,0), "ENGINE_ctrl_cmd_string"}, |
82 | {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, | 78 | {ERR_PACK(0,ENGINE_F_ENGINE_FINISH,0), "ENGINE_finish"}, |
83 | {ERR_FUNC(ENGINE_F_ENGINE_FREE), "ENGINE_free"}, | 79 | {ERR_PACK(0,ENGINE_F_ENGINE_FREE,0), "ENGINE_free"}, |
84 | {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, | 80 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_CIPHER,0), "ENGINE_get_cipher"}, |
85 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, | 81 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_DEFAULT_TYPE,0), "ENGINE_GET_DEFAULT_TYPE"}, |
86 | {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, | 82 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_DIGEST,0), "ENGINE_get_digest"}, |
87 | {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"}, | 83 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_NEXT,0), "ENGINE_get_next"}, |
88 | {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"}, | 84 | {ERR_PACK(0,ENGINE_F_ENGINE_GET_PREV,0), "ENGINE_get_prev"}, |
89 | {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"}, | 85 | {ERR_PACK(0,ENGINE_F_ENGINE_INIT,0), "ENGINE_init"}, |
90 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"}, | 86 | {ERR_PACK(0,ENGINE_F_ENGINE_LIST_ADD,0), "ENGINE_LIST_ADD"}, |
91 | {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, | 87 | {ERR_PACK(0,ENGINE_F_ENGINE_LIST_REMOVE,0), "ENGINE_LIST_REMOVE"}, |
92 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, | 88 | {ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PRIVATE_KEY,0), "ENGINE_load_private_key"}, |
93 | {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, | 89 | {ERR_PACK(0,ENGINE_F_ENGINE_LOAD_PUBLIC_KEY,0), "ENGINE_load_public_key"}, |
94 | {ERR_FUNC(ENGINE_F_ENGINE_MODULE_INIT), "ENGINE_MODULE_INIT"}, | 90 | {ERR_PACK(0,ENGINE_F_ENGINE_MODULE_INIT,0), "ENGINE_MODULE_INIT"}, |
95 | {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, | 91 | {ERR_PACK(0,ENGINE_F_ENGINE_NEW,0), "ENGINE_new"}, |
96 | {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, | 92 | {ERR_PACK(0,ENGINE_F_ENGINE_REMOVE,0), "ENGINE_remove"}, |
97 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, | 93 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_STRING,0), "ENGINE_set_default_string"}, |
98 | {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"}, | 94 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_DEFAULT_TYPE,0), "ENGINE_SET_DEFAULT_TYPE"}, |
99 | {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"}, | 95 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_ID,0), "ENGINE_set_id"}, |
100 | {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, | 96 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"}, |
101 | {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, | 97 | {ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"}, |
102 | {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, | 98 | {ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"}, |
103 | {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, | 99 | {ERR_PACK(0,ENGINE_F_ENGINE_UP_REF,0), "ENGINE_up_ref"}, |
104 | {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, | 100 | {ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"}, |
105 | {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, | 101 | {ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"}, |
106 | {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, | 102 | {ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"}, |
107 | {ERR_FUNC(ENGINE_F_SET_DATA_CTX), "SET_DATA_CTX"}, | 103 | {ERR_PACK(0,ENGINE_F_SET_DATA_CTX,0), "SET_DATA_CTX"}, |
108 | {0,NULL} | 104 | {0,NULL} |
109 | }; | 105 | }; |
110 | 106 | ||
111 | static ERR_STRING_DATA ENGINE_str_reasons[]= | 107 | static ERR_STRING_DATA ENGINE_str_reasons[]= |
112 | { | 108 | { |
113 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) ,"already loaded"}, | 109 | {ENGINE_R_ALREADY_LOADED ,"already loaded"}, |
114 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER),"argument is not a number"}, | 110 | {ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER ,"argument is not a number"}, |
115 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) ,"cmd not executable"}, | 111 | {ENGINE_R_CMD_NOT_EXECUTABLE ,"cmd not executable"}, |
116 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT),"command takes input"}, | 112 | {ENGINE_R_COMMAND_TAKES_INPUT ,"command takes input"}, |
117 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT),"command takes no input"}, | 113 | {ENGINE_R_COMMAND_TAKES_NO_INPUT ,"command takes no input"}, |
118 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID),"conflicting engine id"}, | 114 | {ENGINE_R_CONFLICTING_ENGINE_ID ,"conflicting engine id"}, |
119 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED),"ctrl command not implemented"}, | 115 | {ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, |
120 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) ,"dh not implemented"}, | 116 | {ENGINE_R_DH_NOT_IMPLEMENTED ,"dh not implemented"}, |
121 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED),"dsa not implemented"}, | 117 | {ENGINE_R_DSA_NOT_IMPLEMENTED ,"dsa not implemented"}, |
122 | {ERR_REASON(ENGINE_R_DSO_FAILURE) ,"DSO failure"}, | 118 | {ENGINE_R_DSO_FAILURE ,"DSO failure"}, |
123 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) ,"dso not found"}, | 119 | {ENGINE_R_DSO_NOT_FOUND ,"dso not found"}, |
124 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR),"engines section error"}, | 120 | {ENGINE_R_ENGINES_SECTION_ERROR ,"engines section error"}, |
125 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST),"engine is not in the list"}, | 121 | {ENGINE_R_ENGINE_IS_NOT_IN_LIST ,"engine is not in the list"}, |
126 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR),"engine section error"}, | 122 | {ENGINE_R_ENGINE_SECTION_ERROR ,"engine section error"}, |
127 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY),"failed loading private key"}, | 123 | {ENGINE_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"}, |
128 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY),"failed loading public key"}, | 124 | {ENGINE_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"}, |
129 | {ERR_REASON(ENGINE_R_FINISH_FAILED) ,"finish failed"}, | 125 | {ENGINE_R_FINISH_FAILED ,"finish failed"}, |
130 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) ,"could not obtain hardware handle"}, | 126 | {ENGINE_R_GET_HANDLE_FAILED ,"could not obtain hardware handle"}, |
131 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) ,"'id' or 'name' missing"}, | 127 | {ENGINE_R_ID_OR_NAME_MISSING ,"'id' or 'name' missing"}, |
132 | {ERR_REASON(ENGINE_R_INIT_FAILED) ,"init failed"}, | 128 | {ENGINE_R_INIT_FAILED ,"init failed"}, |
133 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR),"internal list error"}, | 129 | {ENGINE_R_INTERNAL_LIST_ERROR ,"internal list error"}, |
134 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) ,"invalid argument"}, | 130 | {ENGINE_R_INVALID_ARGUMENT ,"invalid argument"}, |
135 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) ,"invalid cmd name"}, | 131 | {ENGINE_R_INVALID_CMD_NAME ,"invalid cmd name"}, |
136 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) ,"invalid cmd number"}, | 132 | {ENGINE_R_INVALID_CMD_NUMBER ,"invalid cmd number"}, |
137 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) ,"invalid init value"}, | 133 | {ENGINE_R_INVALID_INIT_VALUE ,"invalid init value"}, |
138 | {ERR_REASON(ENGINE_R_INVALID_STRING) ,"invalid string"}, | 134 | {ENGINE_R_INVALID_STRING ,"invalid string"}, |
139 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) ,"not initialised"}, | 135 | {ENGINE_R_NOT_INITIALISED ,"not initialised"}, |
140 | {ERR_REASON(ENGINE_R_NOT_LOADED) ,"not loaded"}, | 136 | {ENGINE_R_NOT_LOADED ,"not loaded"}, |
141 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION),"no control function"}, | 137 | {ENGINE_R_NO_CONTROL_FUNCTION ,"no control function"}, |
142 | {ERR_REASON(ENGINE_R_NO_INDEX) ,"no index"}, | 138 | {ENGINE_R_NO_INDEX ,"no index"}, |
143 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) ,"no load function"}, | 139 | {ENGINE_R_NO_LOAD_FUNCTION ,"no load function"}, |
144 | {ERR_REASON(ENGINE_R_NO_REFERENCE) ,"no reference"}, | 140 | {ENGINE_R_NO_REFERENCE ,"no reference"}, |
145 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) ,"no such engine"}, | 141 | {ENGINE_R_NO_SUCH_ENGINE ,"no such engine"}, |
146 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) ,"no unload function"}, | 142 | {ENGINE_R_NO_UNLOAD_FUNCTION ,"no unload function"}, |
147 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) ,"provide parameters"}, | 143 | {ENGINE_R_PROVIDE_PARAMETERS ,"provide parameters"}, |
148 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED),"rsa not implemented"}, | 144 | {ENGINE_R_RSA_NOT_IMPLEMENTED ,"rsa not implemented"}, |
149 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER),"unimplemented cipher"}, | 145 | {ENGINE_R_UNIMPLEMENTED_CIPHER ,"unimplemented cipher"}, |
150 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST),"unimplemented digest"}, | 146 | {ENGINE_R_UNIMPLEMENTED_DIGEST ,"unimplemented digest"}, |
151 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY),"version incompatibility"}, | 147 | {ENGINE_R_VERSION_INCOMPATIBILITY ,"version incompatibility"}, |
152 | {0,NULL} | 148 | {0,NULL} |
153 | }; | 149 | }; |
154 | 150 | ||
@@ -162,8 +158,8 @@ void ERR_load_ENGINE_strings(void) | |||
162 | { | 158 | { |
163 | init=0; | 159 | init=0; |
164 | #ifndef OPENSSL_NO_ERR | 160 | #ifndef OPENSSL_NO_ERR |
165 | ERR_load_strings(0,ENGINE_str_functs); | 161 | ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_functs); |
166 | ERR_load_strings(0,ENGINE_str_reasons); | 162 | ERR_load_strings(ERR_LIB_ENGINE,ENGINE_str_reasons); |
167 | #endif | 163 | #endif |
168 | 164 | ||
169 | } | 165 | } |
diff --git a/src/lib/libcrypto/engine/enginetest.c b/src/lib/libcrypto/engine/enginetest.c new file mode 100644 index 0000000000..c2d0297392 --- /dev/null +++ b/src/lib/libcrypto/engine/enginetest.c | |||
@@ -0,0 +1,283 @@ | |||
1 | /* crypto/engine/enginetest.c */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-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 <stdio.h> | ||
60 | #include <string.h> | ||
61 | |||
62 | #ifdef OPENSSL_NO_ENGINE | ||
63 | int main(int argc, char *argv[]) | ||
64 | { | ||
65 | printf("No ENGINE support\n"); | ||
66 | return(0); | ||
67 | } | ||
68 | #else | ||
69 | #include <openssl/e_os2.h> | ||
70 | #include <openssl/buffer.h> | ||
71 | #include <openssl/crypto.h> | ||
72 | #include <openssl/engine.h> | ||
73 | #include <openssl/err.h> | ||
74 | |||
75 | static void display_engine_list() | ||
76 | { | ||
77 | ENGINE *h; | ||
78 | int loop; | ||
79 | |||
80 | h = ENGINE_get_first(); | ||
81 | loop = 0; | ||
82 | printf("listing available engine types\n"); | ||
83 | while(h) | ||
84 | { | ||
85 | printf("engine %i, id = \"%s\", name = \"%s\"\n", | ||
86 | loop++, ENGINE_get_id(h), ENGINE_get_name(h)); | ||
87 | h = ENGINE_get_next(h); | ||
88 | } | ||
89 | printf("end of list\n"); | ||
90 | /* ENGINE_get_first() increases the struct_ref counter, so we | ||
91 | must call ENGINE_free() to decrease it again */ | ||
92 | ENGINE_free(h); | ||
93 | } | ||
94 | |||
95 | int main(int argc, char *argv[]) | ||
96 | { | ||
97 | ENGINE *block[512]; | ||
98 | char buf[256]; | ||
99 | const char *id, *name; | ||
100 | ENGINE *ptr; | ||
101 | int loop; | ||
102 | int to_return = 1; | ||
103 | ENGINE *new_h1 = NULL; | ||
104 | ENGINE *new_h2 = NULL; | ||
105 | ENGINE *new_h3 = NULL; | ||
106 | ENGINE *new_h4 = NULL; | ||
107 | |||
108 | /* enable memory leak checking unless explicitly disabled */ | ||
109 | if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) | ||
110 | { | ||
111 | CRYPTO_malloc_debug_init(); | ||
112 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | /* OPENSSL_DEBUG_MEMORY=off */ | ||
117 | CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); | ||
118 | } | ||
119 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
120 | ERR_load_crypto_strings(); | ||
121 | |||
122 | memset(block, 0, 512 * sizeof(ENGINE *)); | ||
123 | if(((new_h1 = ENGINE_new()) == NULL) || | ||
124 | !ENGINE_set_id(new_h1, "test_id0") || | ||
125 | !ENGINE_set_name(new_h1, "First test item") || | ||
126 | ((new_h2 = ENGINE_new()) == NULL) || | ||
127 | !ENGINE_set_id(new_h2, "test_id1") || | ||
128 | !ENGINE_set_name(new_h2, "Second test item") || | ||
129 | ((new_h3 = ENGINE_new()) == NULL) || | ||
130 | !ENGINE_set_id(new_h3, "test_id2") || | ||
131 | !ENGINE_set_name(new_h3, "Third test item") || | ||
132 | ((new_h4 = ENGINE_new()) == NULL) || | ||
133 | !ENGINE_set_id(new_h4, "test_id3") || | ||
134 | !ENGINE_set_name(new_h4, "Fourth test item")) | ||
135 | { | ||
136 | printf("Couldn't set up test ENGINE structures\n"); | ||
137 | goto end; | ||
138 | } | ||
139 | printf("\nenginetest beginning\n\n"); | ||
140 | display_engine_list(); | ||
141 | if(!ENGINE_add(new_h1)) | ||
142 | { | ||
143 | printf("Add failed!\n"); | ||
144 | goto end; | ||
145 | } | ||
146 | display_engine_list(); | ||
147 | ptr = ENGINE_get_first(); | ||
148 | if(!ENGINE_remove(ptr)) | ||
149 | { | ||
150 | printf("Remove failed!\n"); | ||
151 | goto end; | ||
152 | } | ||
153 | if (ptr) | ||
154 | ENGINE_free(ptr); | ||
155 | display_engine_list(); | ||
156 | if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) | ||
157 | { | ||
158 | printf("Add failed!\n"); | ||
159 | goto end; | ||
160 | } | ||
161 | display_engine_list(); | ||
162 | if(!ENGINE_remove(new_h2)) | ||
163 | { | ||
164 | printf("Remove failed!\n"); | ||
165 | goto end; | ||
166 | } | ||
167 | display_engine_list(); | ||
168 | if(!ENGINE_add(new_h4)) | ||
169 | { | ||
170 | printf("Add failed!\n"); | ||
171 | goto end; | ||
172 | } | ||
173 | display_engine_list(); | ||
174 | if(ENGINE_add(new_h3)) | ||
175 | { | ||
176 | printf("Add *should* have failed but didn't!\n"); | ||
177 | goto end; | ||
178 | } | ||
179 | else | ||
180 | printf("Add that should fail did.\n"); | ||
181 | ERR_clear_error(); | ||
182 | if(ENGINE_remove(new_h2)) | ||
183 | { | ||
184 | printf("Remove *should* have failed but didn't!\n"); | ||
185 | goto end; | ||
186 | } | ||
187 | else | ||
188 | printf("Remove that should fail did.\n"); | ||
189 | ERR_clear_error(); | ||
190 | if(!ENGINE_remove(new_h3)) | ||
191 | { | ||
192 | printf("Remove failed!\n"); | ||
193 | goto end; | ||
194 | } | ||
195 | display_engine_list(); | ||
196 | if(!ENGINE_remove(new_h4)) | ||
197 | { | ||
198 | printf("Remove failed!\n"); | ||
199 | goto end; | ||
200 | } | ||
201 | display_engine_list(); | ||
202 | /* Depending on whether there's any hardware support compiled | ||
203 | * in, this remove may be destined to fail. */ | ||
204 | ptr = ENGINE_get_first(); | ||
205 | if(ptr) | ||
206 | if(!ENGINE_remove(ptr)) | ||
207 | printf("Remove failed!i - probably no hardware " | ||
208 | "support present.\n"); | ||
209 | if (ptr) | ||
210 | ENGINE_free(ptr); | ||
211 | display_engine_list(); | ||
212 | if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) | ||
213 | { | ||
214 | printf("Couldn't add and remove to an empty list!\n"); | ||
215 | goto end; | ||
216 | } | ||
217 | else | ||
218 | printf("Successfully added and removed to an empty list!\n"); | ||
219 | printf("About to beef up the engine-type list\n"); | ||
220 | for(loop = 0; loop < 512; loop++) | ||
221 | { | ||
222 | sprintf(buf, "id%i", loop); | ||
223 | id = BUF_strdup(buf); | ||
224 | sprintf(buf, "Fake engine type %i", loop); | ||
225 | name = BUF_strdup(buf); | ||
226 | if(((block[loop] = ENGINE_new()) == NULL) || | ||
227 | !ENGINE_set_id(block[loop], id) || | ||
228 | !ENGINE_set_name(block[loop], name)) | ||
229 | { | ||
230 | printf("Couldn't create block of ENGINE structures.\n" | ||
231 | "I'll probably also core-dump now, damn.\n"); | ||
232 | goto end; | ||
233 | } | ||
234 | } | ||
235 | for(loop = 0; loop < 512; loop++) | ||
236 | { | ||
237 | if(!ENGINE_add(block[loop])) | ||
238 | { | ||
239 | printf("\nAdding stopped at %i, (%s,%s)\n", | ||
240 | loop, ENGINE_get_id(block[loop]), | ||
241 | ENGINE_get_name(block[loop])); | ||
242 | goto cleanup_loop; | ||
243 | } | ||
244 | else | ||
245 | printf("."); fflush(stdout); | ||
246 | } | ||
247 | cleanup_loop: | ||
248 | printf("\nAbout to empty the engine-type list\n"); | ||
249 | while((ptr = ENGINE_get_first()) != NULL) | ||
250 | { | ||
251 | if(!ENGINE_remove(ptr)) | ||
252 | { | ||
253 | printf("\nRemove failed!\n"); | ||
254 | goto end; | ||
255 | } | ||
256 | ENGINE_free(ptr); | ||
257 | printf("."); fflush(stdout); | ||
258 | } | ||
259 | for(loop = 0; loop < 512; loop++) | ||
260 | { | ||
261 | OPENSSL_free((void *)ENGINE_get_id(block[loop])); | ||
262 | OPENSSL_free((void *)ENGINE_get_name(block[loop])); | ||
263 | } | ||
264 | printf("\nTests completed happily\n"); | ||
265 | to_return = 0; | ||
266 | end: | ||
267 | if(to_return) | ||
268 | ERR_print_errors_fp(stderr); | ||
269 | if(new_h1) ENGINE_free(new_h1); | ||
270 | if(new_h2) ENGINE_free(new_h2); | ||
271 | if(new_h3) ENGINE_free(new_h3); | ||
272 | if(new_h4) ENGINE_free(new_h4); | ||
273 | for(loop = 0; loop < 512; loop++) | ||
274 | if(block[loop]) | ||
275 | ENGINE_free(block[loop]); | ||
276 | ENGINE_cleanup(); | ||
277 | CRYPTO_cleanup_all_ex_data(); | ||
278 | ERR_free_strings(); | ||
279 | ERR_remove_state(0); | ||
280 | CRYPTO_mem_leaks_fp(stderr); | ||
281 | return to_return; | ||
282 | } | ||
283 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw.ec b/src/lib/libcrypto/engine/hw.ec new file mode 100644 index 0000000000..5481a43918 --- /dev/null +++ b/src/lib/libcrypto/engine/hw.ec | |||
@@ -0,0 +1,8 @@ | |||
1 | L AEPHK hw_aep_err.h hw_aep_err.c | ||
2 | L ATALLA hw_atalla_err.h hw_atalla_err.c | ||
3 | L CSWIFT hw_cswift_err.h hw_cswift_err.c | ||
4 | L HWCRHK hw_ncipher_err.h hw_ncipher_err.c | ||
5 | L NURON hw_nuron_err.h hw_nuron_err.c | ||
6 | L SUREWARE hw_sureware_err.h hw_sureware_err.c | ||
7 | L UBSEC hw_ubsec_err.h hw_ubsec_err.c | ||
8 | L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca.c b/src/lib/libcrypto/engine/hw_4758_cca.c new file mode 100644 index 0000000000..4f5ae8a46d --- /dev/null +++ b/src/lib/libcrypto/engine/hw_4758_cca.c | |||
@@ -0,0 +1,969 @@ | |||
1 | /* Author: Maurice Gittens <maurice@gittens.nl> */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@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 <stdio.h> | ||
57 | #include <openssl/crypto.h> | ||
58 | /* #include <openssl/pem.h> */ | ||
59 | #include "cryptlib.h" | ||
60 | #include <openssl/dso.h> | ||
61 | #include <openssl/x509.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/engine.h> | ||
64 | |||
65 | #ifndef OPENSSL_NO_HW | ||
66 | #ifndef OPENSSL_NO_HW_4758_CCA | ||
67 | |||
68 | #ifdef FLAT_INC | ||
69 | #include "hw_4758_cca.h" | ||
70 | #else | ||
71 | #include "vendor_defns/hw_4758_cca.h" | ||
72 | #endif | ||
73 | |||
74 | #include "hw_4758_cca_err.c" | ||
75 | |||
76 | static int ibm_4758_cca_destroy(ENGINE *e); | ||
77 | static int ibm_4758_cca_init(ENGINE *e); | ||
78 | static int ibm_4758_cca_finish(ENGINE *e); | ||
79 | static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
80 | |||
81 | /* rsa functions */ | ||
82 | /*---------------*/ | ||
83 | #ifndef OPENSSL_NO_RSA | ||
84 | static int cca_rsa_pub_enc(int flen, const unsigned char *from, | ||
85 | unsigned char *to, RSA *rsa,int padding); | ||
86 | static int cca_rsa_priv_dec(int flen, const unsigned char *from, | ||
87 | unsigned char *to, RSA *rsa,int padding); | ||
88 | static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len, | ||
89 | unsigned char *sigret, unsigned int *siglen, const RSA *rsa); | ||
90 | static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len, | ||
91 | unsigned char *sigbuf, unsigned int siglen, const RSA *rsa); | ||
92 | |||
93 | /* utility functions */ | ||
94 | /*-----------------------*/ | ||
95 | static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*, | ||
96 | UI_METHOD *ui_method, void *callback_data); | ||
97 | static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*, | ||
98 | UI_METHOD *ui_method, void *callback_data); | ||
99 | |||
100 | static int getModulusAndExponent(const unsigned char *token, long *exponentLength, | ||
101 | unsigned char *exponent, long *modulusLength, | ||
102 | long *modulusFieldLength, unsigned char *modulus); | ||
103 | #endif | ||
104 | |||
105 | /* RAND number functions */ | ||
106 | /*-----------------------*/ | ||
107 | static int cca_get_random_bytes(unsigned char*, int ); | ||
108 | static int cca_random_status(void); | ||
109 | |||
110 | static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
111 | int idx,long argl, void *argp); | ||
112 | |||
113 | /* Function pointers for CCA verbs */ | ||
114 | /*---------------------------------*/ | ||
115 | #ifndef OPENSSL_NO_RSA | ||
116 | static F_KEYRECORDREAD keyRecordRead; | ||
117 | static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate; | ||
118 | static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify; | ||
119 | static F_PUBLICKEYEXTRACT publicKeyExtract; | ||
120 | static F_PKAENCRYPT pkaEncrypt; | ||
121 | static F_PKADECRYPT pkaDecrypt; | ||
122 | #endif | ||
123 | static F_RANDOMNUMBERGENERATE randomNumberGenerate; | ||
124 | |||
125 | /* static variables */ | ||
126 | /*------------------*/ | ||
127 | static const char *CCA4758_LIB_NAME = NULL; | ||
128 | static const char *get_CCA4758_LIB_NAME(void) | ||
129 | { | ||
130 | if(CCA4758_LIB_NAME) | ||
131 | return CCA4758_LIB_NAME; | ||
132 | return CCA_LIB_NAME; | ||
133 | } | ||
134 | static void free_CCA4758_LIB_NAME(void) | ||
135 | { | ||
136 | if(CCA4758_LIB_NAME) | ||
137 | OPENSSL_free((void*)CCA4758_LIB_NAME); | ||
138 | CCA4758_LIB_NAME = NULL; | ||
139 | } | ||
140 | static long set_CCA4758_LIB_NAME(const char *name) | ||
141 | { | ||
142 | free_CCA4758_LIB_NAME(); | ||
143 | return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
144 | } | ||
145 | #ifndef OPENSSL_NO_RSA | ||
146 | static const char* n_keyRecordRead = CSNDKRR; | ||
147 | static const char* n_digitalSignatureGenerate = CSNDDSG; | ||
148 | static const char* n_digitalSignatureVerify = CSNDDSV; | ||
149 | static const char* n_publicKeyExtract = CSNDPKX; | ||
150 | static const char* n_pkaEncrypt = CSNDPKE; | ||
151 | static const char* n_pkaDecrypt = CSNDPKD; | ||
152 | #endif | ||
153 | static const char* n_randomNumberGenerate = CSNBRNG; | ||
154 | |||
155 | static int hndidx = -1; | ||
156 | static DSO *dso = NULL; | ||
157 | |||
158 | /* openssl engine initialization structures */ | ||
159 | /*------------------------------------------*/ | ||
160 | |||
161 | #define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE | ||
162 | static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = { | ||
163 | {CCA4758_CMD_SO_PATH, | ||
164 | "SO_PATH", | ||
165 | "Specifies the path to the '4758cca' shared library", | ||
166 | ENGINE_CMD_FLAG_STRING}, | ||
167 | {0, NULL, NULL, 0} | ||
168 | }; | ||
169 | |||
170 | #ifndef OPENSSL_NO_RSA | ||
171 | static RSA_METHOD ibm_4758_cca_rsa = | ||
172 | { | ||
173 | "IBM 4758 CCA RSA method", | ||
174 | cca_rsa_pub_enc, | ||
175 | NULL, | ||
176 | NULL, | ||
177 | cca_rsa_priv_dec, | ||
178 | NULL, /*rsa_mod_exp,*/ | ||
179 | NULL, /*mod_exp_mont,*/ | ||
180 | NULL, /* init */ | ||
181 | NULL, /* finish */ | ||
182 | RSA_FLAG_SIGN_VER, /* flags */ | ||
183 | NULL, /* app_data */ | ||
184 | cca_rsa_sign, /* rsa_sign */ | ||
185 | cca_rsa_verify /* rsa_verify */ | ||
186 | }; | ||
187 | #endif | ||
188 | |||
189 | static RAND_METHOD ibm_4758_cca_rand = | ||
190 | { | ||
191 | /* "IBM 4758 RAND method", */ | ||
192 | NULL, /* seed */ | ||
193 | cca_get_random_bytes, /* get random bytes from the card */ | ||
194 | NULL, /* cleanup */ | ||
195 | NULL, /* add */ | ||
196 | cca_get_random_bytes, /* pseudo rand */ | ||
197 | cca_random_status, /* status */ | ||
198 | }; | ||
199 | |||
200 | static const char *engine_4758_cca_id = "4758cca"; | ||
201 | static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support"; | ||
202 | |||
203 | /* engine implementation */ | ||
204 | /*-----------------------*/ | ||
205 | static int bind_helper(ENGINE *e) | ||
206 | { | ||
207 | if(!ENGINE_set_id(e, engine_4758_cca_id) || | ||
208 | !ENGINE_set_name(e, engine_4758_cca_name) || | ||
209 | #ifndef OPENSSL_NO_RSA | ||
210 | !ENGINE_set_RSA(e, &ibm_4758_cca_rsa) || | ||
211 | #endif | ||
212 | !ENGINE_set_RAND(e, &ibm_4758_cca_rand) || | ||
213 | !ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) || | ||
214 | !ENGINE_set_init_function(e, ibm_4758_cca_init) || | ||
215 | !ENGINE_set_finish_function(e, ibm_4758_cca_finish) || | ||
216 | !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) || | ||
217 | !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) || | ||
218 | !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) || | ||
219 | !ENGINE_set_cmd_defns(e, cca4758_cmd_defns)) | ||
220 | return 0; | ||
221 | /* Ensure the error handling is set up */ | ||
222 | ERR_load_CCA4758_strings(); | ||
223 | return 1; | ||
224 | } | ||
225 | |||
226 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
227 | static ENGINE *engine_4758_cca(void) | ||
228 | { | ||
229 | ENGINE *ret = ENGINE_new(); | ||
230 | if(!ret) | ||
231 | return NULL; | ||
232 | if(!bind_helper(ret)) | ||
233 | { | ||
234 | ENGINE_free(ret); | ||
235 | return NULL; | ||
236 | } | ||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | void ENGINE_load_4758cca(void) | ||
241 | { | ||
242 | ENGINE *e_4758 = engine_4758_cca(); | ||
243 | if (!e_4758) return; | ||
244 | ENGINE_add(e_4758); | ||
245 | ENGINE_free(e_4758); | ||
246 | ERR_clear_error(); | ||
247 | } | ||
248 | #endif | ||
249 | |||
250 | static int ibm_4758_cca_destroy(ENGINE *e) | ||
251 | { | ||
252 | ERR_unload_CCA4758_strings(); | ||
253 | free_CCA4758_LIB_NAME(); | ||
254 | return 1; | ||
255 | } | ||
256 | |||
257 | static int ibm_4758_cca_init(ENGINE *e) | ||
258 | { | ||
259 | if(dso) | ||
260 | { | ||
261 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED); | ||
262 | goto err; | ||
263 | } | ||
264 | |||
265 | dso = DSO_load(NULL, get_CCA4758_LIB_NAME(), NULL, 0); | ||
266 | if(!dso) | ||
267 | { | ||
268 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
269 | goto err; | ||
270 | } | ||
271 | |||
272 | #ifndef OPENSSL_NO_RSA | ||
273 | if(!(keyRecordRead = (F_KEYRECORDREAD) | ||
274 | DSO_bind_func(dso, n_keyRecordRead)) || | ||
275 | !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) | ||
276 | DSO_bind_func(dso, n_randomNumberGenerate)) || | ||
277 | !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE) | ||
278 | DSO_bind_func(dso, n_digitalSignatureGenerate)) || | ||
279 | !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY) | ||
280 | DSO_bind_func(dso, n_digitalSignatureVerify)) || | ||
281 | !(publicKeyExtract = (F_PUBLICKEYEXTRACT) | ||
282 | DSO_bind_func(dso, n_publicKeyExtract)) || | ||
283 | !(pkaEncrypt = (F_PKAENCRYPT) | ||
284 | DSO_bind_func(dso, n_pkaEncrypt)) || | ||
285 | !(pkaDecrypt = (F_PKADECRYPT) | ||
286 | DSO_bind_func(dso, n_pkaDecrypt))) | ||
287 | { | ||
288 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
289 | goto err; | ||
290 | } | ||
291 | #else | ||
292 | if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE) | ||
293 | DSO_bind_func(dso, n_randomNumberGenerate))) | ||
294 | { | ||
295 | CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE); | ||
296 | goto err; | ||
297 | } | ||
298 | #endif | ||
299 | |||
300 | hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle", | ||
301 | NULL, NULL, cca_ex_free); | ||
302 | |||
303 | return 1; | ||
304 | err: | ||
305 | if(dso) | ||
306 | DSO_free(dso); | ||
307 | dso = NULL; | ||
308 | |||
309 | keyRecordRead = (F_KEYRECORDREAD)0; | ||
310 | randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0; | ||
311 | digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0; | ||
312 | digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0; | ||
313 | publicKeyExtract = (F_PUBLICKEYEXTRACT)0; | ||
314 | pkaEncrypt = (F_PKAENCRYPT)0; | ||
315 | pkaDecrypt = (F_PKADECRYPT)0; | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | static int ibm_4758_cca_finish(ENGINE *e) | ||
320 | { | ||
321 | free_CCA4758_LIB_NAME(); | ||
322 | if(!dso) | ||
323 | { | ||
324 | CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH, | ||
325 | CCA4758_R_NOT_LOADED); | ||
326 | return 0; | ||
327 | } | ||
328 | if(!DSO_free(dso)) | ||
329 | { | ||
330 | CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH, | ||
331 | CCA4758_R_UNIT_FAILURE); | ||
332 | return 0; | ||
333 | } | ||
334 | dso = NULL; | ||
335 | keyRecordRead = (F_KEYRECORDREAD)0; | ||
336 | randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0; | ||
337 | digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0; | ||
338 | digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0; | ||
339 | publicKeyExtract = (F_PUBLICKEYEXTRACT)0; | ||
340 | pkaEncrypt = (F_PKAENCRYPT)0; | ||
341 | pkaDecrypt = (F_PKADECRYPT)0; | ||
342 | return 1; | ||
343 | } | ||
344 | |||
345 | static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
346 | { | ||
347 | int initialised = ((dso == NULL) ? 0 : 1); | ||
348 | switch(cmd) | ||
349 | { | ||
350 | case CCA4758_CMD_SO_PATH: | ||
351 | if(p == NULL) | ||
352 | { | ||
353 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
354 | ERR_R_PASSED_NULL_PARAMETER); | ||
355 | return 0; | ||
356 | } | ||
357 | if(initialised) | ||
358 | { | ||
359 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
360 | CCA4758_R_ALREADY_LOADED); | ||
361 | return 0; | ||
362 | } | ||
363 | return set_CCA4758_LIB_NAME((const char *)p); | ||
364 | default: | ||
365 | break; | ||
366 | } | ||
367 | CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL, | ||
368 | CCA4758_R_COMMAND_NOT_IMPLEMENTED); | ||
369 | return 0; | ||
370 | } | ||
371 | |||
372 | #ifndef OPENSSL_NO_RSA | ||
373 | |||
374 | #define MAX_CCA_PKA_TOKEN_SIZE 2500 | ||
375 | |||
376 | static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id, | ||
377 | UI_METHOD *ui_method, void *callback_data) | ||
378 | { | ||
379 | RSA *rtmp = NULL; | ||
380 | EVP_PKEY *res = NULL; | ||
381 | unsigned char* keyToken = NULL; | ||
382 | unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE]; | ||
383 | long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
384 | long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
385 | long returnCode; | ||
386 | long reasonCode; | ||
387 | long exitDataLength = 0; | ||
388 | long ruleArrayLength = 0; | ||
389 | unsigned char exitData[8]; | ||
390 | unsigned char ruleArray[8]; | ||
391 | unsigned char keyLabel[64]; | ||
392 | long keyLabelLength = strlen(key_id); | ||
393 | unsigned char modulus[256]; | ||
394 | long modulusFieldLength = sizeof(modulus); | ||
395 | long modulusLength = 0; | ||
396 | unsigned char exponent[256]; | ||
397 | long exponentLength = sizeof(exponent); | ||
398 | |||
399 | if (keyLabelLength > sizeof(keyLabel)) | ||
400 | { | ||
401 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
402 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
403 | return NULL; | ||
404 | } | ||
405 | |||
406 | memset(keyLabel,' ', sizeof(keyLabel)); | ||
407 | memcpy(keyLabel, key_id, keyLabelLength); | ||
408 | |||
409 | keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long)); | ||
410 | if (!keyToken) | ||
411 | { | ||
412 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
413 | ERR_R_MALLOC_FAILURE); | ||
414 | goto err; | ||
415 | } | ||
416 | |||
417 | keyRecordRead(&returnCode, &reasonCode, &exitDataLength, | ||
418 | exitData, &ruleArrayLength, ruleArray, keyLabel, | ||
419 | &keyTokenLength, keyToken+sizeof(long)); | ||
420 | |||
421 | if (returnCode) | ||
422 | { | ||
423 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
424 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
425 | goto err; | ||
426 | } | ||
427 | |||
428 | publicKeyExtract(&returnCode, &reasonCode, &exitDataLength, | ||
429 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
430 | keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken); | ||
431 | |||
432 | if (returnCode) | ||
433 | { | ||
434 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
435 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
436 | goto err; | ||
437 | } | ||
438 | |||
439 | if (!getModulusAndExponent(pubKeyToken, &exponentLength, | ||
440 | exponent, &modulusLength, &modulusFieldLength, | ||
441 | modulus)) | ||
442 | { | ||
443 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
444 | CCA4758_R_FAILED_LOADING_PRIVATE_KEY); | ||
445 | goto err; | ||
446 | } | ||
447 | |||
448 | (*(long*)keyToken) = keyTokenLength; | ||
449 | rtmp = RSA_new_method(e); | ||
450 | RSA_set_ex_data(rtmp, hndidx, (char *)keyToken); | ||
451 | |||
452 | rtmp->e = BN_bin2bn(exponent, exponentLength, NULL); | ||
453 | rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL); | ||
454 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
455 | |||
456 | res = EVP_PKEY_new(); | ||
457 | EVP_PKEY_assign_RSA(res, rtmp); | ||
458 | |||
459 | return res; | ||
460 | err: | ||
461 | if (keyToken) | ||
462 | OPENSSL_free(keyToken); | ||
463 | if (res) | ||
464 | EVP_PKEY_free(res); | ||
465 | if (rtmp) | ||
466 | RSA_free(rtmp); | ||
467 | return NULL; | ||
468 | } | ||
469 | |||
470 | static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id, | ||
471 | UI_METHOD *ui_method, void *callback_data) | ||
472 | { | ||
473 | RSA *rtmp = NULL; | ||
474 | EVP_PKEY *res = NULL; | ||
475 | unsigned char* keyToken = NULL; | ||
476 | long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE; | ||
477 | long returnCode; | ||
478 | long reasonCode; | ||
479 | long exitDataLength = 0; | ||
480 | long ruleArrayLength = 0; | ||
481 | unsigned char exitData[8]; | ||
482 | unsigned char ruleArray[8]; | ||
483 | unsigned char keyLabel[64]; | ||
484 | long keyLabelLength = strlen(key_id); | ||
485 | unsigned char modulus[512]; | ||
486 | long modulusFieldLength = sizeof(modulus); | ||
487 | long modulusLength = 0; | ||
488 | unsigned char exponent[512]; | ||
489 | long exponentLength = sizeof(exponent); | ||
490 | |||
491 | if (keyLabelLength > sizeof(keyLabel)) | ||
492 | { | ||
493 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
494 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
495 | return NULL; | ||
496 | } | ||
497 | |||
498 | memset(keyLabel,' ', sizeof(keyLabel)); | ||
499 | memcpy(keyLabel, key_id, keyLabelLength); | ||
500 | |||
501 | keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long)); | ||
502 | if (!keyToken) | ||
503 | { | ||
504 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY, | ||
505 | ERR_R_MALLOC_FAILURE); | ||
506 | goto err; | ||
507 | } | ||
508 | |||
509 | keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
510 | &ruleArrayLength, ruleArray, keyLabel, &keyTokenLength, | ||
511 | keyToken+sizeof(long)); | ||
512 | |||
513 | if (returnCode) | ||
514 | { | ||
515 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
516 | ERR_R_MALLOC_FAILURE); | ||
517 | goto err; | ||
518 | } | ||
519 | |||
520 | if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength, | ||
521 | exponent, &modulusLength, &modulusFieldLength, modulus)) | ||
522 | { | ||
523 | CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY, | ||
524 | CCA4758_R_FAILED_LOADING_PUBLIC_KEY); | ||
525 | goto err; | ||
526 | } | ||
527 | |||
528 | (*(long*)keyToken) = keyTokenLength; | ||
529 | rtmp = RSA_new_method(e); | ||
530 | RSA_set_ex_data(rtmp, hndidx, (char *)keyToken); | ||
531 | rtmp->e = BN_bin2bn(exponent, exponentLength, NULL); | ||
532 | rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL); | ||
533 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
534 | res = EVP_PKEY_new(); | ||
535 | EVP_PKEY_assign_RSA(res, rtmp); | ||
536 | |||
537 | return res; | ||
538 | err: | ||
539 | if (keyToken) | ||
540 | OPENSSL_free(keyToken); | ||
541 | if (res) | ||
542 | EVP_PKEY_free(res); | ||
543 | if (rtmp) | ||
544 | RSA_free(rtmp); | ||
545 | return NULL; | ||
546 | } | ||
547 | |||
548 | static int cca_rsa_pub_enc(int flen, const unsigned char *from, | ||
549 | unsigned char *to, RSA *rsa,int padding) | ||
550 | { | ||
551 | long returnCode; | ||
552 | long reasonCode; | ||
553 | long lflen = flen; | ||
554 | long exitDataLength = 0; | ||
555 | unsigned char exitData[8]; | ||
556 | long ruleArrayLength = 1; | ||
557 | unsigned char ruleArray[8] = "PKCS-1.2"; | ||
558 | long dataStructureLength = 0; | ||
559 | unsigned char dataStructure[8]; | ||
560 | long outputLength = RSA_size(rsa); | ||
561 | long keyTokenLength; | ||
562 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
563 | |||
564 | keyTokenLength = *(long*)keyToken; | ||
565 | keyToken+=sizeof(long); | ||
566 | |||
567 | pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
568 | &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from, | ||
569 | &dataStructureLength, dataStructure, &keyTokenLength, | ||
570 | keyToken, &outputLength, to); | ||
571 | |||
572 | if (returnCode || reasonCode) | ||
573 | return -(returnCode << 16 | reasonCode); | ||
574 | return outputLength; | ||
575 | } | ||
576 | |||
577 | static int cca_rsa_priv_dec(int flen, const unsigned char *from, | ||
578 | unsigned char *to, RSA *rsa,int padding) | ||
579 | { | ||
580 | long returnCode; | ||
581 | long reasonCode; | ||
582 | long lflen = flen; | ||
583 | long exitDataLength = 0; | ||
584 | unsigned char exitData[8]; | ||
585 | long ruleArrayLength = 1; | ||
586 | unsigned char ruleArray[8] = "PKCS-1.2"; | ||
587 | long dataStructureLength = 0; | ||
588 | unsigned char dataStructure[8]; | ||
589 | long outputLength = RSA_size(rsa); | ||
590 | long keyTokenLength; | ||
591 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
592 | |||
593 | keyTokenLength = *(long*)keyToken; | ||
594 | keyToken+=sizeof(long); | ||
595 | |||
596 | pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData, | ||
597 | &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from, | ||
598 | &dataStructureLength, dataStructure, &keyTokenLength, | ||
599 | keyToken, &outputLength, to); | ||
600 | |||
601 | return (returnCode | reasonCode) ? 0 : 1; | ||
602 | } | ||
603 | |||
604 | #define SSL_SIG_LEN 36 | ||
605 | |||
606 | static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len, | ||
607 | unsigned char *sigbuf, unsigned int siglen, const RSA *rsa) | ||
608 | { | ||
609 | long returnCode; | ||
610 | long reasonCode; | ||
611 | long lsiglen = siglen; | ||
612 | long exitDataLength = 0; | ||
613 | unsigned char exitData[8]; | ||
614 | long ruleArrayLength = 1; | ||
615 | unsigned char ruleArray[8] = "PKCS-1.1"; | ||
616 | long keyTokenLength; | ||
617 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
618 | long length = SSL_SIG_LEN; | ||
619 | long keyLength ; | ||
620 | unsigned char *hashBuffer = NULL; | ||
621 | X509_SIG sig; | ||
622 | ASN1_TYPE parameter; | ||
623 | X509_ALGOR algorithm; | ||
624 | ASN1_OCTET_STRING digest; | ||
625 | |||
626 | keyTokenLength = *(long*)keyToken; | ||
627 | keyToken+=sizeof(long); | ||
628 | |||
629 | if (type == NID_md5 || type == NID_sha1) | ||
630 | { | ||
631 | sig.algor = &algorithm; | ||
632 | algorithm.algorithm = OBJ_nid2obj(type); | ||
633 | |||
634 | if (!algorithm.algorithm) | ||
635 | { | ||
636 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
637 | CCA4758_R_UNKNOWN_ALGORITHM_TYPE); | ||
638 | return 0; | ||
639 | } | ||
640 | |||
641 | if (!algorithm.algorithm->length) | ||
642 | { | ||
643 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
644 | CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); | ||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | parameter.type = V_ASN1_NULL; | ||
649 | parameter.value.ptr = NULL; | ||
650 | algorithm.parameter = ¶meter; | ||
651 | |||
652 | sig.digest = &digest; | ||
653 | sig.digest->data = (unsigned char*)m; | ||
654 | sig.digest->length = m_len; | ||
655 | |||
656 | length = i2d_X509_SIG(&sig, NULL); | ||
657 | } | ||
658 | |||
659 | keyLength = RSA_size(rsa); | ||
660 | |||
661 | if (length - RSA_PKCS1_PADDING > keyLength) | ||
662 | { | ||
663 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
664 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | switch (type) | ||
669 | { | ||
670 | case NID_md5_sha1 : | ||
671 | if (m_len != SSL_SIG_LEN) | ||
672 | { | ||
673 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
674 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
675 | return 0; | ||
676 | } | ||
677 | |||
678 | hashBuffer = (unsigned char *)m; | ||
679 | length = m_len; | ||
680 | break; | ||
681 | case NID_md5 : | ||
682 | { | ||
683 | unsigned char *ptr; | ||
684 | ptr = hashBuffer = OPENSSL_malloc( | ||
685 | (unsigned int)keyLength+1); | ||
686 | if (!hashBuffer) | ||
687 | { | ||
688 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
689 | ERR_R_MALLOC_FAILURE); | ||
690 | return 0; | ||
691 | } | ||
692 | |||
693 | i2d_X509_SIG(&sig, &ptr); | ||
694 | } | ||
695 | break; | ||
696 | case NID_sha1 : | ||
697 | { | ||
698 | unsigned char *ptr; | ||
699 | ptr = hashBuffer = OPENSSL_malloc( | ||
700 | (unsigned int)keyLength+1); | ||
701 | if (!hashBuffer) | ||
702 | { | ||
703 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
704 | ERR_R_MALLOC_FAILURE); | ||
705 | return 0; | ||
706 | } | ||
707 | i2d_X509_SIG(&sig, &ptr); | ||
708 | } | ||
709 | break; | ||
710 | default: | ||
711 | return 0; | ||
712 | } | ||
713 | |||
714 | digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength, | ||
715 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
716 | keyToken, &length, hashBuffer, &lsiglen, sigbuf); | ||
717 | |||
718 | if (type == NID_sha1 || type == NID_md5) | ||
719 | { | ||
720 | OPENSSL_cleanse(hashBuffer, keyLength+1); | ||
721 | OPENSSL_free(hashBuffer); | ||
722 | } | ||
723 | |||
724 | return ((returnCode || reasonCode) ? 0 : 1); | ||
725 | } | ||
726 | |||
727 | #define SSL_SIG_LEN 36 | ||
728 | |||
729 | static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len, | ||
730 | unsigned char *sigret, unsigned int *siglen, const RSA *rsa) | ||
731 | { | ||
732 | long returnCode; | ||
733 | long reasonCode; | ||
734 | long exitDataLength = 0; | ||
735 | unsigned char exitData[8]; | ||
736 | long ruleArrayLength = 1; | ||
737 | unsigned char ruleArray[8] = "PKCS-1.1"; | ||
738 | long outputLength=256; | ||
739 | long outputBitLength; | ||
740 | long keyTokenLength; | ||
741 | unsigned char *hashBuffer = NULL; | ||
742 | unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); | ||
743 | long length = SSL_SIG_LEN; | ||
744 | long keyLength ; | ||
745 | X509_SIG sig; | ||
746 | ASN1_TYPE parameter; | ||
747 | X509_ALGOR algorithm; | ||
748 | ASN1_OCTET_STRING digest; | ||
749 | |||
750 | keyTokenLength = *(long*)keyToken; | ||
751 | keyToken+=sizeof(long); | ||
752 | |||
753 | if (type == NID_md5 || type == NID_sha1) | ||
754 | { | ||
755 | sig.algor = &algorithm; | ||
756 | algorithm.algorithm = OBJ_nid2obj(type); | ||
757 | |||
758 | if (!algorithm.algorithm) | ||
759 | { | ||
760 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
761 | CCA4758_R_UNKNOWN_ALGORITHM_TYPE); | ||
762 | return 0; | ||
763 | } | ||
764 | |||
765 | if (!algorithm.algorithm->length) | ||
766 | { | ||
767 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
768 | CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); | ||
769 | return 0; | ||
770 | } | ||
771 | |||
772 | parameter.type = V_ASN1_NULL; | ||
773 | parameter.value.ptr = NULL; | ||
774 | algorithm.parameter = ¶meter; | ||
775 | |||
776 | sig.digest = &digest; | ||
777 | sig.digest->data = (unsigned char*)m; | ||
778 | sig.digest->length = m_len; | ||
779 | |||
780 | length = i2d_X509_SIG(&sig, NULL); | ||
781 | } | ||
782 | |||
783 | keyLength = RSA_size(rsa); | ||
784 | |||
785 | if (length - RSA_PKCS1_PADDING > keyLength) | ||
786 | { | ||
787 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
788 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | switch (type) | ||
793 | { | ||
794 | case NID_md5_sha1 : | ||
795 | if (m_len != SSL_SIG_LEN) | ||
796 | { | ||
797 | CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, | ||
798 | CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
799 | return 0; | ||
800 | } | ||
801 | hashBuffer = (unsigned char*)m; | ||
802 | length = m_len; | ||
803 | break; | ||
804 | case NID_md5 : | ||
805 | { | ||
806 | unsigned char *ptr; | ||
807 | ptr = hashBuffer = OPENSSL_malloc( | ||
808 | (unsigned int)keyLength+1); | ||
809 | if (!hashBuffer) | ||
810 | { | ||
811 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
812 | ERR_R_MALLOC_FAILURE); | ||
813 | return 0; | ||
814 | } | ||
815 | i2d_X509_SIG(&sig, &ptr); | ||
816 | } | ||
817 | break; | ||
818 | case NID_sha1 : | ||
819 | { | ||
820 | unsigned char *ptr; | ||
821 | ptr = hashBuffer = OPENSSL_malloc( | ||
822 | (unsigned int)keyLength+1); | ||
823 | if (!hashBuffer) | ||
824 | { | ||
825 | CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, | ||
826 | ERR_R_MALLOC_FAILURE); | ||
827 | return 0; | ||
828 | } | ||
829 | i2d_X509_SIG(&sig, &ptr); | ||
830 | } | ||
831 | break; | ||
832 | default: | ||
833 | return 0; | ||
834 | } | ||
835 | |||
836 | digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength, | ||
837 | exitData, &ruleArrayLength, ruleArray, &keyTokenLength, | ||
838 | keyToken, &length, hashBuffer, &outputLength, &outputBitLength, | ||
839 | sigret); | ||
840 | |||
841 | if (type == NID_sha1 || type == NID_md5) | ||
842 | { | ||
843 | OPENSSL_cleanse(hashBuffer, keyLength+1); | ||
844 | OPENSSL_free(hashBuffer); | ||
845 | } | ||
846 | |||
847 | *siglen = outputLength; | ||
848 | |||
849 | return ((returnCode || reasonCode) ? 0 : 1); | ||
850 | } | ||
851 | |||
852 | static int getModulusAndExponent(const unsigned char*token, long *exponentLength, | ||
853 | unsigned char *exponent, long *modulusLength, long *modulusFieldLength, | ||
854 | unsigned char *modulus) | ||
855 | { | ||
856 | unsigned long len; | ||
857 | |||
858 | if (*token++ != (char)0x1E) /* internal PKA token? */ | ||
859 | return 0; | ||
860 | |||
861 | if (*token++) /* token version must be zero */ | ||
862 | return 0; | ||
863 | |||
864 | len = *token++; | ||
865 | len = len << 8; | ||
866 | len |= (unsigned char)*token++; | ||
867 | |||
868 | token += 4; /* skip reserved bytes */ | ||
869 | |||
870 | if (*token++ == (char)0x04) | ||
871 | { | ||
872 | if (*token++) /* token version must be zero */ | ||
873 | return 0; | ||
874 | |||
875 | len = *token++; | ||
876 | len = len << 8; | ||
877 | len |= (unsigned char)*token++; | ||
878 | |||
879 | token+=2; /* skip reserved section */ | ||
880 | |||
881 | len = *token++; | ||
882 | len = len << 8; | ||
883 | len |= (unsigned char)*token++; | ||
884 | |||
885 | *exponentLength = len; | ||
886 | |||
887 | len = *token++; | ||
888 | len = len << 8; | ||
889 | len |= (unsigned char)*token++; | ||
890 | |||
891 | *modulusLength = len; | ||
892 | |||
893 | len = *token++; | ||
894 | len = len << 8; | ||
895 | len |= (unsigned char)*token++; | ||
896 | |||
897 | *modulusFieldLength = len; | ||
898 | |||
899 | memcpy(exponent, token, *exponentLength); | ||
900 | token+= *exponentLength; | ||
901 | |||
902 | memcpy(modulus, token, *modulusFieldLength); | ||
903 | return 1; | ||
904 | } | ||
905 | return 0; | ||
906 | } | ||
907 | |||
908 | #endif /* OPENSSL_NO_RSA */ | ||
909 | |||
910 | static int cca_random_status(void) | ||
911 | { | ||
912 | return 1; | ||
913 | } | ||
914 | |||
915 | static int cca_get_random_bytes(unsigned char* buf, int num) | ||
916 | { | ||
917 | long ret_code; | ||
918 | long reason_code; | ||
919 | long exit_data_length; | ||
920 | unsigned char exit_data[4]; | ||
921 | unsigned char form[] = "RANDOM "; | ||
922 | unsigned char rand_buf[8]; | ||
923 | |||
924 | while(num >= sizeof(rand_buf)) | ||
925 | { | ||
926 | randomNumberGenerate(&ret_code, &reason_code, &exit_data_length, | ||
927 | exit_data, form, rand_buf); | ||
928 | if (ret_code) | ||
929 | return 0; | ||
930 | num -= sizeof(rand_buf); | ||
931 | memcpy(buf, rand_buf, sizeof(rand_buf)); | ||
932 | buf += sizeof(rand_buf); | ||
933 | } | ||
934 | |||
935 | if (num) | ||
936 | { | ||
937 | randomNumberGenerate(&ret_code, &reason_code, NULL, NULL, | ||
938 | form, rand_buf); | ||
939 | if (ret_code) | ||
940 | return 0; | ||
941 | memcpy(buf, rand_buf, num); | ||
942 | } | ||
943 | |||
944 | return 1; | ||
945 | } | ||
946 | |||
947 | static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx, | ||
948 | long argl, void *argp) | ||
949 | { | ||
950 | if (item) | ||
951 | OPENSSL_free(item); | ||
952 | } | ||
953 | |||
954 | /* Goo to handle building as a dynamic engine */ | ||
955 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
956 | static int bind_fn(ENGINE *e, const char *id) | ||
957 | { | ||
958 | if(id && (strcmp(id, engine_4758_cca_id) != 0)) | ||
959 | return 0; | ||
960 | if(!bind_helper(e)) | ||
961 | return 0; | ||
962 | return 1; | ||
963 | } | ||
964 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
965 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
966 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
967 | |||
968 | #endif /* !OPENSSL_NO_HW_4758_CCA */ | ||
969 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.c b/src/lib/libcrypto/engine/hw_4758_cca_err.c new file mode 100644 index 0000000000..7ea5c63707 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_4758_cca_err.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* hw_4758_cca_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-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 | |||
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 "hw_4758_cca_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA CCA4758_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"}, | ||
70 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"}, | ||
71 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"}, | ||
72 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"}, | ||
73 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"}, | ||
74 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"}, | ||
75 | {ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"}, | ||
76 | {0,NULL} | ||
77 | }; | ||
78 | |||
79 | static ERR_STRING_DATA CCA4758_str_reasons[]= | ||
80 | { | ||
81 | {CCA4758_R_ALREADY_LOADED ,"already loaded"}, | ||
82 | {CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"}, | ||
83 | {CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"}, | ||
84 | {CCA4758_R_DSO_FAILURE ,"dso failure"}, | ||
85 | {CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"}, | ||
86 | {CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"}, | ||
87 | {CCA4758_R_NOT_LOADED ,"not loaded"}, | ||
88 | {CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
89 | {CCA4758_R_UNIT_FAILURE ,"unit failure"}, | ||
90 | {CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, | ||
91 | {0,NULL} | ||
92 | }; | ||
93 | |||
94 | #endif | ||
95 | |||
96 | #ifdef CCA4758_LIB_NAME | ||
97 | static ERR_STRING_DATA CCA4758_lib_name[]= | ||
98 | { | ||
99 | {0 ,CCA4758_LIB_NAME}, | ||
100 | {0,NULL} | ||
101 | }; | ||
102 | #endif | ||
103 | |||
104 | |||
105 | static int CCA4758_lib_error_code=0; | ||
106 | static int CCA4758_error_init=1; | ||
107 | |||
108 | static void ERR_load_CCA4758_strings(void) | ||
109 | { | ||
110 | if (CCA4758_lib_error_code == 0) | ||
111 | CCA4758_lib_error_code=ERR_get_next_error_library(); | ||
112 | |||
113 | if (CCA4758_error_init) | ||
114 | { | ||
115 | CCA4758_error_init=0; | ||
116 | #ifndef OPENSSL_NO_ERR | ||
117 | ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_functs); | ||
118 | ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_reasons); | ||
119 | #endif | ||
120 | |||
121 | #ifdef CCA4758_LIB_NAME | ||
122 | CCA4758_lib_name->error = ERR_PACK(CCA4758_lib_error_code,0,0); | ||
123 | ERR_load_strings(0,CCA4758_lib_name); | ||
124 | #endif | ||
125 | } | ||
126 | } | ||
127 | |||
128 | static void ERR_unload_CCA4758_strings(void) | ||
129 | { | ||
130 | if (CCA4758_error_init == 0) | ||
131 | { | ||
132 | #ifndef OPENSSL_NO_ERR | ||
133 | ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_functs); | ||
134 | ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_reasons); | ||
135 | #endif | ||
136 | |||
137 | #ifdef CCA4758_LIB_NAME | ||
138 | ERR_unload_strings(0,CCA4758_lib_name); | ||
139 | #endif | ||
140 | CCA4758_error_init=1; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | static void ERR_CCA4758_error(int function, int reason, char *file, int line) | ||
145 | { | ||
146 | if (CCA4758_lib_error_code == 0) | ||
147 | CCA4758_lib_error_code=ERR_get_next_error_library(); | ||
148 | ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line); | ||
149 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.h b/src/lib/libcrypto/engine/hw_4758_cca_err.h new file mode 100644 index 0000000000..2fc563ab11 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_4758_cca_err.h | |||
@@ -0,0 +1,93 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_CCA4758_ERR_H | ||
56 | #define HEADER_CCA4758_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_CCA4758_strings(void); | ||
63 | static void ERR_unload_CCA4758_strings(void); | ||
64 | static void ERR_CCA4758_error(int function, int reason, char *file, int line); | ||
65 | #define CCA4758err(f,r) ERR_CCA4758_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the CCA4758 functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define CCA4758_F_IBM_4758_CCA_CTRL 100 | ||
71 | #define CCA4758_F_IBM_4758_CCA_FINISH 101 | ||
72 | #define CCA4758_F_IBM_4758_CCA_INIT 102 | ||
73 | #define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103 | ||
74 | #define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104 | ||
75 | #define CCA4758_F_IBM_4758_CCA_SIGN 105 | ||
76 | #define CCA4758_F_IBM_4758_CCA_VERIFY 106 | ||
77 | |||
78 | /* Reason codes. */ | ||
79 | #define CCA4758_R_ALREADY_LOADED 100 | ||
80 | #define CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD 101 | ||
81 | #define CCA4758_R_COMMAND_NOT_IMPLEMENTED 102 | ||
82 | #define CCA4758_R_DSO_FAILURE 103 | ||
83 | #define CCA4758_R_FAILED_LOADING_PRIVATE_KEY 104 | ||
84 | #define CCA4758_R_FAILED_LOADING_PUBLIC_KEY 105 | ||
85 | #define CCA4758_R_NOT_LOADED 106 | ||
86 | #define CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107 | ||
87 | #define CCA4758_R_UNIT_FAILURE 108 | ||
88 | #define CCA4758_R_UNKNOWN_ALGORITHM_TYPE 109 | ||
89 | |||
90 | #ifdef __cplusplus | ||
91 | } | ||
92 | #endif | ||
93 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c new file mode 100644 index 0000000000..8b8380a582 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_aep.c | |||
@@ -0,0 +1,1119 @@ | |||
1 | /* crypto/engine/hw_aep.c */ | ||
2 | /* | ||
3 | */ | ||
4 | /* ==================================================================== | ||
5 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in | ||
16 | * the documentation and/or other materials provided with the | ||
17 | * distribution. | ||
18 | * | ||
19 | * 3. All advertising materials mentioning features or use of this | ||
20 | * software must display the following acknowledgment: | ||
21 | * "This product includes software developed by the OpenSSL Project | ||
22 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
23 | * | ||
24 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
25 | * endorse or promote products derived from this software without | ||
26 | * prior written permission. For written permission, please contact | ||
27 | * licensing@OpenSSL.org. | ||
28 | * | ||
29 | * 5. Products derived from this software may not be called "OpenSSL" | ||
30 | * nor may "OpenSSL" appear in their names without prior written | ||
31 | * permission of the OpenSSL Project. | ||
32 | * | ||
33 | * 6. Redistributions of any form whatsoever must retain the following | ||
34 | * acknowledgment: | ||
35 | * "This product includes software developed by the OpenSSL Project | ||
36 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
37 | * | ||
38 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
39 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
41 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
49 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
50 | * ==================================================================== | ||
51 | * | ||
52 | * This product includes cryptographic software written by Eric Young | ||
53 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
54 | * Hudson (tjh@cryptsoft.com). | ||
55 | * | ||
56 | */ | ||
57 | |||
58 | #include <stdio.h> | ||
59 | #include <openssl/bn.h> | ||
60 | #include <string.h> | ||
61 | |||
62 | #include <openssl/e_os2.h> | ||
63 | #if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__) | ||
64 | #include <sys/types.h> | ||
65 | #include <unistd.h> | ||
66 | #else | ||
67 | #include <process.h> | ||
68 | typedef int pid_t; | ||
69 | #endif | ||
70 | |||
71 | #include <openssl/crypto.h> | ||
72 | #include <openssl/dso.h> | ||
73 | #include <openssl/engine.h> | ||
74 | #include <openssl/buffer.h> | ||
75 | |||
76 | #ifndef OPENSSL_NO_HW | ||
77 | #ifndef OPENSSL_NO_HW_AEP | ||
78 | #ifdef FLAT_INC | ||
79 | #include "aep.h" | ||
80 | #else | ||
81 | #include "vendor_defns/aep.h" | ||
82 | #endif | ||
83 | |||
84 | #define AEP_LIB_NAME "aep engine" | ||
85 | #define FAIL_TO_SW 0x10101010 | ||
86 | |||
87 | #include "hw_aep_err.c" | ||
88 | |||
89 | static int aep_init(ENGINE *e); | ||
90 | static int aep_finish(ENGINE *e); | ||
91 | static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
92 | static int aep_destroy(ENGINE *e); | ||
93 | |||
94 | static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection); | ||
95 | static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection); | ||
96 | static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection); | ||
97 | static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use); | ||
98 | |||
99 | /* BIGNUM stuff */ | ||
100 | static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
101 | const BIGNUM *m, BN_CTX *ctx); | ||
102 | |||
103 | static AEP_RV aep_mod_exp_crt(BIGNUM *r,const BIGNUM *a, const BIGNUM *p, | ||
104 | const BIGNUM *q, const BIGNUM *dmp1,const BIGNUM *dmq1, | ||
105 | const BIGNUM *iqmp, BN_CTX *ctx); | ||
106 | |||
107 | /* RSA stuff */ | ||
108 | #ifndef OPENSSL_NO_RSA | ||
109 | static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
110 | #endif | ||
111 | |||
112 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
113 | static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
114 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
115 | |||
116 | /* DSA stuff */ | ||
117 | #ifndef OPENSSL_NO_DSA | ||
118 | static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
119 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
120 | BN_CTX *ctx, BN_MONT_CTX *in_mont); | ||
121 | |||
122 | static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
123 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
124 | BN_MONT_CTX *m_ctx); | ||
125 | #endif | ||
126 | |||
127 | /* DH stuff */ | ||
128 | /* This function is aliased to mod_exp (with the DH and mont dropped). */ | ||
129 | #ifndef OPENSSL_NO_DH | ||
130 | static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
131 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
132 | #endif | ||
133 | |||
134 | /* rand stuff */ | ||
135 | #ifdef AEPRAND | ||
136 | static int aep_rand(unsigned char *buf, int num); | ||
137 | static int aep_rand_status(void); | ||
138 | #endif | ||
139 | |||
140 | /* Bignum conversion stuff */ | ||
141 | static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize); | ||
142 | static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, | ||
143 | unsigned char* AEP_BigNum); | ||
144 | static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize, | ||
145 | unsigned char* AEP_BigNum); | ||
146 | |||
147 | /* The definitions for control commands specific to this engine */ | ||
148 | #define AEP_CMD_SO_PATH ENGINE_CMD_BASE | ||
149 | static const ENGINE_CMD_DEFN aep_cmd_defns[] = | ||
150 | { | ||
151 | { AEP_CMD_SO_PATH, | ||
152 | "SO_PATH", | ||
153 | "Specifies the path to the 'aep' shared library", | ||
154 | ENGINE_CMD_FLAG_STRING | ||
155 | }, | ||
156 | {0, NULL, NULL, 0} | ||
157 | }; | ||
158 | |||
159 | #ifndef OPENSSL_NO_RSA | ||
160 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
161 | static RSA_METHOD aep_rsa = | ||
162 | { | ||
163 | "Aep RSA method", | ||
164 | NULL, /*rsa_pub_encrypt*/ | ||
165 | NULL, /*rsa_pub_decrypt*/ | ||
166 | NULL, /*rsa_priv_encrypt*/ | ||
167 | NULL, /*rsa_priv_encrypt*/ | ||
168 | aep_rsa_mod_exp, /*rsa_mod_exp*/ | ||
169 | aep_mod_exp_mont, /*bn_mod_exp*/ | ||
170 | NULL, /*init*/ | ||
171 | NULL, /*finish*/ | ||
172 | 0, /*flags*/ | ||
173 | NULL, /*app_data*/ | ||
174 | NULL, /*rsa_sign*/ | ||
175 | NULL /*rsa_verify*/ | ||
176 | }; | ||
177 | #endif | ||
178 | |||
179 | #ifndef OPENSSL_NO_DSA | ||
180 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
181 | static DSA_METHOD aep_dsa = | ||
182 | { | ||
183 | "Aep DSA method", | ||
184 | NULL, /* dsa_do_sign */ | ||
185 | NULL, /* dsa_sign_setup */ | ||
186 | NULL, /* dsa_do_verify */ | ||
187 | aep_dsa_mod_exp, /* dsa_mod_exp */ | ||
188 | aep_mod_exp_dsa, /* bn_mod_exp */ | ||
189 | NULL, /* init */ | ||
190 | NULL, /* finish */ | ||
191 | 0, /* flags */ | ||
192 | NULL /* app_data */ | ||
193 | }; | ||
194 | #endif | ||
195 | |||
196 | #ifndef OPENSSL_NO_DH | ||
197 | /* Our internal DH_METHOD that we provide pointers to */ | ||
198 | static DH_METHOD aep_dh = | ||
199 | { | ||
200 | "Aep DH method", | ||
201 | NULL, | ||
202 | NULL, | ||
203 | aep_mod_exp_dh, | ||
204 | NULL, | ||
205 | NULL, | ||
206 | 0, | ||
207 | NULL | ||
208 | }; | ||
209 | #endif | ||
210 | |||
211 | #ifdef AEPRAND | ||
212 | /* our internal RAND_method that we provide pointers to */ | ||
213 | static RAND_METHOD aep_random = | ||
214 | { | ||
215 | /*"AEP RAND method", */ | ||
216 | NULL, | ||
217 | aep_rand, | ||
218 | NULL, | ||
219 | NULL, | ||
220 | aep_rand, | ||
221 | aep_rand_status, | ||
222 | }; | ||
223 | #endif | ||
224 | |||
225 | /*Define an array of structures to hold connections*/ | ||
226 | static AEP_CONNECTION_ENTRY aep_app_conn_table[MAX_PROCESS_CONNECTIONS]; | ||
227 | |||
228 | /*Used to determine if this is a new process*/ | ||
229 | static pid_t recorded_pid = 0; | ||
230 | |||
231 | #ifdef AEPRAND | ||
232 | static AEP_U8 rand_block[RAND_BLK_SIZE]; | ||
233 | static AEP_U32 rand_block_bytes = 0; | ||
234 | #endif | ||
235 | |||
236 | /* Constants used when creating the ENGINE */ | ||
237 | static const char *engine_aep_id = "aep"; | ||
238 | static const char *engine_aep_name = "Aep hardware engine support"; | ||
239 | |||
240 | static int max_key_len = 2176; | ||
241 | |||
242 | |||
243 | /* This internal function is used by ENGINE_aep() and possibly by the | ||
244 | * "dynamic" ENGINE support too */ | ||
245 | static int bind_aep(ENGINE *e) | ||
246 | { | ||
247 | #ifndef OPENSSL_NO_RSA | ||
248 | const RSA_METHOD *meth1; | ||
249 | #endif | ||
250 | #ifndef OPENSSL_NO_DSA | ||
251 | const DSA_METHOD *meth2; | ||
252 | #endif | ||
253 | #ifndef OPENSSL_NO_DH | ||
254 | const DH_METHOD *meth3; | ||
255 | #endif | ||
256 | |||
257 | if(!ENGINE_set_id(e, engine_aep_id) || | ||
258 | !ENGINE_set_name(e, engine_aep_name) || | ||
259 | #ifndef OPENSSL_NO_RSA | ||
260 | !ENGINE_set_RSA(e, &aep_rsa) || | ||
261 | #endif | ||
262 | #ifndef OPENSSL_NO_DSA | ||
263 | !ENGINE_set_DSA(e, &aep_dsa) || | ||
264 | #endif | ||
265 | #ifndef OPENSSL_NO_DH | ||
266 | !ENGINE_set_DH(e, &aep_dh) || | ||
267 | #endif | ||
268 | #ifdef AEPRAND | ||
269 | !ENGINE_set_RAND(e, &aep_random) || | ||
270 | #endif | ||
271 | !ENGINE_set_init_function(e, aep_init) || | ||
272 | !ENGINE_set_destroy_function(e, aep_destroy) || | ||
273 | !ENGINE_set_finish_function(e, aep_finish) || | ||
274 | !ENGINE_set_ctrl_function(e, aep_ctrl) || | ||
275 | !ENGINE_set_cmd_defns(e, aep_cmd_defns)) | ||
276 | return 0; | ||
277 | |||
278 | #ifndef OPENSSL_NO_RSA | ||
279 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
280 | * to the aep-specific mod_exp and mod_exp_crt so we use | ||
281 | * those functions. NB: We don't use ENGINE_openssl() or | ||
282 | * anything "more generic" because something like the RSAref | ||
283 | * code may not hook properly, and if you own one of these | ||
284 | * cards then you have the right to do RSA operations on it | ||
285 | * anyway! */ | ||
286 | meth1 = RSA_PKCS1_SSLeay(); | ||
287 | aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
288 | aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
289 | aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
290 | aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
291 | #endif | ||
292 | |||
293 | |||
294 | #ifndef OPENSSL_NO_DSA | ||
295 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
296 | * bits. */ | ||
297 | meth2 = DSA_OpenSSL(); | ||
298 | aep_dsa.dsa_do_sign = meth2->dsa_do_sign; | ||
299 | aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup; | ||
300 | aep_dsa.dsa_do_verify = meth2->dsa_do_verify; | ||
301 | |||
302 | aep_dsa = *DSA_get_default_method(); | ||
303 | aep_dsa.dsa_mod_exp = aep_dsa_mod_exp; | ||
304 | aep_dsa.bn_mod_exp = aep_mod_exp_dsa; | ||
305 | #endif | ||
306 | |||
307 | #ifndef OPENSSL_NO_DH | ||
308 | /* Much the same for Diffie-Hellman */ | ||
309 | meth3 = DH_OpenSSL(); | ||
310 | aep_dh.generate_key = meth3->generate_key; | ||
311 | aep_dh.compute_key = meth3->compute_key; | ||
312 | aep_dh.bn_mod_exp = meth3->bn_mod_exp; | ||
313 | #endif | ||
314 | |||
315 | /* Ensure the aep error handling is set up */ | ||
316 | ERR_load_AEPHK_strings(); | ||
317 | |||
318 | return 1; | ||
319 | } | ||
320 | |||
321 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
322 | static int bind_helper(ENGINE *e, const char *id) | ||
323 | { | ||
324 | if(id && (strcmp(id, engine_aep_id) != 0)) | ||
325 | return 0; | ||
326 | if(!bind_aep(e)) | ||
327 | return 0; | ||
328 | return 1; | ||
329 | } | ||
330 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
331 | IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) | ||
332 | #else | ||
333 | static ENGINE *engine_aep(void) | ||
334 | { | ||
335 | ENGINE *ret = ENGINE_new(); | ||
336 | if(!ret) | ||
337 | return NULL; | ||
338 | if(!bind_aep(ret)) | ||
339 | { | ||
340 | ENGINE_free(ret); | ||
341 | return NULL; | ||
342 | } | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | void ENGINE_load_aep(void) | ||
347 | { | ||
348 | /* Copied from eng_[openssl|dyn].c */ | ||
349 | ENGINE *toadd = engine_aep(); | ||
350 | if(!toadd) return; | ||
351 | ENGINE_add(toadd); | ||
352 | ENGINE_free(toadd); | ||
353 | ERR_clear_error(); | ||
354 | } | ||
355 | #endif | ||
356 | |||
357 | /* This is a process-global DSO handle used for loading and unloading | ||
358 | * the Aep library. NB: This is only set (or unset) during an | ||
359 | * init() or finish() call (reference counts permitting) and they're | ||
360 | * operating with global locks, so this should be thread-safe | ||
361 | * implicitly. */ | ||
362 | static DSO *aep_dso = NULL; | ||
363 | |||
364 | /* These are the static string constants for the DSO file name and the function | ||
365 | * symbol names to bind to. | ||
366 | */ | ||
367 | static const char *AEP_LIBNAME = NULL; | ||
368 | static const char *get_AEP_LIBNAME(void) | ||
369 | { | ||
370 | if(AEP_LIBNAME) | ||
371 | return AEP_LIBNAME; | ||
372 | return "aep"; | ||
373 | } | ||
374 | static void free_AEP_LIBNAME(void) | ||
375 | { | ||
376 | if(AEP_LIBNAME) | ||
377 | OPENSSL_free((void*)AEP_LIBNAME); | ||
378 | AEP_LIBNAME = NULL; | ||
379 | } | ||
380 | static long set_AEP_LIBNAME(const char *name) | ||
381 | { | ||
382 | free_AEP_LIBNAME(); | ||
383 | return ((AEP_LIBNAME = BUF_strdup(name)) != NULL ? 1 : 0); | ||
384 | } | ||
385 | |||
386 | static const char *AEP_F1 = "AEP_ModExp"; | ||
387 | static const char *AEP_F2 = "AEP_ModExpCrt"; | ||
388 | #ifdef AEPRAND | ||
389 | static const char *AEP_F3 = "AEP_GenRandom"; | ||
390 | #endif | ||
391 | static const char *AEP_F4 = "AEP_Finalize"; | ||
392 | static const char *AEP_F5 = "AEP_Initialize"; | ||
393 | static const char *AEP_F6 = "AEP_OpenConnection"; | ||
394 | static const char *AEP_F7 = "AEP_SetBNCallBacks"; | ||
395 | static const char *AEP_F8 = "AEP_CloseConnection"; | ||
396 | |||
397 | /* These are the function pointers that are (un)set when the library has | ||
398 | * successfully (un)loaded. */ | ||
399 | static t_AEP_OpenConnection *p_AEP_OpenConnection = NULL; | ||
400 | static t_AEP_CloseConnection *p_AEP_CloseConnection = NULL; | ||
401 | static t_AEP_ModExp *p_AEP_ModExp = NULL; | ||
402 | static t_AEP_ModExpCrt *p_AEP_ModExpCrt = NULL; | ||
403 | #ifdef AEPRAND | ||
404 | static t_AEP_GenRandom *p_AEP_GenRandom = NULL; | ||
405 | #endif | ||
406 | static t_AEP_Initialize *p_AEP_Initialize = NULL; | ||
407 | static t_AEP_Finalize *p_AEP_Finalize = NULL; | ||
408 | static t_AEP_SetBNCallBacks *p_AEP_SetBNCallBacks = NULL; | ||
409 | |||
410 | /* (de)initialisation functions. */ | ||
411 | static int aep_init(ENGINE *e) | ||
412 | { | ||
413 | t_AEP_ModExp *p1; | ||
414 | t_AEP_ModExpCrt *p2; | ||
415 | #ifdef AEPRAND | ||
416 | t_AEP_GenRandom *p3; | ||
417 | #endif | ||
418 | t_AEP_Finalize *p4; | ||
419 | t_AEP_Initialize *p5; | ||
420 | t_AEP_OpenConnection *p6; | ||
421 | t_AEP_SetBNCallBacks *p7; | ||
422 | t_AEP_CloseConnection *p8; | ||
423 | |||
424 | int to_return = 0; | ||
425 | |||
426 | if(aep_dso != NULL) | ||
427 | { | ||
428 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED); | ||
429 | goto err; | ||
430 | } | ||
431 | /* Attempt to load libaep.so. */ | ||
432 | |||
433 | aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0); | ||
434 | |||
435 | if(aep_dso == NULL) | ||
436 | { | ||
437 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED); | ||
438 | goto err; | ||
439 | } | ||
440 | |||
441 | if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) || | ||
442 | !(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) || | ||
443 | #ifdef AEPRAND | ||
444 | !(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) || | ||
445 | #endif | ||
446 | !(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) || | ||
447 | !(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) || | ||
448 | !(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) || | ||
449 | !(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) || | ||
450 | !(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8))) | ||
451 | { | ||
452 | AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED); | ||
453 | goto err; | ||
454 | } | ||
455 | |||
456 | /* Copy the pointers */ | ||
457 | |||
458 | p_AEP_ModExp = p1; | ||
459 | p_AEP_ModExpCrt = p2; | ||
460 | #ifdef AEPRAND | ||
461 | p_AEP_GenRandom = p3; | ||
462 | #endif | ||
463 | p_AEP_Finalize = p4; | ||
464 | p_AEP_Initialize = p5; | ||
465 | p_AEP_OpenConnection = p6; | ||
466 | p_AEP_SetBNCallBacks = p7; | ||
467 | p_AEP_CloseConnection = p8; | ||
468 | |||
469 | to_return = 1; | ||
470 | |||
471 | return to_return; | ||
472 | |||
473 | err: | ||
474 | |||
475 | if(aep_dso) | ||
476 | DSO_free(aep_dso); | ||
477 | |||
478 | p_AEP_OpenConnection = NULL; | ||
479 | p_AEP_ModExp = NULL; | ||
480 | p_AEP_ModExpCrt = NULL; | ||
481 | #ifdef AEPRAND | ||
482 | p_AEP_GenRandom = NULL; | ||
483 | #endif | ||
484 | p_AEP_Initialize = NULL; | ||
485 | p_AEP_Finalize = NULL; | ||
486 | p_AEP_SetBNCallBacks = NULL; | ||
487 | p_AEP_CloseConnection = NULL; | ||
488 | |||
489 | return to_return; | ||
490 | } | ||
491 | |||
492 | /* Destructor (complements the "ENGINE_aep()" constructor) */ | ||
493 | static int aep_destroy(ENGINE *e) | ||
494 | { | ||
495 | free_AEP_LIBNAME(); | ||
496 | ERR_unload_AEPHK_strings(); | ||
497 | return 1; | ||
498 | } | ||
499 | |||
500 | static int aep_finish(ENGINE *e) | ||
501 | { | ||
502 | int to_return = 0, in_use; | ||
503 | AEP_RV rv; | ||
504 | |||
505 | if(aep_dso == NULL) | ||
506 | { | ||
507 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED); | ||
508 | goto err; | ||
509 | } | ||
510 | |||
511 | rv = aep_close_all_connections(0, &in_use); | ||
512 | if (rv != AEP_R_OK) | ||
513 | { | ||
514 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CLOSE_HANDLES_FAILED); | ||
515 | goto err; | ||
516 | } | ||
517 | if (in_use) | ||
518 | { | ||
519 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CONNECTIONS_IN_USE); | ||
520 | goto err; | ||
521 | } | ||
522 | |||
523 | rv = p_AEP_Finalize(); | ||
524 | if (rv != AEP_R_OK) | ||
525 | { | ||
526 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_FINALIZE_FAILED); | ||
527 | goto err; | ||
528 | } | ||
529 | |||
530 | if(!DSO_free(aep_dso)) | ||
531 | { | ||
532 | AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_UNIT_FAILURE); | ||
533 | goto err; | ||
534 | } | ||
535 | |||
536 | aep_dso = NULL; | ||
537 | p_AEP_CloseConnection = NULL; | ||
538 | p_AEP_OpenConnection = NULL; | ||
539 | p_AEP_ModExp = NULL; | ||
540 | p_AEP_ModExpCrt = NULL; | ||
541 | #ifdef AEPRAND | ||
542 | p_AEP_GenRandom = NULL; | ||
543 | #endif | ||
544 | p_AEP_Initialize = NULL; | ||
545 | p_AEP_Finalize = NULL; | ||
546 | p_AEP_SetBNCallBacks = NULL; | ||
547 | |||
548 | to_return = 1; | ||
549 | err: | ||
550 | return to_return; | ||
551 | } | ||
552 | |||
553 | static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
554 | { | ||
555 | int initialised = ((aep_dso == NULL) ? 0 : 1); | ||
556 | switch(cmd) | ||
557 | { | ||
558 | case AEP_CMD_SO_PATH: | ||
559 | if(p == NULL) | ||
560 | { | ||
561 | AEPHKerr(AEPHK_F_AEP_CTRL, | ||
562 | ERR_R_PASSED_NULL_PARAMETER); | ||
563 | return 0; | ||
564 | } | ||
565 | if(initialised) | ||
566 | { | ||
567 | AEPHKerr(AEPHK_F_AEP_CTRL, | ||
568 | AEPHK_R_ALREADY_LOADED); | ||
569 | return 0; | ||
570 | } | ||
571 | return set_AEP_LIBNAME((const char*)p); | ||
572 | default: | ||
573 | break; | ||
574 | } | ||
575 | AEPHKerr(AEPHK_F_AEP_CTRL,AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
576 | return 0; | ||
577 | } | ||
578 | |||
579 | static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
580 | const BIGNUM *m, BN_CTX *ctx) | ||
581 | { | ||
582 | int to_return = 0; | ||
583 | int r_len = 0; | ||
584 | AEP_CONNECTION_HNDL hConnection; | ||
585 | AEP_RV rv; | ||
586 | |||
587 | r_len = BN_num_bits(m); | ||
588 | |||
589 | /* Perform in software if modulus is too large for hardware. */ | ||
590 | |||
591 | if (r_len > max_key_len){ | ||
592 | AEPHKerr(AEPHK_F_AEP_MOD_EXP, AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
593 | return BN_mod_exp(r, a, p, m, ctx); | ||
594 | } | ||
595 | |||
596 | /*Grab a connection from the pool*/ | ||
597 | rv = aep_get_connection(&hConnection); | ||
598 | if (rv != AEP_R_OK) | ||
599 | { | ||
600 | AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_GET_HANDLE_FAILED); | ||
601 | return BN_mod_exp(r, a, p, m, ctx); | ||
602 | } | ||
603 | |||
604 | /*To the card with the mod exp*/ | ||
605 | rv = p_AEP_ModExp(hConnection,(void*)a, (void*)p,(void*)m, (void*)r,NULL); | ||
606 | |||
607 | if (rv != AEP_R_OK) | ||
608 | { | ||
609 | AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_MOD_EXP_FAILED); | ||
610 | rv = aep_close_connection(hConnection); | ||
611 | return BN_mod_exp(r, a, p, m, ctx); | ||
612 | } | ||
613 | |||
614 | /*Return the connection to the pool*/ | ||
615 | rv = aep_return_connection(hConnection); | ||
616 | if (rv != AEP_R_OK) | ||
617 | { | ||
618 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
619 | goto err; | ||
620 | } | ||
621 | |||
622 | to_return = 1; | ||
623 | err: | ||
624 | return to_return; | ||
625 | } | ||
626 | |||
627 | static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
628 | const BIGNUM *q, const BIGNUM *dmp1, | ||
629 | const BIGNUM *dmq1,const BIGNUM *iqmp, BN_CTX *ctx) | ||
630 | { | ||
631 | AEP_RV rv = AEP_R_OK; | ||
632 | AEP_CONNECTION_HNDL hConnection; | ||
633 | |||
634 | /*Grab a connection from the pool*/ | ||
635 | rv = aep_get_connection(&hConnection); | ||
636 | if (rv != AEP_R_OK) | ||
637 | { | ||
638 | AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_GET_HANDLE_FAILED); | ||
639 | return FAIL_TO_SW; | ||
640 | } | ||
641 | |||
642 | /*To the card with the mod exp*/ | ||
643 | rv = p_AEP_ModExpCrt(hConnection,(void*)a, (void*)p, (void*)q, (void*)dmp1,(void*)dmq1, | ||
644 | (void*)iqmp,(void*)r,NULL); | ||
645 | if (rv != AEP_R_OK) | ||
646 | { | ||
647 | AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_MOD_EXP_CRT_FAILED); | ||
648 | rv = aep_close_connection(hConnection); | ||
649 | return FAIL_TO_SW; | ||
650 | } | ||
651 | |||
652 | /*Return the connection to the pool*/ | ||
653 | rv = aep_return_connection(hConnection); | ||
654 | if (rv != AEP_R_OK) | ||
655 | { | ||
656 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
657 | goto err; | ||
658 | } | ||
659 | |||
660 | err: | ||
661 | return rv; | ||
662 | } | ||
663 | |||
664 | |||
665 | #ifdef AEPRAND | ||
666 | static int aep_rand(unsigned char *buf,int len ) | ||
667 | { | ||
668 | AEP_RV rv = AEP_R_OK; | ||
669 | AEP_CONNECTION_HNDL hConnection; | ||
670 | |||
671 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
672 | |||
673 | /*Can the request be serviced with what's already in the buffer?*/ | ||
674 | if (len <= rand_block_bytes) | ||
675 | { | ||
676 | memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len); | ||
677 | rand_block_bytes -= len; | ||
678 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
679 | } | ||
680 | else | ||
681 | /*If not the get another block of random bytes*/ | ||
682 | { | ||
683 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
684 | |||
685 | rv = aep_get_connection(&hConnection); | ||
686 | if (rv != AEP_R_OK) | ||
687 | { | ||
688 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_HANDLE_FAILED); | ||
689 | goto err_nounlock; | ||
690 | } | ||
691 | |||
692 | if (len > RAND_BLK_SIZE) | ||
693 | { | ||
694 | rv = p_AEP_GenRandom(hConnection, len, 2, buf, NULL); | ||
695 | if (rv != AEP_R_OK) | ||
696 | { | ||
697 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED); | ||
698 | goto err_nounlock; | ||
699 | } | ||
700 | } | ||
701 | else | ||
702 | { | ||
703 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | ||
704 | |||
705 | rv = p_AEP_GenRandom(hConnection, RAND_BLK_SIZE, 2, &rand_block[0], NULL); | ||
706 | if (rv != AEP_R_OK) | ||
707 | { | ||
708 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED); | ||
709 | |||
710 | goto err; | ||
711 | } | ||
712 | |||
713 | rand_block_bytes = RAND_BLK_SIZE; | ||
714 | |||
715 | memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len); | ||
716 | rand_block_bytes -= len; | ||
717 | |||
718 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
719 | } | ||
720 | |||
721 | rv = aep_return_connection(hConnection); | ||
722 | if (rv != AEP_R_OK) | ||
723 | { | ||
724 | AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED); | ||
725 | |||
726 | goto err_nounlock; | ||
727 | } | ||
728 | } | ||
729 | |||
730 | return 1; | ||
731 | err: | ||
732 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | ||
733 | err_nounlock: | ||
734 | return 0; | ||
735 | } | ||
736 | |||
737 | static int aep_rand_status(void) | ||
738 | { | ||
739 | return 1; | ||
740 | } | ||
741 | #endif | ||
742 | |||
743 | #ifndef OPENSSL_NO_RSA | ||
744 | static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
745 | { | ||
746 | BN_CTX *ctx = NULL; | ||
747 | int to_return = 0; | ||
748 | AEP_RV rv = AEP_R_OK; | ||
749 | |||
750 | if ((ctx = BN_CTX_new()) == NULL) | ||
751 | goto err; | ||
752 | |||
753 | if (!aep_dso) | ||
754 | { | ||
755 | AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED); | ||
756 | goto err; | ||
757 | } | ||
758 | |||
759 | /*See if we have all the necessary bits for a crt*/ | ||
760 | if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp) | ||
761 | { | ||
762 | rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx); | ||
763 | |||
764 | if (rv == FAIL_TO_SW){ | ||
765 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
766 | to_return = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
767 | goto err; | ||
768 | } | ||
769 | else if (rv != AEP_R_OK) | ||
770 | goto err; | ||
771 | } | ||
772 | else | ||
773 | { | ||
774 | if (!rsa->d || !rsa->n) | ||
775 | { | ||
776 | AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS); | ||
777 | goto err; | ||
778 | } | ||
779 | |||
780 | rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx); | ||
781 | if (rv != AEP_R_OK) | ||
782 | goto err; | ||
783 | |||
784 | } | ||
785 | |||
786 | to_return = 1; | ||
787 | |||
788 | err: | ||
789 | if(ctx) | ||
790 | BN_CTX_free(ctx); | ||
791 | return to_return; | ||
792 | } | ||
793 | #endif | ||
794 | |||
795 | #ifndef OPENSSL_NO_DSA | ||
796 | static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
797 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
798 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
799 | { | ||
800 | BIGNUM t; | ||
801 | int to_return = 0; | ||
802 | BN_init(&t); | ||
803 | |||
804 | /* let rr = a1 ^ p1 mod m */ | ||
805 | if (!aep_mod_exp(rr,a1,p1,m,ctx)) goto end; | ||
806 | /* let t = a2 ^ p2 mod m */ | ||
807 | if (!aep_mod_exp(&t,a2,p2,m,ctx)) goto end; | ||
808 | /* let rr = rr * t mod m */ | ||
809 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
810 | to_return = 1; | ||
811 | end: | ||
812 | BN_free(&t); | ||
813 | return to_return; | ||
814 | } | ||
815 | |||
816 | static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
817 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
818 | BN_MONT_CTX *m_ctx) | ||
819 | { | ||
820 | return aep_mod_exp(r, a, p, m, ctx); | ||
821 | } | ||
822 | #endif | ||
823 | |||
824 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
825 | static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
826 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
827 | { | ||
828 | return aep_mod_exp(r, a, p, m, ctx); | ||
829 | } | ||
830 | |||
831 | #ifndef OPENSSL_NO_DH | ||
832 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
833 | static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
834 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
835 | BN_MONT_CTX *m_ctx) | ||
836 | { | ||
837 | return aep_mod_exp(r, a, p, m, ctx); | ||
838 | } | ||
839 | #endif | ||
840 | |||
841 | static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection) | ||
842 | { | ||
843 | int count; | ||
844 | AEP_RV rv = AEP_R_OK; | ||
845 | |||
846 | /*Get the current process id*/ | ||
847 | pid_t curr_pid; | ||
848 | |||
849 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
850 | |||
851 | curr_pid = getpid(); | ||
852 | |||
853 | /*Check if this is the first time this is being called from the current | ||
854 | process*/ | ||
855 | if (recorded_pid != curr_pid) | ||
856 | { | ||
857 | /*Remember our pid so we can check if we're in a new process*/ | ||
858 | recorded_pid = curr_pid; | ||
859 | |||
860 | /*Call Finalize to make sure we have not inherited some data | ||
861 | from a parent process*/ | ||
862 | p_AEP_Finalize(); | ||
863 | |||
864 | /*Initialise the AEP API*/ | ||
865 | rv = p_AEP_Initialize(NULL); | ||
866 | |||
867 | if (rv != AEP_R_OK) | ||
868 | { | ||
869 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_INIT_FAILURE); | ||
870 | recorded_pid = 0; | ||
871 | goto end; | ||
872 | } | ||
873 | |||
874 | /*Set the AEP big num call back functions*/ | ||
875 | rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum, | ||
876 | &ConvertAEPBigNum); | ||
877 | |||
878 | if (rv != AEP_R_OK) | ||
879 | { | ||
880 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE); | ||
881 | recorded_pid = 0; | ||
882 | goto end; | ||
883 | } | ||
884 | |||
885 | #ifdef AEPRAND | ||
886 | /*Reset the rand byte count*/ | ||
887 | rand_block_bytes = 0; | ||
888 | #endif | ||
889 | |||
890 | /*Init the structures*/ | ||
891 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
892 | { | ||
893 | aep_app_conn_table[count].conn_state = NotConnected; | ||
894 | aep_app_conn_table[count].conn_hndl = 0; | ||
895 | } | ||
896 | |||
897 | /*Open a connection*/ | ||
898 | rv = p_AEP_OpenConnection(phConnection); | ||
899 | |||
900 | if (rv != AEP_R_OK) | ||
901 | { | ||
902 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE); | ||
903 | recorded_pid = 0; | ||
904 | goto end; | ||
905 | } | ||
906 | |||
907 | aep_app_conn_table[0].conn_state = InUse; | ||
908 | aep_app_conn_table[0].conn_hndl = *phConnection; | ||
909 | goto end; | ||
910 | } | ||
911 | /*Check the existing connections to see if we can find a free one*/ | ||
912 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
913 | { | ||
914 | if (aep_app_conn_table[count].conn_state == Connected) | ||
915 | { | ||
916 | aep_app_conn_table[count].conn_state = InUse; | ||
917 | *phConnection = aep_app_conn_table[count].conn_hndl; | ||
918 | goto end; | ||
919 | } | ||
920 | } | ||
921 | /*If no connections available, we're going to have to try | ||
922 | to open a new one*/ | ||
923 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
924 | { | ||
925 | if (aep_app_conn_table[count].conn_state == NotConnected) | ||
926 | { | ||
927 | /*Open a connection*/ | ||
928 | rv = p_AEP_OpenConnection(phConnection); | ||
929 | |||
930 | if (rv != AEP_R_OK) | ||
931 | { | ||
932 | AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE); | ||
933 | goto end; | ||
934 | } | ||
935 | |||
936 | aep_app_conn_table[count].conn_state = InUse; | ||
937 | aep_app_conn_table[count].conn_hndl = *phConnection; | ||
938 | goto end; | ||
939 | } | ||
940 | } | ||
941 | rv = AEP_R_GENERAL_ERROR; | ||
942 | end: | ||
943 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
944 | return rv; | ||
945 | } | ||
946 | |||
947 | |||
948 | static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection) | ||
949 | { | ||
950 | int count; | ||
951 | |||
952 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
953 | |||
954 | /*Find the connection item that matches this connection handle*/ | ||
955 | for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
956 | { | ||
957 | if (aep_app_conn_table[count].conn_hndl == hConnection) | ||
958 | { | ||
959 | aep_app_conn_table[count].conn_state = Connected; | ||
960 | break; | ||
961 | } | ||
962 | } | ||
963 | |||
964 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
965 | |||
966 | return AEP_R_OK; | ||
967 | } | ||
968 | |||
969 | static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection) | ||
970 | { | ||
971 | int count; | ||
972 | AEP_RV rv = AEP_R_OK; | ||
973 | |||
974 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
975 | |||
976 | /*Find the connection item that matches this connection handle*/ | ||
977 | for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
978 | { | ||
979 | if (aep_app_conn_table[count].conn_hndl == hConnection) | ||
980 | { | ||
981 | rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl); | ||
982 | if (rv != AEP_R_OK) | ||
983 | goto end; | ||
984 | aep_app_conn_table[count].conn_state = NotConnected; | ||
985 | aep_app_conn_table[count].conn_hndl = 0; | ||
986 | break; | ||
987 | } | ||
988 | } | ||
989 | |||
990 | end: | ||
991 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
992 | return rv; | ||
993 | } | ||
994 | |||
995 | static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use) | ||
996 | { | ||
997 | int count; | ||
998 | AEP_RV rv = AEP_R_OK; | ||
999 | |||
1000 | *in_use = 0; | ||
1001 | if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
1002 | for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++) | ||
1003 | { | ||
1004 | switch (aep_app_conn_table[count].conn_state) | ||
1005 | { | ||
1006 | case Connected: | ||
1007 | rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl); | ||
1008 | if (rv != AEP_R_OK) | ||
1009 | goto end; | ||
1010 | aep_app_conn_table[count].conn_state = NotConnected; | ||
1011 | aep_app_conn_table[count].conn_hndl = 0; | ||
1012 | break; | ||
1013 | case InUse: | ||
1014 | (*in_use)++; | ||
1015 | break; | ||
1016 | case NotConnected: | ||
1017 | break; | ||
1018 | } | ||
1019 | } | ||
1020 | end: | ||
1021 | if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
1022 | return rv; | ||
1023 | } | ||
1024 | |||
1025 | /*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums. | ||
1026 | Note only 32bit Openssl build support*/ | ||
1027 | |||
1028 | static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize) | ||
1029 | { | ||
1030 | BIGNUM* bn; | ||
1031 | |||
1032 | /*Cast the ArbBigNum pointer to our BIGNUM struct*/ | ||
1033 | bn = (BIGNUM*) ArbBigNum; | ||
1034 | |||
1035 | #ifdef SIXTY_FOUR_BIT_LONG | ||
1036 | *BigNumSize = bn->top << 3; | ||
1037 | #else | ||
1038 | /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit | ||
1039 | words) multiplies by 4*/ | ||
1040 | *BigNumSize = bn->top << 2; | ||
1041 | #endif | ||
1042 | |||
1043 | return AEP_R_OK; | ||
1044 | } | ||
1045 | |||
1046 | static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize, | ||
1047 | unsigned char* AEP_BigNum) | ||
1048 | { | ||
1049 | BIGNUM* bn; | ||
1050 | |||
1051 | #ifndef SIXTY_FOUR_BIT_LONG | ||
1052 | unsigned char* buf; | ||
1053 | int i; | ||
1054 | #endif | ||
1055 | |||
1056 | /*Cast the ArbBigNum pointer to our BIGNUM struct*/ | ||
1057 | bn = (BIGNUM*) ArbBigNum; | ||
1058 | |||
1059 | #ifdef SIXTY_FOUR_BIT_LONG | ||
1060 | memcpy(AEP_BigNum, bn->d, BigNumSize); | ||
1061 | #else | ||
1062 | /*Must copy data into a (monotone) least significant byte first format | ||
1063 | performing endian conversion if necessary*/ | ||
1064 | for(i=0;i<bn->top;i++) | ||
1065 | { | ||
1066 | buf = (unsigned char*)&bn->d[i]; | ||
1067 | |||
1068 | *((AEP_U32*)AEP_BigNum) = (AEP_U32) | ||
1069 | ((unsigned) buf[1] << 8 | buf[0]) | | ||
1070 | ((unsigned) buf[3] << 8 | buf[2]) << 16; | ||
1071 | |||
1072 | AEP_BigNum += 4; | ||
1073 | } | ||
1074 | #endif | ||
1075 | |||
1076 | return AEP_R_OK; | ||
1077 | } | ||
1078 | |||
1079 | /*Turn an AEP Big Num back to a user big num*/ | ||
1080 | static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize, | ||
1081 | unsigned char* AEP_BigNum) | ||
1082 | { | ||
1083 | BIGNUM* bn; | ||
1084 | #ifndef SIXTY_FOUR_BIT_LONG | ||
1085 | int i; | ||
1086 | #endif | ||
1087 | |||
1088 | bn = (BIGNUM*)ArbBigNum; | ||
1089 | |||
1090 | /*Expand the result bn so that it can hold our big num. | ||
1091 | Size is in bits*/ | ||
1092 | bn_expand(bn, (int)(BigNumSize << 3)); | ||
1093 | |||
1094 | #ifdef SIXTY_FOUR_BIT_LONG | ||
1095 | bn->top = BigNumSize >> 3; | ||
1096 | |||
1097 | if((BigNumSize & 7) != 0) | ||
1098 | bn->top++; | ||
1099 | |||
1100 | memset(bn->d, 0, bn->top << 3); | ||
1101 | |||
1102 | memcpy(bn->d, AEP_BigNum, BigNumSize); | ||
1103 | #else | ||
1104 | bn->top = BigNumSize >> 2; | ||
1105 | |||
1106 | for(i=0;i<bn->top;i++) | ||
1107 | { | ||
1108 | bn->d[i] = (AEP_U32) | ||
1109 | ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 | | ||
1110 | ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]); | ||
1111 | AEP_BigNum += 4; | ||
1112 | } | ||
1113 | #endif | ||
1114 | |||
1115 | return AEP_R_OK; | ||
1116 | } | ||
1117 | |||
1118 | #endif /* !OPENSSL_NO_HW_AEP */ | ||
1119 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_aep_err.c b/src/lib/libcrypto/engine/hw_aep_err.c new file mode 100644 index 0000000000..092f532946 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_aep_err.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* hw_aep_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_aep_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA AEPHK_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"}, | ||
70 | {ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"}, | ||
71 | {ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"}, | ||
72 | {ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"}, | ||
73 | {ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"}, | ||
74 | {ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"}, | ||
75 | {ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"}, | ||
76 | {ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"}, | ||
77 | {0,NULL} | ||
78 | }; | ||
79 | |||
80 | static ERR_STRING_DATA AEPHK_str_reasons[]= | ||
81 | { | ||
82 | {AEPHK_R_ALREADY_LOADED ,"already loaded"}, | ||
83 | {AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"}, | ||
84 | {AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"}, | ||
85 | {AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
86 | {AEPHK_R_FINALIZE_FAILED ,"finalize failed"}, | ||
87 | {AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"}, | ||
88 | {AEPHK_R_GET_RANDOM_FAILED ,"get random failed"}, | ||
89 | {AEPHK_R_INIT_FAILURE ,"init failure"}, | ||
90 | {AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
91 | {AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"}, | ||
92 | {AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"}, | ||
93 | {AEPHK_R_NOT_LOADED ,"not loaded"}, | ||
94 | {AEPHK_R_OK ,"ok"}, | ||
95 | {AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"}, | ||
96 | {AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"}, | ||
97 | {AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
98 | {AEPHK_R_UNIT_FAILURE ,"unit failure"}, | ||
99 | {0,NULL} | ||
100 | }; | ||
101 | |||
102 | #endif | ||
103 | |||
104 | #ifdef AEPHK_LIB_NAME | ||
105 | static ERR_STRING_DATA AEPHK_lib_name[]= | ||
106 | { | ||
107 | {0 ,AEPHK_LIB_NAME}, | ||
108 | {0,NULL} | ||
109 | }; | ||
110 | #endif | ||
111 | |||
112 | |||
113 | static int AEPHK_lib_error_code=0; | ||
114 | static int AEPHK_error_init=1; | ||
115 | |||
116 | static void ERR_load_AEPHK_strings(void) | ||
117 | { | ||
118 | if (AEPHK_lib_error_code == 0) | ||
119 | AEPHK_lib_error_code=ERR_get_next_error_library(); | ||
120 | |||
121 | if (AEPHK_error_init) | ||
122 | { | ||
123 | AEPHK_error_init=0; | ||
124 | #ifndef OPENSSL_NO_ERR | ||
125 | ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs); | ||
126 | ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons); | ||
127 | #endif | ||
128 | |||
129 | #ifdef AEPHK_LIB_NAME | ||
130 | AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0); | ||
131 | ERR_load_strings(0,AEPHK_lib_name); | ||
132 | #endif | ||
133 | } | ||
134 | } | ||
135 | |||
136 | static void ERR_unload_AEPHK_strings(void) | ||
137 | { | ||
138 | if (AEPHK_error_init == 0) | ||
139 | { | ||
140 | #ifndef OPENSSL_NO_ERR | ||
141 | ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs); | ||
142 | ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons); | ||
143 | #endif | ||
144 | |||
145 | #ifdef AEPHK_LIB_NAME | ||
146 | ERR_unload_strings(0,AEPHK_lib_name); | ||
147 | #endif | ||
148 | AEPHK_error_init=1; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | static void ERR_AEPHK_error(int function, int reason, char *file, int line) | ||
153 | { | ||
154 | if (AEPHK_lib_error_code == 0) | ||
155 | AEPHK_lib_error_code=ERR_get_next_error_library(); | ||
156 | ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line); | ||
157 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_aep_err.h b/src/lib/libcrypto/engine/hw_aep_err.h new file mode 100644 index 0000000000..8fe4cf921f --- /dev/null +++ b/src/lib/libcrypto/engine/hw_aep_err.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /* ==================================================================== | ||
2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in | ||
13 | * the documentation and/or other materials provided with the | ||
14 | * distribution. | ||
15 | * | ||
16 | * 3. All advertising materials mentioning features or use of this | ||
17 | * software must display the following acknowledgment: | ||
18 | * "This product includes software developed by the OpenSSL Project | ||
19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
20 | * | ||
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
22 | * endorse or promote products derived from this software without | ||
23 | * prior written permission. For written permission, please contact | ||
24 | * openssl-core@openssl.org. | ||
25 | * | ||
26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
27 | * nor may "OpenSSL" appear in their names without prior written | ||
28 | * permission of the OpenSSL Project. | ||
29 | * | ||
30 | * 6. Redistributions of any form whatsoever must retain the following | ||
31 | * acknowledgment: | ||
32 | * "This product includes software developed by the OpenSSL Project | ||
33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
34 | * | ||
35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
47 | * ==================================================================== | ||
48 | * | ||
49 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_AEPHK_ERR_H | ||
56 | #define HEADER_AEPHK_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_AEPHK_strings(void); | ||
63 | static void ERR_unload_AEPHK_strings(void); | ||
64 | static void ERR_AEPHK_error(int function, int reason, char *file, int line); | ||
65 | #define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the AEPHK functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define AEPHK_F_AEP_CTRL 100 | ||
71 | #define AEPHK_F_AEP_FINISH 101 | ||
72 | #define AEPHK_F_AEP_GET_CONNECTION 102 | ||
73 | #define AEPHK_F_AEP_INIT 103 | ||
74 | #define AEPHK_F_AEP_MOD_EXP 104 | ||
75 | #define AEPHK_F_AEP_MOD_EXP_CRT 105 | ||
76 | #define AEPHK_F_AEP_RAND 106 | ||
77 | #define AEPHK_F_AEP_RSA_MOD_EXP 107 | ||
78 | |||
79 | /* Reason codes. */ | ||
80 | #define AEPHK_R_ALREADY_LOADED 100 | ||
81 | #define AEPHK_R_CLOSE_HANDLES_FAILED 101 | ||
82 | #define AEPHK_R_CONNECTIONS_IN_USE 102 | ||
83 | #define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103 | ||
84 | #define AEPHK_R_FINALIZE_FAILED 104 | ||
85 | #define AEPHK_R_GET_HANDLE_FAILED 105 | ||
86 | #define AEPHK_R_GET_RANDOM_FAILED 106 | ||
87 | #define AEPHK_R_INIT_FAILURE 107 | ||
88 | #define AEPHK_R_MISSING_KEY_COMPONENTS 108 | ||
89 | #define AEPHK_R_MOD_EXP_CRT_FAILED 109 | ||
90 | #define AEPHK_R_MOD_EXP_FAILED 110 | ||
91 | #define AEPHK_R_NOT_LOADED 111 | ||
92 | #define AEPHK_R_OK 112 | ||
93 | #define AEPHK_R_RETURN_CONNECTION_FAILED 113 | ||
94 | #define AEPHK_R_SETBNCALLBACK_FAILURE 114 | ||
95 | #define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116 | ||
96 | #define AEPHK_R_UNIT_FAILURE 115 | ||
97 | |||
98 | #ifdef __cplusplus | ||
99 | } | ||
100 | #endif | ||
101 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libcrypto/engine/hw_atalla.c new file mode 100644 index 0000000000..e9eff9fad1 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_atalla.c | |||
@@ -0,0 +1,594 @@ | |||
1 | /* crypto/engine/hw_atalla.c */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-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 <stdio.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/dso.h> | ||
63 | #include <openssl/engine.h> | ||
64 | |||
65 | #ifndef OPENSSL_NO_HW | ||
66 | #ifndef OPENSSL_NO_HW_ATALLA | ||
67 | |||
68 | #ifdef FLAT_INC | ||
69 | #include "atalla.h" | ||
70 | #else | ||
71 | #include "vendor_defns/atalla.h" | ||
72 | #endif | ||
73 | |||
74 | #define ATALLA_LIB_NAME "atalla engine" | ||
75 | #include "hw_atalla_err.c" | ||
76 | |||
77 | static int atalla_destroy(ENGINE *e); | ||
78 | static int atalla_init(ENGINE *e); | ||
79 | static int atalla_finish(ENGINE *e); | ||
80 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
81 | |||
82 | /* BIGNUM stuff */ | ||
83 | static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
84 | const BIGNUM *m, BN_CTX *ctx); | ||
85 | |||
86 | #ifndef OPENSSL_NO_RSA | ||
87 | /* RSA stuff */ | ||
88 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
89 | #endif | ||
90 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
91 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
92 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
93 | |||
94 | #ifndef OPENSSL_NO_DSA | ||
95 | /* DSA stuff */ | ||
96 | static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
97 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
98 | BN_CTX *ctx, BN_MONT_CTX *in_mont); | ||
99 | static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
100 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
101 | BN_MONT_CTX *m_ctx); | ||
102 | #endif | ||
103 | |||
104 | #ifndef OPENSSL_NO_DH | ||
105 | /* DH stuff */ | ||
106 | /* This function is alised to mod_exp (with the DH and mont dropped). */ | ||
107 | static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
108 | const BIGNUM *a, const BIGNUM *p, | ||
109 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
110 | #endif | ||
111 | |||
112 | /* The definitions for control commands specific to this engine */ | ||
113 | #define ATALLA_CMD_SO_PATH ENGINE_CMD_BASE | ||
114 | static const ENGINE_CMD_DEFN atalla_cmd_defns[] = { | ||
115 | {ATALLA_CMD_SO_PATH, | ||
116 | "SO_PATH", | ||
117 | "Specifies the path to the 'atasi' shared library", | ||
118 | ENGINE_CMD_FLAG_STRING}, | ||
119 | {0, NULL, NULL, 0} | ||
120 | }; | ||
121 | |||
122 | #ifndef OPENSSL_NO_RSA | ||
123 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
124 | static RSA_METHOD atalla_rsa = | ||
125 | { | ||
126 | "Atalla RSA method", | ||
127 | NULL, | ||
128 | NULL, | ||
129 | NULL, | ||
130 | NULL, | ||
131 | atalla_rsa_mod_exp, | ||
132 | atalla_mod_exp_mont, | ||
133 | NULL, | ||
134 | NULL, | ||
135 | 0, | ||
136 | NULL, | ||
137 | NULL, | ||
138 | NULL | ||
139 | }; | ||
140 | #endif | ||
141 | |||
142 | #ifndef OPENSSL_NO_DSA | ||
143 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
144 | static DSA_METHOD atalla_dsa = | ||
145 | { | ||
146 | "Atalla DSA method", | ||
147 | NULL, /* dsa_do_sign */ | ||
148 | NULL, /* dsa_sign_setup */ | ||
149 | NULL, /* dsa_do_verify */ | ||
150 | atalla_dsa_mod_exp, /* dsa_mod_exp */ | ||
151 | atalla_mod_exp_dsa, /* bn_mod_exp */ | ||
152 | NULL, /* init */ | ||
153 | NULL, /* finish */ | ||
154 | 0, /* flags */ | ||
155 | NULL /* app_data */ | ||
156 | }; | ||
157 | #endif | ||
158 | |||
159 | #ifndef OPENSSL_NO_DH | ||
160 | /* Our internal DH_METHOD that we provide pointers to */ | ||
161 | static DH_METHOD atalla_dh = | ||
162 | { | ||
163 | "Atalla DH method", | ||
164 | NULL, | ||
165 | NULL, | ||
166 | atalla_mod_exp_dh, | ||
167 | NULL, | ||
168 | NULL, | ||
169 | 0, | ||
170 | NULL | ||
171 | }; | ||
172 | #endif | ||
173 | |||
174 | /* Constants used when creating the ENGINE */ | ||
175 | static const char *engine_atalla_id = "atalla"; | ||
176 | static const char *engine_atalla_name = "Atalla hardware engine support"; | ||
177 | |||
178 | /* This internal function is used by ENGINE_atalla() and possibly by the | ||
179 | * "dynamic" ENGINE support too */ | ||
180 | static int bind_helper(ENGINE *e) | ||
181 | { | ||
182 | #ifndef OPENSSL_NO_RSA | ||
183 | const RSA_METHOD *meth1; | ||
184 | #endif | ||
185 | #ifndef OPENSSL_NO_DSA | ||
186 | const DSA_METHOD *meth2; | ||
187 | #endif | ||
188 | #ifndef OPENSSL_NO_DH | ||
189 | const DH_METHOD *meth3; | ||
190 | #endif | ||
191 | if(!ENGINE_set_id(e, engine_atalla_id) || | ||
192 | !ENGINE_set_name(e, engine_atalla_name) || | ||
193 | #ifndef OPENSSL_NO_RSA | ||
194 | !ENGINE_set_RSA(e, &atalla_rsa) || | ||
195 | #endif | ||
196 | #ifndef OPENSSL_NO_DSA | ||
197 | !ENGINE_set_DSA(e, &atalla_dsa) || | ||
198 | #endif | ||
199 | #ifndef OPENSSL_NO_DH | ||
200 | !ENGINE_set_DH(e, &atalla_dh) || | ||
201 | #endif | ||
202 | !ENGINE_set_destroy_function(e, atalla_destroy) || | ||
203 | !ENGINE_set_init_function(e, atalla_init) || | ||
204 | !ENGINE_set_finish_function(e, atalla_finish) || | ||
205 | !ENGINE_set_ctrl_function(e, atalla_ctrl) || | ||
206 | !ENGINE_set_cmd_defns(e, atalla_cmd_defns)) | ||
207 | return 0; | ||
208 | |||
209 | #ifndef OPENSSL_NO_RSA | ||
210 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
211 | * to the atalla-specific mod_exp and mod_exp_crt so we use | ||
212 | * those functions. NB: We don't use ENGINE_openssl() or | ||
213 | * anything "more generic" because something like the RSAref | ||
214 | * code may not hook properly, and if you own one of these | ||
215 | * cards then you have the right to do RSA operations on it | ||
216 | * anyway! */ | ||
217 | meth1 = RSA_PKCS1_SSLeay(); | ||
218 | atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
219 | atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
220 | atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
221 | atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
222 | #endif | ||
223 | |||
224 | #ifndef OPENSSL_NO_DSA | ||
225 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
226 | * bits. */ | ||
227 | meth2 = DSA_OpenSSL(); | ||
228 | atalla_dsa.dsa_do_sign = meth2->dsa_do_sign; | ||
229 | atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup; | ||
230 | atalla_dsa.dsa_do_verify = meth2->dsa_do_verify; | ||
231 | #endif | ||
232 | |||
233 | #ifndef OPENSSL_NO_DH | ||
234 | /* Much the same for Diffie-Hellman */ | ||
235 | meth3 = DH_OpenSSL(); | ||
236 | atalla_dh.generate_key = meth3->generate_key; | ||
237 | atalla_dh.compute_key = meth3->compute_key; | ||
238 | #endif | ||
239 | |||
240 | /* Ensure the atalla error handling is set up */ | ||
241 | ERR_load_ATALLA_strings(); | ||
242 | return 1; | ||
243 | } | ||
244 | |||
245 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
246 | static ENGINE *engine_atalla(void) | ||
247 | { | ||
248 | ENGINE *ret = ENGINE_new(); | ||
249 | if(!ret) | ||
250 | return NULL; | ||
251 | if(!bind_helper(ret)) | ||
252 | { | ||
253 | ENGINE_free(ret); | ||
254 | return NULL; | ||
255 | } | ||
256 | return ret; | ||
257 | } | ||
258 | |||
259 | void ENGINE_load_atalla(void) | ||
260 | { | ||
261 | /* Copied from eng_[openssl|dyn].c */ | ||
262 | ENGINE *toadd = engine_atalla(); | ||
263 | if(!toadd) return; | ||
264 | ENGINE_add(toadd); | ||
265 | ENGINE_free(toadd); | ||
266 | ERR_clear_error(); | ||
267 | } | ||
268 | #endif | ||
269 | |||
270 | /* This is a process-global DSO handle used for loading and unloading | ||
271 | * the Atalla library. NB: This is only set (or unset) during an | ||
272 | * init() or finish() call (reference counts permitting) and they're | ||
273 | * operating with global locks, so this should be thread-safe | ||
274 | * implicitly. */ | ||
275 | static DSO *atalla_dso = NULL; | ||
276 | |||
277 | /* These are the function pointers that are (un)set when the library has | ||
278 | * successfully (un)loaded. */ | ||
279 | static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL; | ||
280 | static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL; | ||
281 | static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL; | ||
282 | |||
283 | /* These are the static string constants for the DSO file name and the function | ||
284 | * symbol names to bind to. Regrettably, the DSO name on *nix appears to be | ||
285 | * "atasi.so" rather than something more consistent like "libatasi.so". At the | ||
286 | * time of writing, I'm not sure what the file name on win32 is but clearly | ||
287 | * native name translation is not possible (eg libatasi.so on *nix, and | ||
288 | * atasi.dll on win32). For the purposes of testing, I have created a symbollic | ||
289 | * link called "libatasi.so" so that we can use native name-translation - a | ||
290 | * better solution will be needed. */ | ||
291 | static const char *ATALLA_LIBNAME = NULL; | ||
292 | static const char *get_ATALLA_LIBNAME(void) | ||
293 | { | ||
294 | if(ATALLA_LIBNAME) | ||
295 | return ATALLA_LIBNAME; | ||
296 | return "atasi"; | ||
297 | } | ||
298 | static void free_ATALLA_LIBNAME(void) | ||
299 | { | ||
300 | if(ATALLA_LIBNAME) | ||
301 | OPENSSL_free((void*)ATALLA_LIBNAME); | ||
302 | ATALLA_LIBNAME = NULL; | ||
303 | } | ||
304 | static long set_ATALLA_LIBNAME(const char *name) | ||
305 | { | ||
306 | free_ATALLA_LIBNAME(); | ||
307 | return (((ATALLA_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
308 | } | ||
309 | static const char *ATALLA_F1 = "ASI_GetHardwareConfig"; | ||
310 | static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn"; | ||
311 | static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics"; | ||
312 | |||
313 | /* Destructor (complements the "ENGINE_atalla()" constructor) */ | ||
314 | static int atalla_destroy(ENGINE *e) | ||
315 | { | ||
316 | free_ATALLA_LIBNAME(); | ||
317 | /* Unload the atalla error strings so any error state including our | ||
318 | * functs or reasons won't lead to a segfault (they simply get displayed | ||
319 | * without corresponding string data because none will be found). */ | ||
320 | ERR_unload_ATALLA_strings(); | ||
321 | return 1; | ||
322 | } | ||
323 | |||
324 | /* (de)initialisation functions. */ | ||
325 | static int atalla_init(ENGINE *e) | ||
326 | { | ||
327 | tfnASI_GetHardwareConfig *p1; | ||
328 | tfnASI_RSAPrivateKeyOpFn *p2; | ||
329 | tfnASI_GetPerformanceStatistics *p3; | ||
330 | /* Not sure of the origin of this magic value, but Ben's code had it | ||
331 | * and it seemed to have been working for a few people. :-) */ | ||
332 | unsigned int config_buf[1024]; | ||
333 | |||
334 | if(atalla_dso != NULL) | ||
335 | { | ||
336 | ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_ALREADY_LOADED); | ||
337 | goto err; | ||
338 | } | ||
339 | /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be | ||
340 | * changed unfortunately because the Atalla drivers don't have | ||
341 | * standard library names that can be platform-translated well. */ | ||
342 | /* TODO: Work out how to actually map to the names the Atalla | ||
343 | * drivers really use - for now a symbollic link needs to be | ||
344 | * created on the host system from libatasi.so to atasi.so on | ||
345 | * unix variants. */ | ||
346 | atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0); | ||
347 | if(atalla_dso == NULL) | ||
348 | { | ||
349 | ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED); | ||
350 | goto err; | ||
351 | } | ||
352 | if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func( | ||
353 | atalla_dso, ATALLA_F1)) || | ||
354 | !(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func( | ||
355 | atalla_dso, ATALLA_F2)) || | ||
356 | !(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func( | ||
357 | atalla_dso, ATALLA_F3))) | ||
358 | { | ||
359 | ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED); | ||
360 | goto err; | ||
361 | } | ||
362 | /* Copy the pointers */ | ||
363 | p_Atalla_GetHardwareConfig = p1; | ||
364 | p_Atalla_RSAPrivateKeyOpFn = p2; | ||
365 | p_Atalla_GetPerformanceStatistics = p3; | ||
366 | /* Perform a basic test to see if there's actually any unit | ||
367 | * running. */ | ||
368 | if(p1(0L, config_buf) != 0) | ||
369 | { | ||
370 | ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_UNIT_FAILURE); | ||
371 | goto err; | ||
372 | } | ||
373 | /* Everything's fine. */ | ||
374 | return 1; | ||
375 | err: | ||
376 | if(atalla_dso) | ||
377 | DSO_free(atalla_dso); | ||
378 | p_Atalla_GetHardwareConfig = NULL; | ||
379 | p_Atalla_RSAPrivateKeyOpFn = NULL; | ||
380 | p_Atalla_GetPerformanceStatistics = NULL; | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static int atalla_finish(ENGINE *e) | ||
385 | { | ||
386 | free_ATALLA_LIBNAME(); | ||
387 | if(atalla_dso == NULL) | ||
388 | { | ||
389 | ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED); | ||
390 | return 0; | ||
391 | } | ||
392 | if(!DSO_free(atalla_dso)) | ||
393 | { | ||
394 | ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_UNIT_FAILURE); | ||
395 | return 0; | ||
396 | } | ||
397 | atalla_dso = NULL; | ||
398 | p_Atalla_GetHardwareConfig = NULL; | ||
399 | p_Atalla_RSAPrivateKeyOpFn = NULL; | ||
400 | p_Atalla_GetPerformanceStatistics = NULL; | ||
401 | return 1; | ||
402 | } | ||
403 | |||
404 | static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
405 | { | ||
406 | int initialised = ((atalla_dso == NULL) ? 0 : 1); | ||
407 | switch(cmd) | ||
408 | { | ||
409 | case ATALLA_CMD_SO_PATH: | ||
410 | if(p == NULL) | ||
411 | { | ||
412 | ATALLAerr(ATALLA_F_ATALLA_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
413 | return 0; | ||
414 | } | ||
415 | if(initialised) | ||
416 | { | ||
417 | ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_ALREADY_LOADED); | ||
418 | return 0; | ||
419 | } | ||
420 | return set_ATALLA_LIBNAME((const char *)p); | ||
421 | default: | ||
422 | break; | ||
423 | } | ||
424 | ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
429 | const BIGNUM *m, BN_CTX *ctx) | ||
430 | { | ||
431 | /* I need somewhere to store temporary serialised values for | ||
432 | * use with the Atalla API calls. A neat cheat - I'll use | ||
433 | * BIGNUMs from the BN_CTX but access their arrays directly as | ||
434 | * byte arrays <grin>. This way I don't have to clean anything | ||
435 | * up. */ | ||
436 | BIGNUM *modulus; | ||
437 | BIGNUM *exponent; | ||
438 | BIGNUM *argument; | ||
439 | BIGNUM *result; | ||
440 | RSAPrivateKey keydata; | ||
441 | int to_return, numbytes; | ||
442 | |||
443 | modulus = exponent = argument = result = NULL; | ||
444 | to_return = 0; /* expect failure */ | ||
445 | |||
446 | if(!atalla_dso) | ||
447 | { | ||
448 | ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_NOT_LOADED); | ||
449 | goto err; | ||
450 | } | ||
451 | /* Prepare the params */ | ||
452 | BN_CTX_start(ctx); | ||
453 | modulus = BN_CTX_get(ctx); | ||
454 | exponent = BN_CTX_get(ctx); | ||
455 | argument = BN_CTX_get(ctx); | ||
456 | result = BN_CTX_get(ctx); | ||
457 | if (!result) | ||
458 | { | ||
459 | ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_CTX_FULL); | ||
460 | goto err; | ||
461 | } | ||
462 | if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) || | ||
463 | !bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top)) | ||
464 | { | ||
465 | ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_EXPAND_FAIL); | ||
466 | goto err; | ||
467 | } | ||
468 | /* Prepare the key-data */ | ||
469 | memset(&keydata, 0,sizeof keydata); | ||
470 | numbytes = BN_num_bytes(m); | ||
471 | memset(exponent->d, 0, numbytes); | ||
472 | memset(modulus->d, 0, numbytes); | ||
473 | BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p)); | ||
474 | BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m)); | ||
475 | keydata.privateExponent.data = (unsigned char *)exponent->d; | ||
476 | keydata.privateExponent.len = numbytes; | ||
477 | keydata.modulus.data = (unsigned char *)modulus->d; | ||
478 | keydata.modulus.len = numbytes; | ||
479 | /* Prepare the argument */ | ||
480 | memset(argument->d, 0, numbytes); | ||
481 | memset(result->d, 0, numbytes); | ||
482 | BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a)); | ||
483 | /* Perform the operation */ | ||
484 | if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d, | ||
485 | (unsigned char *)argument->d, | ||
486 | keydata.modulus.len) != 0) | ||
487 | { | ||
488 | ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_REQUEST_FAILED); | ||
489 | goto err; | ||
490 | } | ||
491 | /* Convert the response */ | ||
492 | BN_bin2bn((unsigned char *)result->d, numbytes, r); | ||
493 | to_return = 1; | ||
494 | err: | ||
495 | BN_CTX_end(ctx); | ||
496 | return to_return; | ||
497 | } | ||
498 | |||
499 | #ifndef OPENSSL_NO_RSA | ||
500 | static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
501 | { | ||
502 | BN_CTX *ctx = NULL; | ||
503 | int to_return = 0; | ||
504 | |||
505 | if(!atalla_dso) | ||
506 | { | ||
507 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED); | ||
508 | goto err; | ||
509 | } | ||
510 | if((ctx = BN_CTX_new()) == NULL) | ||
511 | goto err; | ||
512 | if(!rsa->d || !rsa->n) | ||
513 | { | ||
514 | ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS); | ||
515 | goto err; | ||
516 | } | ||
517 | to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx); | ||
518 | err: | ||
519 | if(ctx) | ||
520 | BN_CTX_free(ctx); | ||
521 | return to_return; | ||
522 | } | ||
523 | #endif | ||
524 | |||
525 | #ifndef OPENSSL_NO_DSA | ||
526 | /* This code was liberated and adapted from the commented-out code in | ||
527 | * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration | ||
528 | * (it doesn't have a CRT form for RSA), this function means that an | ||
529 | * Atalla system running with a DSA server certificate can handshake | ||
530 | * around 5 or 6 times faster/more than an equivalent system running with | ||
531 | * RSA. Just check out the "signs" statistics from the RSA and DSA parts | ||
532 | * of "openssl speed -engine atalla dsa1024 rsa1024". */ | ||
533 | static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
534 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
535 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
536 | { | ||
537 | BIGNUM t; | ||
538 | int to_return = 0; | ||
539 | |||
540 | BN_init(&t); | ||
541 | /* let rr = a1 ^ p1 mod m */ | ||
542 | if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end; | ||
543 | /* let t = a2 ^ p2 mod m */ | ||
544 | if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end; | ||
545 | /* let rr = rr * t mod m */ | ||
546 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
547 | to_return = 1; | ||
548 | end: | ||
549 | BN_free(&t); | ||
550 | return to_return; | ||
551 | } | ||
552 | |||
553 | static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
554 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
555 | BN_MONT_CTX *m_ctx) | ||
556 | { | ||
557 | return atalla_mod_exp(r, a, p, m, ctx); | ||
558 | } | ||
559 | #endif | ||
560 | |||
561 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
562 | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
563 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
564 | { | ||
565 | return atalla_mod_exp(r, a, p, m, ctx); | ||
566 | } | ||
567 | |||
568 | #ifndef OPENSSL_NO_DH | ||
569 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
570 | static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
571 | const BIGNUM *a, const BIGNUM *p, | ||
572 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
573 | { | ||
574 | return atalla_mod_exp(r, a, p, m, ctx); | ||
575 | } | ||
576 | #endif | ||
577 | |||
578 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
579 | * shared-library. */ | ||
580 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
581 | static int bind_fn(ENGINE *e, const char *id) | ||
582 | { | ||
583 | if(id && (strcmp(id, engine_atalla_id) != 0)) | ||
584 | return 0; | ||
585 | if(!bind_helper(e)) | ||
586 | return 0; | ||
587 | return 1; | ||
588 | } | ||
589 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
590 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
591 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
592 | |||
593 | #endif /* !OPENSSL_NO_HW_ATALLA */ | ||
594 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.c b/src/lib/libcrypto/engine/hw_atalla_err.c new file mode 100644 index 0000000000..1df9c4570c --- /dev/null +++ b/src/lib/libcrypto/engine/hw_atalla_err.c | |||
@@ -0,0 +1,145 @@ | |||
1 | /* hw_atalla_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_atalla_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA ATALLA_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"}, | ||
70 | {ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"}, | ||
71 | {ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"}, | ||
72 | {ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"}, | ||
73 | {ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"}, | ||
74 | {0,NULL} | ||
75 | }; | ||
76 | |||
77 | static ERR_STRING_DATA ATALLA_str_reasons[]= | ||
78 | { | ||
79 | {ATALLA_R_ALREADY_LOADED ,"already loaded"}, | ||
80 | {ATALLA_R_BN_CTX_FULL ,"bn ctx full"}, | ||
81 | {ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"}, | ||
82 | {ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
83 | {ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
84 | {ATALLA_R_NOT_LOADED ,"not loaded"}, | ||
85 | {ATALLA_R_REQUEST_FAILED ,"request failed"}, | ||
86 | {ATALLA_R_UNIT_FAILURE ,"unit failure"}, | ||
87 | {0,NULL} | ||
88 | }; | ||
89 | |||
90 | #endif | ||
91 | |||
92 | #ifdef ATALLA_LIB_NAME | ||
93 | static ERR_STRING_DATA ATALLA_lib_name[]= | ||
94 | { | ||
95 | {0 ,ATALLA_LIB_NAME}, | ||
96 | {0,NULL} | ||
97 | }; | ||
98 | #endif | ||
99 | |||
100 | |||
101 | static int ATALLA_lib_error_code=0; | ||
102 | static int ATALLA_error_init=1; | ||
103 | |||
104 | static void ERR_load_ATALLA_strings(void) | ||
105 | { | ||
106 | if (ATALLA_lib_error_code == 0) | ||
107 | ATALLA_lib_error_code=ERR_get_next_error_library(); | ||
108 | |||
109 | if (ATALLA_error_init) | ||
110 | { | ||
111 | ATALLA_error_init=0; | ||
112 | #ifndef OPENSSL_NO_ERR | ||
113 | ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs); | ||
114 | ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons); | ||
115 | #endif | ||
116 | |||
117 | #ifdef ATALLA_LIB_NAME | ||
118 | ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0); | ||
119 | ERR_load_strings(0,ATALLA_lib_name); | ||
120 | #endif | ||
121 | } | ||
122 | } | ||
123 | |||
124 | static void ERR_unload_ATALLA_strings(void) | ||
125 | { | ||
126 | if (ATALLA_error_init == 0) | ||
127 | { | ||
128 | #ifndef OPENSSL_NO_ERR | ||
129 | ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs); | ||
130 | ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons); | ||
131 | #endif | ||
132 | |||
133 | #ifdef ATALLA_LIB_NAME | ||
134 | ERR_unload_strings(0,ATALLA_lib_name); | ||
135 | #endif | ||
136 | ATALLA_error_init=1; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | static void ERR_ATALLA_error(int function, int reason, char *file, int line) | ||
141 | { | ||
142 | if (ATALLA_lib_error_code == 0) | ||
143 | ATALLA_lib_error_code=ERR_get_next_error_library(); | ||
144 | ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line); | ||
145 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.h b/src/lib/libcrypto/engine/hw_atalla_err.h new file mode 100644 index 0000000000..cdac052d8c --- /dev/null +++ b/src/lib/libcrypto/engine/hw_atalla_err.h | |||
@@ -0,0 +1,89 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_ATALLA_ERR_H | ||
56 | #define HEADER_ATALLA_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_ATALLA_strings(void); | ||
63 | static void ERR_unload_ATALLA_strings(void); | ||
64 | static void ERR_ATALLA_error(int function, int reason, char *file, int line); | ||
65 | #define ATALLAerr(f,r) ERR_ATALLA_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the ATALLA functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define ATALLA_F_ATALLA_CTRL 100 | ||
71 | #define ATALLA_F_ATALLA_FINISH 101 | ||
72 | #define ATALLA_F_ATALLA_INIT 102 | ||
73 | #define ATALLA_F_ATALLA_MOD_EXP 103 | ||
74 | #define ATALLA_F_ATALLA_RSA_MOD_EXP 104 | ||
75 | |||
76 | /* Reason codes. */ | ||
77 | #define ATALLA_R_ALREADY_LOADED 100 | ||
78 | #define ATALLA_R_BN_CTX_FULL 101 | ||
79 | #define ATALLA_R_BN_EXPAND_FAIL 102 | ||
80 | #define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED 103 | ||
81 | #define ATALLA_R_MISSING_KEY_COMPONENTS 104 | ||
82 | #define ATALLA_R_NOT_LOADED 105 | ||
83 | #define ATALLA_R_REQUEST_FAILED 106 | ||
84 | #define ATALLA_R_UNIT_FAILURE 107 | ||
85 | |||
86 | #ifdef __cplusplus | ||
87 | } | ||
88 | #endif | ||
89 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c new file mode 100644 index 0000000000..d3b186c132 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_cryptodev.c | |||
@@ -0,0 +1,1354 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002-2004 Theo de Raadt | ||
3 | * Copyright (c) 2002 Bob Beck <beck@openbsd.org> | ||
4 | * Copyright (c) 2002 Markus Friedl | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | #include <openssl/objects.h> | ||
30 | #include <openssl/engine.h> | ||
31 | #include <openssl/evp.h> | ||
32 | |||
33 | #if (defined(__unix__) || defined(unix)) && !defined(USG) | ||
34 | #include <sys/param.h> | ||
35 | # if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041) | ||
36 | # define HAVE_CRYPTODEV | ||
37 | # endif | ||
38 | # if (OpenBSD >= 200110) | ||
39 | # define HAVE_SYSLOG_R | ||
40 | # endif | ||
41 | #endif | ||
42 | |||
43 | #ifndef HAVE_CRYPTODEV | ||
44 | |||
45 | void | ||
46 | ENGINE_load_cryptodev(void) | ||
47 | { | ||
48 | /* This is a NOP on platforms without /dev/crypto */ | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | #else | ||
53 | |||
54 | #include <sys/types.h> | ||
55 | #include <crypto/cryptodev.h> | ||
56 | #include <sys/ioctl.h> | ||
57 | |||
58 | #include <errno.h> | ||
59 | #include <stdio.h> | ||
60 | #include <unistd.h> | ||
61 | #include <fcntl.h> | ||
62 | #include <stdarg.h> | ||
63 | #include <syslog.h> | ||
64 | #include <errno.h> | ||
65 | #include <string.h> | ||
66 | |||
67 | #ifdef __i386__ | ||
68 | #include <sys/sysctl.h> | ||
69 | #include <machine/cpu.h> | ||
70 | #include <machine/specialreg.h> | ||
71 | |||
72 | #include <ssl/aes.h> | ||
73 | |||
74 | static int check_viac3aes(void); | ||
75 | #endif | ||
76 | |||
77 | struct dev_crypto_state { | ||
78 | struct session_op d_sess; | ||
79 | int d_fd; | ||
80 | }; | ||
81 | |||
82 | struct dev_crypto_cipher { | ||
83 | int c_id; | ||
84 | int c_nid; | ||
85 | int c_ivmax; | ||
86 | int c_keylen; | ||
87 | }; | ||
88 | |||
89 | static u_int32_t cryptodev_asymfeat = 0; | ||
90 | |||
91 | static int get_asym_dev_crypto(void); | ||
92 | static int open_dev_crypto(void); | ||
93 | static int get_dev_crypto(void); | ||
94 | static struct dev_crypto_cipher *cipher_nid_to_cryptodev(int nid); | ||
95 | static int get_cryptodev_ciphers(const int **cnids); | ||
96 | /*static int get_cryptodev_digests(const int **cnids);*/ | ||
97 | static int cryptodev_usable_ciphers(const int **nids); | ||
98 | static int cryptodev_usable_digests(const int **nids); | ||
99 | static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
100 | const unsigned char *in, unsigned int inl); | ||
101 | static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
102 | const unsigned char *iv, int enc); | ||
103 | static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx); | ||
104 | static int cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
105 | const int **nids, int nid); | ||
106 | static int cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
107 | const int **nids, int nid); | ||
108 | static int bn2crparam(const BIGNUM *a, struct crparam *crp); | ||
109 | static int crparam2bn(struct crparam *crp, BIGNUM *a); | ||
110 | static void zapparams(struct crypt_kop *kop); | ||
111 | static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, | ||
112 | int slen, BIGNUM *s); | ||
113 | |||
114 | static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, | ||
115 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
116 | static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, | ||
117 | RSA *rsa); | ||
118 | static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
119 | static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
120 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
121 | static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
122 | BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
123 | BN_CTX *ctx, BN_MONT_CTX *mont); | ||
124 | static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, | ||
125 | int dlen, DSA *dsa); | ||
126 | static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
127 | DSA_SIG *sig, DSA *dsa); | ||
128 | static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
129 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
130 | BN_MONT_CTX *m_ctx); | ||
131 | static int cryptodev_dh_compute_key(unsigned char *key, | ||
132 | const BIGNUM *pub_key, DH *dh); | ||
133 | static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, | ||
134 | void (*f)()); | ||
135 | void ENGINE_load_cryptodev(void); | ||
136 | |||
137 | static const ENGINE_CMD_DEFN cryptodev_defns[] = { | ||
138 | { 0, NULL, NULL, 0 } | ||
139 | }; | ||
140 | |||
141 | static struct dev_crypto_cipher ciphers[] = { | ||
142 | { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, }, | ||
143 | { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, }, | ||
144 | { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, }, | ||
145 | { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, }, | ||
146 | { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, }, | ||
147 | { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, }, | ||
148 | { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, }, | ||
149 | { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, }, | ||
150 | { 0, NID_undef, 0, 0, }, | ||
151 | }; | ||
152 | |||
153 | #if 0 /* UNUSED */ | ||
154 | static struct { | ||
155 | int id; | ||
156 | int nid; | ||
157 | } digests[] = { | ||
158 | { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, }, | ||
159 | { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, }, | ||
160 | { CRYPTO_MD5_KPDK, NID_undef, }, | ||
161 | { CRYPTO_SHA1_KPDK, NID_undef, }, | ||
162 | { CRYPTO_MD5, NID_md5, }, | ||
163 | { CRYPTO_SHA1, NID_undef, }, | ||
164 | { 0, NID_undef, }, | ||
165 | }; | ||
166 | #endif | ||
167 | |||
168 | /* | ||
169 | * Return a fd if /dev/crypto seems usable, -1 otherwise. | ||
170 | */ | ||
171 | static int | ||
172 | open_dev_crypto(void) | ||
173 | { | ||
174 | static int fd = -1; | ||
175 | |||
176 | if (fd == -1) { | ||
177 | if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1) | ||
178 | return (-1); | ||
179 | /* close on exec */ | ||
180 | if (fcntl(fd, F_SETFD, 1) == -1) { | ||
181 | close(fd); | ||
182 | fd = -1; | ||
183 | return (-1); | ||
184 | } | ||
185 | } | ||
186 | return (fd); | ||
187 | } | ||
188 | |||
189 | static int | ||
190 | get_dev_crypto(void) | ||
191 | { | ||
192 | int fd, retfd; | ||
193 | |||
194 | if ((fd = open_dev_crypto()) == -1) | ||
195 | return (-1); | ||
196 | if (ioctl(fd, CRIOGET, &retfd) == -1) { | ||
197 | close(fd); | ||
198 | return (-1); | ||
199 | } | ||
200 | |||
201 | /* close on exec */ | ||
202 | if (fcntl(retfd, F_SETFD, 1) == -1) { | ||
203 | close(retfd); | ||
204 | return (-1); | ||
205 | } | ||
206 | return (retfd); | ||
207 | } | ||
208 | |||
209 | /* Caching version for asym operations */ | ||
210 | static int | ||
211 | get_asym_dev_crypto(void) | ||
212 | { | ||
213 | static int fd = -1; | ||
214 | |||
215 | if (fd == -1) | ||
216 | fd = get_dev_crypto(); | ||
217 | return fd; | ||
218 | } | ||
219 | |||
220 | /* convert libcrypto nids to cryptodev */ | ||
221 | static struct dev_crypto_cipher * | ||
222 | cipher_nid_to_cryptodev(int nid) | ||
223 | { | ||
224 | int i; | ||
225 | |||
226 | for (i = 0; ciphers[i].c_id; i++) | ||
227 | if (ciphers[i].c_nid == nid) | ||
228 | return (&ciphers[i]); | ||
229 | return (NULL); | ||
230 | } | ||
231 | |||
232 | /* | ||
233 | * Find out what ciphers /dev/crypto will let us have a session for. | ||
234 | * XXX note, that some of these openssl doesn't deal with yet! | ||
235 | * returning them here is harmless, as long as we return NULL | ||
236 | * when asked for a handler in the cryptodev_engine_ciphers routine | ||
237 | */ | ||
238 | static int | ||
239 | get_cryptodev_ciphers(const int **cnids) | ||
240 | { | ||
241 | static int nids[CRYPTO_ALGORITHM_MAX]; | ||
242 | struct session_op sess; | ||
243 | int fd, i, count = 0; | ||
244 | |||
245 | if ((fd = get_dev_crypto()) < 0) { | ||
246 | *cnids = NULL; | ||
247 | return (0); | ||
248 | } | ||
249 | memset(&sess, 0, sizeof(sess)); | ||
250 | sess.key = (caddr_t)"123456781234567812345678"; | ||
251 | |||
252 | for (i = 0; ciphers[i].c_id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
253 | if (ciphers[i].c_nid == NID_undef) | ||
254 | continue; | ||
255 | sess.cipher = ciphers[i].c_id; | ||
256 | sess.keylen = ciphers[i].c_keylen; | ||
257 | sess.mac = 0; | ||
258 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | ||
259 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | ||
260 | nids[count++] = ciphers[i].c_nid; | ||
261 | } | ||
262 | close(fd); | ||
263 | |||
264 | #if defined(__i386__) | ||
265 | /* | ||
266 | * On i386, always check for the VIA C3 AES instructions; | ||
267 | * even if /dev/crypto is disabled. | ||
268 | */ | ||
269 | if (check_viac3aes() >= 1) { | ||
270 | int have_NID_aes_128_cbc = 0; | ||
271 | int have_NID_aes_192_cbc = 0; | ||
272 | int have_NID_aes_256_cbc = 0; | ||
273 | |||
274 | for (i = 0; i < count; i++) { | ||
275 | if (nids[i] == NID_aes_128_cbc) | ||
276 | have_NID_aes_128_cbc = 1; | ||
277 | if (nids[i] == NID_aes_192_cbc) | ||
278 | have_NID_aes_192_cbc = 1; | ||
279 | if (nids[i] == NID_aes_256_cbc) | ||
280 | have_NID_aes_256_cbc = 1; | ||
281 | } | ||
282 | if (!have_NID_aes_128_cbc) | ||
283 | nids[count++] = NID_aes_128_cbc; | ||
284 | if (!have_NID_aes_192_cbc) | ||
285 | nids[count++] = NID_aes_192_cbc; | ||
286 | if (!have_NID_aes_256_cbc) | ||
287 | nids[count++] = NID_aes_256_cbc; | ||
288 | } | ||
289 | #endif | ||
290 | |||
291 | if (count > 0) | ||
292 | *cnids = nids; | ||
293 | else | ||
294 | *cnids = NULL; | ||
295 | return (count); | ||
296 | } | ||
297 | |||
298 | /* | ||
299 | * Find out what digests /dev/crypto will let us have a session for. | ||
300 | * XXX note, that some of these openssl doesn't deal with yet! | ||
301 | * returning them here is harmless, as long as we return NULL | ||
302 | * when asked for a handler in the cryptodev_engine_digests routine | ||
303 | */ | ||
304 | #if 0 /* UNUSED */ | ||
305 | static int | ||
306 | get_cryptodev_digests(const int **cnids) | ||
307 | { | ||
308 | static int nids[CRYPTO_ALGORITHM_MAX]; | ||
309 | struct session_op sess; | ||
310 | int fd, i, count = 0; | ||
311 | |||
312 | if ((fd = get_dev_crypto()) < 0) { | ||
313 | *cnids = NULL; | ||
314 | return (0); | ||
315 | } | ||
316 | memset(&sess, 0, sizeof(sess)); | ||
317 | for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) { | ||
318 | if (digests[i].nid == NID_undef) | ||
319 | continue; | ||
320 | sess.mac = digests[i].id; | ||
321 | sess.cipher = 0; | ||
322 | if (ioctl(fd, CIOCGSESSION, &sess) != -1 && | ||
323 | ioctl(fd, CIOCFSESSION, &sess.ses) != -1) | ||
324 | nids[count++] = digests[i].nid; | ||
325 | } | ||
326 | close(fd); | ||
327 | |||
328 | if (count > 0) | ||
329 | *cnids = nids; | ||
330 | else | ||
331 | *cnids = NULL; | ||
332 | return (count); | ||
333 | } | ||
334 | #endif | ||
335 | |||
336 | /* | ||
337 | * Find the useable ciphers|digests from dev/crypto - this is the first | ||
338 | * thing called by the engine init crud which determines what it | ||
339 | * can use for ciphers from this engine. We want to return | ||
340 | * only what we can do, anythine else is handled by software. | ||
341 | * | ||
342 | * If we can't initialize the device to do anything useful for | ||
343 | * any reason, we want to return a NULL array, and 0 length, | ||
344 | * which forces everything to be done is software. By putting | ||
345 | * the initalization of the device in here, we ensure we can | ||
346 | * use this engine as the default, and if for whatever reason | ||
347 | * /dev/crypto won't do what we want it will just be done in | ||
348 | * software | ||
349 | * | ||
350 | * This can (should) be greatly expanded to perhaps take into | ||
351 | * account speed of the device, and what we want to do. | ||
352 | * (although the disabling of particular alg's could be controlled | ||
353 | * by the device driver with sysctl's.) - this is where we | ||
354 | * want most of the decisions made about what we actually want | ||
355 | * to use from /dev/crypto. | ||
356 | */ | ||
357 | static int | ||
358 | cryptodev_usable_ciphers(const int **nids) | ||
359 | { | ||
360 | return (get_cryptodev_ciphers(nids)); | ||
361 | } | ||
362 | |||
363 | static int | ||
364 | cryptodev_usable_digests(const int **nids) | ||
365 | { | ||
366 | /* | ||
367 | * XXXX just disable all digests for now, because it sucks. | ||
368 | * we need a better way to decide this - i.e. I may not | ||
369 | * want digests on slow cards like hifn on fast machines, | ||
370 | * but might want them on slow or loaded machines, etc. | ||
371 | * will also want them when using crypto cards that don't | ||
372 | * suck moose gonads - would be nice to be able to decide something | ||
373 | * as reasonable default without having hackery that's card dependent. | ||
374 | * of course, the default should probably be just do everything, | ||
375 | * with perhaps a sysctl to turn algoritms off (or have them off | ||
376 | * by default) on cards that generally suck like the hifn. | ||
377 | */ | ||
378 | *nids = NULL; | ||
379 | return (0); | ||
380 | } | ||
381 | |||
382 | static int | ||
383 | cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
384 | const unsigned char *in, unsigned int inl) | ||
385 | { | ||
386 | struct crypt_op cryp; | ||
387 | struct dev_crypto_state *state = ctx->cipher_data; | ||
388 | struct session_op *sess = &state->d_sess; | ||
389 | void *iiv; | ||
390 | unsigned char save_iv[EVP_MAX_IV_LENGTH]; | ||
391 | |||
392 | if (state->d_fd < 0) | ||
393 | return (0); | ||
394 | if (!inl) | ||
395 | return (1); | ||
396 | if ((inl % ctx->cipher->block_size) != 0) | ||
397 | return (0); | ||
398 | |||
399 | memset(&cryp, 0, sizeof(cryp)); | ||
400 | |||
401 | cryp.ses = sess->ses; | ||
402 | cryp.flags = 0; | ||
403 | cryp.len = inl; | ||
404 | cryp.src = (caddr_t) in; | ||
405 | cryp.dst = (caddr_t) out; | ||
406 | cryp.mac = 0; | ||
407 | |||
408 | cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT; | ||
409 | |||
410 | if (ctx->cipher->iv_len) { | ||
411 | cryp.iv = (caddr_t) ctx->iv; | ||
412 | if (!ctx->encrypt) { | ||
413 | iiv = (void *) in + inl - ctx->cipher->iv_len; | ||
414 | memcpy(save_iv, iiv, ctx->cipher->iv_len); | ||
415 | } | ||
416 | } else | ||
417 | cryp.iv = NULL; | ||
418 | |||
419 | if (ioctl(state->d_fd, CIOCCRYPT, &cryp) == -1) { | ||
420 | /* XXX need better errror handling | ||
421 | * this can fail for a number of different reasons. | ||
422 | */ | ||
423 | return (0); | ||
424 | } | ||
425 | |||
426 | if (ctx->cipher->iv_len) { | ||
427 | if (ctx->encrypt) | ||
428 | iiv = (void *) out + inl - ctx->cipher->iv_len; | ||
429 | else | ||
430 | iiv = save_iv; | ||
431 | memcpy(ctx->iv, iiv, ctx->cipher->iv_len); | ||
432 | } | ||
433 | return (1); | ||
434 | } | ||
435 | |||
436 | static int | ||
437 | cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
438 | const unsigned char *iv, int enc) | ||
439 | { | ||
440 | struct dev_crypto_state *state = ctx->cipher_data; | ||
441 | struct session_op *sess = &state->d_sess; | ||
442 | struct dev_crypto_cipher *cipher; | ||
443 | |||
444 | if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NULL) | ||
445 | return (0); | ||
446 | |||
447 | if (ctx->cipher->iv_len > cipher->c_ivmax) | ||
448 | return (0); | ||
449 | |||
450 | if (ctx->key_len != cipher->c_keylen) | ||
451 | return (0); | ||
452 | |||
453 | memset(sess, 0, sizeof(struct session_op)); | ||
454 | |||
455 | if ((state->d_fd = get_dev_crypto()) < 0) | ||
456 | return (0); | ||
457 | |||
458 | sess->key = (unsigned char *)key; | ||
459 | sess->keylen = ctx->key_len; | ||
460 | sess->cipher = cipher->c_id; | ||
461 | |||
462 | if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) { | ||
463 | close(state->d_fd); | ||
464 | state->d_fd = -1; | ||
465 | return (0); | ||
466 | } | ||
467 | return (1); | ||
468 | } | ||
469 | |||
470 | /* | ||
471 | * free anything we allocated earlier when initting a | ||
472 | * session, and close the session. | ||
473 | */ | ||
474 | static int | ||
475 | cryptodev_cleanup(EVP_CIPHER_CTX *ctx) | ||
476 | { | ||
477 | int ret = 0; | ||
478 | struct dev_crypto_state *state = ctx->cipher_data; | ||
479 | struct session_op *sess = &state->d_sess; | ||
480 | |||
481 | if (state->d_fd < 0) | ||
482 | return (0); | ||
483 | |||
484 | /* XXX if this ioctl fails, someting's wrong. the invoker | ||
485 | * may have called us with a bogus ctx, or we could | ||
486 | * have a device that for whatever reason just doesn't | ||
487 | * want to play ball - it's not clear what's right | ||
488 | * here - should this be an error? should it just | ||
489 | * increase a counter, hmm. For right now, we return | ||
490 | * 0 - I don't believe that to be "right". we could | ||
491 | * call the gorpy openssl lib error handlers that | ||
492 | * print messages to users of the library. hmm.. | ||
493 | */ | ||
494 | |||
495 | if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) == -1) { | ||
496 | ret = 0; | ||
497 | } else { | ||
498 | ret = 1; | ||
499 | } | ||
500 | close(state->d_fd); | ||
501 | state->d_fd = -1; | ||
502 | |||
503 | return (ret); | ||
504 | } | ||
505 | |||
506 | /* | ||
507 | * libcrypto EVP stuff - this is how we get wired to EVP so the engine | ||
508 | * gets called when libcrypto requests a cipher NID. | ||
509 | */ | ||
510 | |||
511 | /* DES CBC EVP */ | ||
512 | const EVP_CIPHER cryptodev_des_cbc = { | ||
513 | NID_des_cbc, | ||
514 | 8, 8, 8, | ||
515 | EVP_CIPH_CBC_MODE, | ||
516 | cryptodev_init_key, | ||
517 | cryptodev_cipher, | ||
518 | cryptodev_cleanup, | ||
519 | sizeof(struct dev_crypto_state), | ||
520 | EVP_CIPHER_set_asn1_iv, | ||
521 | EVP_CIPHER_get_asn1_iv, | ||
522 | NULL | ||
523 | }; | ||
524 | |||
525 | /* 3DES CBC EVP */ | ||
526 | const EVP_CIPHER cryptodev_3des_cbc = { | ||
527 | NID_des_ede3_cbc, | ||
528 | 8, 24, 8, | ||
529 | EVP_CIPH_CBC_MODE, | ||
530 | cryptodev_init_key, | ||
531 | cryptodev_cipher, | ||
532 | cryptodev_cleanup, | ||
533 | sizeof(struct dev_crypto_state), | ||
534 | EVP_CIPHER_set_asn1_iv, | ||
535 | EVP_CIPHER_get_asn1_iv, | ||
536 | NULL | ||
537 | }; | ||
538 | |||
539 | const EVP_CIPHER cryptodev_bf_cbc = { | ||
540 | NID_bf_cbc, | ||
541 | 8, 16, 8, | ||
542 | EVP_CIPH_CBC_MODE, | ||
543 | cryptodev_init_key, | ||
544 | cryptodev_cipher, | ||
545 | cryptodev_cleanup, | ||
546 | sizeof(struct dev_crypto_state), | ||
547 | EVP_CIPHER_set_asn1_iv, | ||
548 | EVP_CIPHER_get_asn1_iv, | ||
549 | NULL | ||
550 | }; | ||
551 | |||
552 | const EVP_CIPHER cryptodev_cast_cbc = { | ||
553 | NID_cast5_cbc, | ||
554 | 8, 16, 8, | ||
555 | EVP_CIPH_CBC_MODE, | ||
556 | cryptodev_init_key, | ||
557 | cryptodev_cipher, | ||
558 | cryptodev_cleanup, | ||
559 | sizeof(struct dev_crypto_state), | ||
560 | EVP_CIPHER_set_asn1_iv, | ||
561 | EVP_CIPHER_get_asn1_iv, | ||
562 | NULL | ||
563 | }; | ||
564 | |||
565 | EVP_CIPHER cryptodev_aes_128_cbc = { | ||
566 | NID_aes_128_cbc, | ||
567 | 16, 16, 16, | ||
568 | EVP_CIPH_CBC_MODE, | ||
569 | cryptodev_init_key, | ||
570 | cryptodev_cipher, | ||
571 | cryptodev_cleanup, | ||
572 | sizeof(struct dev_crypto_state), | ||
573 | EVP_CIPHER_set_asn1_iv, | ||
574 | EVP_CIPHER_get_asn1_iv, | ||
575 | NULL | ||
576 | }; | ||
577 | |||
578 | EVP_CIPHER cryptodev_aes_192_cbc = { | ||
579 | NID_aes_192_cbc, | ||
580 | 16, 24, 16, | ||
581 | EVP_CIPH_CBC_MODE, | ||
582 | cryptodev_init_key, | ||
583 | cryptodev_cipher, | ||
584 | cryptodev_cleanup, | ||
585 | sizeof(struct dev_crypto_state), | ||
586 | EVP_CIPHER_set_asn1_iv, | ||
587 | EVP_CIPHER_get_asn1_iv, | ||
588 | NULL | ||
589 | }; | ||
590 | |||
591 | EVP_CIPHER cryptodev_aes_256_cbc = { | ||
592 | NID_aes_256_cbc, | ||
593 | 16, 32, 16, | ||
594 | EVP_CIPH_CBC_MODE, | ||
595 | cryptodev_init_key, | ||
596 | cryptodev_cipher, | ||
597 | cryptodev_cleanup, | ||
598 | sizeof(struct dev_crypto_state), | ||
599 | EVP_CIPHER_set_asn1_iv, | ||
600 | EVP_CIPHER_get_asn1_iv, | ||
601 | NULL | ||
602 | }; | ||
603 | |||
604 | #if defined(__i386__) | ||
605 | |||
606 | static inline void | ||
607 | viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep, | ||
608 | void *iv) | ||
609 | { | ||
610 | #ifdef notdef | ||
611 | printf("cw %x[%x %x %x %x] src %x dst %x key %x rep %x iv %x\n", | ||
612 | cw, cw[0], cw[1], cw[2], cw[3], | ||
613 | src, dst, key, rep, iv); | ||
614 | #endif | ||
615 | /* | ||
616 | * Clear bit 30 of EFLAGS. | ||
617 | */ | ||
618 | __asm __volatile("pushfl; popfl"); | ||
619 | |||
620 | /* | ||
621 | * Cannot simply place key into "b" register, since the compiler | ||
622 | * -pic mode uses that register; so instead we must dance a little. | ||
623 | */ | ||
624 | __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" : | ||
625 | : "mr" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst) | ||
626 | : "memory", "cc"); | ||
627 | } | ||
628 | |||
629 | #define ISUNALIGNED(x) ((long)(x)) & 15 | ||
630 | #define DOALIGN(v) ((void *)(((long)(v) + 15) & ~15)) | ||
631 | |||
632 | static int | ||
633 | xcrypt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
634 | const unsigned char *in, unsigned int inl) | ||
635 | { | ||
636 | unsigned char *save_iv_store[EVP_MAX_IV_LENGTH + 15]; | ||
637 | unsigned char *save_iv = DOALIGN(save_iv_store); | ||
638 | unsigned char *ivs_store[EVP_MAX_IV_LENGTH + 15]; | ||
639 | unsigned char *ivs = DOALIGN(ivs_store); | ||
640 | void *iiv, *iv = NULL, *ivp = NULL; | ||
641 | const void *usein = in; | ||
642 | void *useout = out, *spare; | ||
643 | int cws[4 + 3], *cw = DOALIGN(cws); | ||
644 | |||
645 | if (!inl) | ||
646 | return (1); | ||
647 | if ((inl % ctx->cipher->block_size) != 0) | ||
648 | return (0); | ||
649 | |||
650 | if (ISUNALIGNED(in) || ISUNALIGNED(out)) { | ||
651 | spare = malloc(inl); | ||
652 | if (spare == NULL) | ||
653 | return (0); | ||
654 | |||
655 | if (ISUNALIGNED(in)) { | ||
656 | bcopy(in, spare, inl); | ||
657 | usein = spare; | ||
658 | } | ||
659 | if (ISUNALIGNED(out)) | ||
660 | useout = spare; | ||
661 | } | ||
662 | |||
663 | cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_SW | | ||
664 | C3_CRYPT_CWLO_NORMAL; | ||
665 | cw[0] |= ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT; | ||
666 | cw[1] = cw[2] = cw[3] = 0; | ||
667 | |||
668 | switch (ctx->key_len * 8) { | ||
669 | case 128: | ||
670 | cw[0] |= C3_CRYPT_CWLO_KEY128; | ||
671 | break; | ||
672 | case 192: | ||
673 | cw[0] |= C3_CRYPT_CWLO_KEY192; | ||
674 | break; | ||
675 | case 256: | ||
676 | cw[0] |= C3_CRYPT_CWLO_KEY256; | ||
677 | break; | ||
678 | } | ||
679 | |||
680 | if (ctx->cipher->iv_len) { | ||
681 | iv = (caddr_t) ctx->iv; | ||
682 | if (!ctx->encrypt) { | ||
683 | iiv = (void *) in + inl - ctx->cipher->iv_len; | ||
684 | memcpy(save_iv, iiv, ctx->cipher->iv_len); | ||
685 | } | ||
686 | } | ||
687 | |||
688 | ivp = iv; | ||
689 | if (ISUNALIGNED(iv)) { | ||
690 | bcopy(iv, ivs, ctx->cipher->iv_len); | ||
691 | ivp = ivs; | ||
692 | } | ||
693 | |||
694 | viac3_xcrypt_cbc(cw, usein, useout, ctx->cipher_data, inl / 16, ivp); | ||
695 | |||
696 | if (ISUNALIGNED(out)) { | ||
697 | bcopy(spare, out, inl); | ||
698 | free(spare); | ||
699 | } | ||
700 | |||
701 | if (ivp == ivs) | ||
702 | bcopy(ivp, iv, ctx->cipher->iv_len); | ||
703 | |||
704 | if (ctx->cipher->iv_len) { | ||
705 | if (ctx->encrypt) | ||
706 | iiv = (void *) out + inl - ctx->cipher->iv_len; | ||
707 | else | ||
708 | iiv = save_iv; | ||
709 | memcpy(ctx->iv, iiv, ctx->cipher->iv_len); | ||
710 | } | ||
711 | return (1); | ||
712 | } | ||
713 | |||
714 | static int | ||
715 | xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
716 | const unsigned char *iv, int enc) | ||
717 | { | ||
718 | AES_KEY *k = ctx->cipher_data; | ||
719 | #ifndef AES_ASM | ||
720 | int i; | ||
721 | #endif | ||
722 | |||
723 | bzero(k, sizeof *k); | ||
724 | if (enc) | ||
725 | AES_set_encrypt_key(key, ctx->key_len * 8, k); | ||
726 | else | ||
727 | AES_set_decrypt_key(key, ctx->key_len * 8, k); | ||
728 | |||
729 | #ifndef AES_ASM | ||
730 | /* | ||
731 | * XXX Damn OpenSSL byte swaps the expanded key!! | ||
732 | * | ||
733 | * XXX But only if we're using the C implementation of AES | ||
734 | */ | ||
735 | for (i = 0; i < 4 * (AES_MAXNR + 1); i++) | ||
736 | k->rd_key[i] = htonl(k->rd_key[i]); | ||
737 | #endif | ||
738 | |||
739 | return (1); | ||
740 | } | ||
741 | |||
742 | static int | ||
743 | xcrypt_cleanup(EVP_CIPHER_CTX *ctx) | ||
744 | { | ||
745 | bzero(ctx->cipher_data, ctx->cipher->ctx_size); | ||
746 | return (1); | ||
747 | } | ||
748 | |||
749 | static int | ||
750 | check_viac3aes(void) | ||
751 | { | ||
752 | int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value; | ||
753 | size_t size = sizeof(value); | ||
754 | |||
755 | if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, | ||
756 | NULL, 0) < 0) | ||
757 | return (0); | ||
758 | if (value == 0) | ||
759 | return (0); | ||
760 | |||
761 | if (value & C3_HAS_AES) { | ||
762 | cryptodev_aes_128_cbc.init = xcrypt_init_key; | ||
763 | cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher; | ||
764 | cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup; | ||
765 | cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY); | ||
766 | |||
767 | cryptodev_aes_192_cbc.init = xcrypt_init_key; | ||
768 | cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher; | ||
769 | cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup; | ||
770 | cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY); | ||
771 | |||
772 | cryptodev_aes_256_cbc.init = xcrypt_init_key; | ||
773 | cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher; | ||
774 | cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup; | ||
775 | cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY); | ||
776 | } | ||
777 | return (value); | ||
778 | } | ||
779 | #endif /* __i386__ */ | ||
780 | |||
781 | /* | ||
782 | * Registered by the ENGINE when used to find out how to deal with | ||
783 | * a particular NID in the ENGINE. this says what we'll do at the | ||
784 | * top level - note, that list is restricted by what we answer with | ||
785 | */ | ||
786 | static int | ||
787 | cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
788 | const int **nids, int nid) | ||
789 | { | ||
790 | if (!cipher) | ||
791 | return (cryptodev_usable_ciphers(nids)); | ||
792 | |||
793 | switch (nid) { | ||
794 | case NID_des_ede3_cbc: | ||
795 | *cipher = &cryptodev_3des_cbc; | ||
796 | break; | ||
797 | case NID_des_cbc: | ||
798 | *cipher = &cryptodev_des_cbc; | ||
799 | break; | ||
800 | case NID_bf_cbc: | ||
801 | *cipher = &cryptodev_bf_cbc; | ||
802 | break; | ||
803 | case NID_cast5_cbc: | ||
804 | *cipher = &cryptodev_cast_cbc; | ||
805 | break; | ||
806 | case NID_aes_128_cbc: | ||
807 | *cipher = &cryptodev_aes_128_cbc; | ||
808 | break; | ||
809 | case NID_aes_192_cbc: | ||
810 | *cipher = &cryptodev_aes_192_cbc; | ||
811 | break; | ||
812 | case NID_aes_256_cbc: | ||
813 | *cipher = &cryptodev_aes_256_cbc; | ||
814 | break; | ||
815 | default: | ||
816 | *cipher = NULL; | ||
817 | break; | ||
818 | } | ||
819 | return (*cipher != NULL); | ||
820 | } | ||
821 | |||
822 | static int | ||
823 | cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest, | ||
824 | const int **nids, int nid) | ||
825 | { | ||
826 | if (!digest) | ||
827 | return (cryptodev_usable_digests(nids)); | ||
828 | |||
829 | switch (nid) { | ||
830 | case NID_md5: | ||
831 | *digest = NULL; /* need to make a clean md5 critter */ | ||
832 | break; | ||
833 | default: | ||
834 | *digest = NULL; | ||
835 | break; | ||
836 | } | ||
837 | return (*digest != NULL); | ||
838 | } | ||
839 | |||
840 | /* | ||
841 | * Convert a BIGNUM to the representation that /dev/crypto needs. | ||
842 | * Upon completion of use, the caller is responsible for freeing | ||
843 | * crp->crp_p. | ||
844 | */ | ||
845 | static int | ||
846 | bn2crparam(const BIGNUM *a, struct crparam *crp) | ||
847 | { | ||
848 | int i, j, k; | ||
849 | ssize_t bytes, bits; | ||
850 | u_char *b; | ||
851 | |||
852 | crp->crp_p = NULL; | ||
853 | crp->crp_nbits = 0; | ||
854 | |||
855 | bits = BN_num_bits(a); | ||
856 | bytes = (bits + 7) / 8; | ||
857 | |||
858 | b = malloc(bytes); | ||
859 | if (b == NULL) | ||
860 | return (1); | ||
861 | |||
862 | crp->crp_p = b; | ||
863 | crp->crp_nbits = bits; | ||
864 | |||
865 | for (i = 0, j = 0; i < a->top; i++) { | ||
866 | for (k = 0; k < BN_BITS2 / 8; k++) { | ||
867 | if ((j + k) >= bytes) | ||
868 | return (0); | ||
869 | b[j + k] = a->d[i] >> (k * 8); | ||
870 | } | ||
871 | j += BN_BITS2 / 8; | ||
872 | } | ||
873 | return (0); | ||
874 | } | ||
875 | |||
876 | /* Convert a /dev/crypto parameter to a BIGNUM */ | ||
877 | static int | ||
878 | crparam2bn(struct crparam *crp, BIGNUM *a) | ||
879 | { | ||
880 | u_int8_t *pd; | ||
881 | int i, bytes; | ||
882 | |||
883 | bytes = (crp->crp_nbits + 7) / 8; | ||
884 | |||
885 | if (bytes == 0) | ||
886 | return (-1); | ||
887 | |||
888 | if ((pd = (u_int8_t *) malloc(bytes)) == NULL) | ||
889 | return (-1); | ||
890 | |||
891 | for (i = 0; i < bytes; i++) | ||
892 | pd[i] = crp->crp_p[bytes - i - 1]; | ||
893 | |||
894 | BN_bin2bn(pd, bytes, a); | ||
895 | free(pd); | ||
896 | |||
897 | return (0); | ||
898 | } | ||
899 | |||
900 | static void | ||
901 | zapparams(struct crypt_kop *kop) | ||
902 | { | ||
903 | int i; | ||
904 | |||
905 | for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) { | ||
906 | if (kop->crk_param[i].crp_p) | ||
907 | free(kop->crk_param[i].crp_p); | ||
908 | kop->crk_param[i].crp_p = NULL; | ||
909 | kop->crk_param[i].crp_nbits = 0; | ||
910 | } | ||
911 | } | ||
912 | |||
913 | static int | ||
914 | cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s) | ||
915 | { | ||
916 | int fd, ret = -1; | ||
917 | |||
918 | if ((fd = get_asym_dev_crypto()) < 0) | ||
919 | return (ret); | ||
920 | |||
921 | if (r) { | ||
922 | kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char)); | ||
923 | kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8; | ||
924 | kop->crk_oparams++; | ||
925 | } | ||
926 | if (s) { | ||
927 | kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char)); | ||
928 | kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8; | ||
929 | kop->crk_oparams++; | ||
930 | } | ||
931 | |||
932 | if (ioctl(fd, CIOCKEY, kop) == 0) { | ||
933 | if (r) | ||
934 | crparam2bn(&kop->crk_param[kop->crk_iparams], r); | ||
935 | if (s) | ||
936 | crparam2bn(&kop->crk_param[kop->crk_iparams+1], s); | ||
937 | ret = 0; | ||
938 | } | ||
939 | |||
940 | return (ret); | ||
941 | } | ||
942 | |||
943 | static int | ||
944 | cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
945 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
946 | { | ||
947 | struct crypt_kop kop; | ||
948 | int ret = 1; | ||
949 | |||
950 | /* Currently, we know we can do mod exp iff we can do any | ||
951 | * asymmetric operations at all. | ||
952 | */ | ||
953 | if (cryptodev_asymfeat == 0) { | ||
954 | ret = BN_mod_exp(r, a, p, m, ctx); | ||
955 | return (ret); | ||
956 | } | ||
957 | |||
958 | memset(&kop, 0, sizeof kop); | ||
959 | kop.crk_op = CRK_MOD_EXP; | ||
960 | |||
961 | /* inputs: a^p % m */ | ||
962 | if (bn2crparam(a, &kop.crk_param[0])) | ||
963 | goto err; | ||
964 | if (bn2crparam(p, &kop.crk_param[1])) | ||
965 | goto err; | ||
966 | if (bn2crparam(m, &kop.crk_param[2])) | ||
967 | goto err; | ||
968 | kop.crk_iparams = 3; | ||
969 | |||
970 | if (cryptodev_asym(&kop, BN_num_bytes(m), r, 0, NULL) == -1) { | ||
971 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
972 | ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont); | ||
973 | } | ||
974 | err: | ||
975 | zapparams(&kop); | ||
976 | return (ret); | ||
977 | } | ||
978 | |||
979 | static int | ||
980 | cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
981 | { | ||
982 | int r; | ||
983 | BN_CTX *ctx; | ||
984 | |||
985 | ctx = BN_CTX_new(); | ||
986 | r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL); | ||
987 | BN_CTX_free(ctx); | ||
988 | return (r); | ||
989 | } | ||
990 | |||
991 | static int | ||
992 | cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
993 | { | ||
994 | struct crypt_kop kop; | ||
995 | int ret = 1; | ||
996 | |||
997 | if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) { | ||
998 | /* XXX 0 means failure?? */ | ||
999 | return (0); | ||
1000 | } | ||
1001 | |||
1002 | memset(&kop, 0, sizeof kop); | ||
1003 | kop.crk_op = CRK_MOD_EXP_CRT; | ||
1004 | /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */ | ||
1005 | if (bn2crparam(rsa->p, &kop.crk_param[0])) | ||
1006 | goto err; | ||
1007 | if (bn2crparam(rsa->q, &kop.crk_param[1])) | ||
1008 | goto err; | ||
1009 | if (bn2crparam(I, &kop.crk_param[2])) | ||
1010 | goto err; | ||
1011 | if (bn2crparam(rsa->dmp1, &kop.crk_param[3])) | ||
1012 | goto err; | ||
1013 | if (bn2crparam(rsa->dmq1, &kop.crk_param[4])) | ||
1014 | goto err; | ||
1015 | if (bn2crparam(rsa->iqmp, &kop.crk_param[5])) | ||
1016 | goto err; | ||
1017 | kop.crk_iparams = 6; | ||
1018 | |||
1019 | if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL) == -1) { | ||
1020 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
1021 | ret = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
1022 | } | ||
1023 | err: | ||
1024 | zapparams(&kop); | ||
1025 | return (ret); | ||
1026 | } | ||
1027 | |||
1028 | static RSA_METHOD cryptodev_rsa = { | ||
1029 | "cryptodev RSA method", | ||
1030 | NULL, /* rsa_pub_enc */ | ||
1031 | NULL, /* rsa_pub_dec */ | ||
1032 | NULL, /* rsa_priv_enc */ | ||
1033 | NULL, /* rsa_priv_dec */ | ||
1034 | NULL, | ||
1035 | NULL, | ||
1036 | NULL, /* init */ | ||
1037 | NULL, /* finish */ | ||
1038 | 0, /* flags */ | ||
1039 | NULL, /* app_data */ | ||
1040 | NULL, /* rsa_sign */ | ||
1041 | NULL /* rsa_verify */ | ||
1042 | }; | ||
1043 | |||
1044 | static int | ||
1045 | cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
1046 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
1047 | { | ||
1048 | return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
1049 | } | ||
1050 | |||
1051 | static int | ||
1052 | cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g, | ||
1053 | BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p, | ||
1054 | BN_CTX *ctx, BN_MONT_CTX *mont) | ||
1055 | { | ||
1056 | BIGNUM t2; | ||
1057 | int ret = 0; | ||
1058 | |||
1059 | BN_init(&t2); | ||
1060 | |||
1061 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
1062 | /* let t1 = g ^ u1 mod p */ | ||
1063 | ret = 0; | ||
1064 | |||
1065 | if (!dsa->meth->bn_mod_exp(dsa,t1,dsa->g,u1,dsa->p,ctx,mont)) | ||
1066 | goto err; | ||
1067 | |||
1068 | /* let t2 = y ^ u2 mod p */ | ||
1069 | if (!dsa->meth->bn_mod_exp(dsa,&t2,dsa->pub_key,u2,dsa->p,ctx,mont)) | ||
1070 | goto err; | ||
1071 | /* let u1 = t1 * t2 mod p */ | ||
1072 | if (!BN_mod_mul(u1,t1,&t2,dsa->p,ctx)) | ||
1073 | goto err; | ||
1074 | |||
1075 | BN_copy(t1,u1); | ||
1076 | |||
1077 | ret = 1; | ||
1078 | err: | ||
1079 | BN_free(&t2); | ||
1080 | return(ret); | ||
1081 | } | ||
1082 | |||
1083 | static DSA_SIG * | ||
1084 | cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
1085 | { | ||
1086 | struct crypt_kop kop; | ||
1087 | BIGNUM *r = NULL, *s = NULL; | ||
1088 | DSA_SIG *dsaret = NULL; | ||
1089 | |||
1090 | if ((r = BN_new()) == NULL) | ||
1091 | goto err; | ||
1092 | if ((s = BN_new()) == NULL) { | ||
1093 | BN_free(r); | ||
1094 | goto err; | ||
1095 | } | ||
1096 | |||
1097 | memset(&kop, 0, sizeof kop); | ||
1098 | kop.crk_op = CRK_DSA_SIGN; | ||
1099 | |||
1100 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */ | ||
1101 | kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
1102 | kop.crk_param[0].crp_nbits = dlen * 8; | ||
1103 | if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
1104 | goto err; | ||
1105 | if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
1106 | goto err; | ||
1107 | if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
1108 | goto err; | ||
1109 | if (bn2crparam(dsa->priv_key, &kop.crk_param[4])) | ||
1110 | goto err; | ||
1111 | kop.crk_iparams = 5; | ||
1112 | |||
1113 | if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r, | ||
1114 | BN_num_bytes(dsa->q), s) == 0) { | ||
1115 | dsaret = DSA_SIG_new(); | ||
1116 | dsaret->r = r; | ||
1117 | dsaret->s = s; | ||
1118 | } else { | ||
1119 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
1120 | BN_free(r); | ||
1121 | BN_free(s); | ||
1122 | dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa); | ||
1123 | } | ||
1124 | err: | ||
1125 | kop.crk_param[0].crp_p = NULL; | ||
1126 | zapparams(&kop); | ||
1127 | return (dsaret); | ||
1128 | } | ||
1129 | |||
1130 | static int | ||
1131 | cryptodev_dsa_verify(const unsigned char *dgst, int dlen, | ||
1132 | DSA_SIG *sig, DSA *dsa) | ||
1133 | { | ||
1134 | struct crypt_kop kop; | ||
1135 | int dsaret = 1; | ||
1136 | |||
1137 | memset(&kop, 0, sizeof kop); | ||
1138 | kop.crk_op = CRK_DSA_VERIFY; | ||
1139 | |||
1140 | /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */ | ||
1141 | kop.crk_param[0].crp_p = (caddr_t)dgst; | ||
1142 | kop.crk_param[0].crp_nbits = dlen * 8; | ||
1143 | if (bn2crparam(dsa->p, &kop.crk_param[1])) | ||
1144 | goto err; | ||
1145 | if (bn2crparam(dsa->q, &kop.crk_param[2])) | ||
1146 | goto err; | ||
1147 | if (bn2crparam(dsa->g, &kop.crk_param[3])) | ||
1148 | goto err; | ||
1149 | if (bn2crparam(dsa->pub_key, &kop.crk_param[4])) | ||
1150 | goto err; | ||
1151 | if (bn2crparam(sig->r, &kop.crk_param[5])) | ||
1152 | goto err; | ||
1153 | if (bn2crparam(sig->s, &kop.crk_param[6])) | ||
1154 | goto err; | ||
1155 | kop.crk_iparams = 7; | ||
1156 | |||
1157 | if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) { | ||
1158 | dsaret = kop.crk_status; | ||
1159 | } else { | ||
1160 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
1161 | |||
1162 | dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa); | ||
1163 | } | ||
1164 | err: | ||
1165 | kop.crk_param[0].crp_p = NULL; | ||
1166 | zapparams(&kop); | ||
1167 | return (dsaret); | ||
1168 | } | ||
1169 | |||
1170 | static DSA_METHOD cryptodev_dsa = { | ||
1171 | "cryptodev DSA method", | ||
1172 | NULL, | ||
1173 | NULL, /* dsa_sign_setup */ | ||
1174 | NULL, | ||
1175 | NULL, /* dsa_mod_exp */ | ||
1176 | NULL, | ||
1177 | NULL, /* init */ | ||
1178 | NULL, /* finish */ | ||
1179 | 0, /* flags */ | ||
1180 | NULL /* app_data */ | ||
1181 | }; | ||
1182 | |||
1183 | static int | ||
1184 | cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
1185 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
1186 | BN_MONT_CTX *m_ctx) | ||
1187 | { | ||
1188 | return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx)); | ||
1189 | } | ||
1190 | |||
1191 | static int | ||
1192 | cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) | ||
1193 | { | ||
1194 | struct crypt_kop kop; | ||
1195 | int dhret = 1; | ||
1196 | int fd, keylen; | ||
1197 | |||
1198 | if ((fd = get_asym_dev_crypto()) < 0) { | ||
1199 | const DH_METHOD *meth = DH_OpenSSL(); | ||
1200 | |||
1201 | return ((meth->compute_key)(key, pub_key, dh)); | ||
1202 | } | ||
1203 | |||
1204 | keylen = BN_num_bits(dh->p); | ||
1205 | |||
1206 | memset(&kop, 0, sizeof kop); | ||
1207 | kop.crk_op = CRK_DH_COMPUTE_KEY; | ||
1208 | |||
1209 | /* inputs: dh->priv_key pub_key dh->p key */ | ||
1210 | if (bn2crparam(dh->priv_key, &kop.crk_param[0])) | ||
1211 | goto err; | ||
1212 | if (bn2crparam(pub_key, &kop.crk_param[1])) | ||
1213 | goto err; | ||
1214 | if (bn2crparam(dh->p, &kop.crk_param[2])) | ||
1215 | goto err; | ||
1216 | kop.crk_iparams = 3; | ||
1217 | |||
1218 | kop.crk_param[3].crp_p = key; | ||
1219 | kop.crk_param[3].crp_nbits = keylen * 8; | ||
1220 | kop.crk_oparams = 1; | ||
1221 | |||
1222 | if (ioctl(fd, CIOCKEY, &kop) == -1) { | ||
1223 | const DH_METHOD *meth = DH_OpenSSL(); | ||
1224 | |||
1225 | dhret = (meth->compute_key)(key, pub_key, dh); | ||
1226 | } | ||
1227 | err: | ||
1228 | kop.crk_param[3].crp_p = NULL; | ||
1229 | zapparams(&kop); | ||
1230 | return (dhret); | ||
1231 | } | ||
1232 | |||
1233 | static DH_METHOD cryptodev_dh = { | ||
1234 | "cryptodev DH method", | ||
1235 | NULL, /* cryptodev_dh_generate_key */ | ||
1236 | NULL, | ||
1237 | NULL, | ||
1238 | NULL, | ||
1239 | NULL, | ||
1240 | 0, /* flags */ | ||
1241 | NULL /* app_data */ | ||
1242 | }; | ||
1243 | |||
1244 | /* | ||
1245 | * ctrl right now is just a wrapper that doesn't do much | ||
1246 | * but I expect we'll want some options soon. | ||
1247 | */ | ||
1248 | static int | ||
1249 | cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
1250 | { | ||
1251 | #ifdef HAVE_SYSLOG_R | ||
1252 | struct syslog_data sd = SYSLOG_DATA_INIT; | ||
1253 | #endif | ||
1254 | |||
1255 | switch (cmd) { | ||
1256 | default: | ||
1257 | #ifdef HAVE_SYSLOG_R | ||
1258 | syslog_r(LOG_ERR, &sd, | ||
1259 | "cryptodev_ctrl: unknown command %d", cmd); | ||
1260 | #else | ||
1261 | syslog(LOG_ERR, "cryptodev_ctrl: unknown command %d", cmd); | ||
1262 | #endif | ||
1263 | break; | ||
1264 | } | ||
1265 | return (1); | ||
1266 | } | ||
1267 | |||
1268 | void | ||
1269 | ENGINE_load_cryptodev(void) | ||
1270 | { | ||
1271 | ENGINE *engine = ENGINE_new(); | ||
1272 | int fd; | ||
1273 | |||
1274 | if (engine == NULL) | ||
1275 | return; | ||
1276 | if ((fd = get_dev_crypto()) < 0) { | ||
1277 | ENGINE_free(engine); | ||
1278 | return; | ||
1279 | } | ||
1280 | |||
1281 | /* | ||
1282 | * find out what asymmetric crypto algorithms we support | ||
1283 | */ | ||
1284 | if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) { | ||
1285 | close(fd); | ||
1286 | ENGINE_free(engine); | ||
1287 | return; | ||
1288 | } | ||
1289 | close(fd); | ||
1290 | |||
1291 | if (!ENGINE_set_id(engine, "cryptodev") || | ||
1292 | !ENGINE_set_name(engine, "BSD cryptodev engine") || | ||
1293 | !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) || | ||
1294 | !ENGINE_set_digests(engine, cryptodev_engine_digests) || | ||
1295 | !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) || | ||
1296 | !ENGINE_set_cmd_defns(engine, cryptodev_defns)) { | ||
1297 | ENGINE_free(engine); | ||
1298 | return; | ||
1299 | } | ||
1300 | |||
1301 | if (ENGINE_set_RSA(engine, &cryptodev_rsa)) { | ||
1302 | const RSA_METHOD *rsa_meth = RSA_PKCS1_SSLeay(); | ||
1303 | |||
1304 | cryptodev_rsa.bn_mod_exp = rsa_meth->bn_mod_exp; | ||
1305 | cryptodev_rsa.rsa_mod_exp = rsa_meth->rsa_mod_exp; | ||
1306 | cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc; | ||
1307 | cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec; | ||
1308 | cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_enc; | ||
1309 | cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec; | ||
1310 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
1311 | cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp; | ||
1312 | if (cryptodev_asymfeat & CRF_MOD_EXP_CRT) | ||
1313 | cryptodev_rsa.rsa_mod_exp = | ||
1314 | cryptodev_rsa_mod_exp; | ||
1315 | else | ||
1316 | cryptodev_rsa.rsa_mod_exp = | ||
1317 | cryptodev_rsa_nocrt_mod_exp; | ||
1318 | } | ||
1319 | } | ||
1320 | |||
1321 | if (ENGINE_set_DSA(engine, &cryptodev_dsa)) { | ||
1322 | const DSA_METHOD *meth = DSA_OpenSSL(); | ||
1323 | |||
1324 | memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD)); | ||
1325 | if (cryptodev_asymfeat & CRF_DSA_SIGN) | ||
1326 | cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign; | ||
1327 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
1328 | cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp; | ||
1329 | cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp; | ||
1330 | } | ||
1331 | if (cryptodev_asymfeat & CRF_DSA_VERIFY) | ||
1332 | cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify; | ||
1333 | } | ||
1334 | |||
1335 | if (ENGINE_set_DH(engine, &cryptodev_dh)){ | ||
1336 | const DH_METHOD *dh_meth = DH_OpenSSL(); | ||
1337 | |||
1338 | cryptodev_dh.generate_key = dh_meth->generate_key; | ||
1339 | cryptodev_dh.compute_key = dh_meth->compute_key; | ||
1340 | cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp; | ||
1341 | if (cryptodev_asymfeat & CRF_MOD_EXP) { | ||
1342 | cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh; | ||
1343 | if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY) | ||
1344 | cryptodev_dh.compute_key = | ||
1345 | cryptodev_dh_compute_key; | ||
1346 | } | ||
1347 | } | ||
1348 | |||
1349 | ENGINE_add(engine); | ||
1350 | ENGINE_free(engine); | ||
1351 | ERR_clear_error(); | ||
1352 | } | ||
1353 | |||
1354 | #endif /* HAVE_CRYPTODEV */ | ||
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c new file mode 100644 index 0000000000..f128ee5a68 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_cswift.c | |||
@@ -0,0 +1,997 @@ | |||
1 | /* crypto/engine/hw_cswift.c */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-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 <stdio.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/dso.h> | ||
63 | #include <openssl/engine.h> | ||
64 | |||
65 | #ifndef OPENSSL_NO_HW | ||
66 | #ifndef OPENSSL_NO_HW_CSWIFT | ||
67 | |||
68 | /* Attribution notice: Rainbow have generously allowed me to reproduce | ||
69 | * the necessary definitions here from their API. This means the support | ||
70 | * can build independently of whether application builders have the | ||
71 | * API or hardware. This will allow developers to easily produce software | ||
72 | * that has latent hardware support for any users that have accelerators | ||
73 | * installed, without the developers themselves needing anything extra. | ||
74 | * | ||
75 | * I have only clipped the parts from the CryptoSwift header files that | ||
76 | * are (or seem) relevant to the CryptoSwift support code. This is | ||
77 | * simply to keep the file sizes reasonable. | ||
78 | * [Geoff] | ||
79 | */ | ||
80 | #ifdef FLAT_INC | ||
81 | #include "cswift.h" | ||
82 | #else | ||
83 | #include "vendor_defns/cswift.h" | ||
84 | #endif | ||
85 | |||
86 | #define CSWIFT_LIB_NAME "cswift engine" | ||
87 | #include "hw_cswift_err.c" | ||
88 | |||
89 | static int cswift_destroy(ENGINE *e); | ||
90 | static int cswift_init(ENGINE *e); | ||
91 | static int cswift_finish(ENGINE *e); | ||
92 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
93 | |||
94 | /* BIGNUM stuff */ | ||
95 | static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
96 | const BIGNUM *m, BN_CTX *ctx); | ||
97 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
98 | const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1, | ||
99 | const BIGNUM *iqmp, BN_CTX *ctx); | ||
100 | |||
101 | #ifndef OPENSSL_NO_RSA | ||
102 | /* RSA stuff */ | ||
103 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
104 | #endif | ||
105 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
106 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
107 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
108 | |||
109 | #ifndef OPENSSL_NO_DSA | ||
110 | /* DSA stuff */ | ||
111 | static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
112 | static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
113 | DSA_SIG *sig, DSA *dsa); | ||
114 | #endif | ||
115 | |||
116 | #ifndef OPENSSL_NO_DH | ||
117 | /* DH stuff */ | ||
118 | /* This function is alised to mod_exp (with the DH and mont dropped). */ | ||
119 | static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
120 | const BIGNUM *a, const BIGNUM *p, | ||
121 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
122 | #endif | ||
123 | |||
124 | /* RAND stuff */ | ||
125 | static int cswift_rand_bytes(unsigned char *buf, int num); | ||
126 | static int cswift_rand_status(void); | ||
127 | |||
128 | /* The definitions for control commands specific to this engine */ | ||
129 | #define CSWIFT_CMD_SO_PATH ENGINE_CMD_BASE | ||
130 | static const ENGINE_CMD_DEFN cswift_cmd_defns[] = { | ||
131 | {CSWIFT_CMD_SO_PATH, | ||
132 | "SO_PATH", | ||
133 | "Specifies the path to the 'cswift' shared library", | ||
134 | ENGINE_CMD_FLAG_STRING}, | ||
135 | {0, NULL, NULL, 0} | ||
136 | }; | ||
137 | |||
138 | #ifndef OPENSSL_NO_RSA | ||
139 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
140 | static RSA_METHOD cswift_rsa = | ||
141 | { | ||
142 | "CryptoSwift RSA method", | ||
143 | NULL, | ||
144 | NULL, | ||
145 | NULL, | ||
146 | NULL, | ||
147 | cswift_rsa_mod_exp, | ||
148 | cswift_mod_exp_mont, | ||
149 | NULL, | ||
150 | NULL, | ||
151 | 0, | ||
152 | NULL, | ||
153 | NULL, | ||
154 | NULL | ||
155 | }; | ||
156 | #endif | ||
157 | |||
158 | #ifndef OPENSSL_NO_DSA | ||
159 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
160 | static DSA_METHOD cswift_dsa = | ||
161 | { | ||
162 | "CryptoSwift DSA method", | ||
163 | cswift_dsa_sign, | ||
164 | NULL, /* dsa_sign_setup */ | ||
165 | cswift_dsa_verify, | ||
166 | NULL, /* dsa_mod_exp */ | ||
167 | NULL, /* bn_mod_exp */ | ||
168 | NULL, /* init */ | ||
169 | NULL, /* finish */ | ||
170 | 0, /* flags */ | ||
171 | NULL /* app_data */ | ||
172 | }; | ||
173 | #endif | ||
174 | |||
175 | #ifndef OPENSSL_NO_DH | ||
176 | /* Our internal DH_METHOD that we provide pointers to */ | ||
177 | static DH_METHOD cswift_dh = | ||
178 | { | ||
179 | "CryptoSwift DH method", | ||
180 | NULL, | ||
181 | NULL, | ||
182 | cswift_mod_exp_dh, | ||
183 | NULL, | ||
184 | NULL, | ||
185 | 0, | ||
186 | NULL | ||
187 | }; | ||
188 | #endif | ||
189 | |||
190 | static RAND_METHOD cswift_random = | ||
191 | { | ||
192 | /* "CryptoSwift RAND method", */ | ||
193 | NULL, | ||
194 | cswift_rand_bytes, | ||
195 | NULL, | ||
196 | NULL, | ||
197 | cswift_rand_bytes, | ||
198 | cswift_rand_status, | ||
199 | }; | ||
200 | |||
201 | |||
202 | /* Constants used when creating the ENGINE */ | ||
203 | static const char *engine_cswift_id = "cswift"; | ||
204 | static const char *engine_cswift_name = "CryptoSwift hardware engine support"; | ||
205 | |||
206 | /* This internal function is used by ENGINE_cswift() and possibly by the | ||
207 | * "dynamic" ENGINE support too */ | ||
208 | static int bind_helper(ENGINE *e) | ||
209 | { | ||
210 | #ifndef OPENSSL_NO_RSA | ||
211 | const RSA_METHOD *meth1; | ||
212 | #endif | ||
213 | #ifndef OPENSSL_NO_DH | ||
214 | const DH_METHOD *meth2; | ||
215 | #endif | ||
216 | if(!ENGINE_set_id(e, engine_cswift_id) || | ||
217 | !ENGINE_set_name(e, engine_cswift_name) || | ||
218 | #ifndef OPENSSL_NO_RSA | ||
219 | !ENGINE_set_RSA(e, &cswift_rsa) || | ||
220 | #endif | ||
221 | #ifndef OPENSSL_NO_DSA | ||
222 | !ENGINE_set_DSA(e, &cswift_dsa) || | ||
223 | #endif | ||
224 | #ifndef OPENSSL_NO_DH | ||
225 | !ENGINE_set_DH(e, &cswift_dh) || | ||
226 | #endif | ||
227 | !ENGINE_set_RAND(e, &cswift_random) || | ||
228 | !ENGINE_set_destroy_function(e, cswift_destroy) || | ||
229 | !ENGINE_set_init_function(e, cswift_init) || | ||
230 | !ENGINE_set_finish_function(e, cswift_finish) || | ||
231 | !ENGINE_set_ctrl_function(e, cswift_ctrl) || | ||
232 | !ENGINE_set_cmd_defns(e, cswift_cmd_defns)) | ||
233 | return 0; | ||
234 | |||
235 | #ifndef OPENSSL_NO_RSA | ||
236 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
237 | * to the cswift-specific mod_exp and mod_exp_crt so we use | ||
238 | * those functions. NB: We don't use ENGINE_openssl() or | ||
239 | * anything "more generic" because something like the RSAref | ||
240 | * code may not hook properly, and if you own one of these | ||
241 | * cards then you have the right to do RSA operations on it | ||
242 | * anyway! */ | ||
243 | meth1 = RSA_PKCS1_SSLeay(); | ||
244 | cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
245 | cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
246 | cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
247 | cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
248 | #endif | ||
249 | |||
250 | #ifndef OPENSSL_NO_DH | ||
251 | /* Much the same for Diffie-Hellman */ | ||
252 | meth2 = DH_OpenSSL(); | ||
253 | cswift_dh.generate_key = meth2->generate_key; | ||
254 | cswift_dh.compute_key = meth2->compute_key; | ||
255 | #endif | ||
256 | |||
257 | /* Ensure the cswift error handling is set up */ | ||
258 | ERR_load_CSWIFT_strings(); | ||
259 | return 1; | ||
260 | } | ||
261 | |||
262 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
263 | static ENGINE *engine_cswift(void) | ||
264 | { | ||
265 | ENGINE *ret = ENGINE_new(); | ||
266 | if(!ret) | ||
267 | return NULL; | ||
268 | if(!bind_helper(ret)) | ||
269 | { | ||
270 | ENGINE_free(ret); | ||
271 | return NULL; | ||
272 | } | ||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | void ENGINE_load_cswift(void) | ||
277 | { | ||
278 | /* Copied from eng_[openssl|dyn].c */ | ||
279 | ENGINE *toadd = engine_cswift(); | ||
280 | if(!toadd) return; | ||
281 | ENGINE_add(toadd); | ||
282 | ENGINE_free(toadd); | ||
283 | ERR_clear_error(); | ||
284 | } | ||
285 | #endif | ||
286 | |||
287 | /* This is a process-global DSO handle used for loading and unloading | ||
288 | * the CryptoSwift library. NB: This is only set (or unset) during an | ||
289 | * init() or finish() call (reference counts permitting) and they're | ||
290 | * operating with global locks, so this should be thread-safe | ||
291 | * implicitly. */ | ||
292 | static DSO *cswift_dso = NULL; | ||
293 | |||
294 | /* These are the function pointers that are (un)set when the library has | ||
295 | * successfully (un)loaded. */ | ||
296 | t_swAcquireAccContext *p_CSwift_AcquireAccContext = NULL; | ||
297 | t_swAttachKeyParam *p_CSwift_AttachKeyParam = NULL; | ||
298 | t_swSimpleRequest *p_CSwift_SimpleRequest = NULL; | ||
299 | t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL; | ||
300 | |||
301 | /* Used in the DSO operations. */ | ||
302 | static const char *CSWIFT_LIBNAME = NULL; | ||
303 | static const char *get_CSWIFT_LIBNAME(void) | ||
304 | { | ||
305 | if(CSWIFT_LIBNAME) | ||
306 | return CSWIFT_LIBNAME; | ||
307 | return "swift"; | ||
308 | } | ||
309 | static void free_CSWIFT_LIBNAME(void) | ||
310 | { | ||
311 | if(CSWIFT_LIBNAME) | ||
312 | OPENSSL_free((void*)CSWIFT_LIBNAME); | ||
313 | CSWIFT_LIBNAME = NULL; | ||
314 | } | ||
315 | static long set_CSWIFT_LIBNAME(const char *name) | ||
316 | { | ||
317 | free_CSWIFT_LIBNAME(); | ||
318 | return (((CSWIFT_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
319 | } | ||
320 | static const char *CSWIFT_F1 = "swAcquireAccContext"; | ||
321 | static const char *CSWIFT_F2 = "swAttachKeyParam"; | ||
322 | static const char *CSWIFT_F3 = "swSimpleRequest"; | ||
323 | static const char *CSWIFT_F4 = "swReleaseAccContext"; | ||
324 | |||
325 | |||
326 | /* CryptoSwift library functions and mechanics - these are used by the | ||
327 | * higher-level functions further down. NB: As and where there's no | ||
328 | * error checking, take a look lower down where these functions are | ||
329 | * called, the checking and error handling is probably down there. */ | ||
330 | |||
331 | /* utility function to obtain a context */ | ||
332 | static int get_context(SW_CONTEXT_HANDLE *hac) | ||
333 | { | ||
334 | SW_STATUS status; | ||
335 | |||
336 | status = p_CSwift_AcquireAccContext(hac); | ||
337 | if(status != SW_OK) | ||
338 | return 0; | ||
339 | return 1; | ||
340 | } | ||
341 | |||
342 | /* similarly to release one. */ | ||
343 | static void release_context(SW_CONTEXT_HANDLE hac) | ||
344 | { | ||
345 | p_CSwift_ReleaseAccContext(hac); | ||
346 | } | ||
347 | |||
348 | /* Destructor (complements the "ENGINE_cswift()" constructor) */ | ||
349 | static int cswift_destroy(ENGINE *e) | ||
350 | { | ||
351 | free_CSWIFT_LIBNAME(); | ||
352 | ERR_unload_CSWIFT_strings(); | ||
353 | return 1; | ||
354 | } | ||
355 | |||
356 | /* (de)initialisation functions. */ | ||
357 | static int cswift_init(ENGINE *e) | ||
358 | { | ||
359 | SW_CONTEXT_HANDLE hac; | ||
360 | t_swAcquireAccContext *p1; | ||
361 | t_swAttachKeyParam *p2; | ||
362 | t_swSimpleRequest *p3; | ||
363 | t_swReleaseAccContext *p4; | ||
364 | |||
365 | if(cswift_dso != NULL) | ||
366 | { | ||
367 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_ALREADY_LOADED); | ||
368 | goto err; | ||
369 | } | ||
370 | /* Attempt to load libswift.so/swift.dll/whatever. */ | ||
371 | cswift_dso = DSO_load(NULL, get_CSWIFT_LIBNAME(), NULL, 0); | ||
372 | if(cswift_dso == NULL) | ||
373 | { | ||
374 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED); | ||
375 | goto err; | ||
376 | } | ||
377 | if(!(p1 = (t_swAcquireAccContext *) | ||
378 | DSO_bind_func(cswift_dso, CSWIFT_F1)) || | ||
379 | !(p2 = (t_swAttachKeyParam *) | ||
380 | DSO_bind_func(cswift_dso, CSWIFT_F2)) || | ||
381 | !(p3 = (t_swSimpleRequest *) | ||
382 | DSO_bind_func(cswift_dso, CSWIFT_F3)) || | ||
383 | !(p4 = (t_swReleaseAccContext *) | ||
384 | DSO_bind_func(cswift_dso, CSWIFT_F4))) | ||
385 | { | ||
386 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED); | ||
387 | goto err; | ||
388 | } | ||
389 | /* Copy the pointers */ | ||
390 | p_CSwift_AcquireAccContext = p1; | ||
391 | p_CSwift_AttachKeyParam = p2; | ||
392 | p_CSwift_SimpleRequest = p3; | ||
393 | p_CSwift_ReleaseAccContext = p4; | ||
394 | /* Try and get a context - if not, we may have a DSO but no | ||
395 | * accelerator! */ | ||
396 | if(!get_context(&hac)) | ||
397 | { | ||
398 | CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_UNIT_FAILURE); | ||
399 | goto err; | ||
400 | } | ||
401 | release_context(hac); | ||
402 | /* Everything's fine. */ | ||
403 | return 1; | ||
404 | err: | ||
405 | if(cswift_dso) | ||
406 | DSO_free(cswift_dso); | ||
407 | p_CSwift_AcquireAccContext = NULL; | ||
408 | p_CSwift_AttachKeyParam = NULL; | ||
409 | p_CSwift_SimpleRequest = NULL; | ||
410 | p_CSwift_ReleaseAccContext = NULL; | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | static int cswift_finish(ENGINE *e) | ||
415 | { | ||
416 | free_CSWIFT_LIBNAME(); | ||
417 | if(cswift_dso == NULL) | ||
418 | { | ||
419 | CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED); | ||
420 | return 0; | ||
421 | } | ||
422 | if(!DSO_free(cswift_dso)) | ||
423 | { | ||
424 | CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_UNIT_FAILURE); | ||
425 | return 0; | ||
426 | } | ||
427 | cswift_dso = NULL; | ||
428 | p_CSwift_AcquireAccContext = NULL; | ||
429 | p_CSwift_AttachKeyParam = NULL; | ||
430 | p_CSwift_SimpleRequest = NULL; | ||
431 | p_CSwift_ReleaseAccContext = NULL; | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
436 | { | ||
437 | int initialised = ((cswift_dso == NULL) ? 0 : 1); | ||
438 | switch(cmd) | ||
439 | { | ||
440 | case CSWIFT_CMD_SO_PATH: | ||
441 | if(p == NULL) | ||
442 | { | ||
443 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
444 | return 0; | ||
445 | } | ||
446 | if(initialised) | ||
447 | { | ||
448 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED); | ||
449 | return 0; | ||
450 | } | ||
451 | return set_CSWIFT_LIBNAME((const char *)p); | ||
452 | default: | ||
453 | break; | ||
454 | } | ||
455 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | /* Un petit mod_exp */ | ||
460 | static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
461 | const BIGNUM *m, BN_CTX *ctx) | ||
462 | { | ||
463 | /* I need somewhere to store temporary serialised values for | ||
464 | * use with the CryptoSwift API calls. A neat cheat - I'll use | ||
465 | * BIGNUMs from the BN_CTX but access their arrays directly as | ||
466 | * byte arrays <grin>. This way I don't have to clean anything | ||
467 | * up. */ | ||
468 | BIGNUM *modulus; | ||
469 | BIGNUM *exponent; | ||
470 | BIGNUM *argument; | ||
471 | BIGNUM *result; | ||
472 | SW_STATUS sw_status; | ||
473 | SW_LARGENUMBER arg, res; | ||
474 | SW_PARAM sw_param; | ||
475 | SW_CONTEXT_HANDLE hac; | ||
476 | int to_return, acquired; | ||
477 | |||
478 | modulus = exponent = argument = result = NULL; | ||
479 | to_return = 0; /* expect failure */ | ||
480 | acquired = 0; | ||
481 | |||
482 | if(!get_context(&hac)) | ||
483 | { | ||
484 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_UNIT_FAILURE); | ||
485 | goto err; | ||
486 | } | ||
487 | acquired = 1; | ||
488 | /* Prepare the params */ | ||
489 | BN_CTX_start(ctx); | ||
490 | modulus = BN_CTX_get(ctx); | ||
491 | exponent = BN_CTX_get(ctx); | ||
492 | argument = BN_CTX_get(ctx); | ||
493 | result = BN_CTX_get(ctx); | ||
494 | if(!result) | ||
495 | { | ||
496 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_CTX_FULL); | ||
497 | goto err; | ||
498 | } | ||
499 | if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, p->top) || | ||
500 | !bn_wexpand(argument, a->top) || !bn_wexpand(result, m->top)) | ||
501 | { | ||
502 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_EXPAND_FAIL); | ||
503 | goto err; | ||
504 | } | ||
505 | sw_param.type = SW_ALG_EXP; | ||
506 | sw_param.up.exp.modulus.nbytes = BN_bn2bin(m, | ||
507 | (unsigned char *)modulus->d); | ||
508 | sw_param.up.exp.modulus.value = (unsigned char *)modulus->d; | ||
509 | sw_param.up.exp.exponent.nbytes = BN_bn2bin(p, | ||
510 | (unsigned char *)exponent->d); | ||
511 | sw_param.up.exp.exponent.value = (unsigned char *)exponent->d; | ||
512 | /* Attach the key params */ | ||
513 | sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); | ||
514 | switch(sw_status) | ||
515 | { | ||
516 | case SW_OK: | ||
517 | break; | ||
518 | case SW_ERR_INPUT_SIZE: | ||
519 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BAD_KEY_SIZE); | ||
520 | goto err; | ||
521 | default: | ||
522 | { | ||
523 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
524 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); | ||
525 | sprintf(tmpbuf, "%ld", sw_status); | ||
526 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
527 | } | ||
528 | goto err; | ||
529 | } | ||
530 | /* Prepare the argument and response */ | ||
531 | arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d); | ||
532 | arg.value = (unsigned char *)argument->d; | ||
533 | res.nbytes = BN_num_bytes(m); | ||
534 | memset(result->d, 0, res.nbytes); | ||
535 | res.value = (unsigned char *)result->d; | ||
536 | /* Perform the operation */ | ||
537 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1, | ||
538 | &res, 1)) != SW_OK) | ||
539 | { | ||
540 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
541 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED); | ||
542 | sprintf(tmpbuf, "%ld", sw_status); | ||
543 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
544 | goto err; | ||
545 | } | ||
546 | /* Convert the response */ | ||
547 | BN_bin2bn((unsigned char *)result->d, res.nbytes, r); | ||
548 | to_return = 1; | ||
549 | err: | ||
550 | if(acquired) | ||
551 | release_context(hac); | ||
552 | BN_CTX_end(ctx); | ||
553 | return to_return; | ||
554 | } | ||
555 | |||
556 | /* Un petit mod_exp chinois */ | ||
557 | static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
558 | const BIGNUM *q, const BIGNUM *dmp1, | ||
559 | const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx) | ||
560 | { | ||
561 | SW_STATUS sw_status; | ||
562 | SW_LARGENUMBER arg, res; | ||
563 | SW_PARAM sw_param; | ||
564 | SW_CONTEXT_HANDLE hac; | ||
565 | BIGNUM *rsa_p = NULL; | ||
566 | BIGNUM *rsa_q = NULL; | ||
567 | BIGNUM *rsa_dmp1 = NULL; | ||
568 | BIGNUM *rsa_dmq1 = NULL; | ||
569 | BIGNUM *rsa_iqmp = NULL; | ||
570 | BIGNUM *argument = NULL; | ||
571 | BIGNUM *result = NULL; | ||
572 | int to_return = 0; /* expect failure */ | ||
573 | int acquired = 0; | ||
574 | |||
575 | if(!get_context(&hac)) | ||
576 | { | ||
577 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_UNIT_FAILURE); | ||
578 | goto err; | ||
579 | } | ||
580 | acquired = 1; | ||
581 | /* Prepare the params */ | ||
582 | BN_CTX_start(ctx); | ||
583 | rsa_p = BN_CTX_get(ctx); | ||
584 | rsa_q = BN_CTX_get(ctx); | ||
585 | rsa_dmp1 = BN_CTX_get(ctx); | ||
586 | rsa_dmq1 = BN_CTX_get(ctx); | ||
587 | rsa_iqmp = BN_CTX_get(ctx); | ||
588 | argument = BN_CTX_get(ctx); | ||
589 | result = BN_CTX_get(ctx); | ||
590 | if(!result) | ||
591 | { | ||
592 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL); | ||
593 | goto err; | ||
594 | } | ||
595 | if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) || | ||
596 | !bn_wexpand(rsa_dmp1, dmp1->top) || | ||
597 | !bn_wexpand(rsa_dmq1, dmq1->top) || | ||
598 | !bn_wexpand(rsa_iqmp, iqmp->top) || | ||
599 | !bn_wexpand(argument, a->top) || | ||
600 | !bn_wexpand(result, p->top + q->top)) | ||
601 | { | ||
602 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL); | ||
603 | goto err; | ||
604 | } | ||
605 | sw_param.type = SW_ALG_CRT; | ||
606 | sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d); | ||
607 | sw_param.up.crt.p.value = (unsigned char *)rsa_p->d; | ||
608 | sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d); | ||
609 | sw_param.up.crt.q.value = (unsigned char *)rsa_q->d; | ||
610 | sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1, | ||
611 | (unsigned char *)rsa_dmp1->d); | ||
612 | sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d; | ||
613 | sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1, | ||
614 | (unsigned char *)rsa_dmq1->d); | ||
615 | sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d; | ||
616 | sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp, | ||
617 | (unsigned char *)rsa_iqmp->d); | ||
618 | sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d; | ||
619 | /* Attach the key params */ | ||
620 | sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); | ||
621 | switch(sw_status) | ||
622 | { | ||
623 | case SW_OK: | ||
624 | break; | ||
625 | case SW_ERR_INPUT_SIZE: | ||
626 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BAD_KEY_SIZE); | ||
627 | goto err; | ||
628 | default: | ||
629 | { | ||
630 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
631 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); | ||
632 | sprintf(tmpbuf, "%ld", sw_status); | ||
633 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
634 | } | ||
635 | goto err; | ||
636 | } | ||
637 | /* Prepare the argument and response */ | ||
638 | arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d); | ||
639 | arg.value = (unsigned char *)argument->d; | ||
640 | res.nbytes = 2 * BN_num_bytes(p); | ||
641 | memset(result->d, 0, res.nbytes); | ||
642 | res.value = (unsigned char *)result->d; | ||
643 | /* Perform the operation */ | ||
644 | if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1, | ||
645 | &res, 1)) != SW_OK) | ||
646 | { | ||
647 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
648 | CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED); | ||
649 | sprintf(tmpbuf, "%ld", sw_status); | ||
650 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
651 | goto err; | ||
652 | } | ||
653 | /* Convert the response */ | ||
654 | BN_bin2bn((unsigned char *)result->d, res.nbytes, r); | ||
655 | to_return = 1; | ||
656 | err: | ||
657 | if(acquired) | ||
658 | release_context(hac); | ||
659 | BN_CTX_end(ctx); | ||
660 | return to_return; | ||
661 | } | ||
662 | |||
663 | #ifndef OPENSSL_NO_RSA | ||
664 | static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
665 | { | ||
666 | BN_CTX *ctx; | ||
667 | int to_return = 0; | ||
668 | |||
669 | if((ctx = BN_CTX_new()) == NULL) | ||
670 | goto err; | ||
671 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
672 | { | ||
673 | CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS); | ||
674 | goto err; | ||
675 | } | ||
676 | to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1, | ||
677 | rsa->dmq1, rsa->iqmp, ctx); | ||
678 | err: | ||
679 | if(ctx) | ||
680 | BN_CTX_free(ctx); | ||
681 | return to_return; | ||
682 | } | ||
683 | #endif | ||
684 | |||
685 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
686 | static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
687 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
688 | { | ||
689 | return cswift_mod_exp(r, a, p, m, ctx); | ||
690 | } | ||
691 | |||
692 | #ifndef OPENSSL_NO_DSA | ||
693 | static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
694 | { | ||
695 | SW_CONTEXT_HANDLE hac; | ||
696 | SW_PARAM sw_param; | ||
697 | SW_STATUS sw_status; | ||
698 | SW_LARGENUMBER arg, res; | ||
699 | unsigned char *ptr; | ||
700 | BN_CTX *ctx; | ||
701 | BIGNUM *dsa_p = NULL; | ||
702 | BIGNUM *dsa_q = NULL; | ||
703 | BIGNUM *dsa_g = NULL; | ||
704 | BIGNUM *dsa_key = NULL; | ||
705 | BIGNUM *result = NULL; | ||
706 | DSA_SIG *to_return = NULL; | ||
707 | int acquired = 0; | ||
708 | |||
709 | if((ctx = BN_CTX_new()) == NULL) | ||
710 | goto err; | ||
711 | if(!get_context(&hac)) | ||
712 | { | ||
713 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_UNIT_FAILURE); | ||
714 | goto err; | ||
715 | } | ||
716 | acquired = 1; | ||
717 | /* Prepare the params */ | ||
718 | BN_CTX_start(ctx); | ||
719 | dsa_p = BN_CTX_get(ctx); | ||
720 | dsa_q = BN_CTX_get(ctx); | ||
721 | dsa_g = BN_CTX_get(ctx); | ||
722 | dsa_key = BN_CTX_get(ctx); | ||
723 | result = BN_CTX_get(ctx); | ||
724 | if(!result) | ||
725 | { | ||
726 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_CTX_FULL); | ||
727 | goto err; | ||
728 | } | ||
729 | if(!bn_wexpand(dsa_p, dsa->p->top) || | ||
730 | !bn_wexpand(dsa_q, dsa->q->top) || | ||
731 | !bn_wexpand(dsa_g, dsa->g->top) || | ||
732 | !bn_wexpand(dsa_key, dsa->priv_key->top) || | ||
733 | !bn_wexpand(result, dsa->p->top)) | ||
734 | { | ||
735 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_EXPAND_FAIL); | ||
736 | goto err; | ||
737 | } | ||
738 | sw_param.type = SW_ALG_DSA; | ||
739 | sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p, | ||
740 | (unsigned char *)dsa_p->d); | ||
741 | sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d; | ||
742 | sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q, | ||
743 | (unsigned char *)dsa_q->d); | ||
744 | sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d; | ||
745 | sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g, | ||
746 | (unsigned char *)dsa_g->d); | ||
747 | sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d; | ||
748 | sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->priv_key, | ||
749 | (unsigned char *)dsa_key->d); | ||
750 | sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d; | ||
751 | /* Attach the key params */ | ||
752 | sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); | ||
753 | switch(sw_status) | ||
754 | { | ||
755 | case SW_OK: | ||
756 | break; | ||
757 | case SW_ERR_INPUT_SIZE: | ||
758 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BAD_KEY_SIZE); | ||
759 | goto err; | ||
760 | default: | ||
761 | { | ||
762 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
763 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); | ||
764 | sprintf(tmpbuf, "%ld", sw_status); | ||
765 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
766 | } | ||
767 | goto err; | ||
768 | } | ||
769 | /* Prepare the argument and response */ | ||
770 | arg.nbytes = dlen; | ||
771 | arg.value = (unsigned char *)dgst; | ||
772 | res.nbytes = BN_num_bytes(dsa->p); | ||
773 | memset(result->d, 0, res.nbytes); | ||
774 | res.value = (unsigned char *)result->d; | ||
775 | /* Perform the operation */ | ||
776 | sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_SIGN, &arg, 1, | ||
777 | &res, 1); | ||
778 | if(sw_status != SW_OK) | ||
779 | { | ||
780 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
781 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED); | ||
782 | sprintf(tmpbuf, "%ld", sw_status); | ||
783 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
784 | goto err; | ||
785 | } | ||
786 | /* Convert the response */ | ||
787 | ptr = (unsigned char *)result->d; | ||
788 | if((to_return = DSA_SIG_new()) == NULL) | ||
789 | goto err; | ||
790 | to_return->r = BN_bin2bn((unsigned char *)result->d, 20, NULL); | ||
791 | to_return->s = BN_bin2bn((unsigned char *)result->d + 20, 20, NULL); | ||
792 | |||
793 | err: | ||
794 | if(acquired) | ||
795 | release_context(hac); | ||
796 | if(ctx) | ||
797 | { | ||
798 | BN_CTX_end(ctx); | ||
799 | BN_CTX_free(ctx); | ||
800 | } | ||
801 | return to_return; | ||
802 | } | ||
803 | |||
804 | static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
805 | DSA_SIG *sig, DSA *dsa) | ||
806 | { | ||
807 | SW_CONTEXT_HANDLE hac; | ||
808 | SW_PARAM sw_param; | ||
809 | SW_STATUS sw_status; | ||
810 | SW_LARGENUMBER arg[2], res; | ||
811 | unsigned long sig_result; | ||
812 | BN_CTX *ctx; | ||
813 | BIGNUM *dsa_p = NULL; | ||
814 | BIGNUM *dsa_q = NULL; | ||
815 | BIGNUM *dsa_g = NULL; | ||
816 | BIGNUM *dsa_key = NULL; | ||
817 | BIGNUM *argument = NULL; | ||
818 | int to_return = -1; | ||
819 | int acquired = 0; | ||
820 | |||
821 | if((ctx = BN_CTX_new()) == NULL) | ||
822 | goto err; | ||
823 | if(!get_context(&hac)) | ||
824 | { | ||
825 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_UNIT_FAILURE); | ||
826 | goto err; | ||
827 | } | ||
828 | acquired = 1; | ||
829 | /* Prepare the params */ | ||
830 | BN_CTX_start(ctx); | ||
831 | dsa_p = BN_CTX_get(ctx); | ||
832 | dsa_q = BN_CTX_get(ctx); | ||
833 | dsa_g = BN_CTX_get(ctx); | ||
834 | dsa_key = BN_CTX_get(ctx); | ||
835 | argument = BN_CTX_get(ctx); | ||
836 | if(!argument) | ||
837 | { | ||
838 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_CTX_FULL); | ||
839 | goto err; | ||
840 | } | ||
841 | if(!bn_wexpand(dsa_p, dsa->p->top) || | ||
842 | !bn_wexpand(dsa_q, dsa->q->top) || | ||
843 | !bn_wexpand(dsa_g, dsa->g->top) || | ||
844 | !bn_wexpand(dsa_key, dsa->pub_key->top) || | ||
845 | !bn_wexpand(argument, 40)) | ||
846 | { | ||
847 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_EXPAND_FAIL); | ||
848 | goto err; | ||
849 | } | ||
850 | sw_param.type = SW_ALG_DSA; | ||
851 | sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p, | ||
852 | (unsigned char *)dsa_p->d); | ||
853 | sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d; | ||
854 | sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q, | ||
855 | (unsigned char *)dsa_q->d); | ||
856 | sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d; | ||
857 | sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g, | ||
858 | (unsigned char *)dsa_g->d); | ||
859 | sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d; | ||
860 | sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key, | ||
861 | (unsigned char *)dsa_key->d); | ||
862 | sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d; | ||
863 | /* Attach the key params */ | ||
864 | sw_status = p_CSwift_AttachKeyParam(hac, &sw_param); | ||
865 | switch(sw_status) | ||
866 | { | ||
867 | case SW_OK: | ||
868 | break; | ||
869 | case SW_ERR_INPUT_SIZE: | ||
870 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BAD_KEY_SIZE); | ||
871 | goto err; | ||
872 | default: | ||
873 | { | ||
874 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
875 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); | ||
876 | sprintf(tmpbuf, "%ld", sw_status); | ||
877 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
878 | } | ||
879 | goto err; | ||
880 | } | ||
881 | /* Prepare the argument and response */ | ||
882 | arg[0].nbytes = dgst_len; | ||
883 | arg[0].value = (unsigned char *)dgst; | ||
884 | arg[1].nbytes = 40; | ||
885 | arg[1].value = (unsigned char *)argument->d; | ||
886 | memset(arg[1].value, 0, 40); | ||
887 | BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r)); | ||
888 | BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s)); | ||
889 | res.nbytes = 4; /* unsigned long */ | ||
890 | res.value = (unsigned char *)(&sig_result); | ||
891 | /* Perform the operation */ | ||
892 | sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2, | ||
893 | &res, 1); | ||
894 | if(sw_status != SW_OK) | ||
895 | { | ||
896 | char tmpbuf[DECIMAL_SIZE(sw_status)+1]; | ||
897 | CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED); | ||
898 | sprintf(tmpbuf, "%ld", sw_status); | ||
899 | ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf); | ||
900 | goto err; | ||
901 | } | ||
902 | /* Convert the response */ | ||
903 | to_return = ((sig_result == 0) ? 0 : 1); | ||
904 | |||
905 | err: | ||
906 | if(acquired) | ||
907 | release_context(hac); | ||
908 | if(ctx) | ||
909 | { | ||
910 | BN_CTX_end(ctx); | ||
911 | BN_CTX_free(ctx); | ||
912 | } | ||
913 | return to_return; | ||
914 | } | ||
915 | #endif | ||
916 | |||
917 | #ifndef OPENSSL_NO_DH | ||
918 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
919 | static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
920 | const BIGNUM *a, const BIGNUM *p, | ||
921 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
922 | { | ||
923 | return cswift_mod_exp(r, a, p, m, ctx); | ||
924 | } | ||
925 | #endif | ||
926 | |||
927 | /* Random bytes are good */ | ||
928 | static int cswift_rand_bytes(unsigned char *buf, int num) | ||
929 | { | ||
930 | SW_CONTEXT_HANDLE hac; | ||
931 | SW_STATUS swrc; | ||
932 | SW_LARGENUMBER largenum; | ||
933 | size_t nbytes = 0; | ||
934 | int acquired = 0; | ||
935 | int to_return = 0; /* assume failure */ | ||
936 | |||
937 | if (!get_context(&hac)) | ||
938 | { | ||
939 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_UNIT_FAILURE); | ||
940 | goto err; | ||
941 | } | ||
942 | acquired = 1; | ||
943 | |||
944 | while (nbytes < (size_t)num) | ||
945 | { | ||
946 | /* tell CryptoSwift how many bytes we want and where we want it. | ||
947 | * Note: - CryptoSwift cannot do more than 4096 bytes at a time. | ||
948 | * - CryptoSwift can only do multiple of 32-bits. */ | ||
949 | largenum.value = (SW_BYTE *) buf + nbytes; | ||
950 | if (4096 > num - nbytes) | ||
951 | largenum.nbytes = num - nbytes; | ||
952 | else | ||
953 | largenum.nbytes = 4096; | ||
954 | |||
955 | swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1); | ||
956 | if (swrc != SW_OK) | ||
957 | { | ||
958 | char tmpbuf[20]; | ||
959 | CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED); | ||
960 | sprintf(tmpbuf, "%ld", swrc); | ||
961 | ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf); | ||
962 | goto err; | ||
963 | } | ||
964 | |||
965 | nbytes += largenum.nbytes; | ||
966 | } | ||
967 | to_return = 1; /* success */ | ||
968 | |||
969 | err: | ||
970 | if (acquired) | ||
971 | release_context(hac); | ||
972 | return to_return; | ||
973 | } | ||
974 | |||
975 | static int cswift_rand_status(void) | ||
976 | { | ||
977 | return 1; | ||
978 | } | ||
979 | |||
980 | |||
981 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
982 | * shared-library. */ | ||
983 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
984 | static int bind_fn(ENGINE *e, const char *id) | ||
985 | { | ||
986 | if(id && (strcmp(id, engine_cswift_id) != 0)) | ||
987 | return 0; | ||
988 | if(!bind_helper(e)) | ||
989 | return 0; | ||
990 | return 1; | ||
991 | } | ||
992 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
993 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
994 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
995 | |||
996 | #endif /* !OPENSSL_NO_HW_CSWIFT */ | ||
997 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.c b/src/lib/libcrypto/engine/hw_cswift_err.c new file mode 100644 index 0000000000..684f53bf27 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_cswift_err.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* hw_cswift_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_cswift_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA CSWIFT_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"}, | ||
70 | {ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"}, | ||
71 | {ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"}, | ||
72 | {ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"}, | ||
73 | {ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"}, | ||
74 | {ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"}, | ||
75 | {ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"}, | ||
76 | {ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"}, | ||
77 | {0,NULL} | ||
78 | }; | ||
79 | |||
80 | static ERR_STRING_DATA CSWIFT_str_reasons[]= | ||
81 | { | ||
82 | {CSWIFT_R_ALREADY_LOADED ,"already loaded"}, | ||
83 | {CSWIFT_R_BAD_KEY_SIZE ,"bad key size"}, | ||
84 | {CSWIFT_R_BN_CTX_FULL ,"bn ctx full"}, | ||
85 | {CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"}, | ||
86 | {CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
87 | {CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
88 | {CSWIFT_R_NOT_LOADED ,"not loaded"}, | ||
89 | {CSWIFT_R_REQUEST_FAILED ,"request failed"}, | ||
90 | {CSWIFT_R_UNIT_FAILURE ,"unit failure"}, | ||
91 | {0,NULL} | ||
92 | }; | ||
93 | |||
94 | #endif | ||
95 | |||
96 | #ifdef CSWIFT_LIB_NAME | ||
97 | static ERR_STRING_DATA CSWIFT_lib_name[]= | ||
98 | { | ||
99 | {0 ,CSWIFT_LIB_NAME}, | ||
100 | {0,NULL} | ||
101 | }; | ||
102 | #endif | ||
103 | |||
104 | |||
105 | static int CSWIFT_lib_error_code=0; | ||
106 | static int CSWIFT_error_init=1; | ||
107 | |||
108 | static void ERR_load_CSWIFT_strings(void) | ||
109 | { | ||
110 | if (CSWIFT_lib_error_code == 0) | ||
111 | CSWIFT_lib_error_code=ERR_get_next_error_library(); | ||
112 | |||
113 | if (CSWIFT_error_init) | ||
114 | { | ||
115 | CSWIFT_error_init=0; | ||
116 | #ifndef OPENSSL_NO_ERR | ||
117 | ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs); | ||
118 | ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons); | ||
119 | #endif | ||
120 | |||
121 | #ifdef CSWIFT_LIB_NAME | ||
122 | CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0); | ||
123 | ERR_load_strings(0,CSWIFT_lib_name); | ||
124 | #endif | ||
125 | } | ||
126 | } | ||
127 | |||
128 | static void ERR_unload_CSWIFT_strings(void) | ||
129 | { | ||
130 | if (CSWIFT_error_init == 0) | ||
131 | { | ||
132 | #ifndef OPENSSL_NO_ERR | ||
133 | ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs); | ||
134 | ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons); | ||
135 | #endif | ||
136 | |||
137 | #ifdef CSWIFT_LIB_NAME | ||
138 | ERR_unload_strings(0,CSWIFT_lib_name); | ||
139 | #endif | ||
140 | CSWIFT_error_init=1; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | static void ERR_CSWIFT_error(int function, int reason, char *file, int line) | ||
145 | { | ||
146 | if (CSWIFT_lib_error_code == 0) | ||
147 | CSWIFT_lib_error_code=ERR_get_next_error_library(); | ||
148 | ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line); | ||
149 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.h b/src/lib/libcrypto/engine/hw_cswift_err.h new file mode 100644 index 0000000000..7120c3216f --- /dev/null +++ b/src/lib/libcrypto/engine/hw_cswift_err.h | |||
@@ -0,0 +1,93 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_CSWIFT_ERR_H | ||
56 | #define HEADER_CSWIFT_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_CSWIFT_strings(void); | ||
63 | static void ERR_unload_CSWIFT_strings(void); | ||
64 | static void ERR_CSWIFT_error(int function, int reason, char *file, int line); | ||
65 | #define CSWIFTerr(f,r) ERR_CSWIFT_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the CSWIFT functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define CSWIFT_F_CSWIFT_CTRL 100 | ||
71 | #define CSWIFT_F_CSWIFT_DSA_SIGN 101 | ||
72 | #define CSWIFT_F_CSWIFT_DSA_VERIFY 102 | ||
73 | #define CSWIFT_F_CSWIFT_FINISH 103 | ||
74 | #define CSWIFT_F_CSWIFT_INIT 104 | ||
75 | #define CSWIFT_F_CSWIFT_MOD_EXP 105 | ||
76 | #define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106 | ||
77 | #define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107 | ||
78 | |||
79 | /* Reason codes. */ | ||
80 | #define CSWIFT_R_ALREADY_LOADED 100 | ||
81 | #define CSWIFT_R_BAD_KEY_SIZE 101 | ||
82 | #define CSWIFT_R_BN_CTX_FULL 102 | ||
83 | #define CSWIFT_R_BN_EXPAND_FAIL 103 | ||
84 | #define CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED 104 | ||
85 | #define CSWIFT_R_MISSING_KEY_COMPONENTS 105 | ||
86 | #define CSWIFT_R_NOT_LOADED 106 | ||
87 | #define CSWIFT_R_REQUEST_FAILED 107 | ||
88 | #define CSWIFT_R_UNIT_FAILURE 108 | ||
89 | |||
90 | #ifdef __cplusplus | ||
91 | } | ||
92 | #endif | ||
93 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c new file mode 100644 index 0000000000..0d1c6b8df0 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ncipher.c | |||
@@ -0,0 +1,1388 @@ | |||
1 | /* crypto/engine/hw_ncipher.c -*- mode: C; c-file-style: "eay" -*- */ | ||
2 | /* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe | ||
3 | * (geoff@geoffthorpe.net) and Dr Stephen N Henson (shenson@bigfoot.com) | ||
4 | * for the OpenSSL project 2000. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | * | ||
54 | * This product includes cryptographic software written by Eric Young | ||
55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
56 | * Hudson (tjh@cryptsoft.com). | ||
57 | * | ||
58 | */ | ||
59 | |||
60 | #include <stdio.h> | ||
61 | #include <string.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/crypto.h> | ||
64 | #include <openssl/pem.h> | ||
65 | #include <openssl/dso.h> | ||
66 | #include <openssl/engine.h> | ||
67 | #include <openssl/ui.h> | ||
68 | |||
69 | #ifndef OPENSSL_NO_HW | ||
70 | #ifndef OPENSSL_NO_HW_NCIPHER | ||
71 | |||
72 | /* Attribution notice: nCipher have said several times that it's OK for | ||
73 | * us to implement a general interface to their boxes, and recently declared | ||
74 | * their HWCryptoHook to be public, and therefore available for us to use. | ||
75 | * Thanks, nCipher. | ||
76 | * | ||
77 | * The hwcryptohook.h included here is from May 2000. | ||
78 | * [Richard Levitte] | ||
79 | */ | ||
80 | #ifdef FLAT_INC | ||
81 | #include "hwcryptohook.h" | ||
82 | #else | ||
83 | #include "vendor_defns/hwcryptohook.h" | ||
84 | #endif | ||
85 | |||
86 | #define HWCRHK_LIB_NAME "hwcrhk engine" | ||
87 | #include "hw_ncipher_err.c" | ||
88 | |||
89 | static int hwcrhk_destroy(ENGINE *e); | ||
90 | static int hwcrhk_init(ENGINE *e); | ||
91 | static int hwcrhk_finish(ENGINE *e); | ||
92 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
93 | |||
94 | /* Functions to handle mutexes if have dynamic locks */ | ||
95 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*); | ||
96 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*); | ||
97 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*); | ||
98 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*); | ||
99 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
100 | /* Functions to handle mutexes if only have static locks */ | ||
101 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
102 | HWCryptoHook_CallerContext *c); | ||
103 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m); | ||
104 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m); | ||
105 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m); | ||
106 | #endif | ||
107 | |||
108 | /* BIGNUM stuff */ | ||
109 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
110 | const BIGNUM *m, BN_CTX *ctx); | ||
111 | |||
112 | #ifndef OPENSSL_NO_RSA | ||
113 | /* RSA stuff */ | ||
114 | static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa); | ||
115 | #endif | ||
116 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
117 | static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
118 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
119 | |||
120 | #ifndef OPENSSL_NO_DH | ||
121 | /* DH stuff */ | ||
122 | /* This function is alised to mod_exp (with the DH and mont dropped). */ | ||
123 | static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
124 | const BIGNUM *a, const BIGNUM *p, | ||
125 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
126 | #endif | ||
127 | |||
128 | /* RAND stuff */ | ||
129 | static int hwcrhk_rand_bytes(unsigned char *buf, int num); | ||
130 | static int hwcrhk_rand_status(void); | ||
131 | |||
132 | /* KM stuff */ | ||
133 | static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, | ||
134 | UI_METHOD *ui_method, void *callback_data); | ||
135 | static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id, | ||
136 | UI_METHOD *ui_method, void *callback_data); | ||
137 | static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
138 | int ind,long argl, void *argp); | ||
139 | |||
140 | /* Interaction stuff */ | ||
141 | static int hwcrhk_insert_card(const char *prompt_info, | ||
142 | const char *wrong_info, | ||
143 | HWCryptoHook_PassphraseContext *ppctx, | ||
144 | HWCryptoHook_CallerContext *cactx); | ||
145 | static int hwcrhk_get_pass(const char *prompt_info, | ||
146 | int *len_io, char *buf, | ||
147 | HWCryptoHook_PassphraseContext *ppctx, | ||
148 | HWCryptoHook_CallerContext *cactx); | ||
149 | static void hwcrhk_log_message(void *logstr, const char *message); | ||
150 | |||
151 | /* The definitions for control commands specific to this engine */ | ||
152 | #define HWCRHK_CMD_SO_PATH ENGINE_CMD_BASE | ||
153 | #define HWCRHK_CMD_FORK_CHECK (ENGINE_CMD_BASE + 1) | ||
154 | #define HWCRHK_CMD_THREAD_LOCKING (ENGINE_CMD_BASE + 2) | ||
155 | #define HWCRHK_CMD_SET_USER_INTERFACE (ENGINE_CMD_BASE + 3) | ||
156 | #define HWCRHK_CMD_SET_CALLBACK_DATA (ENGINE_CMD_BASE + 4) | ||
157 | static const ENGINE_CMD_DEFN hwcrhk_cmd_defns[] = { | ||
158 | {HWCRHK_CMD_SO_PATH, | ||
159 | "SO_PATH", | ||
160 | "Specifies the path to the 'hwcrhk' shared library", | ||
161 | ENGINE_CMD_FLAG_STRING}, | ||
162 | {HWCRHK_CMD_FORK_CHECK, | ||
163 | "FORK_CHECK", | ||
164 | "Turns fork() checking on or off (boolean)", | ||
165 | ENGINE_CMD_FLAG_NUMERIC}, | ||
166 | {HWCRHK_CMD_THREAD_LOCKING, | ||
167 | "THREAD_LOCKING", | ||
168 | "Turns thread-safe locking on or off (boolean)", | ||
169 | ENGINE_CMD_FLAG_NUMERIC}, | ||
170 | {HWCRHK_CMD_SET_USER_INTERFACE, | ||
171 | "SET_USER_INTERFACE", | ||
172 | "Set the global user interface (internal)", | ||
173 | ENGINE_CMD_FLAG_INTERNAL}, | ||
174 | {HWCRHK_CMD_SET_CALLBACK_DATA, | ||
175 | "SET_CALLBACK_DATA", | ||
176 | "Set the global user interface extra data (internal)", | ||
177 | ENGINE_CMD_FLAG_INTERNAL}, | ||
178 | {0, NULL, NULL, 0} | ||
179 | }; | ||
180 | |||
181 | #ifndef OPENSSL_NO_RSA | ||
182 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
183 | static RSA_METHOD hwcrhk_rsa = | ||
184 | { | ||
185 | "nCipher RSA method", | ||
186 | NULL, | ||
187 | NULL, | ||
188 | NULL, | ||
189 | NULL, | ||
190 | hwcrhk_rsa_mod_exp, | ||
191 | hwcrhk_mod_exp_mont, | ||
192 | NULL, | ||
193 | NULL, | ||
194 | 0, | ||
195 | NULL, | ||
196 | NULL, | ||
197 | NULL | ||
198 | }; | ||
199 | #endif | ||
200 | |||
201 | #ifndef OPENSSL_NO_DH | ||
202 | /* Our internal DH_METHOD that we provide pointers to */ | ||
203 | static DH_METHOD hwcrhk_dh = | ||
204 | { | ||
205 | "nCipher DH method", | ||
206 | NULL, | ||
207 | NULL, | ||
208 | hwcrhk_mod_exp_dh, | ||
209 | NULL, | ||
210 | NULL, | ||
211 | 0, | ||
212 | NULL | ||
213 | }; | ||
214 | #endif | ||
215 | |||
216 | static RAND_METHOD hwcrhk_rand = | ||
217 | { | ||
218 | /* "nCipher RAND method", */ | ||
219 | NULL, | ||
220 | hwcrhk_rand_bytes, | ||
221 | NULL, | ||
222 | NULL, | ||
223 | hwcrhk_rand_bytes, | ||
224 | hwcrhk_rand_status, | ||
225 | }; | ||
226 | |||
227 | /* Constants used when creating the ENGINE */ | ||
228 | static const char *engine_hwcrhk_id = "chil"; | ||
229 | static const char *engine_hwcrhk_name = "nCipher hardware engine support"; | ||
230 | |||
231 | /* Internal stuff for HWCryptoHook */ | ||
232 | |||
233 | /* Some structures needed for proper use of thread locks */ | ||
234 | /* hwcryptohook.h has some typedefs that turn struct HWCryptoHook_MutexValue | ||
235 | into HWCryptoHook_Mutex */ | ||
236 | struct HWCryptoHook_MutexValue | ||
237 | { | ||
238 | int lockid; | ||
239 | }; | ||
240 | |||
241 | /* hwcryptohook.h has some typedefs that turn | ||
242 | struct HWCryptoHook_PassphraseContextValue | ||
243 | into HWCryptoHook_PassphraseContext */ | ||
244 | struct HWCryptoHook_PassphraseContextValue | ||
245 | { | ||
246 | UI_METHOD *ui_method; | ||
247 | void *callback_data; | ||
248 | }; | ||
249 | |||
250 | /* hwcryptohook.h has some typedefs that turn | ||
251 | struct HWCryptoHook_CallerContextValue | ||
252 | into HWCryptoHook_CallerContext */ | ||
253 | struct HWCryptoHook_CallerContextValue | ||
254 | { | ||
255 | pem_password_cb *password_callback; /* Deprecated! Only present for | ||
256 | backward compatibility! */ | ||
257 | UI_METHOD *ui_method; | ||
258 | void *callback_data; | ||
259 | }; | ||
260 | |||
261 | /* The MPI structure in HWCryptoHook is pretty compatible with OpenSSL | ||
262 | BIGNUM's, so lets define a couple of conversion macros */ | ||
263 | #define BN2MPI(mp, bn) \ | ||
264 | {mp.size = bn->top * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;} | ||
265 | #define MPI2BN(bn, mp) \ | ||
266 | {mp.size = bn->dmax * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;} | ||
267 | |||
268 | static BIO *logstream = NULL; | ||
269 | static int disable_mutex_callbacks = 0; | ||
270 | |||
271 | /* One might wonder why these are needed, since one can pass down at least | ||
272 | a UI_METHOD and a pointer to callback data to the key-loading functions. | ||
273 | The thing is that the ModExp and RSAImmed functions can load keys as well, | ||
274 | if the data they get is in a special, nCipher-defined format (hint: if you | ||
275 | look at the private exponent of the RSA data as a string, you'll see this | ||
276 | string: "nCipher KM tool key id", followed by some bytes, followed a key | ||
277 | identity string, followed by more bytes. This happens when you use "embed" | ||
278 | keys instead of "hwcrhk" keys). Unfortunately, those functions do not take | ||
279 | any passphrase or caller context, and our functions can't really take any | ||
280 | callback data either. Still, the "insert_card" and "get_passphrase" | ||
281 | callbacks may be called down the line, and will need to know what user | ||
282 | interface callbacks to call, and having callback data from the application | ||
283 | may be a nice thing as well, so we need to keep track of that globally. */ | ||
284 | static HWCryptoHook_CallerContext password_context = { NULL, NULL, NULL }; | ||
285 | |||
286 | /* Stuff to pass to the HWCryptoHook library */ | ||
287 | static HWCryptoHook_InitInfo hwcrhk_globals = { | ||
288 | HWCryptoHook_InitFlags_SimpleForkCheck, /* Flags */ | ||
289 | &logstream, /* logstream */ | ||
290 | sizeof(BN_ULONG), /* limbsize */ | ||
291 | 0, /* mslimb first: false for BNs */ | ||
292 | -1, /* msbyte first: use native */ | ||
293 | 0, /* Max mutexes, 0 = no small limit */ | ||
294 | 0, /* Max simultaneous, 0 = default */ | ||
295 | |||
296 | /* The next few are mutex stuff: we write wrapper functions | ||
297 | around the OS mutex functions. We initialise them to 0 | ||
298 | here, and change that to actual function pointers in hwcrhk_init() | ||
299 | if dynamic locks are supported (that is, if the application | ||
300 | programmer has made sure of setting up callbacks bafore starting | ||
301 | this engine) *and* if disable_mutex_callbacks hasn't been set by | ||
302 | a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */ | ||
303 | sizeof(HWCryptoHook_Mutex), | ||
304 | 0, | ||
305 | 0, | ||
306 | 0, | ||
307 | 0, | ||
308 | |||
309 | /* The next few are condvar stuff: we write wrapper functions | ||
310 | round the OS functions. Currently not implemented and not | ||
311 | and absolute necessity even in threaded programs, therefore | ||
312 | 0'ed. Will hopefully be implemented some day, since it | ||
313 | enhances the efficiency of HWCryptoHook. */ | ||
314 | 0, /* sizeof(HWCryptoHook_CondVar), */ | ||
315 | 0, /* hwcrhk_cv_init, */ | ||
316 | 0, /* hwcrhk_cv_wait, */ | ||
317 | 0, /* hwcrhk_cv_signal, */ | ||
318 | 0, /* hwcrhk_cv_broadcast, */ | ||
319 | 0, /* hwcrhk_cv_destroy, */ | ||
320 | |||
321 | hwcrhk_get_pass, /* pass phrase */ | ||
322 | hwcrhk_insert_card, /* insert a card */ | ||
323 | hwcrhk_log_message /* Log message */ | ||
324 | }; | ||
325 | |||
326 | |||
327 | /* Now, to our own code */ | ||
328 | |||
329 | /* This internal function is used by ENGINE_ncipher() and possibly by the | ||
330 | * "dynamic" ENGINE support too */ | ||
331 | static int bind_helper(ENGINE *e) | ||
332 | { | ||
333 | #ifndef OPENSSL_NO_RSA | ||
334 | const RSA_METHOD *meth1; | ||
335 | #endif | ||
336 | #ifndef OPENSSL_NO_DH | ||
337 | const DH_METHOD *meth2; | ||
338 | #endif | ||
339 | if(!ENGINE_set_id(e, engine_hwcrhk_id) || | ||
340 | !ENGINE_set_name(e, engine_hwcrhk_name) || | ||
341 | #ifndef OPENSSL_NO_RSA | ||
342 | !ENGINE_set_RSA(e, &hwcrhk_rsa) || | ||
343 | #endif | ||
344 | #ifndef OPENSSL_NO_DH | ||
345 | !ENGINE_set_DH(e, &hwcrhk_dh) || | ||
346 | #endif | ||
347 | !ENGINE_set_RAND(e, &hwcrhk_rand) || | ||
348 | !ENGINE_set_destroy_function(e, hwcrhk_destroy) || | ||
349 | !ENGINE_set_init_function(e, hwcrhk_init) || | ||
350 | !ENGINE_set_finish_function(e, hwcrhk_finish) || | ||
351 | !ENGINE_set_ctrl_function(e, hwcrhk_ctrl) || | ||
352 | !ENGINE_set_load_privkey_function(e, hwcrhk_load_privkey) || | ||
353 | !ENGINE_set_load_pubkey_function(e, hwcrhk_load_pubkey) || | ||
354 | !ENGINE_set_cmd_defns(e, hwcrhk_cmd_defns)) | ||
355 | return 0; | ||
356 | |||
357 | #ifndef OPENSSL_NO_RSA | ||
358 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
359 | * to the cswift-specific mod_exp and mod_exp_crt so we use | ||
360 | * those functions. NB: We don't use ENGINE_openssl() or | ||
361 | * anything "more generic" because something like the RSAref | ||
362 | * code may not hook properly, and if you own one of these | ||
363 | * cards then you have the right to do RSA operations on it | ||
364 | * anyway! */ | ||
365 | meth1 = RSA_PKCS1_SSLeay(); | ||
366 | hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
367 | hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
368 | hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
369 | hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
370 | #endif | ||
371 | |||
372 | #ifndef OPENSSL_NO_DH | ||
373 | /* Much the same for Diffie-Hellman */ | ||
374 | meth2 = DH_OpenSSL(); | ||
375 | hwcrhk_dh.generate_key = meth2->generate_key; | ||
376 | hwcrhk_dh.compute_key = meth2->compute_key; | ||
377 | #endif | ||
378 | |||
379 | /* Ensure the hwcrhk error handling is set up */ | ||
380 | ERR_load_HWCRHK_strings(); | ||
381 | return 1; | ||
382 | } | ||
383 | |||
384 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
385 | static ENGINE *engine_ncipher(void) | ||
386 | { | ||
387 | ENGINE *ret = ENGINE_new(); | ||
388 | if(!ret) | ||
389 | return NULL; | ||
390 | if(!bind_helper(ret)) | ||
391 | { | ||
392 | ENGINE_free(ret); | ||
393 | return NULL; | ||
394 | } | ||
395 | return ret; | ||
396 | } | ||
397 | |||
398 | void ENGINE_load_chil(void) | ||
399 | { | ||
400 | /* Copied from eng_[openssl|dyn].c */ | ||
401 | ENGINE *toadd = engine_ncipher(); | ||
402 | if(!toadd) return; | ||
403 | ENGINE_add(toadd); | ||
404 | ENGINE_free(toadd); | ||
405 | ERR_clear_error(); | ||
406 | } | ||
407 | #endif | ||
408 | |||
409 | /* This is a process-global DSO handle used for loading and unloading | ||
410 | * the HWCryptoHook library. NB: This is only set (or unset) during an | ||
411 | * init() or finish() call (reference counts permitting) and they're | ||
412 | * operating with global locks, so this should be thread-safe | ||
413 | * implicitly. */ | ||
414 | static DSO *hwcrhk_dso = NULL; | ||
415 | static HWCryptoHook_ContextHandle hwcrhk_context = 0; | ||
416 | #ifndef OPENSSL_NO_RSA | ||
417 | static int hndidx_rsa = -1; /* Index for KM handle. Not really used yet. */ | ||
418 | #endif | ||
419 | |||
420 | /* These are the function pointers that are (un)set when the library has | ||
421 | * successfully (un)loaded. */ | ||
422 | static HWCryptoHook_Init_t *p_hwcrhk_Init = NULL; | ||
423 | static HWCryptoHook_Finish_t *p_hwcrhk_Finish = NULL; | ||
424 | static HWCryptoHook_ModExp_t *p_hwcrhk_ModExp = NULL; | ||
425 | #ifndef OPENSSL_NO_RSA | ||
426 | static HWCryptoHook_RSA_t *p_hwcrhk_RSA = NULL; | ||
427 | #endif | ||
428 | static HWCryptoHook_RandomBytes_t *p_hwcrhk_RandomBytes = NULL; | ||
429 | #ifndef OPENSSL_NO_RSA | ||
430 | static HWCryptoHook_RSALoadKey_t *p_hwcrhk_RSALoadKey = NULL; | ||
431 | static HWCryptoHook_RSAGetPublicKey_t *p_hwcrhk_RSAGetPublicKey = NULL; | ||
432 | static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL; | ||
433 | #endif | ||
434 | static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL; | ||
435 | |||
436 | /* Used in the DSO operations. */ | ||
437 | static const char *HWCRHK_LIBNAME = NULL; | ||
438 | static void free_HWCRHK_LIBNAME(void) | ||
439 | { | ||
440 | if(HWCRHK_LIBNAME) | ||
441 | OPENSSL_free((void*)HWCRHK_LIBNAME); | ||
442 | HWCRHK_LIBNAME = NULL; | ||
443 | } | ||
444 | static const char *get_HWCRHK_LIBNAME(void) | ||
445 | { | ||
446 | if(HWCRHK_LIBNAME) | ||
447 | return HWCRHK_LIBNAME; | ||
448 | return "nfhwcrhk"; | ||
449 | } | ||
450 | static long set_HWCRHK_LIBNAME(const char *name) | ||
451 | { | ||
452 | free_HWCRHK_LIBNAME(); | ||
453 | return (((HWCRHK_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
454 | } | ||
455 | static const char *n_hwcrhk_Init = "HWCryptoHook_Init"; | ||
456 | static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish"; | ||
457 | static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp"; | ||
458 | #ifndef OPENSSL_NO_RSA | ||
459 | static const char *n_hwcrhk_RSA = "HWCryptoHook_RSA"; | ||
460 | #endif | ||
461 | static const char *n_hwcrhk_RandomBytes = "HWCryptoHook_RandomBytes"; | ||
462 | #ifndef OPENSSL_NO_RSA | ||
463 | static const char *n_hwcrhk_RSALoadKey = "HWCryptoHook_RSALoadKey"; | ||
464 | static const char *n_hwcrhk_RSAGetPublicKey = "HWCryptoHook_RSAGetPublicKey"; | ||
465 | static const char *n_hwcrhk_RSAUnloadKey = "HWCryptoHook_RSAUnloadKey"; | ||
466 | #endif | ||
467 | static const char *n_hwcrhk_ModExpCRT = "HWCryptoHook_ModExpCRT"; | ||
468 | |||
469 | /* HWCryptoHook library functions and mechanics - these are used by the | ||
470 | * higher-level functions further down. NB: As and where there's no | ||
471 | * error checking, take a look lower down where these functions are | ||
472 | * called, the checking and error handling is probably down there. */ | ||
473 | |||
474 | /* utility function to obtain a context */ | ||
475 | static int get_context(HWCryptoHook_ContextHandle *hac, | ||
476 | HWCryptoHook_CallerContext *cac) | ||
477 | { | ||
478 | char tempbuf[1024]; | ||
479 | HWCryptoHook_ErrMsgBuf rmsg; | ||
480 | |||
481 | rmsg.buf = tempbuf; | ||
482 | rmsg.size = sizeof(tempbuf); | ||
483 | |||
484 | *hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg, | ||
485 | cac); | ||
486 | if (!*hac) | ||
487 | return 0; | ||
488 | return 1; | ||
489 | } | ||
490 | |||
491 | /* similarly to release one. */ | ||
492 | static void release_context(HWCryptoHook_ContextHandle hac) | ||
493 | { | ||
494 | p_hwcrhk_Finish(hac); | ||
495 | } | ||
496 | |||
497 | /* Destructor (complements the "ENGINE_ncipher()" constructor) */ | ||
498 | static int hwcrhk_destroy(ENGINE *e) | ||
499 | { | ||
500 | free_HWCRHK_LIBNAME(); | ||
501 | ERR_unload_HWCRHK_strings(); | ||
502 | return 1; | ||
503 | } | ||
504 | |||
505 | /* (de)initialisation functions. */ | ||
506 | static int hwcrhk_init(ENGINE *e) | ||
507 | { | ||
508 | HWCryptoHook_Init_t *p1; | ||
509 | HWCryptoHook_Finish_t *p2; | ||
510 | HWCryptoHook_ModExp_t *p3; | ||
511 | #ifndef OPENSSL_NO_RSA | ||
512 | HWCryptoHook_RSA_t *p4; | ||
513 | HWCryptoHook_RSALoadKey_t *p5; | ||
514 | HWCryptoHook_RSAGetPublicKey_t *p6; | ||
515 | HWCryptoHook_RSAUnloadKey_t *p7; | ||
516 | #endif | ||
517 | HWCryptoHook_RandomBytes_t *p8; | ||
518 | HWCryptoHook_ModExpCRT_t *p9; | ||
519 | |||
520 | if(hwcrhk_dso != NULL) | ||
521 | { | ||
522 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_ALREADY_LOADED); | ||
523 | goto err; | ||
524 | } | ||
525 | /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */ | ||
526 | hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0); | ||
527 | if(hwcrhk_dso == NULL) | ||
528 | { | ||
529 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE); | ||
530 | goto err; | ||
531 | } | ||
532 | if(!(p1 = (HWCryptoHook_Init_t *) | ||
533 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) || | ||
534 | !(p2 = (HWCryptoHook_Finish_t *) | ||
535 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) || | ||
536 | !(p3 = (HWCryptoHook_ModExp_t *) | ||
537 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) || | ||
538 | #ifndef OPENSSL_NO_RSA | ||
539 | !(p4 = (HWCryptoHook_RSA_t *) | ||
540 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) || | ||
541 | !(p5 = (HWCryptoHook_RSALoadKey_t *) | ||
542 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) || | ||
543 | !(p6 = (HWCryptoHook_RSAGetPublicKey_t *) | ||
544 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) || | ||
545 | !(p7 = (HWCryptoHook_RSAUnloadKey_t *) | ||
546 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) || | ||
547 | #endif | ||
548 | !(p8 = (HWCryptoHook_RandomBytes_t *) | ||
549 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) || | ||
550 | !(p9 = (HWCryptoHook_ModExpCRT_t *) | ||
551 | DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT))) | ||
552 | { | ||
553 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE); | ||
554 | goto err; | ||
555 | } | ||
556 | /* Copy the pointers */ | ||
557 | p_hwcrhk_Init = p1; | ||
558 | p_hwcrhk_Finish = p2; | ||
559 | p_hwcrhk_ModExp = p3; | ||
560 | #ifndef OPENSSL_NO_RSA | ||
561 | p_hwcrhk_RSA = p4; | ||
562 | p_hwcrhk_RSALoadKey = p5; | ||
563 | p_hwcrhk_RSAGetPublicKey = p6; | ||
564 | p_hwcrhk_RSAUnloadKey = p7; | ||
565 | #endif | ||
566 | p_hwcrhk_RandomBytes = p8; | ||
567 | p_hwcrhk_ModExpCRT = p9; | ||
568 | |||
569 | /* Check if the application decided to support dynamic locks, | ||
570 | and if it does, use them. */ | ||
571 | if (disable_mutex_callbacks == 0) | ||
572 | { | ||
573 | if (CRYPTO_get_dynlock_create_callback() != NULL && | ||
574 | CRYPTO_get_dynlock_lock_callback() != NULL && | ||
575 | CRYPTO_get_dynlock_destroy_callback() != NULL) | ||
576 | { | ||
577 | hwcrhk_globals.mutex_init = hwcrhk_mutex_init; | ||
578 | hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock; | ||
579 | hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock; | ||
580 | hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy; | ||
581 | } | ||
582 | else if (CRYPTO_get_locking_callback() != NULL) | ||
583 | { | ||
584 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DYNAMIC_LOCKING_MISSING); | ||
585 | ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()"); | ||
586 | #if 1 /* This is a HACK which will disappear in 0.9.8 */ | ||
587 | hwcrhk_globals.maxmutexes = 1; /* Only have one lock */ | ||
588 | hwcrhk_globals.mutex_init = hwcrhk_static_mutex_init; | ||
589 | hwcrhk_globals.mutex_acquire = hwcrhk_static_mutex_lock; | ||
590 | hwcrhk_globals.mutex_release = hwcrhk_static_mutex_unlock; | ||
591 | hwcrhk_globals.mutex_destroy = hwcrhk_static_mutex_destroy; | ||
592 | #else | ||
593 | goto err; | ||
594 | #endif | ||
595 | } | ||
596 | } | ||
597 | |||
598 | /* Try and get a context - if not, we may have a DSO but no | ||
599 | * accelerator! */ | ||
600 | if(!get_context(&hwcrhk_context, &password_context)) | ||
601 | { | ||
602 | HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE); | ||
603 | goto err; | ||
604 | } | ||
605 | /* Everything's fine. */ | ||
606 | #ifndef OPENSSL_NO_RSA | ||
607 | if (hndidx_rsa == -1) | ||
608 | hndidx_rsa = RSA_get_ex_new_index(0, | ||
609 | "nFast HWCryptoHook RSA key handle", | ||
610 | NULL, NULL, hwcrhk_ex_free); | ||
611 | #endif | ||
612 | return 1; | ||
613 | err: | ||
614 | if(hwcrhk_dso) | ||
615 | DSO_free(hwcrhk_dso); | ||
616 | hwcrhk_dso = NULL; | ||
617 | p_hwcrhk_Init = NULL; | ||
618 | p_hwcrhk_Finish = NULL; | ||
619 | p_hwcrhk_ModExp = NULL; | ||
620 | #ifndef OPENSSL_NO_RSA | ||
621 | p_hwcrhk_RSA = NULL; | ||
622 | p_hwcrhk_RSALoadKey = NULL; | ||
623 | p_hwcrhk_RSAGetPublicKey = NULL; | ||
624 | p_hwcrhk_RSAUnloadKey = NULL; | ||
625 | #endif | ||
626 | p_hwcrhk_ModExpCRT = NULL; | ||
627 | p_hwcrhk_RandomBytes = NULL; | ||
628 | return 0; | ||
629 | } | ||
630 | |||
631 | static int hwcrhk_finish(ENGINE *e) | ||
632 | { | ||
633 | int to_return = 1; | ||
634 | free_HWCRHK_LIBNAME(); | ||
635 | if(hwcrhk_dso == NULL) | ||
636 | { | ||
637 | HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED); | ||
638 | to_return = 0; | ||
639 | goto err; | ||
640 | } | ||
641 | release_context(hwcrhk_context); | ||
642 | if(!DSO_free(hwcrhk_dso)) | ||
643 | { | ||
644 | HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_DSO_FAILURE); | ||
645 | to_return = 0; | ||
646 | goto err; | ||
647 | } | ||
648 | err: | ||
649 | if (logstream) | ||
650 | BIO_free(logstream); | ||
651 | hwcrhk_dso = NULL; | ||
652 | p_hwcrhk_Init = NULL; | ||
653 | p_hwcrhk_Finish = NULL; | ||
654 | p_hwcrhk_ModExp = NULL; | ||
655 | #ifndef OPENSSL_NO_RSA | ||
656 | p_hwcrhk_RSA = NULL; | ||
657 | p_hwcrhk_RSALoadKey = NULL; | ||
658 | p_hwcrhk_RSAGetPublicKey = NULL; | ||
659 | p_hwcrhk_RSAUnloadKey = NULL; | ||
660 | #endif | ||
661 | p_hwcrhk_ModExpCRT = NULL; | ||
662 | p_hwcrhk_RandomBytes = NULL; | ||
663 | return to_return; | ||
664 | } | ||
665 | |||
666 | static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
667 | { | ||
668 | int to_return = 1; | ||
669 | |||
670 | switch(cmd) | ||
671 | { | ||
672 | case HWCRHK_CMD_SO_PATH: | ||
673 | if(hwcrhk_dso) | ||
674 | { | ||
675 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_ALREADY_LOADED); | ||
676 | return 0; | ||
677 | } | ||
678 | if(p == NULL) | ||
679 | { | ||
680 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
681 | return 0; | ||
682 | } | ||
683 | return set_HWCRHK_LIBNAME((const char *)p); | ||
684 | case ENGINE_CTRL_SET_LOGSTREAM: | ||
685 | { | ||
686 | BIO *bio = (BIO *)p; | ||
687 | |||
688 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
689 | if (logstream) | ||
690 | { | ||
691 | BIO_free(logstream); | ||
692 | logstream = NULL; | ||
693 | } | ||
694 | if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1) | ||
695 | logstream = bio; | ||
696 | else | ||
697 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_BIO_WAS_FREED); | ||
698 | } | ||
699 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
700 | break; | ||
701 | case ENGINE_CTRL_SET_PASSWORD_CALLBACK: | ||
702 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
703 | password_context.password_callback = (pem_password_cb *)f; | ||
704 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
705 | break; | ||
706 | case ENGINE_CTRL_SET_USER_INTERFACE: | ||
707 | case HWCRHK_CMD_SET_USER_INTERFACE: | ||
708 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
709 | password_context.ui_method = (UI_METHOD *)p; | ||
710 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
711 | break; | ||
712 | case ENGINE_CTRL_SET_CALLBACK_DATA: | ||
713 | case HWCRHK_CMD_SET_CALLBACK_DATA: | ||
714 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
715 | password_context.callback_data = p; | ||
716 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
717 | break; | ||
718 | /* this enables or disables the "SimpleForkCheck" flag used in the | ||
719 | * initialisation structure. */ | ||
720 | case ENGINE_CTRL_CHIL_SET_FORKCHECK: | ||
721 | case HWCRHK_CMD_FORK_CHECK: | ||
722 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
723 | if(i) | ||
724 | hwcrhk_globals.flags |= | ||
725 | HWCryptoHook_InitFlags_SimpleForkCheck; | ||
726 | else | ||
727 | hwcrhk_globals.flags &= | ||
728 | ~HWCryptoHook_InitFlags_SimpleForkCheck; | ||
729 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
730 | break; | ||
731 | /* This will prevent the initialisation function from "installing" | ||
732 | * the mutex-handling callbacks, even if they are available from | ||
733 | * within the library (or were provided to the library from the | ||
734 | * calling application). This is to remove any baggage for | ||
735 | * applications not using multithreading. */ | ||
736 | case ENGINE_CTRL_CHIL_NO_LOCKING: | ||
737 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
738 | disable_mutex_callbacks = 1; | ||
739 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
740 | break; | ||
741 | case HWCRHK_CMD_THREAD_LOCKING: | ||
742 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
743 | disable_mutex_callbacks = ((i == 0) ? 0 : 1); | ||
744 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
745 | break; | ||
746 | |||
747 | /* The command isn't understood by this engine */ | ||
748 | default: | ||
749 | HWCRHKerr(HWCRHK_F_HWCRHK_CTRL, | ||
750 | HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
751 | to_return = 0; | ||
752 | break; | ||
753 | } | ||
754 | |||
755 | return to_return; | ||
756 | } | ||
757 | |||
758 | static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id, | ||
759 | UI_METHOD *ui_method, void *callback_data) | ||
760 | { | ||
761 | #ifndef OPENSSL_NO_RSA | ||
762 | RSA *rtmp = NULL; | ||
763 | #endif | ||
764 | EVP_PKEY *res = NULL; | ||
765 | #ifndef OPENSSL_NO_RSA | ||
766 | HWCryptoHook_MPI e, n; | ||
767 | HWCryptoHook_RSAKeyHandle *hptr; | ||
768 | #endif | ||
769 | #if !defined(OPENSSL_NO_RSA) | ||
770 | char tempbuf[1024]; | ||
771 | HWCryptoHook_ErrMsgBuf rmsg; | ||
772 | #endif | ||
773 | HWCryptoHook_PassphraseContext ppctx; | ||
774 | |||
775 | #if !defined(OPENSSL_NO_RSA) | ||
776 | rmsg.buf = tempbuf; | ||
777 | rmsg.size = sizeof(tempbuf); | ||
778 | #endif | ||
779 | |||
780 | if(!hwcrhk_context) | ||
781 | { | ||
782 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
783 | HWCRHK_R_NOT_INITIALISED); | ||
784 | goto err; | ||
785 | } | ||
786 | #ifndef OPENSSL_NO_RSA | ||
787 | hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle)); | ||
788 | if (!hptr) | ||
789 | { | ||
790 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
791 | ERR_R_MALLOC_FAILURE); | ||
792 | goto err; | ||
793 | } | ||
794 | ppctx.ui_method = ui_method; | ||
795 | ppctx.callback_data = callback_data; | ||
796 | if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr, | ||
797 | &rmsg, &ppctx)) | ||
798 | { | ||
799 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
800 | HWCRHK_R_CHIL_ERROR); | ||
801 | ERR_add_error_data(1,rmsg.buf); | ||
802 | goto err; | ||
803 | } | ||
804 | if (!*hptr) | ||
805 | { | ||
806 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY, | ||
807 | HWCRHK_R_NO_KEY); | ||
808 | goto err; | ||
809 | } | ||
810 | #endif | ||
811 | #ifndef OPENSSL_NO_RSA | ||
812 | rtmp = RSA_new_method(eng); | ||
813 | RSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr); | ||
814 | rtmp->e = BN_new(); | ||
815 | rtmp->n = BN_new(); | ||
816 | rtmp->flags |= RSA_FLAG_EXT_PKEY; | ||
817 | MPI2BN(rtmp->e, e); | ||
818 | MPI2BN(rtmp->n, n); | ||
819 | if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg) | ||
820 | != HWCRYPTOHOOK_ERROR_MPISIZE) | ||
821 | { | ||
822 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,HWCRHK_R_CHIL_ERROR); | ||
823 | ERR_add_error_data(1,rmsg.buf); | ||
824 | goto err; | ||
825 | } | ||
826 | |||
827 | bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG)); | ||
828 | bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG)); | ||
829 | MPI2BN(rtmp->e, e); | ||
830 | MPI2BN(rtmp->n, n); | ||
831 | |||
832 | if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)) | ||
833 | { | ||
834 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
835 | HWCRHK_R_CHIL_ERROR); | ||
836 | ERR_add_error_data(1,rmsg.buf); | ||
837 | goto err; | ||
838 | } | ||
839 | rtmp->e->top = e.size / sizeof(BN_ULONG); | ||
840 | bn_fix_top(rtmp->e); | ||
841 | rtmp->n->top = n.size / sizeof(BN_ULONG); | ||
842 | bn_fix_top(rtmp->n); | ||
843 | |||
844 | res = EVP_PKEY_new(); | ||
845 | EVP_PKEY_assign_RSA(res, rtmp); | ||
846 | #endif | ||
847 | |||
848 | if (!res) | ||
849 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
850 | HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED); | ||
851 | |||
852 | return res; | ||
853 | err: | ||
854 | if (res) | ||
855 | EVP_PKEY_free(res); | ||
856 | #ifndef OPENSSL_NO_RSA | ||
857 | if (rtmp) | ||
858 | RSA_free(rtmp); | ||
859 | #endif | ||
860 | return NULL; | ||
861 | } | ||
862 | |||
863 | static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id, | ||
864 | UI_METHOD *ui_method, void *callback_data) | ||
865 | { | ||
866 | EVP_PKEY *res = NULL; | ||
867 | |||
868 | #ifndef OPENSSL_NO_RSA | ||
869 | res = hwcrhk_load_privkey(eng, key_id, | ||
870 | ui_method, callback_data); | ||
871 | #endif | ||
872 | |||
873 | if (res) | ||
874 | switch(res->type) | ||
875 | { | ||
876 | #ifndef OPENSSL_NO_RSA | ||
877 | case EVP_PKEY_RSA: | ||
878 | { | ||
879 | RSA *rsa = NULL; | ||
880 | |||
881 | CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY); | ||
882 | rsa = res->pkey.rsa; | ||
883 | res->pkey.rsa = RSA_new(); | ||
884 | res->pkey.rsa->n = rsa->n; | ||
885 | res->pkey.rsa->e = rsa->e; | ||
886 | rsa->n = NULL; | ||
887 | rsa->e = NULL; | ||
888 | CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY); | ||
889 | RSA_free(rsa); | ||
890 | } | ||
891 | break; | ||
892 | #endif | ||
893 | default: | ||
894 | HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY, | ||
895 | HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
896 | goto err; | ||
897 | } | ||
898 | |||
899 | return res; | ||
900 | err: | ||
901 | if (res) | ||
902 | EVP_PKEY_free(res); | ||
903 | return NULL; | ||
904 | } | ||
905 | |||
906 | /* A little mod_exp */ | ||
907 | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
908 | const BIGNUM *m, BN_CTX *ctx) | ||
909 | { | ||
910 | char tempbuf[1024]; | ||
911 | HWCryptoHook_ErrMsgBuf rmsg; | ||
912 | /* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's, | ||
913 | we use them directly, plus a little macro magic. We only | ||
914 | thing we need to make sure of is that enough space is allocated. */ | ||
915 | HWCryptoHook_MPI m_a, m_p, m_n, m_r; | ||
916 | int to_return, ret; | ||
917 | |||
918 | to_return = 0; /* expect failure */ | ||
919 | rmsg.buf = tempbuf; | ||
920 | rmsg.size = sizeof(tempbuf); | ||
921 | |||
922 | if(!hwcrhk_context) | ||
923 | { | ||
924 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED); | ||
925 | goto err; | ||
926 | } | ||
927 | /* Prepare the params */ | ||
928 | bn_expand2(r, m->top); /* Check for error !! */ | ||
929 | BN2MPI(m_a, a); | ||
930 | BN2MPI(m_p, p); | ||
931 | BN2MPI(m_n, m); | ||
932 | MPI2BN(r, m_r); | ||
933 | |||
934 | /* Perform the operation */ | ||
935 | ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg); | ||
936 | |||
937 | /* Convert the response */ | ||
938 | r->top = m_r.size / sizeof(BN_ULONG); | ||
939 | bn_fix_top(r); | ||
940 | |||
941 | if (ret < 0) | ||
942 | { | ||
943 | /* FIXME: When this error is returned, HWCryptoHook is | ||
944 | telling us that falling back to software computation | ||
945 | might be a good thing. */ | ||
946 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
947 | { | ||
948 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FALLBACK); | ||
949 | } | ||
950 | else | ||
951 | { | ||
952 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FAILED); | ||
953 | } | ||
954 | ERR_add_error_data(1,rmsg.buf); | ||
955 | goto err; | ||
956 | } | ||
957 | |||
958 | to_return = 1; | ||
959 | err: | ||
960 | return to_return; | ||
961 | } | ||
962 | |||
963 | #ifndef OPENSSL_NO_RSA | ||
964 | static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa) | ||
965 | { | ||
966 | char tempbuf[1024]; | ||
967 | HWCryptoHook_ErrMsgBuf rmsg; | ||
968 | HWCryptoHook_RSAKeyHandle *hptr; | ||
969 | int to_return = 0, ret; | ||
970 | |||
971 | rmsg.buf = tempbuf; | ||
972 | rmsg.size = sizeof(tempbuf); | ||
973 | |||
974 | if(!hwcrhk_context) | ||
975 | { | ||
976 | HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED); | ||
977 | goto err; | ||
978 | } | ||
979 | |||
980 | /* This provides support for nForce keys. Since that's opaque data | ||
981 | all we do is provide a handle to the proper key and let HWCryptoHook | ||
982 | take care of the rest. */ | ||
983 | if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx_rsa)) | ||
984 | != NULL) | ||
985 | { | ||
986 | HWCryptoHook_MPI m_a, m_r; | ||
987 | |||
988 | if(!rsa->n) | ||
989 | { | ||
990 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
991 | HWCRHK_R_MISSING_KEY_COMPONENTS); | ||
992 | goto err; | ||
993 | } | ||
994 | |||
995 | /* Prepare the params */ | ||
996 | bn_expand2(r, rsa->n->top); /* Check for error !! */ | ||
997 | BN2MPI(m_a, I); | ||
998 | MPI2BN(r, m_r); | ||
999 | |||
1000 | /* Perform the operation */ | ||
1001 | ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg); | ||
1002 | |||
1003 | /* Convert the response */ | ||
1004 | r->top = m_r.size / sizeof(BN_ULONG); | ||
1005 | bn_fix_top(r); | ||
1006 | |||
1007 | if (ret < 0) | ||
1008 | { | ||
1009 | /* FIXME: When this error is returned, HWCryptoHook is | ||
1010 | telling us that falling back to software computation | ||
1011 | might be a good thing. */ | ||
1012 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
1013 | { | ||
1014 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
1015 | HWCRHK_R_REQUEST_FALLBACK); | ||
1016 | } | ||
1017 | else | ||
1018 | { | ||
1019 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
1020 | HWCRHK_R_REQUEST_FAILED); | ||
1021 | } | ||
1022 | ERR_add_error_data(1,rmsg.buf); | ||
1023 | goto err; | ||
1024 | } | ||
1025 | } | ||
1026 | else | ||
1027 | { | ||
1028 | HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r; | ||
1029 | |||
1030 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
1031 | { | ||
1032 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
1033 | HWCRHK_R_MISSING_KEY_COMPONENTS); | ||
1034 | goto err; | ||
1035 | } | ||
1036 | |||
1037 | /* Prepare the params */ | ||
1038 | bn_expand2(r, rsa->n->top); /* Check for error !! */ | ||
1039 | BN2MPI(m_a, I); | ||
1040 | BN2MPI(m_p, rsa->p); | ||
1041 | BN2MPI(m_q, rsa->q); | ||
1042 | BN2MPI(m_dmp1, rsa->dmp1); | ||
1043 | BN2MPI(m_dmq1, rsa->dmq1); | ||
1044 | BN2MPI(m_iqmp, rsa->iqmp); | ||
1045 | MPI2BN(r, m_r); | ||
1046 | |||
1047 | /* Perform the operation */ | ||
1048 | ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q, | ||
1049 | m_dmp1, m_dmq1, m_iqmp, &m_r, &rmsg); | ||
1050 | |||
1051 | /* Convert the response */ | ||
1052 | r->top = m_r.size / sizeof(BN_ULONG); | ||
1053 | bn_fix_top(r); | ||
1054 | |||
1055 | if (ret < 0) | ||
1056 | { | ||
1057 | /* FIXME: When this error is returned, HWCryptoHook is | ||
1058 | telling us that falling back to software computation | ||
1059 | might be a good thing. */ | ||
1060 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
1061 | { | ||
1062 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
1063 | HWCRHK_R_REQUEST_FALLBACK); | ||
1064 | } | ||
1065 | else | ||
1066 | { | ||
1067 | HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP, | ||
1068 | HWCRHK_R_REQUEST_FAILED); | ||
1069 | } | ||
1070 | ERR_add_error_data(1,rmsg.buf); | ||
1071 | goto err; | ||
1072 | } | ||
1073 | } | ||
1074 | /* If we're here, we must be here with some semblance of success :-) */ | ||
1075 | to_return = 1; | ||
1076 | err: | ||
1077 | return to_return; | ||
1078 | } | ||
1079 | #endif | ||
1080 | |||
1081 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
1082 | static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
1083 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
1084 | { | ||
1085 | return hwcrhk_mod_exp(r, a, p, m, ctx); | ||
1086 | } | ||
1087 | |||
1088 | #ifndef OPENSSL_NO_DH | ||
1089 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
1090 | static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
1091 | const BIGNUM *a, const BIGNUM *p, | ||
1092 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
1093 | { | ||
1094 | return hwcrhk_mod_exp(r, a, p, m, ctx); | ||
1095 | } | ||
1096 | #endif | ||
1097 | |||
1098 | /* Random bytes are good */ | ||
1099 | static int hwcrhk_rand_bytes(unsigned char *buf, int num) | ||
1100 | { | ||
1101 | char tempbuf[1024]; | ||
1102 | HWCryptoHook_ErrMsgBuf rmsg; | ||
1103 | int to_return = 0; /* assume failure */ | ||
1104 | int ret; | ||
1105 | |||
1106 | rmsg.buf = tempbuf; | ||
1107 | rmsg.size = sizeof(tempbuf); | ||
1108 | |||
1109 | if(!hwcrhk_context) | ||
1110 | { | ||
1111 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES,HWCRHK_R_NOT_INITIALISED); | ||
1112 | goto err; | ||
1113 | } | ||
1114 | |||
1115 | ret = p_hwcrhk_RandomBytes(hwcrhk_context, buf, num, &rmsg); | ||
1116 | if (ret < 0) | ||
1117 | { | ||
1118 | /* FIXME: When this error is returned, HWCryptoHook is | ||
1119 | telling us that falling back to software computation | ||
1120 | might be a good thing. */ | ||
1121 | if(ret == HWCRYPTOHOOK_ERROR_FALLBACK) | ||
1122 | { | ||
1123 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES, | ||
1124 | HWCRHK_R_REQUEST_FALLBACK); | ||
1125 | } | ||
1126 | else | ||
1127 | { | ||
1128 | HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES, | ||
1129 | HWCRHK_R_REQUEST_FAILED); | ||
1130 | } | ||
1131 | ERR_add_error_data(1,rmsg.buf); | ||
1132 | goto err; | ||
1133 | } | ||
1134 | to_return = 1; | ||
1135 | err: | ||
1136 | return to_return; | ||
1137 | } | ||
1138 | |||
1139 | static int hwcrhk_rand_status(void) | ||
1140 | { | ||
1141 | return 1; | ||
1142 | } | ||
1143 | |||
1144 | /* This cleans up an RSA KM key, called when ex_data is freed */ | ||
1145 | |||
1146 | static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
1147 | int ind,long argl, void *argp) | ||
1148 | { | ||
1149 | char tempbuf[1024]; | ||
1150 | HWCryptoHook_ErrMsgBuf rmsg; | ||
1151 | #ifndef OPENSSL_NO_RSA | ||
1152 | HWCryptoHook_RSAKeyHandle *hptr; | ||
1153 | #endif | ||
1154 | #if !defined(OPENSSL_NO_RSA) | ||
1155 | int ret; | ||
1156 | #endif | ||
1157 | |||
1158 | rmsg.buf = tempbuf; | ||
1159 | rmsg.size = sizeof(tempbuf); | ||
1160 | |||
1161 | #ifndef OPENSSL_NO_RSA | ||
1162 | hptr = (HWCryptoHook_RSAKeyHandle *) item; | ||
1163 | if(hptr) | ||
1164 | { | ||
1165 | ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL); | ||
1166 | OPENSSL_free(hptr); | ||
1167 | } | ||
1168 | #endif | ||
1169 | } | ||
1170 | |||
1171 | /* Mutex calls: since the HWCryptoHook model closely follows the POSIX model | ||
1172 | * these just wrap the POSIX functions and add some logging. | ||
1173 | */ | ||
1174 | |||
1175 | static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt, | ||
1176 | HWCryptoHook_CallerContext *cactx) | ||
1177 | { | ||
1178 | mt->lockid = CRYPTO_get_new_dynlockid(); | ||
1179 | if (mt->lockid == 0) | ||
1180 | return 1; /* failure */ | ||
1181 | return 0; /* success */ | ||
1182 | } | ||
1183 | |||
1184 | static int hwcrhk_mutex_lock(HWCryptoHook_Mutex *mt) | ||
1185 | { | ||
1186 | CRYPTO_w_lock(mt->lockid); | ||
1187 | return 0; | ||
1188 | } | ||
1189 | |||
1190 | static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex * mt) | ||
1191 | { | ||
1192 | CRYPTO_w_unlock(mt->lockid); | ||
1193 | } | ||
1194 | |||
1195 | static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt) | ||
1196 | { | ||
1197 | CRYPTO_destroy_dynlockid(mt->lockid); | ||
1198 | } | ||
1199 | |||
1200 | /* Mutex upcalls to use if the application does not support dynamic locks */ | ||
1201 | |||
1202 | static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m, | ||
1203 | HWCryptoHook_CallerContext *c) | ||
1204 | { | ||
1205 | return 0; | ||
1206 | } | ||
1207 | static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m) | ||
1208 | { | ||
1209 | CRYPTO_w_lock(CRYPTO_LOCK_HWCRHK); | ||
1210 | return 0; | ||
1211 | } | ||
1212 | static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m) | ||
1213 | { | ||
1214 | CRYPTO_w_unlock(CRYPTO_LOCK_HWCRHK); | ||
1215 | } | ||
1216 | static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m) | ||
1217 | { | ||
1218 | } | ||
1219 | |||
1220 | static int hwcrhk_get_pass(const char *prompt_info, | ||
1221 | int *len_io, char *buf, | ||
1222 | HWCryptoHook_PassphraseContext *ppctx, | ||
1223 | HWCryptoHook_CallerContext *cactx) | ||
1224 | { | ||
1225 | pem_password_cb *callback = NULL; | ||
1226 | void *callback_data = NULL; | ||
1227 | UI_METHOD *ui_method = NULL; | ||
1228 | |||
1229 | if (cactx) | ||
1230 | { | ||
1231 | if (cactx->ui_method) | ||
1232 | ui_method = cactx->ui_method; | ||
1233 | if (cactx->password_callback) | ||
1234 | callback = cactx->password_callback; | ||
1235 | if (cactx->callback_data) | ||
1236 | callback_data = cactx->callback_data; | ||
1237 | } | ||
1238 | if (ppctx) | ||
1239 | { | ||
1240 | if (ppctx->ui_method) | ||
1241 | { | ||
1242 | ui_method = ppctx->ui_method; | ||
1243 | callback = NULL; | ||
1244 | } | ||
1245 | if (ppctx->callback_data) | ||
1246 | callback_data = ppctx->callback_data; | ||
1247 | } | ||
1248 | if (callback == NULL && ui_method == NULL) | ||
1249 | { | ||
1250 | HWCRHKerr(HWCRHK_F_HWCRHK_GET_PASS,HWCRHK_R_NO_CALLBACK); | ||
1251 | return -1; | ||
1252 | } | ||
1253 | |||
1254 | if (ui_method) | ||
1255 | { | ||
1256 | UI *ui = UI_new_method(ui_method); | ||
1257 | if (ui) | ||
1258 | { | ||
1259 | int ok; | ||
1260 | char *prompt = UI_construct_prompt(ui, | ||
1261 | "pass phrase", prompt_info); | ||
1262 | |||
1263 | ok = UI_add_input_string(ui,prompt, | ||
1264 | UI_INPUT_FLAG_DEFAULT_PWD, | ||
1265 | buf,0,(*len_io) - 1); | ||
1266 | UI_add_user_data(ui, callback_data); | ||
1267 | UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0); | ||
1268 | |||
1269 | if (ok >= 0) | ||
1270 | do | ||
1271 | { | ||
1272 | ok=UI_process(ui); | ||
1273 | } | ||
1274 | while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0)); | ||
1275 | |||
1276 | if (ok >= 0) | ||
1277 | *len_io = strlen(buf); | ||
1278 | |||
1279 | UI_free(ui); | ||
1280 | OPENSSL_free(prompt); | ||
1281 | } | ||
1282 | } | ||
1283 | else | ||
1284 | { | ||
1285 | *len_io = callback(buf, *len_io, 0, callback_data); | ||
1286 | } | ||
1287 | if(!*len_io) | ||
1288 | return -1; | ||
1289 | return 0; | ||
1290 | } | ||
1291 | |||
1292 | static int hwcrhk_insert_card(const char *prompt_info, | ||
1293 | const char *wrong_info, | ||
1294 | HWCryptoHook_PassphraseContext *ppctx, | ||
1295 | HWCryptoHook_CallerContext *cactx) | ||
1296 | { | ||
1297 | int ok = -1; | ||
1298 | UI *ui; | ||
1299 | void *callback_data = NULL; | ||
1300 | UI_METHOD *ui_method = NULL; | ||
1301 | |||
1302 | if (cactx) | ||
1303 | { | ||
1304 | if (cactx->ui_method) | ||
1305 | ui_method = cactx->ui_method; | ||
1306 | if (cactx->callback_data) | ||
1307 | callback_data = cactx->callback_data; | ||
1308 | } | ||
1309 | if (ppctx) | ||
1310 | { | ||
1311 | if (ppctx->ui_method) | ||
1312 | ui_method = ppctx->ui_method; | ||
1313 | if (ppctx->callback_data) | ||
1314 | callback_data = ppctx->callback_data; | ||
1315 | } | ||
1316 | if (ui_method == NULL) | ||
1317 | { | ||
1318 | HWCRHKerr(HWCRHK_F_HWCRHK_INSERT_CARD, | ||
1319 | HWCRHK_R_NO_CALLBACK); | ||
1320 | return -1; | ||
1321 | } | ||
1322 | |||
1323 | ui = UI_new_method(ui_method); | ||
1324 | |||
1325 | if (ui) | ||
1326 | { | ||
1327 | char answer; | ||
1328 | char buf[BUFSIZ]; | ||
1329 | |||
1330 | if (wrong_info) | ||
1331 | BIO_snprintf(buf, sizeof(buf)-1, | ||
1332 | "Current card: \"%s\"\n", wrong_info); | ||
1333 | ok = UI_dup_info_string(ui, buf); | ||
1334 | if (ok >= 0 && prompt_info) | ||
1335 | { | ||
1336 | BIO_snprintf(buf, sizeof(buf)-1, | ||
1337 | "Insert card \"%s\"", prompt_info); | ||
1338 | ok = UI_dup_input_boolean(ui, buf, | ||
1339 | "\n then hit <enter> or C<enter> to cancel\n", | ||
1340 | "\r\n", "Cc", UI_INPUT_FLAG_ECHO, &answer); | ||
1341 | } | ||
1342 | UI_add_user_data(ui, callback_data); | ||
1343 | |||
1344 | if (ok >= 0) | ||
1345 | ok = UI_process(ui); | ||
1346 | UI_free(ui); | ||
1347 | |||
1348 | if (ok == -2 || (ok >= 0 && answer == 'C')) | ||
1349 | ok = 1; | ||
1350 | else if (ok < 0) | ||
1351 | ok = -1; | ||
1352 | else | ||
1353 | ok = 0; | ||
1354 | } | ||
1355 | return ok; | ||
1356 | } | ||
1357 | |||
1358 | static void hwcrhk_log_message(void *logstr, const char *message) | ||
1359 | { | ||
1360 | BIO *lstream = NULL; | ||
1361 | |||
1362 | CRYPTO_w_lock(CRYPTO_LOCK_BIO); | ||
1363 | if (logstr) | ||
1364 | lstream=*(BIO **)logstr; | ||
1365 | if (lstream) | ||
1366 | { | ||
1367 | BIO_printf(lstream, "%s\n", message); | ||
1368 | } | ||
1369 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); | ||
1370 | } | ||
1371 | |||
1372 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
1373 | * shared-library. */ | ||
1374 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
1375 | static int bind_fn(ENGINE *e, const char *id) | ||
1376 | { | ||
1377 | if(id && (strcmp(id, engine_hwcrhk_id) != 0)) | ||
1378 | return 0; | ||
1379 | if(!bind_helper(e)) | ||
1380 | return 0; | ||
1381 | return 1; | ||
1382 | } | ||
1383 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
1384 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
1385 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
1386 | |||
1387 | #endif /* !OPENSSL_NO_HW_NCIPHER */ | ||
1388 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.c b/src/lib/libcrypto/engine/hw_ncipher_err.c new file mode 100644 index 0000000000..5bc94581b7 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ncipher_err.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* hw_ncipher_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-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 | |||
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 "hw_ncipher_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA HWCRHK_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"}, | ||
70 | {ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"}, | ||
71 | {ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"}, | ||
72 | {ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"}, | ||
73 | {ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"}, | ||
74 | {ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"}, | ||
75 | {ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"}, | ||
76 | {ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"}, | ||
77 | {ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"}, | ||
78 | {ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"}, | ||
79 | {0,NULL} | ||
80 | }; | ||
81 | |||
82 | static ERR_STRING_DATA HWCRHK_str_reasons[]= | ||
83 | { | ||
84 | {HWCRHK_R_ALREADY_LOADED ,"already loaded"}, | ||
85 | {HWCRHK_R_BIO_WAS_FREED ,"bio was freed"}, | ||
86 | {HWCRHK_R_CHIL_ERROR ,"chil error"}, | ||
87 | {HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
88 | {HWCRHK_R_DSO_FAILURE ,"dso failure"}, | ||
89 | {HWCRHK_R_DYNAMIC_LOCKING_MISSING ,"dynamic locking missing"}, | ||
90 | {HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
91 | {HWCRHK_R_NOT_INITIALISED ,"not initialised"}, | ||
92 | {HWCRHK_R_NOT_LOADED ,"not loaded"}, | ||
93 | {HWCRHK_R_NO_CALLBACK ,"no callback"}, | ||
94 | {HWCRHK_R_NO_KEY ,"no key"}, | ||
95 | {HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"}, | ||
96 | {HWCRHK_R_REQUEST_FAILED ,"request failed"}, | ||
97 | {HWCRHK_R_REQUEST_FALLBACK ,"request fallback"}, | ||
98 | {HWCRHK_R_UNIT_FAILURE ,"unit failure"}, | ||
99 | {0,NULL} | ||
100 | }; | ||
101 | |||
102 | #endif | ||
103 | |||
104 | #ifdef HWCRHK_LIB_NAME | ||
105 | static ERR_STRING_DATA HWCRHK_lib_name[]= | ||
106 | { | ||
107 | {0 ,HWCRHK_LIB_NAME}, | ||
108 | {0,NULL} | ||
109 | }; | ||
110 | #endif | ||
111 | |||
112 | |||
113 | static int HWCRHK_lib_error_code=0; | ||
114 | static int HWCRHK_error_init=1; | ||
115 | |||
116 | static void ERR_load_HWCRHK_strings(void) | ||
117 | { | ||
118 | if (HWCRHK_lib_error_code == 0) | ||
119 | HWCRHK_lib_error_code=ERR_get_next_error_library(); | ||
120 | |||
121 | if (HWCRHK_error_init) | ||
122 | { | ||
123 | HWCRHK_error_init=0; | ||
124 | #ifndef OPENSSL_NO_ERR | ||
125 | ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_functs); | ||
126 | ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons); | ||
127 | #endif | ||
128 | |||
129 | #ifdef HWCRHK_LIB_NAME | ||
130 | HWCRHK_lib_name->error = ERR_PACK(HWCRHK_lib_error_code,0,0); | ||
131 | ERR_load_strings(0,HWCRHK_lib_name); | ||
132 | #endif | ||
133 | } | ||
134 | } | ||
135 | |||
136 | static void ERR_unload_HWCRHK_strings(void) | ||
137 | { | ||
138 | if (HWCRHK_error_init == 0) | ||
139 | { | ||
140 | #ifndef OPENSSL_NO_ERR | ||
141 | ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_functs); | ||
142 | ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons); | ||
143 | #endif | ||
144 | |||
145 | #ifdef HWCRHK_LIB_NAME | ||
146 | ERR_unload_strings(0,HWCRHK_lib_name); | ||
147 | #endif | ||
148 | HWCRHK_error_init=1; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | static void ERR_HWCRHK_error(int function, int reason, char *file, int line) | ||
153 | { | ||
154 | if (HWCRHK_lib_error_code == 0) | ||
155 | HWCRHK_lib_error_code=ERR_get_next_error_library(); | ||
156 | ERR_PUT_error(HWCRHK_lib_error_code,function,reason,file,line); | ||
157 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.h b/src/lib/libcrypto/engine/hw_ncipher_err.h new file mode 100644 index 0000000000..d232d02319 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ncipher_err.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /* ==================================================================== | ||
2 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in | ||
13 | * the documentation and/or other materials provided with the | ||
14 | * distribution. | ||
15 | * | ||
16 | * 3. All advertising materials mentioning features or use of this | ||
17 | * software must display the following acknowledgment: | ||
18 | * "This product includes software developed by the OpenSSL Project | ||
19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
20 | * | ||
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
22 | * endorse or promote products derived from this software without | ||
23 | * prior written permission. For written permission, please contact | ||
24 | * openssl-core@openssl.org. | ||
25 | * | ||
26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
27 | * nor may "OpenSSL" appear in their names without prior written | ||
28 | * permission of the OpenSSL Project. | ||
29 | * | ||
30 | * 6. Redistributions of any form whatsoever must retain the following | ||
31 | * acknowledgment: | ||
32 | * "This product includes software developed by the OpenSSL Project | ||
33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
34 | * | ||
35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
47 | * ==================================================================== | ||
48 | * | ||
49 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_HWCRHK_ERR_H | ||
56 | #define HEADER_HWCRHK_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_HWCRHK_strings(void); | ||
63 | static void ERR_unload_HWCRHK_strings(void); | ||
64 | static void ERR_HWCRHK_error(int function, int reason, char *file, int line); | ||
65 | #define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the HWCRHK functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define HWCRHK_F_HWCRHK_CTRL 100 | ||
71 | #define HWCRHK_F_HWCRHK_FINISH 101 | ||
72 | #define HWCRHK_F_HWCRHK_GET_PASS 102 | ||
73 | #define HWCRHK_F_HWCRHK_INIT 103 | ||
74 | #define HWCRHK_F_HWCRHK_INSERT_CARD 104 | ||
75 | #define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105 | ||
76 | #define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106 | ||
77 | #define HWCRHK_F_HWCRHK_MOD_EXP 107 | ||
78 | #define HWCRHK_F_HWCRHK_RAND_BYTES 108 | ||
79 | #define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109 | ||
80 | |||
81 | /* Reason codes. */ | ||
82 | #define HWCRHK_R_ALREADY_LOADED 100 | ||
83 | #define HWCRHK_R_BIO_WAS_FREED 101 | ||
84 | #define HWCRHK_R_CHIL_ERROR 102 | ||
85 | #define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103 | ||
86 | #define HWCRHK_R_DSO_FAILURE 104 | ||
87 | #define HWCRHK_R_DYNAMIC_LOCKING_MISSING 114 | ||
88 | #define HWCRHK_R_MISSING_KEY_COMPONENTS 105 | ||
89 | #define HWCRHK_R_NOT_INITIALISED 106 | ||
90 | #define HWCRHK_R_NOT_LOADED 107 | ||
91 | #define HWCRHK_R_NO_CALLBACK 108 | ||
92 | #define HWCRHK_R_NO_KEY 109 | ||
93 | #define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110 | ||
94 | #define HWCRHK_R_REQUEST_FAILED 111 | ||
95 | #define HWCRHK_R_REQUEST_FALLBACK 112 | ||
96 | #define HWCRHK_R_UNIT_FAILURE 113 | ||
97 | |||
98 | #ifdef __cplusplus | ||
99 | } | ||
100 | #endif | ||
101 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_nuron.c b/src/lib/libcrypto/engine/hw_nuron.c new file mode 100644 index 0000000000..fb9188bfe5 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_nuron.c | |||
@@ -0,0 +1,418 @@ | |||
1 | /* crypto/engine/hw_nuron.c */ | ||
2 | /* Written by Ben Laurie for the OpenSSL Project, leaning heavily on Geoff | ||
3 | * Thorpe's Atalla implementation. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000-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 <stdio.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/dso.h> | ||
63 | #include <openssl/engine.h> | ||
64 | |||
65 | |||
66 | #ifndef OPENSSL_NO_HW | ||
67 | #ifndef OPENSSL_NO_HW_NURON | ||
68 | |||
69 | #define NURON_LIB_NAME "nuron engine" | ||
70 | #include "hw_nuron_err.c" | ||
71 | |||
72 | static const char *NURON_LIBNAME = NULL; | ||
73 | static const char *get_NURON_LIBNAME(void) | ||
74 | { | ||
75 | if(NURON_LIBNAME) | ||
76 | return NURON_LIBNAME; | ||
77 | return "nuronssl"; | ||
78 | } | ||
79 | static void free_NURON_LIBNAME(void) | ||
80 | { | ||
81 | if(NURON_LIBNAME) | ||
82 | OPENSSL_free((void*)NURON_LIBNAME); | ||
83 | NURON_LIBNAME = NULL; | ||
84 | } | ||
85 | static long set_NURON_LIBNAME(const char *name) | ||
86 | { | ||
87 | free_NURON_LIBNAME(); | ||
88 | return (((NURON_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
89 | } | ||
90 | static const char *NURON_F1 = "nuron_mod_exp"; | ||
91 | |||
92 | /* The definitions for control commands specific to this engine */ | ||
93 | #define NURON_CMD_SO_PATH ENGINE_CMD_BASE | ||
94 | static const ENGINE_CMD_DEFN nuron_cmd_defns[] = { | ||
95 | {NURON_CMD_SO_PATH, | ||
96 | "SO_PATH", | ||
97 | "Specifies the path to the 'nuronssl' shared library", | ||
98 | ENGINE_CMD_FLAG_STRING}, | ||
99 | {0, NULL, NULL, 0} | ||
100 | }; | ||
101 | |||
102 | typedef int tfnModExp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,const BIGNUM *m); | ||
103 | static tfnModExp *pfnModExp = NULL; | ||
104 | |||
105 | static DSO *pvDSOHandle = NULL; | ||
106 | |||
107 | static int nuron_destroy(ENGINE *e) | ||
108 | { | ||
109 | free_NURON_LIBNAME(); | ||
110 | ERR_unload_NURON_strings(); | ||
111 | return 1; | ||
112 | } | ||
113 | |||
114 | static int nuron_init(ENGINE *e) | ||
115 | { | ||
116 | if(pvDSOHandle != NULL) | ||
117 | { | ||
118 | NURONerr(NURON_F_NURON_INIT,NURON_R_ALREADY_LOADED); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | pvDSOHandle = DSO_load(NULL, get_NURON_LIBNAME(), NULL, | ||
123 | DSO_FLAG_NAME_TRANSLATION_EXT_ONLY); | ||
124 | if(!pvDSOHandle) | ||
125 | { | ||
126 | NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_NOT_FOUND); | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | pfnModExp = (tfnModExp *)DSO_bind_func(pvDSOHandle, NURON_F1); | ||
131 | if(!pfnModExp) | ||
132 | { | ||
133 | NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_FUNCTION_NOT_FOUND); | ||
134 | return 0; | ||
135 | } | ||
136 | |||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | static int nuron_finish(ENGINE *e) | ||
141 | { | ||
142 | free_NURON_LIBNAME(); | ||
143 | if(pvDSOHandle == NULL) | ||
144 | { | ||
145 | NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED); | ||
146 | return 0; | ||
147 | } | ||
148 | if(!DSO_free(pvDSOHandle)) | ||
149 | { | ||
150 | NURONerr(NURON_F_NURON_FINISH,NURON_R_DSO_FAILURE); | ||
151 | return 0; | ||
152 | } | ||
153 | pvDSOHandle=NULL; | ||
154 | pfnModExp=NULL; | ||
155 | return 1; | ||
156 | } | ||
157 | |||
158 | static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
159 | { | ||
160 | int initialised = ((pvDSOHandle == NULL) ? 0 : 1); | ||
161 | switch(cmd) | ||
162 | { | ||
163 | case NURON_CMD_SO_PATH: | ||
164 | if(p == NULL) | ||
165 | { | ||
166 | NURONerr(NURON_F_NURON_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
167 | return 0; | ||
168 | } | ||
169 | if(initialised) | ||
170 | { | ||
171 | NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED); | ||
172 | return 0; | ||
173 | } | ||
174 | return set_NURON_LIBNAME((const char *)p); | ||
175 | default: | ||
176 | break; | ||
177 | } | ||
178 | NURONerr(NURON_F_NURON_CTRL,NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p, | ||
183 | const BIGNUM *m,BN_CTX *ctx) | ||
184 | { | ||
185 | if(!pvDSOHandle) | ||
186 | { | ||
187 | NURONerr(NURON_F_NURON_MOD_EXP,NURON_R_NOT_LOADED); | ||
188 | return 0; | ||
189 | } | ||
190 | return pfnModExp(r,a,p,m); | ||
191 | } | ||
192 | |||
193 | #ifndef OPENSSL_NO_RSA | ||
194 | static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
195 | { | ||
196 | return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL); | ||
197 | } | ||
198 | #endif | ||
199 | |||
200 | #ifndef OPENSSL_NO_DSA | ||
201 | /* This code was liberated and adapted from the commented-out code in | ||
202 | * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration | ||
203 | * (it doesn't have a CRT form for RSA), this function means that an | ||
204 | * Atalla system running with a DSA server certificate can handshake | ||
205 | * around 5 or 6 times faster/more than an equivalent system running with | ||
206 | * RSA. Just check out the "signs" statistics from the RSA and DSA parts | ||
207 | * of "openssl speed -engine atalla dsa1024 rsa1024". */ | ||
208 | static int nuron_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
209 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
210 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
211 | { | ||
212 | BIGNUM t; | ||
213 | int to_return = 0; | ||
214 | |||
215 | BN_init(&t); | ||
216 | /* let rr = a1 ^ p1 mod m */ | ||
217 | if (!nuron_mod_exp(rr,a1,p1,m,ctx)) | ||
218 | goto end; | ||
219 | /* let t = a2 ^ p2 mod m */ | ||
220 | if (!nuron_mod_exp(&t,a2,p2,m,ctx)) | ||
221 | goto end; | ||
222 | /* let rr = rr * t mod m */ | ||
223 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) | ||
224 | goto end; | ||
225 | to_return = 1; | ||
226 | end: | ||
227 | BN_free(&t); | ||
228 | return to_return; | ||
229 | } | ||
230 | |||
231 | |||
232 | static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
233 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
234 | BN_MONT_CTX *m_ctx) | ||
235 | { | ||
236 | return nuron_mod_exp(r, a, p, m, ctx); | ||
237 | } | ||
238 | #endif | ||
239 | |||
240 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
241 | static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
242 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
243 | { | ||
244 | return nuron_mod_exp(r, a, p, m, ctx); | ||
245 | } | ||
246 | |||
247 | #ifndef OPENSSL_NO_DH | ||
248 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
249 | static int nuron_mod_exp_dh(const DH *dh, BIGNUM *r, | ||
250 | const BIGNUM *a, const BIGNUM *p, | ||
251 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
252 | { | ||
253 | return nuron_mod_exp(r, a, p, m, ctx); | ||
254 | } | ||
255 | #endif | ||
256 | |||
257 | #ifndef OPENSSL_NO_RSA | ||
258 | static RSA_METHOD nuron_rsa = | ||
259 | { | ||
260 | "Nuron RSA method", | ||
261 | NULL, | ||
262 | NULL, | ||
263 | NULL, | ||
264 | NULL, | ||
265 | nuron_rsa_mod_exp, | ||
266 | nuron_mod_exp_mont, | ||
267 | NULL, | ||
268 | NULL, | ||
269 | 0, | ||
270 | NULL, | ||
271 | NULL, | ||
272 | NULL | ||
273 | }; | ||
274 | #endif | ||
275 | |||
276 | #ifndef OPENSSL_NO_DSA | ||
277 | static DSA_METHOD nuron_dsa = | ||
278 | { | ||
279 | "Nuron DSA method", | ||
280 | NULL, /* dsa_do_sign */ | ||
281 | NULL, /* dsa_sign_setup */ | ||
282 | NULL, /* dsa_do_verify */ | ||
283 | nuron_dsa_mod_exp, /* dsa_mod_exp */ | ||
284 | nuron_mod_exp_dsa, /* bn_mod_exp */ | ||
285 | NULL, /* init */ | ||
286 | NULL, /* finish */ | ||
287 | 0, /* flags */ | ||
288 | NULL /* app_data */ | ||
289 | }; | ||
290 | #endif | ||
291 | |||
292 | #ifndef OPENSSL_NO_DH | ||
293 | static DH_METHOD nuron_dh = | ||
294 | { | ||
295 | "Nuron DH method", | ||
296 | NULL, | ||
297 | NULL, | ||
298 | nuron_mod_exp_dh, | ||
299 | NULL, | ||
300 | NULL, | ||
301 | 0, | ||
302 | NULL | ||
303 | }; | ||
304 | #endif | ||
305 | |||
306 | /* Constants used when creating the ENGINE */ | ||
307 | static const char *engine_nuron_id = "nuron"; | ||
308 | static const char *engine_nuron_name = "Nuron hardware engine support"; | ||
309 | |||
310 | /* This internal function is used by ENGINE_nuron() and possibly by the | ||
311 | * "dynamic" ENGINE support too */ | ||
312 | static int bind_helper(ENGINE *e) | ||
313 | { | ||
314 | #ifndef OPENSSL_NO_RSA | ||
315 | const RSA_METHOD *meth1; | ||
316 | #endif | ||
317 | #ifndef OPENSSL_NO_DSA | ||
318 | const DSA_METHOD *meth2; | ||
319 | #endif | ||
320 | #ifndef OPENSSL_NO_DH | ||
321 | const DH_METHOD *meth3; | ||
322 | #endif | ||
323 | if(!ENGINE_set_id(e, engine_nuron_id) || | ||
324 | !ENGINE_set_name(e, engine_nuron_name) || | ||
325 | #ifndef OPENSSL_NO_RSA | ||
326 | !ENGINE_set_RSA(e, &nuron_rsa) || | ||
327 | #endif | ||
328 | #ifndef OPENSSL_NO_DSA | ||
329 | !ENGINE_set_DSA(e, &nuron_dsa) || | ||
330 | #endif | ||
331 | #ifndef OPENSSL_NO_DH | ||
332 | !ENGINE_set_DH(e, &nuron_dh) || | ||
333 | #endif | ||
334 | !ENGINE_set_destroy_function(e, nuron_destroy) || | ||
335 | !ENGINE_set_init_function(e, nuron_init) || | ||
336 | !ENGINE_set_finish_function(e, nuron_finish) || | ||
337 | !ENGINE_set_ctrl_function(e, nuron_ctrl) || | ||
338 | !ENGINE_set_cmd_defns(e, nuron_cmd_defns)) | ||
339 | return 0; | ||
340 | |||
341 | #ifndef OPENSSL_NO_RSA | ||
342 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
343 | * to the nuron-specific mod_exp and mod_exp_crt so we use | ||
344 | * those functions. NB: We don't use ENGINE_openssl() or | ||
345 | * anything "more generic" because something like the RSAref | ||
346 | * code may not hook properly, and if you own one of these | ||
347 | * cards then you have the right to do RSA operations on it | ||
348 | * anyway! */ | ||
349 | meth1=RSA_PKCS1_SSLeay(); | ||
350 | nuron_rsa.rsa_pub_enc=meth1->rsa_pub_enc; | ||
351 | nuron_rsa.rsa_pub_dec=meth1->rsa_pub_dec; | ||
352 | nuron_rsa.rsa_priv_enc=meth1->rsa_priv_enc; | ||
353 | nuron_rsa.rsa_priv_dec=meth1->rsa_priv_dec; | ||
354 | #endif | ||
355 | |||
356 | #ifndef OPENSSL_NO_DSA | ||
357 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
358 | * bits. */ | ||
359 | meth2=DSA_OpenSSL(); | ||
360 | nuron_dsa.dsa_do_sign=meth2->dsa_do_sign; | ||
361 | nuron_dsa.dsa_sign_setup=meth2->dsa_sign_setup; | ||
362 | nuron_dsa.dsa_do_verify=meth2->dsa_do_verify; | ||
363 | #endif | ||
364 | |||
365 | #ifndef OPENSSL_NO_DH | ||
366 | /* Much the same for Diffie-Hellman */ | ||
367 | meth3=DH_OpenSSL(); | ||
368 | nuron_dh.generate_key=meth3->generate_key; | ||
369 | nuron_dh.compute_key=meth3->compute_key; | ||
370 | #endif | ||
371 | |||
372 | /* Ensure the nuron error handling is set up */ | ||
373 | ERR_load_NURON_strings(); | ||
374 | return 1; | ||
375 | } | ||
376 | |||
377 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
378 | static ENGINE *engine_nuron(void) | ||
379 | { | ||
380 | ENGINE *ret = ENGINE_new(); | ||
381 | if(!ret) | ||
382 | return NULL; | ||
383 | if(!bind_helper(ret)) | ||
384 | { | ||
385 | ENGINE_free(ret); | ||
386 | return NULL; | ||
387 | } | ||
388 | return ret; | ||
389 | } | ||
390 | |||
391 | void ENGINE_load_nuron(void) | ||
392 | { | ||
393 | /* Copied from eng_[openssl|dyn].c */ | ||
394 | ENGINE *toadd = engine_nuron(); | ||
395 | if(!toadd) return; | ||
396 | ENGINE_add(toadd); | ||
397 | ENGINE_free(toadd); | ||
398 | ERR_clear_error(); | ||
399 | } | ||
400 | #endif | ||
401 | |||
402 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
403 | * shared-library. */ | ||
404 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
405 | static int bind_fn(ENGINE *e, const char *id) | ||
406 | { | ||
407 | if(id && (strcmp(id, engine_nuron_id) != 0)) | ||
408 | return 0; | ||
409 | if(!bind_helper(e)) | ||
410 | return 0; | ||
411 | return 1; | ||
412 | } | ||
413 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
414 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
415 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
416 | |||
417 | #endif /* !OPENSSL_NO_HW_NURON */ | ||
418 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.c b/src/lib/libcrypto/engine/hw_nuron_err.c new file mode 100644 index 0000000000..df9d7bde76 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_nuron_err.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* hw_nuron_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_nuron_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA NURON_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"}, | ||
70 | {ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"}, | ||
71 | {ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"}, | ||
72 | {ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"}, | ||
73 | {0,NULL} | ||
74 | }; | ||
75 | |||
76 | static ERR_STRING_DATA NURON_str_reasons[]= | ||
77 | { | ||
78 | {NURON_R_ALREADY_LOADED ,"already loaded"}, | ||
79 | {NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
80 | {NURON_R_DSO_FAILURE ,"dso failure"}, | ||
81 | {NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"}, | ||
82 | {NURON_R_DSO_NOT_FOUND ,"dso not found"}, | ||
83 | {NURON_R_NOT_LOADED ,"not loaded"}, | ||
84 | {0,NULL} | ||
85 | }; | ||
86 | |||
87 | #endif | ||
88 | |||
89 | #ifdef NURON_LIB_NAME | ||
90 | static ERR_STRING_DATA NURON_lib_name[]= | ||
91 | { | ||
92 | {0 ,NURON_LIB_NAME}, | ||
93 | {0,NULL} | ||
94 | }; | ||
95 | #endif | ||
96 | |||
97 | |||
98 | static int NURON_lib_error_code=0; | ||
99 | static int NURON_error_init=1; | ||
100 | |||
101 | static void ERR_load_NURON_strings(void) | ||
102 | { | ||
103 | if (NURON_lib_error_code == 0) | ||
104 | NURON_lib_error_code=ERR_get_next_error_library(); | ||
105 | |||
106 | if (NURON_error_init) | ||
107 | { | ||
108 | NURON_error_init=0; | ||
109 | #ifndef OPENSSL_NO_ERR | ||
110 | ERR_load_strings(NURON_lib_error_code,NURON_str_functs); | ||
111 | ERR_load_strings(NURON_lib_error_code,NURON_str_reasons); | ||
112 | #endif | ||
113 | |||
114 | #ifdef NURON_LIB_NAME | ||
115 | NURON_lib_name->error = ERR_PACK(NURON_lib_error_code,0,0); | ||
116 | ERR_load_strings(0,NURON_lib_name); | ||
117 | #endif | ||
118 | } | ||
119 | } | ||
120 | |||
121 | static void ERR_unload_NURON_strings(void) | ||
122 | { | ||
123 | if (NURON_error_init == 0) | ||
124 | { | ||
125 | #ifndef OPENSSL_NO_ERR | ||
126 | ERR_unload_strings(NURON_lib_error_code,NURON_str_functs); | ||
127 | ERR_unload_strings(NURON_lib_error_code,NURON_str_reasons); | ||
128 | #endif | ||
129 | |||
130 | #ifdef NURON_LIB_NAME | ||
131 | ERR_unload_strings(0,NURON_lib_name); | ||
132 | #endif | ||
133 | NURON_error_init=1; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | static void ERR_NURON_error(int function, int reason, char *file, int line) | ||
138 | { | ||
139 | if (NURON_lib_error_code == 0) | ||
140 | NURON_lib_error_code=ERR_get_next_error_library(); | ||
141 | ERR_PUT_error(NURON_lib_error_code,function,reason,file,line); | ||
142 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.h b/src/lib/libcrypto/engine/hw_nuron_err.h new file mode 100644 index 0000000000..a56bfdf303 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_nuron_err.h | |||
@@ -0,0 +1,86 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_NURON_ERR_H | ||
56 | #define HEADER_NURON_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_NURON_strings(void); | ||
63 | static void ERR_unload_NURON_strings(void); | ||
64 | static void ERR_NURON_error(int function, int reason, char *file, int line); | ||
65 | #define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the NURON functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define NURON_F_NURON_CTRL 100 | ||
71 | #define NURON_F_NURON_FINISH 101 | ||
72 | #define NURON_F_NURON_INIT 102 | ||
73 | #define NURON_F_NURON_MOD_EXP 103 | ||
74 | |||
75 | /* Reason codes. */ | ||
76 | #define NURON_R_ALREADY_LOADED 100 | ||
77 | #define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101 | ||
78 | #define NURON_R_DSO_FAILURE 102 | ||
79 | #define NURON_R_DSO_FUNCTION_NOT_FOUND 103 | ||
80 | #define NURON_R_DSO_NOT_FOUND 104 | ||
81 | #define NURON_R_NOT_LOADED 105 | ||
82 | |||
83 | #ifdef __cplusplus | ||
84 | } | ||
85 | #endif | ||
86 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware.c b/src/lib/libcrypto/engine/hw_sureware.c new file mode 100644 index 0000000000..fca467e690 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_sureware.c | |||
@@ -0,0 +1,1039 @@ | |||
1 | /* Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
2 | * | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in | ||
13 | * the documentation and/or other materials provided with the | ||
14 | * distribution. | ||
15 | * | ||
16 | * 3. All advertising materials mentioning features or use of this | ||
17 | * software must display the following acknowledgment: | ||
18 | * "This product includes software developed by the OpenSSL Project | ||
19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
20 | * | ||
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
22 | * endorse or promote products derived from this software without | ||
23 | * prior written permission. For written permission, please contact | ||
24 | * licensing@OpenSSL.org. | ||
25 | * | ||
26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
27 | * nor may "OpenSSL" appear in their names without prior written | ||
28 | * permission of the OpenSSL Project. | ||
29 | * | ||
30 | * 6. Redistributions of any form whatsoever must retain the following | ||
31 | * acknowledgment: | ||
32 | * "This product includes software developed by the OpenSSL Project | ||
33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
34 | * | ||
35 | * Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
36 | * | ||
37 | * Copyright@2001 Baltimore Technologies Ltd. | ||
38 | * All right Reserved. | ||
39 | * * | ||
40 | * THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND * | ||
41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * | ||
43 | * ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE * | ||
44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * | ||
45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * | ||
46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * | ||
48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * | ||
49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * | ||
50 | * SUCH DAMAGE. * | ||
51 | ====================================================================*/ | ||
52 | |||
53 | #include <stdio.h> | ||
54 | #include "cryptlib.h" | ||
55 | #include <openssl/crypto.h> | ||
56 | #include <openssl/pem.h> | ||
57 | #include <openssl/dso.h> | ||
58 | #include "eng_int.h" | ||
59 | #include "engine.h" | ||
60 | #include <openssl/engine.h> | ||
61 | |||
62 | #ifndef OPENSSL_NO_HW | ||
63 | #ifndef OPENSSL_NO_HW_SUREWARE | ||
64 | |||
65 | #ifdef FLAT_INC | ||
66 | #include "sureware.h" | ||
67 | #else | ||
68 | #include "vendor_defns/sureware.h" | ||
69 | #endif | ||
70 | |||
71 | #define SUREWARE_LIB_NAME "sureware engine" | ||
72 | #include "hw_sureware_err.c" | ||
73 | |||
74 | static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
75 | static int surewarehk_destroy(ENGINE *e); | ||
76 | static int surewarehk_init(ENGINE *e); | ||
77 | static int surewarehk_finish(ENGINE *e); | ||
78 | static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
79 | const BIGNUM *m, BN_CTX *ctx); | ||
80 | |||
81 | /* RSA stuff */ | ||
82 | static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to, | ||
83 | RSA *rsa,int padding); | ||
84 | static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to, | ||
85 | RSA *rsa,int padding); | ||
86 | |||
87 | /* RAND stuff */ | ||
88 | static int surewarehk_rand_bytes(unsigned char *buf, int num); | ||
89 | static void surewarehk_rand_seed(const void *buf, int num); | ||
90 | static void surewarehk_rand_add(const void *buf, int num, double entropy); | ||
91 | |||
92 | /* KM stuff */ | ||
93 | static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id, | ||
94 | UI_METHOD *ui_method, void *callback_data); | ||
95 | static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id, | ||
96 | UI_METHOD *ui_method, void *callback_data); | ||
97 | static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
98 | int idx,long argl, void *argp); | ||
99 | #if 0 | ||
100 | static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
101 | int idx,long argl, void *argp); | ||
102 | #endif | ||
103 | |||
104 | #ifndef OPENSSL_NO_RSA | ||
105 | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | ||
106 | static int surewarehk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
107 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
108 | { | ||
109 | return surewarehk_modexp(r, a, p, m, ctx); | ||
110 | } | ||
111 | |||
112 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
113 | static RSA_METHOD surewarehk_rsa = | ||
114 | { | ||
115 | "SureWare RSA method", | ||
116 | NULL, /* pub_enc*/ | ||
117 | NULL, /* pub_dec*/ | ||
118 | surewarehk_rsa_sign, /* our rsa_sign is OpenSSL priv_enc*/ | ||
119 | surewarehk_rsa_priv_dec, /* priv_dec*/ | ||
120 | NULL, /*mod_exp*/ | ||
121 | surewarehk_mod_exp_mont, /*mod_exp_mongomery*/ | ||
122 | NULL, /* init*/ | ||
123 | NULL, /* finish*/ | ||
124 | 0, /* RSA flag*/ | ||
125 | NULL, | ||
126 | NULL, /* OpenSSL sign*/ | ||
127 | NULL /* OpenSSL verify*/ | ||
128 | }; | ||
129 | #endif | ||
130 | |||
131 | #ifndef OPENSSL_NO_DH | ||
132 | /* Our internal DH_METHOD that we provide pointers to */ | ||
133 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
134 | static int surewarehk_modexp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
135 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
136 | { | ||
137 | return surewarehk_modexp(r, a, p, m, ctx); | ||
138 | } | ||
139 | |||
140 | static DH_METHOD surewarehk_dh = | ||
141 | { | ||
142 | "SureWare DH method", | ||
143 | NULL,/*gen_key*/ | ||
144 | NULL,/*agree,*/ | ||
145 | surewarehk_modexp_dh, /*dh mod exp*/ | ||
146 | NULL, /* init*/ | ||
147 | NULL, /* finish*/ | ||
148 | 0, /* flags*/ | ||
149 | NULL | ||
150 | }; | ||
151 | #endif | ||
152 | |||
153 | static RAND_METHOD surewarehk_rand = | ||
154 | { | ||
155 | /* "SureWare RAND method", */ | ||
156 | surewarehk_rand_seed, | ||
157 | surewarehk_rand_bytes, | ||
158 | NULL,/*cleanup*/ | ||
159 | surewarehk_rand_add, | ||
160 | surewarehk_rand_bytes, | ||
161 | NULL,/*rand_status*/ | ||
162 | }; | ||
163 | |||
164 | #ifndef OPENSSL_NO_DSA | ||
165 | /* DSA stuff */ | ||
166 | static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
167 | static int surewarehk_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
168 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
169 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
170 | { | ||
171 | BIGNUM t; | ||
172 | int to_return = 0; | ||
173 | BN_init(&t); | ||
174 | /* let rr = a1 ^ p1 mod m */ | ||
175 | if (!surewarehk_modexp(rr,a1,p1,m,ctx)) goto end; | ||
176 | /* let t = a2 ^ p2 mod m */ | ||
177 | if (!surewarehk_modexp(&t,a2,p2,m,ctx)) goto end; | ||
178 | /* let rr = rr * t mod m */ | ||
179 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
180 | to_return = 1; | ||
181 | end: | ||
182 | BN_free(&t); | ||
183 | return to_return; | ||
184 | } | ||
185 | |||
186 | static DSA_METHOD surewarehk_dsa = | ||
187 | { | ||
188 | "SureWare DSA method", | ||
189 | surewarehk_dsa_do_sign, | ||
190 | NULL,/*sign setup*/ | ||
191 | NULL,/*verify,*/ | ||
192 | surewarehk_dsa_mod_exp,/*mod exp*/ | ||
193 | NULL,/*bn mod exp*/ | ||
194 | NULL, /*init*/ | ||
195 | NULL,/*finish*/ | ||
196 | 0, | ||
197 | NULL, | ||
198 | }; | ||
199 | #endif | ||
200 | |||
201 | static const char *engine_sureware_id = "sureware"; | ||
202 | static const char *engine_sureware_name = "SureWare hardware engine support"; | ||
203 | |||
204 | /* Now, to our own code */ | ||
205 | |||
206 | /* As this is only ever called once, there's no need for locking | ||
207 | * (indeed - the lock will already be held by our caller!!!) */ | ||
208 | static int bind_sureware(ENGINE *e) | ||
209 | { | ||
210 | #ifndef OPENSSL_NO_RSA | ||
211 | const RSA_METHOD *meth1; | ||
212 | #endif | ||
213 | #ifndef OPENSSL_NO_DSA | ||
214 | const DSA_METHOD *meth2; | ||
215 | #endif | ||
216 | #ifndef OPENSSL_NO_DH | ||
217 | const DH_METHOD *meth3; | ||
218 | #endif | ||
219 | |||
220 | if(!ENGINE_set_id(e, engine_sureware_id) || | ||
221 | !ENGINE_set_name(e, engine_sureware_name) || | ||
222 | #ifndef OPENSSL_NO_RSA | ||
223 | !ENGINE_set_RSA(e, &surewarehk_rsa) || | ||
224 | #endif | ||
225 | #ifndef OPENSSL_NO_DSA | ||
226 | !ENGINE_set_DSA(e, &surewarehk_dsa) || | ||
227 | #endif | ||
228 | #ifndef OPENSSL_NO_DH | ||
229 | !ENGINE_set_DH(e, &surewarehk_dh) || | ||
230 | #endif | ||
231 | !ENGINE_set_RAND(e, &surewarehk_rand) || | ||
232 | !ENGINE_set_destroy_function(e, surewarehk_destroy) || | ||
233 | !ENGINE_set_init_function(e, surewarehk_init) || | ||
234 | !ENGINE_set_finish_function(e, surewarehk_finish) || | ||
235 | !ENGINE_set_ctrl_function(e, surewarehk_ctrl) || | ||
236 | !ENGINE_set_load_privkey_function(e, surewarehk_load_privkey) || | ||
237 | !ENGINE_set_load_pubkey_function(e, surewarehk_load_pubkey)) | ||
238 | return 0; | ||
239 | |||
240 | #ifndef OPENSSL_NO_RSA | ||
241 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
242 | * to the cswift-specific mod_exp and mod_exp_crt so we use | ||
243 | * those functions. NB: We don't use ENGINE_openssl() or | ||
244 | * anything "more generic" because something like the RSAref | ||
245 | * code may not hook properly, and if you own one of these | ||
246 | * cards then you have the right to do RSA operations on it | ||
247 | * anyway! */ | ||
248 | meth1 = RSA_PKCS1_SSLeay(); | ||
249 | if (meth1) | ||
250 | { | ||
251 | surewarehk_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
252 | surewarehk_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
253 | } | ||
254 | #endif | ||
255 | |||
256 | #ifndef OPENSSL_NO_DSA | ||
257 | /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish | ||
258 | * bits. */ | ||
259 | meth2 = DSA_OpenSSL(); | ||
260 | if (meth2) | ||
261 | { | ||
262 | surewarehk_dsa.dsa_do_verify = meth2->dsa_do_verify; | ||
263 | } | ||
264 | #endif | ||
265 | |||
266 | #ifndef OPENSSL_NO_DH | ||
267 | /* Much the same for Diffie-Hellman */ | ||
268 | meth3 = DH_OpenSSL(); | ||
269 | if (meth3) | ||
270 | { | ||
271 | surewarehk_dh.generate_key = meth3->generate_key; | ||
272 | surewarehk_dh.compute_key = meth3->compute_key; | ||
273 | } | ||
274 | #endif | ||
275 | |||
276 | /* Ensure the sureware error handling is set up */ | ||
277 | ERR_load_SUREWARE_strings(); | ||
278 | return 1; | ||
279 | } | ||
280 | |||
281 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
282 | static int bind_helper(ENGINE *e, const char *id) | ||
283 | { | ||
284 | if(id && (strcmp(id, engine_sureware_id) != 0)) | ||
285 | return 0; | ||
286 | if(!bind_sureware(e)) | ||
287 | return 0; | ||
288 | return 1; | ||
289 | } | ||
290 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
291 | IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) | ||
292 | #else | ||
293 | static ENGINE *engine_sureware(void) | ||
294 | { | ||
295 | ENGINE *ret = ENGINE_new(); | ||
296 | if(!ret) | ||
297 | return NULL; | ||
298 | if(!bind_sureware(ret)) | ||
299 | { | ||
300 | ENGINE_free(ret); | ||
301 | return NULL; | ||
302 | } | ||
303 | return ret; | ||
304 | } | ||
305 | |||
306 | void ENGINE_load_sureware(void) | ||
307 | { | ||
308 | /* Copied from eng_[openssl|dyn].c */ | ||
309 | ENGINE *toadd = engine_sureware(); | ||
310 | if(!toadd) return; | ||
311 | ENGINE_add(toadd); | ||
312 | ENGINE_free(toadd); | ||
313 | ERR_clear_error(); | ||
314 | } | ||
315 | #endif | ||
316 | |||
317 | /* This is a process-global DSO handle used for loading and unloading | ||
318 | * the SureWareHook library. NB: This is only set (or unset) during an | ||
319 | * init() or finish() call (reference counts permitting) and they're | ||
320 | * operating with global locks, so this should be thread-safe | ||
321 | * implicitly. */ | ||
322 | static DSO *surewarehk_dso = NULL; | ||
323 | #ifndef OPENSSL_NO_RSA | ||
324 | static int rsaHndidx = -1; /* Index for KM handle. Not really used yet. */ | ||
325 | #endif | ||
326 | #ifndef OPENSSL_NO_DSA | ||
327 | static int dsaHndidx = -1; /* Index for KM handle. Not really used yet. */ | ||
328 | #endif | ||
329 | |||
330 | /* These are the function pointers that are (un)set when the library has | ||
331 | * successfully (un)loaded. */ | ||
332 | static SureWareHook_Init_t *p_surewarehk_Init = NULL; | ||
333 | static SureWareHook_Finish_t *p_surewarehk_Finish = NULL; | ||
334 | static SureWareHook_Rand_Bytes_t *p_surewarehk_Rand_Bytes = NULL; | ||
335 | static SureWareHook_Rand_Seed_t *p_surewarehk_Rand_Seed = NULL; | ||
336 | static SureWareHook_Load_Privkey_t *p_surewarehk_Load_Privkey = NULL; | ||
337 | static SureWareHook_Info_Pubkey_t *p_surewarehk_Info_Pubkey = NULL; | ||
338 | static SureWareHook_Load_Rsa_Pubkey_t *p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
339 | static SureWareHook_Load_Dsa_Pubkey_t *p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
340 | static SureWareHook_Free_t *p_surewarehk_Free=NULL; | ||
341 | static SureWareHook_Rsa_Priv_Dec_t *p_surewarehk_Rsa_Priv_Dec=NULL; | ||
342 | static SureWareHook_Rsa_Sign_t *p_surewarehk_Rsa_Sign=NULL; | ||
343 | static SureWareHook_Dsa_Sign_t *p_surewarehk_Dsa_Sign=NULL; | ||
344 | static SureWareHook_Mod_Exp_t *p_surewarehk_Mod_Exp=NULL; | ||
345 | |||
346 | /* Used in the DSO operations. */ | ||
347 | static const char *surewarehk_LIBNAME = "SureWareHook"; | ||
348 | static const char *n_surewarehk_Init = "SureWareHook_Init"; | ||
349 | static const char *n_surewarehk_Finish = "SureWareHook_Finish"; | ||
350 | static const char *n_surewarehk_Rand_Bytes="SureWareHook_Rand_Bytes"; | ||
351 | static const char *n_surewarehk_Rand_Seed="SureWareHook_Rand_Seed"; | ||
352 | static const char *n_surewarehk_Load_Privkey="SureWareHook_Load_Privkey"; | ||
353 | static const char *n_surewarehk_Info_Pubkey="SureWareHook_Info_Pubkey"; | ||
354 | static const char *n_surewarehk_Load_Rsa_Pubkey="SureWareHook_Load_Rsa_Pubkey"; | ||
355 | static const char *n_surewarehk_Load_Dsa_Pubkey="SureWareHook_Load_Dsa_Pubkey"; | ||
356 | static const char *n_surewarehk_Free="SureWareHook_Free"; | ||
357 | static const char *n_surewarehk_Rsa_Priv_Dec="SureWareHook_Rsa_Priv_Dec"; | ||
358 | static const char *n_surewarehk_Rsa_Sign="SureWareHook_Rsa_Sign"; | ||
359 | static const char *n_surewarehk_Dsa_Sign="SureWareHook_Dsa_Sign"; | ||
360 | static const char *n_surewarehk_Mod_Exp="SureWareHook_Mod_Exp"; | ||
361 | static BIO *logstream = NULL; | ||
362 | |||
363 | /* SureWareHook library functions and mechanics - these are used by the | ||
364 | * higher-level functions further down. NB: As and where there's no | ||
365 | * error checking, take a look lower down where these functions are | ||
366 | * called, the checking and error handling is probably down there. | ||
367 | */ | ||
368 | static int threadsafe=1; | ||
369 | static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
370 | { | ||
371 | int to_return = 1; | ||
372 | |||
373 | switch(cmd) | ||
374 | { | ||
375 | case ENGINE_CTRL_SET_LOGSTREAM: | ||
376 | { | ||
377 | BIO *bio = (BIO *)p; | ||
378 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
379 | if (logstream) | ||
380 | { | ||
381 | BIO_free(logstream); | ||
382 | logstream = NULL; | ||
383 | } | ||
384 | if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1) | ||
385 | logstream = bio; | ||
386 | else | ||
387 | SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL,SUREWARE_R_BIO_WAS_FREED); | ||
388 | } | ||
389 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
390 | break; | ||
391 | /* This will prevent the initialisation function from "installing" | ||
392 | * the mutex-handling callbacks, even if they are available from | ||
393 | * within the library (or were provided to the library from the | ||
394 | * calling application). This is to remove any baggage for | ||
395 | * applications not using multithreading. */ | ||
396 | case ENGINE_CTRL_CHIL_NO_LOCKING: | ||
397 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
398 | threadsafe = 0; | ||
399 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
400 | break; | ||
401 | |||
402 | /* The command isn't understood by this engine */ | ||
403 | default: | ||
404 | SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL, | ||
405 | ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
406 | to_return = 0; | ||
407 | break; | ||
408 | } | ||
409 | |||
410 | return to_return; | ||
411 | } | ||
412 | |||
413 | /* Destructor (complements the "ENGINE_surewarehk()" constructor) */ | ||
414 | static int surewarehk_destroy(ENGINE *e) | ||
415 | { | ||
416 | ERR_unload_SUREWARE_strings(); | ||
417 | return 1; | ||
418 | } | ||
419 | |||
420 | /* (de)initialisation functions. */ | ||
421 | static int surewarehk_init(ENGINE *e) | ||
422 | { | ||
423 | char msg[64]="ENGINE_init"; | ||
424 | SureWareHook_Init_t *p1=NULL; | ||
425 | SureWareHook_Finish_t *p2=NULL; | ||
426 | SureWareHook_Rand_Bytes_t *p3=NULL; | ||
427 | SureWareHook_Rand_Seed_t *p4=NULL; | ||
428 | SureWareHook_Load_Privkey_t *p5=NULL; | ||
429 | SureWareHook_Load_Rsa_Pubkey_t *p6=NULL; | ||
430 | SureWareHook_Free_t *p7=NULL; | ||
431 | SureWareHook_Rsa_Priv_Dec_t *p8=NULL; | ||
432 | SureWareHook_Rsa_Sign_t *p9=NULL; | ||
433 | SureWareHook_Dsa_Sign_t *p12=NULL; | ||
434 | SureWareHook_Info_Pubkey_t *p13=NULL; | ||
435 | SureWareHook_Load_Dsa_Pubkey_t *p14=NULL; | ||
436 | SureWareHook_Mod_Exp_t *p15=NULL; | ||
437 | |||
438 | if(surewarehk_dso != NULL) | ||
439 | { | ||
440 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_ALREADY_LOADED); | ||
441 | goto err; | ||
442 | } | ||
443 | /* Attempt to load libsurewarehk.so/surewarehk.dll/whatever. */ | ||
444 | surewarehk_dso = DSO_load(NULL, surewarehk_LIBNAME, NULL, 0); | ||
445 | if(surewarehk_dso == NULL) | ||
446 | { | ||
447 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE); | ||
448 | goto err; | ||
449 | } | ||
450 | if(!(p1=(SureWareHook_Init_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Init)) || | ||
451 | !(p2=(SureWareHook_Finish_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Finish)) || | ||
452 | !(p3=(SureWareHook_Rand_Bytes_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Bytes)) || | ||
453 | !(p4=(SureWareHook_Rand_Seed_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Seed)) || | ||
454 | !(p5=(SureWareHook_Load_Privkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Privkey)) || | ||
455 | !(p6=(SureWareHook_Load_Rsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Rsa_Pubkey)) || | ||
456 | !(p7=(SureWareHook_Free_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Free)) || | ||
457 | !(p8=(SureWareHook_Rsa_Priv_Dec_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Priv_Dec)) || | ||
458 | !(p9=(SureWareHook_Rsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Sign)) || | ||
459 | !(p12=(SureWareHook_Dsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Dsa_Sign)) || | ||
460 | !(p13=(SureWareHook_Info_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Info_Pubkey)) || | ||
461 | !(p14=(SureWareHook_Load_Dsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Dsa_Pubkey)) || | ||
462 | !(p15=(SureWareHook_Mod_Exp_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Mod_Exp))) | ||
463 | { | ||
464 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE); | ||
465 | goto err; | ||
466 | } | ||
467 | /* Copy the pointers */ | ||
468 | p_surewarehk_Init = p1; | ||
469 | p_surewarehk_Finish = p2; | ||
470 | p_surewarehk_Rand_Bytes = p3; | ||
471 | p_surewarehk_Rand_Seed = p4; | ||
472 | p_surewarehk_Load_Privkey = p5; | ||
473 | p_surewarehk_Load_Rsa_Pubkey = p6; | ||
474 | p_surewarehk_Free = p7; | ||
475 | p_surewarehk_Rsa_Priv_Dec = p8; | ||
476 | p_surewarehk_Rsa_Sign = p9; | ||
477 | p_surewarehk_Dsa_Sign = p12; | ||
478 | p_surewarehk_Info_Pubkey = p13; | ||
479 | p_surewarehk_Load_Dsa_Pubkey = p14; | ||
480 | p_surewarehk_Mod_Exp = p15; | ||
481 | /* Contact the hardware and initialises it. */ | ||
482 | if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE) | ||
483 | { | ||
484 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE); | ||
485 | goto err; | ||
486 | } | ||
487 | if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE) | ||
488 | { | ||
489 | SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE); | ||
490 | goto err; | ||
491 | } | ||
492 | /* try to load the default private key, if failed does not return a failure but | ||
493 | wait for an explicit ENGINE_load_privakey */ | ||
494 | surewarehk_load_privkey(e,NULL,NULL,NULL); | ||
495 | |||
496 | /* Everything's fine. */ | ||
497 | #ifndef OPENSSL_NO_RSA | ||
498 | if (rsaHndidx == -1) | ||
499 | rsaHndidx = RSA_get_ex_new_index(0, | ||
500 | "SureWareHook RSA key handle", | ||
501 | NULL, NULL, surewarehk_ex_free); | ||
502 | #endif | ||
503 | #ifndef OPENSSL_NO_DSA | ||
504 | if (dsaHndidx == -1) | ||
505 | dsaHndidx = DSA_get_ex_new_index(0, | ||
506 | "SureWareHook DSA key handle", | ||
507 | NULL, NULL, surewarehk_ex_free); | ||
508 | #endif | ||
509 | |||
510 | return 1; | ||
511 | err: | ||
512 | if(surewarehk_dso) | ||
513 | DSO_free(surewarehk_dso); | ||
514 | surewarehk_dso = NULL; | ||
515 | p_surewarehk_Init = NULL; | ||
516 | p_surewarehk_Finish = NULL; | ||
517 | p_surewarehk_Rand_Bytes = NULL; | ||
518 | p_surewarehk_Rand_Seed = NULL; | ||
519 | p_surewarehk_Load_Privkey = NULL; | ||
520 | p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
521 | p_surewarehk_Free = NULL; | ||
522 | p_surewarehk_Rsa_Priv_Dec = NULL; | ||
523 | p_surewarehk_Rsa_Sign = NULL; | ||
524 | p_surewarehk_Dsa_Sign = NULL; | ||
525 | p_surewarehk_Info_Pubkey = NULL; | ||
526 | p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
527 | p_surewarehk_Mod_Exp = NULL; | ||
528 | return 0; | ||
529 | } | ||
530 | |||
531 | static int surewarehk_finish(ENGINE *e) | ||
532 | { | ||
533 | int to_return = 1; | ||
534 | if(surewarehk_dso == NULL) | ||
535 | { | ||
536 | SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_NOT_LOADED); | ||
537 | to_return = 0; | ||
538 | goto err; | ||
539 | } | ||
540 | p_surewarehk_Finish(); | ||
541 | if(!DSO_free(surewarehk_dso)) | ||
542 | { | ||
543 | SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_DSO_FAILURE); | ||
544 | to_return = 0; | ||
545 | goto err; | ||
546 | } | ||
547 | err: | ||
548 | if (logstream) | ||
549 | BIO_free(logstream); | ||
550 | surewarehk_dso = NULL; | ||
551 | p_surewarehk_Init = NULL; | ||
552 | p_surewarehk_Finish = NULL; | ||
553 | p_surewarehk_Rand_Bytes = NULL; | ||
554 | p_surewarehk_Rand_Seed = NULL; | ||
555 | p_surewarehk_Load_Privkey = NULL; | ||
556 | p_surewarehk_Load_Rsa_Pubkey = NULL; | ||
557 | p_surewarehk_Free = NULL; | ||
558 | p_surewarehk_Rsa_Priv_Dec = NULL; | ||
559 | p_surewarehk_Rsa_Sign = NULL; | ||
560 | p_surewarehk_Dsa_Sign = NULL; | ||
561 | p_surewarehk_Info_Pubkey = NULL; | ||
562 | p_surewarehk_Load_Dsa_Pubkey = NULL; | ||
563 | p_surewarehk_Mod_Exp = NULL; | ||
564 | return to_return; | ||
565 | } | ||
566 | |||
567 | static void surewarehk_error_handling(char *const msg,int func,int ret) | ||
568 | { | ||
569 | switch (ret) | ||
570 | { | ||
571 | case SUREWAREHOOK_ERROR_UNIT_FAILURE: | ||
572 | ENGINEerr(func,SUREWARE_R_UNIT_FAILURE); | ||
573 | break; | ||
574 | case SUREWAREHOOK_ERROR_FALLBACK: | ||
575 | ENGINEerr(func,SUREWARE_R_REQUEST_FALLBACK); | ||
576 | break; | ||
577 | case SUREWAREHOOK_ERROR_DATA_SIZE: | ||
578 | ENGINEerr(func,SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
579 | break; | ||
580 | case SUREWAREHOOK_ERROR_INVALID_PAD: | ||
581 | ENGINEerr(func,RSA_R_PADDING_CHECK_FAILED); | ||
582 | break; | ||
583 | default: | ||
584 | ENGINEerr(func,SUREWARE_R_REQUEST_FAILED); | ||
585 | break; | ||
586 | case 1:/*nothing*/ | ||
587 | msg[0]='\0'; | ||
588 | } | ||
589 | if (*msg) | ||
590 | { | ||
591 | ERR_add_error_data(1,msg); | ||
592 | if (logstream) | ||
593 | { | ||
594 | CRYPTO_w_lock(CRYPTO_LOCK_BIO); | ||
595 | BIO_write(logstream, msg, strlen(msg)); | ||
596 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO); | ||
597 | } | ||
598 | } | ||
599 | } | ||
600 | |||
601 | static int surewarehk_rand_bytes(unsigned char *buf, int num) | ||
602 | { | ||
603 | int ret=0; | ||
604 | char msg[64]="ENGINE_rand_bytes"; | ||
605 | if(!p_surewarehk_Rand_Bytes) | ||
606 | { | ||
607 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_BYTES,ENGINE_R_NOT_INITIALISED); | ||
608 | } | ||
609 | else | ||
610 | { | ||
611 | ret = p_surewarehk_Rand_Bytes(msg,buf, num); | ||
612 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_BYTES,ret); | ||
613 | } | ||
614 | return ret==1 ? 1 : 0; | ||
615 | } | ||
616 | |||
617 | static void surewarehk_rand_seed(const void *buf, int num) | ||
618 | { | ||
619 | int ret=0; | ||
620 | char msg[64]="ENGINE_rand_seed"; | ||
621 | if(!p_surewarehk_Rand_Seed) | ||
622 | { | ||
623 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_SEED,ENGINE_R_NOT_INITIALISED); | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | ret = p_surewarehk_Rand_Seed(msg,buf, num); | ||
628 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_SEED,ret); | ||
629 | } | ||
630 | } | ||
631 | |||
632 | static void surewarehk_rand_add(const void *buf, int num, double entropy) | ||
633 | { | ||
634 | surewarehk_rand_seed(buf,num); | ||
635 | } | ||
636 | |||
637 | static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype) | ||
638 | { | ||
639 | EVP_PKEY *res = NULL; | ||
640 | #ifndef OPENSSL_NO_RSA | ||
641 | RSA *rsatmp = NULL; | ||
642 | #endif | ||
643 | #ifndef OPENSSL_NO_DSA | ||
644 | DSA *dsatmp=NULL; | ||
645 | #endif | ||
646 | char msg[64]="sureware_load_public"; | ||
647 | int ret=0; | ||
648 | if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey) | ||
649 | { | ||
650 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED); | ||
651 | goto err; | ||
652 | } | ||
653 | switch (keytype) | ||
654 | { | ||
655 | #ifndef OPENSSL_NO_RSA | ||
656 | case 1: /*RSA*/ | ||
657 | /* set private external reference */ | ||
658 | rsatmp = RSA_new_method(e); | ||
659 | RSA_set_ex_data(rsatmp,rsaHndidx,hptr); | ||
660 | rsatmp->flags |= RSA_FLAG_EXT_PKEY; | ||
661 | |||
662 | /* set public big nums*/ | ||
663 | rsatmp->e = BN_new(); | ||
664 | rsatmp->n = BN_new(); | ||
665 | bn_expand2(rsatmp->e, el/sizeof(BN_ULONG)); | ||
666 | bn_expand2(rsatmp->n, el/sizeof(BN_ULONG)); | ||
667 | if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))|| | ||
668 | !rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG))) | ||
669 | goto err; | ||
670 | ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el, | ||
671 | (unsigned long *)rsatmp->n->d, | ||
672 | (unsigned long *)rsatmp->e->d); | ||
673 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret); | ||
674 | if (ret!=1) | ||
675 | { | ||
676 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
677 | goto err; | ||
678 | } | ||
679 | /* normalise pub e and pub n */ | ||
680 | rsatmp->e->top=el/sizeof(BN_ULONG); | ||
681 | bn_fix_top(rsatmp->e); | ||
682 | rsatmp->n->top=el/sizeof(BN_ULONG); | ||
683 | bn_fix_top(rsatmp->n); | ||
684 | /* create an EVP object: engine + rsa key */ | ||
685 | res = EVP_PKEY_new(); | ||
686 | EVP_PKEY_assign_RSA(res, rsatmp); | ||
687 | break; | ||
688 | #endif | ||
689 | |||
690 | #ifndef OPENSSL_NO_DSA | ||
691 | case 2:/*DSA*/ | ||
692 | /* set private/public external reference */ | ||
693 | dsatmp = DSA_new_method(e); | ||
694 | DSA_set_ex_data(dsatmp,dsaHndidx,hptr); | ||
695 | /*dsatmp->flags |= DSA_FLAG_EXT_PKEY;*/ | ||
696 | |||
697 | /* set public key*/ | ||
698 | dsatmp->pub_key = BN_new(); | ||
699 | dsatmp->p = BN_new(); | ||
700 | dsatmp->q = BN_new(); | ||
701 | dsatmp->g = BN_new(); | ||
702 | bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG)); | ||
703 | bn_expand2(dsatmp->p, el/sizeof(BN_ULONG)); | ||
704 | bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG)); | ||
705 | bn_expand2(dsatmp->g, el/sizeof(BN_ULONG)); | ||
706 | if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))|| | ||
707 | !dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) || | ||
708 | !dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) || | ||
709 | !dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG))) | ||
710 | goto err; | ||
711 | |||
712 | ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el, | ||
713 | (unsigned long *)dsatmp->pub_key->d, | ||
714 | (unsigned long *)dsatmp->p->d, | ||
715 | (unsigned long *)dsatmp->q->d, | ||
716 | (unsigned long *)dsatmp->g->d); | ||
717 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret); | ||
718 | if (ret!=1) | ||
719 | { | ||
720 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
721 | goto err; | ||
722 | } | ||
723 | /* set parameters */ | ||
724 | /* normalise pubkey and parameters in case of */ | ||
725 | dsatmp->pub_key->top=el/sizeof(BN_ULONG); | ||
726 | bn_fix_top(dsatmp->pub_key); | ||
727 | dsatmp->p->top=el/sizeof(BN_ULONG); | ||
728 | bn_fix_top(dsatmp->p); | ||
729 | dsatmp->q->top=20/sizeof(BN_ULONG); | ||
730 | bn_fix_top(dsatmp->q); | ||
731 | dsatmp->g->top=el/sizeof(BN_ULONG); | ||
732 | bn_fix_top(dsatmp->g); | ||
733 | |||
734 | /* create an EVP object: engine + rsa key */ | ||
735 | res = EVP_PKEY_new(); | ||
736 | EVP_PKEY_assign_DSA(res, dsatmp); | ||
737 | break; | ||
738 | #endif | ||
739 | |||
740 | default: | ||
741 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
742 | goto err; | ||
743 | } | ||
744 | return res; | ||
745 | err: | ||
746 | if (res) | ||
747 | EVP_PKEY_free(res); | ||
748 | #ifndef OPENSSL_NO_RSA | ||
749 | if (rsatmp) | ||
750 | RSA_free(rsatmp); | ||
751 | #endif | ||
752 | #ifndef OPENSSL_NO_DSA | ||
753 | if (dsatmp) | ||
754 | DSA_free(dsatmp); | ||
755 | #endif | ||
756 | return NULL; | ||
757 | } | ||
758 | |||
759 | static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id, | ||
760 | UI_METHOD *ui_method, void *callback_data) | ||
761 | { | ||
762 | EVP_PKEY *res = NULL; | ||
763 | int ret=0; | ||
764 | unsigned long el=0; | ||
765 | char *hptr=NULL; | ||
766 | char keytype=0; | ||
767 | char msg[64]="ENGINE_load_privkey"; | ||
768 | |||
769 | if(!p_surewarehk_Load_Privkey) | ||
770 | { | ||
771 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_NOT_INITIALISED); | ||
772 | } | ||
773 | else | ||
774 | { | ||
775 | ret=p_surewarehk_Load_Privkey(msg,key_id,&hptr,&el,&keytype); | ||
776 | if (ret!=1) | ||
777 | { | ||
778 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
779 | ERR_add_error_data(1,msg); | ||
780 | } | ||
781 | else | ||
782 | res=sureware_load_public(e,key_id,hptr,el,keytype); | ||
783 | } | ||
784 | return res; | ||
785 | } | ||
786 | |||
787 | static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id, | ||
788 | UI_METHOD *ui_method, void *callback_data) | ||
789 | { | ||
790 | EVP_PKEY *res = NULL; | ||
791 | int ret=0; | ||
792 | unsigned long el=0; | ||
793 | char *hptr=NULL; | ||
794 | char keytype=0; | ||
795 | char msg[64]="ENGINE_load_pubkey"; | ||
796 | |||
797 | if(!p_surewarehk_Info_Pubkey) | ||
798 | { | ||
799 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED); | ||
800 | } | ||
801 | else | ||
802 | { | ||
803 | /* call once to identify if DSA or RSA */ | ||
804 | ret=p_surewarehk_Info_Pubkey(msg,key_id,&el,&keytype); | ||
805 | if (ret!=1) | ||
806 | { | ||
807 | SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
808 | ERR_add_error_data(1,msg); | ||
809 | } | ||
810 | else | ||
811 | res=sureware_load_public(e,key_id,hptr,el,keytype); | ||
812 | } | ||
813 | return res; | ||
814 | } | ||
815 | |||
816 | /* This cleans up an RSA/DSA KM key(do not destroy the key into the hardware) | ||
817 | , called when ex_data is freed */ | ||
818 | static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
819 | int idx,long argl, void *argp) | ||
820 | { | ||
821 | if(!p_surewarehk_Free) | ||
822 | { | ||
823 | SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED); | ||
824 | } | ||
825 | else | ||
826 | p_surewarehk_Free((char *)item,0); | ||
827 | } | ||
828 | |||
829 | #if 0 | ||
830 | /* This cleans up an DH KM key (destroys the key into hardware), | ||
831 | called when ex_data is freed */ | ||
832 | static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, | ||
833 | int idx,long argl, void *argp) | ||
834 | { | ||
835 | if(!p_surewarehk_Free) | ||
836 | { | ||
837 | SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED); | ||
838 | } | ||
839 | else | ||
840 | p_surewarehk_Free((char *)item,1); | ||
841 | } | ||
842 | #endif | ||
843 | |||
844 | /* | ||
845 | * return number of decrypted bytes | ||
846 | */ | ||
847 | #ifndef OPENSSL_NO_RSA | ||
848 | static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to, | ||
849 | RSA *rsa,int padding) | ||
850 | { | ||
851 | int ret=0,tlen; | ||
852 | char *buf=NULL,*hptr=NULL; | ||
853 | char msg[64]="ENGINE_rsa_priv_dec"; | ||
854 | if (!p_surewarehk_Rsa_Priv_Dec) | ||
855 | { | ||
856 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ENGINE_R_NOT_INITIALISED); | ||
857 | } | ||
858 | /* extract ref to private key */ | ||
859 | else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx))) | ||
860 | { | ||
861 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
862 | goto err; | ||
863 | } | ||
864 | /* analyse what padding we can do into the hardware */ | ||
865 | if (padding==RSA_PKCS1_PADDING) | ||
866 | { | ||
867 | /* do it one shot */ | ||
868 | ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD); | ||
869 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret); | ||
870 | if (ret!=1) | ||
871 | goto err; | ||
872 | ret=tlen; | ||
873 | } | ||
874 | else /* do with no padding into hardware */ | ||
875 | { | ||
876 | ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_NO_PAD); | ||
877 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret); | ||
878 | if (ret!=1) | ||
879 | goto err; | ||
880 | /* intermediate buffer for padding */ | ||
881 | if ((buf=OPENSSL_malloc(tlen)) == NULL) | ||
882 | { | ||
883 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ERR_R_MALLOC_FAILURE); | ||
884 | goto err; | ||
885 | } | ||
886 | memcpy(buf,to,tlen);/* transfert to into buf */ | ||
887 | switch (padding) /* check padding in software */ | ||
888 | { | ||
889 | #ifndef OPENSSL_NO_SHA | ||
890 | case RSA_PKCS1_OAEP_PADDING: | ||
891 | ret=RSA_padding_check_PKCS1_OAEP(to,tlen,(unsigned char *)buf,tlen,tlen,NULL,0); | ||
892 | break; | ||
893 | #endif | ||
894 | case RSA_SSLV23_PADDING: | ||
895 | ret=RSA_padding_check_SSLv23(to,tlen,(unsigned char *)buf,flen,tlen); | ||
896 | break; | ||
897 | case RSA_NO_PADDING: | ||
898 | ret=RSA_padding_check_none(to,tlen,(unsigned char *)buf,flen,tlen); | ||
899 | break; | ||
900 | default: | ||
901 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_UNKNOWN_PADDING_TYPE); | ||
902 | goto err; | ||
903 | } | ||
904 | if (ret < 0) | ||
905 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_PADDING_CHECK_FAILED); | ||
906 | } | ||
907 | err: | ||
908 | if (buf) | ||
909 | { | ||
910 | OPENSSL_cleanse(buf,tlen); | ||
911 | OPENSSL_free(buf); | ||
912 | } | ||
913 | return ret; | ||
914 | } | ||
915 | |||
916 | /* | ||
917 | * Does what OpenSSL rsa_priv_enc does. | ||
918 | */ | ||
919 | static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to, | ||
920 | RSA *rsa,int padding) | ||
921 | { | ||
922 | int ret=0,tlen; | ||
923 | char *hptr=NULL; | ||
924 | char msg[64]="ENGINE_rsa_sign"; | ||
925 | if (!p_surewarehk_Rsa_Sign) | ||
926 | { | ||
927 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ENGINE_R_NOT_INITIALISED); | ||
928 | } | ||
929 | /* extract ref to private key */ | ||
930 | else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx))) | ||
931 | { | ||
932 | SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
933 | } | ||
934 | else | ||
935 | { | ||
936 | switch (padding) | ||
937 | { | ||
938 | case RSA_PKCS1_PADDING: /* do it in one shot */ | ||
939 | ret=p_surewarehk_Rsa_Sign(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD); | ||
940 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ret); | ||
941 | break; | ||
942 | case RSA_NO_PADDING: | ||
943 | default: | ||
944 | RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,RSA_R_UNKNOWN_PADDING_TYPE); | ||
945 | } | ||
946 | } | ||
947 | return ret==1 ? tlen : ret; | ||
948 | } | ||
949 | |||
950 | #endif | ||
951 | |||
952 | #ifndef OPENSSL_NO_DSA | ||
953 | /* DSA sign and verify */ | ||
954 | static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *from, int flen, DSA *dsa) | ||
955 | { | ||
956 | int ret=0; | ||
957 | char *hptr=NULL; | ||
958 | DSA_SIG *psign=NULL; | ||
959 | char msg[64]="ENGINE_dsa_do_sign"; | ||
960 | if (!p_surewarehk_Dsa_Sign) | ||
961 | { | ||
962 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ENGINE_R_NOT_INITIALISED); | ||
963 | } | ||
964 | /* extract ref to private key */ | ||
965 | else if (!(hptr=DSA_get_ex_data(dsa, dsaHndidx))) | ||
966 | { | ||
967 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,SUREWARE_R_MISSING_KEY_COMPONENTS); | ||
968 | } | ||
969 | else | ||
970 | { | ||
971 | if((psign = DSA_SIG_new()) == NULL) | ||
972 | { | ||
973 | SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ERR_R_MALLOC_FAILURE); | ||
974 | goto err; | ||
975 | } | ||
976 | psign->r=BN_new(); | ||
977 | psign->s=BN_new(); | ||
978 | bn_expand2(psign->r, 20/sizeof(BN_ULONG)); | ||
979 | bn_expand2(psign->s, 20/sizeof(BN_ULONG)); | ||
980 | if (!psign->r || psign->r->dmax!=20/sizeof(BN_ULONG) || | ||
981 | !psign->s || psign->s->dmax!=20/sizeof(BN_ULONG)) | ||
982 | goto err; | ||
983 | ret=p_surewarehk_Dsa_Sign(msg,flen,from, | ||
984 | (unsigned long *)psign->r->d, | ||
985 | (unsigned long *)psign->s->d, | ||
986 | hptr); | ||
987 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ret); | ||
988 | } | ||
989 | psign->r->top=20/sizeof(BN_ULONG); | ||
990 | bn_fix_top(psign->r); | ||
991 | psign->s->top=20/sizeof(BN_ULONG); | ||
992 | bn_fix_top(psign->s); | ||
993 | |||
994 | err: | ||
995 | if (psign) | ||
996 | { | ||
997 | DSA_SIG_free(psign); | ||
998 | psign=NULL; | ||
999 | } | ||
1000 | return psign; | ||
1001 | } | ||
1002 | #endif | ||
1003 | |||
1004 | static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
1005 | const BIGNUM *m, BN_CTX *ctx) | ||
1006 | { | ||
1007 | int ret=0; | ||
1008 | char msg[64]="ENGINE_modexp"; | ||
1009 | if (!p_surewarehk_Mod_Exp) | ||
1010 | { | ||
1011 | SUREWAREerr(SUREWARE_F_SUREWAREHK_MOD_EXP,ENGINE_R_NOT_INITIALISED); | ||
1012 | } | ||
1013 | else | ||
1014 | { | ||
1015 | bn_expand2(r,m->top); | ||
1016 | if (r && r->dmax==m->top) | ||
1017 | { | ||
1018 | /* do it*/ | ||
1019 | ret=p_surewarehk_Mod_Exp(msg, | ||
1020 | m->top*sizeof(BN_ULONG), | ||
1021 | (unsigned long *)m->d, | ||
1022 | p->top*sizeof(BN_ULONG), | ||
1023 | (unsigned long *)p->d, | ||
1024 | a->top*sizeof(BN_ULONG), | ||
1025 | (unsigned long *)a->d, | ||
1026 | (unsigned long *)r->d); | ||
1027 | surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_MOD_EXP,ret); | ||
1028 | if (ret==1) | ||
1029 | { | ||
1030 | /* normalise result */ | ||
1031 | r->top=m->top; | ||
1032 | bn_fix_top(r); | ||
1033 | } | ||
1034 | } | ||
1035 | } | ||
1036 | return ret; | ||
1037 | } | ||
1038 | #endif /* !OPENSSL_NO_HW_SureWare */ | ||
1039 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.c b/src/lib/libcrypto/engine/hw_sureware_err.c new file mode 100644 index 0000000000..69955dadbb --- /dev/null +++ b/src/lib/libcrypto/engine/hw_sureware_err.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /* hw_sureware_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_sureware_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA SUREWARE_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"}, | ||
70 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"}, | ||
71 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"}, | ||
72 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"}, | ||
73 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"}, | ||
74 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"}, | ||
75 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"}, | ||
76 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"}, | ||
77 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"}, | ||
78 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"}, | ||
79 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"}, | ||
80 | {ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"}, | ||
81 | {0,NULL} | ||
82 | }; | ||
83 | |||
84 | static ERR_STRING_DATA SUREWARE_str_reasons[]= | ||
85 | { | ||
86 | {SUREWARE_R_BIO_WAS_FREED ,"bio was freed"}, | ||
87 | {SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
88 | {SUREWARE_R_REQUEST_FAILED ,"request failed"}, | ||
89 | {SUREWARE_R_REQUEST_FALLBACK ,"request fallback"}, | ||
90 | {SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
91 | {SUREWARE_R_UNIT_FAILURE ,"unit failure"}, | ||
92 | {0,NULL} | ||
93 | }; | ||
94 | |||
95 | #endif | ||
96 | |||
97 | #ifdef SUREWARE_LIB_NAME | ||
98 | static ERR_STRING_DATA SUREWARE_lib_name[]= | ||
99 | { | ||
100 | {0 ,SUREWARE_LIB_NAME}, | ||
101 | {0,NULL} | ||
102 | }; | ||
103 | #endif | ||
104 | |||
105 | |||
106 | static int SUREWARE_lib_error_code=0; | ||
107 | static int SUREWARE_error_init=1; | ||
108 | |||
109 | static void ERR_load_SUREWARE_strings(void) | ||
110 | { | ||
111 | if (SUREWARE_lib_error_code == 0) | ||
112 | SUREWARE_lib_error_code=ERR_get_next_error_library(); | ||
113 | |||
114 | if (SUREWARE_error_init) | ||
115 | { | ||
116 | SUREWARE_error_init=0; | ||
117 | #ifndef OPENSSL_NO_ERR | ||
118 | ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_functs); | ||
119 | ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons); | ||
120 | #endif | ||
121 | |||
122 | #ifdef SUREWARE_LIB_NAME | ||
123 | SUREWARE_lib_name->error = ERR_PACK(SUREWARE_lib_error_code,0,0); | ||
124 | ERR_load_strings(0,SUREWARE_lib_name); | ||
125 | #endif | ||
126 | } | ||
127 | } | ||
128 | |||
129 | static void ERR_unload_SUREWARE_strings(void) | ||
130 | { | ||
131 | if (SUREWARE_error_init == 0) | ||
132 | { | ||
133 | #ifndef OPENSSL_NO_ERR | ||
134 | ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_functs); | ||
135 | ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons); | ||
136 | #endif | ||
137 | |||
138 | #ifdef SUREWARE_LIB_NAME | ||
139 | ERR_unload_strings(0,SUREWARE_lib_name); | ||
140 | #endif | ||
141 | SUREWARE_error_init=1; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | static void ERR_SUREWARE_error(int function, int reason, char *file, int line) | ||
146 | { | ||
147 | if (SUREWARE_lib_error_code == 0) | ||
148 | SUREWARE_lib_error_code=ERR_get_next_error_library(); | ||
149 | ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line); | ||
150 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.h b/src/lib/libcrypto/engine/hw_sureware_err.h new file mode 100644 index 0000000000..bc52af5e05 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_sureware_err.h | |||
@@ -0,0 +1,94 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_SUREWARE_ERR_H | ||
56 | #define HEADER_SUREWARE_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_SUREWARE_strings(void); | ||
63 | static void ERR_unload_SUREWARE_strings(void); | ||
64 | static void ERR_SUREWARE_error(int function, int reason, char *file, int line); | ||
65 | #define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the SUREWARE functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define SUREWARE_F_SUREWAREHK_CTRL 100 | ||
71 | #define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101 | ||
72 | #define SUREWARE_F_SUREWAREHK_EX_FREE 102 | ||
73 | #define SUREWARE_F_SUREWAREHK_FINISH 103 | ||
74 | #define SUREWARE_F_SUREWAREHK_INIT 104 | ||
75 | #define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105 | ||
76 | #define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106 | ||
77 | #define SUREWARE_F_SUREWAREHK_MOD_EXP 107 | ||
78 | #define SUREWARE_F_SUREWAREHK_RAND_BYTES 108 | ||
79 | #define SUREWARE_F_SUREWAREHK_RAND_SEED 109 | ||
80 | #define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110 | ||
81 | #define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111 | ||
82 | |||
83 | /* Reason codes. */ | ||
84 | #define SUREWARE_R_BIO_WAS_FREED 100 | ||
85 | #define SUREWARE_R_MISSING_KEY_COMPONENTS 105 | ||
86 | #define SUREWARE_R_REQUEST_FAILED 101 | ||
87 | #define SUREWARE_R_REQUEST_FALLBACK 102 | ||
88 | #define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103 | ||
89 | #define SUREWARE_R_UNIT_FAILURE 104 | ||
90 | |||
91 | #ifdef __cplusplus | ||
92 | } | ||
93 | #endif | ||
94 | #endif | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c new file mode 100644 index 0000000000..5234a08a07 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ubsec.c | |||
@@ -0,0 +1,1060 @@ | |||
1 | /* crypto/engine/hw_ubsec.c */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | * | ||
5 | * Cloned shamelessly by Joe Tardo. | ||
6 | */ | ||
7 | /* ==================================================================== | ||
8 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * | ||
17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
18 | * notice, this list of conditions and the following disclaimer in | ||
19 | * the documentation and/or other materials provided with the | ||
20 | * distribution. | ||
21 | * | ||
22 | * 3. All advertising materials mentioning features or use of this | ||
23 | * software must display the following acknowledgment: | ||
24 | * "This product includes software developed by the OpenSSL Project | ||
25 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
26 | * | ||
27 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
28 | * endorse or promote products derived from this software without | ||
29 | * prior written permission. For written permission, please contact | ||
30 | * licensing@OpenSSL.org. | ||
31 | * | ||
32 | * 5. Products derived from this software may not be called "OpenSSL" | ||
33 | * nor may "OpenSSL" appear in their names without prior written | ||
34 | * permission of the OpenSSL Project. | ||
35 | * | ||
36 | * 6. Redistributions of any form whatsoever must retain the following | ||
37 | * acknowledgment: | ||
38 | * "This product includes software developed by the OpenSSL Project | ||
39 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
42 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
44 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
45 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
46 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
47 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
48 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
50 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
51 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
52 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
53 | * ==================================================================== | ||
54 | * | ||
55 | * This product includes cryptographic software written by Eric Young | ||
56 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
57 | * Hudson (tjh@cryptsoft.com). | ||
58 | * | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/crypto.h> | ||
63 | #include "cryptlib.h" | ||
64 | #include <openssl/dso.h> | ||
65 | #include <openssl/engine.h> | ||
66 | |||
67 | #ifndef OPENSSL_NO_HW | ||
68 | #ifndef OPENSSL_NO_HW_UBSEC | ||
69 | |||
70 | #ifdef FLAT_INC | ||
71 | #include "hw_ubsec.h" | ||
72 | #else | ||
73 | #include "vendor_defns/hw_ubsec.h" | ||
74 | #endif | ||
75 | |||
76 | #define UBSEC_LIB_NAME "ubsec engine" | ||
77 | #include "hw_ubsec_err.c" | ||
78 | |||
79 | #define FAIL_TO_SOFTWARE -15 | ||
80 | |||
81 | static int ubsec_destroy(ENGINE *e); | ||
82 | static int ubsec_init(ENGINE *e); | ||
83 | static int ubsec_finish(ENGINE *e); | ||
84 | static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()); | ||
85 | static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
86 | const BIGNUM *m, BN_CTX *ctx); | ||
87 | static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
88 | const BIGNUM *q, const BIGNUM *dp, | ||
89 | const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx); | ||
90 | #ifndef OPENSSL_NO_RSA | ||
91 | static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa); | ||
92 | #endif | ||
93 | static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
94 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
95 | #ifndef OPENSSL_NO_DSA | ||
96 | #ifdef NOT_USED | ||
97 | static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
98 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
99 | BN_CTX *ctx, BN_MONT_CTX *in_mont); | ||
100 | static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
101 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
102 | BN_MONT_CTX *m_ctx); | ||
103 | #endif | ||
104 | static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
105 | static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
106 | DSA_SIG *sig, DSA *dsa); | ||
107 | #endif | ||
108 | #ifndef OPENSSL_NO_DH | ||
109 | static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
110 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
111 | BN_MONT_CTX *m_ctx); | ||
112 | static int ubsec_dh_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh); | ||
113 | static int ubsec_dh_generate_key(DH *dh); | ||
114 | #endif | ||
115 | |||
116 | #ifdef NOT_USED | ||
117 | static int ubsec_rand_bytes(unsigned char *buf, int num); | ||
118 | static int ubsec_rand_status(void); | ||
119 | #endif | ||
120 | |||
121 | #define UBSEC_CMD_SO_PATH ENGINE_CMD_BASE | ||
122 | static const ENGINE_CMD_DEFN ubsec_cmd_defns[] = { | ||
123 | {UBSEC_CMD_SO_PATH, | ||
124 | "SO_PATH", | ||
125 | "Specifies the path to the 'ubsec' shared library", | ||
126 | ENGINE_CMD_FLAG_STRING}, | ||
127 | {0, NULL, NULL, 0} | ||
128 | }; | ||
129 | |||
130 | #ifndef OPENSSL_NO_RSA | ||
131 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
132 | static RSA_METHOD ubsec_rsa = | ||
133 | { | ||
134 | "UBSEC RSA method", | ||
135 | NULL, | ||
136 | NULL, | ||
137 | NULL, | ||
138 | NULL, | ||
139 | ubsec_rsa_mod_exp, | ||
140 | ubsec_mod_exp_mont, | ||
141 | NULL, | ||
142 | NULL, | ||
143 | 0, | ||
144 | NULL, | ||
145 | NULL, | ||
146 | NULL | ||
147 | }; | ||
148 | #endif | ||
149 | |||
150 | #ifndef OPENSSL_NO_DSA | ||
151 | /* Our internal DSA_METHOD that we provide pointers to */ | ||
152 | static DSA_METHOD ubsec_dsa = | ||
153 | { | ||
154 | "UBSEC DSA method", | ||
155 | ubsec_dsa_do_sign, /* dsa_do_sign */ | ||
156 | NULL, /* dsa_sign_setup */ | ||
157 | ubsec_dsa_verify, /* dsa_do_verify */ | ||
158 | NULL, /* ubsec_dsa_mod_exp */ /* dsa_mod_exp */ | ||
159 | NULL, /* ubsec_mod_exp_dsa */ /* bn_mod_exp */ | ||
160 | NULL, /* init */ | ||
161 | NULL, /* finish */ | ||
162 | 0, /* flags */ | ||
163 | NULL /* app_data */ | ||
164 | }; | ||
165 | #endif | ||
166 | |||
167 | #ifndef OPENSSL_NO_DH | ||
168 | /* Our internal DH_METHOD that we provide pointers to */ | ||
169 | static DH_METHOD ubsec_dh = | ||
170 | { | ||
171 | "UBSEC DH method", | ||
172 | ubsec_dh_generate_key, | ||
173 | ubsec_dh_compute_key, | ||
174 | ubsec_mod_exp_dh, | ||
175 | NULL, | ||
176 | NULL, | ||
177 | 0, | ||
178 | NULL | ||
179 | }; | ||
180 | #endif | ||
181 | |||
182 | /* Constants used when creating the ENGINE */ | ||
183 | static const char *engine_ubsec_id = "ubsec"; | ||
184 | static const char *engine_ubsec_name = "UBSEC hardware engine support"; | ||
185 | |||
186 | /* This internal function is used by ENGINE_ubsec() and possibly by the | ||
187 | * "dynamic" ENGINE support too */ | ||
188 | static int bind_helper(ENGINE *e) | ||
189 | { | ||
190 | #ifndef OPENSSL_NO_RSA | ||
191 | const RSA_METHOD *meth1; | ||
192 | #endif | ||
193 | #ifndef OPENSSL_NO_DH | ||
194 | #ifndef HAVE_UBSEC_DH | ||
195 | const DH_METHOD *meth3; | ||
196 | #endif /* HAVE_UBSEC_DH */ | ||
197 | #endif | ||
198 | if(!ENGINE_set_id(e, engine_ubsec_id) || | ||
199 | !ENGINE_set_name(e, engine_ubsec_name) || | ||
200 | #ifndef OPENSSL_NO_RSA | ||
201 | !ENGINE_set_RSA(e, &ubsec_rsa) || | ||
202 | #endif | ||
203 | #ifndef OPENSSL_NO_DSA | ||
204 | !ENGINE_set_DSA(e, &ubsec_dsa) || | ||
205 | #endif | ||
206 | #ifndef OPENSSL_NO_DH | ||
207 | !ENGINE_set_DH(e, &ubsec_dh) || | ||
208 | #endif | ||
209 | !ENGINE_set_destroy_function(e, ubsec_destroy) || | ||
210 | !ENGINE_set_init_function(e, ubsec_init) || | ||
211 | !ENGINE_set_finish_function(e, ubsec_finish) || | ||
212 | !ENGINE_set_ctrl_function(e, ubsec_ctrl) || | ||
213 | !ENGINE_set_cmd_defns(e, ubsec_cmd_defns)) | ||
214 | return 0; | ||
215 | |||
216 | #ifndef OPENSSL_NO_RSA | ||
217 | /* We know that the "PKCS1_SSLeay()" functions hook properly | ||
218 | * to the Broadcom-specific mod_exp and mod_exp_crt so we use | ||
219 | * those functions. NB: We don't use ENGINE_openssl() or | ||
220 | * anything "more generic" because something like the RSAref | ||
221 | * code may not hook properly, and if you own one of these | ||
222 | * cards then you have the right to do RSA operations on it | ||
223 | * anyway! */ | ||
224 | meth1 = RSA_PKCS1_SSLeay(); | ||
225 | ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
226 | ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
227 | ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
228 | ubsec_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
229 | #endif | ||
230 | |||
231 | #ifndef OPENSSL_NO_DH | ||
232 | #ifndef HAVE_UBSEC_DH | ||
233 | /* Much the same for Diffie-Hellman */ | ||
234 | meth3 = DH_OpenSSL(); | ||
235 | ubsec_dh.generate_key = meth3->generate_key; | ||
236 | ubsec_dh.compute_key = meth3->compute_key; | ||
237 | #endif /* HAVE_UBSEC_DH */ | ||
238 | #endif | ||
239 | |||
240 | /* Ensure the ubsec error handling is set up */ | ||
241 | ERR_load_UBSEC_strings(); | ||
242 | return 1; | ||
243 | } | ||
244 | |||
245 | #ifndef ENGINE_DYNAMIC_SUPPORT | ||
246 | static ENGINE *engine_ubsec(void) | ||
247 | { | ||
248 | ENGINE *ret = ENGINE_new(); | ||
249 | if(!ret) | ||
250 | return NULL; | ||
251 | if(!bind_helper(ret)) | ||
252 | { | ||
253 | ENGINE_free(ret); | ||
254 | return NULL; | ||
255 | } | ||
256 | return ret; | ||
257 | } | ||
258 | |||
259 | void ENGINE_load_ubsec(void) | ||
260 | { | ||
261 | /* Copied from eng_[openssl|dyn].c */ | ||
262 | ENGINE *toadd = engine_ubsec(); | ||
263 | if(!toadd) return; | ||
264 | ENGINE_add(toadd); | ||
265 | ENGINE_free(toadd); | ||
266 | ERR_clear_error(); | ||
267 | } | ||
268 | #endif | ||
269 | |||
270 | /* This is a process-global DSO handle used for loading and unloading | ||
271 | * the UBSEC library. NB: This is only set (or unset) during an | ||
272 | * init() or finish() call (reference counts permitting) and they're | ||
273 | * operating with global locks, so this should be thread-safe | ||
274 | * implicitly. */ | ||
275 | |||
276 | static DSO *ubsec_dso = NULL; | ||
277 | |||
278 | /* These are the function pointers that are (un)set when the library has | ||
279 | * successfully (un)loaded. */ | ||
280 | |||
281 | static t_UBSEC_ubsec_bytes_to_bits *p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
282 | static t_UBSEC_ubsec_bits_to_bytes *p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
283 | static t_UBSEC_ubsec_open *p_UBSEC_ubsec_open = NULL; | ||
284 | static t_UBSEC_ubsec_close *p_UBSEC_ubsec_close = NULL; | ||
285 | #ifndef OPENSSL_NO_DH | ||
286 | static t_UBSEC_diffie_hellman_generate_ioctl | ||
287 | *p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
288 | static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
289 | #endif | ||
290 | /* #ifndef OPENSSL_NO_RSA */ | ||
291 | static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
292 | static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
293 | /* #endif */ | ||
294 | #ifndef OPENSSL_NO_DSA | ||
295 | static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL; | ||
296 | static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL; | ||
297 | #endif | ||
298 | static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL; | ||
299 | static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL; | ||
300 | static t_UBSEC_max_key_len_ioctl *p_UBSEC_max_key_len_ioctl = NULL; | ||
301 | |||
302 | static int max_key_len = 1024; /* ??? */ | ||
303 | |||
304 | /* | ||
305 | * These are the static string constants for the DSO file name and the function | ||
306 | * symbol names to bind to. | ||
307 | */ | ||
308 | |||
309 | static const char *UBSEC_LIBNAME = NULL; | ||
310 | static const char *get_UBSEC_LIBNAME(void) | ||
311 | { | ||
312 | if(UBSEC_LIBNAME) | ||
313 | return UBSEC_LIBNAME; | ||
314 | return "ubsec"; | ||
315 | } | ||
316 | static void free_UBSEC_LIBNAME(void) | ||
317 | { | ||
318 | if(UBSEC_LIBNAME) | ||
319 | OPENSSL_free((void*)UBSEC_LIBNAME); | ||
320 | UBSEC_LIBNAME = NULL; | ||
321 | } | ||
322 | static long set_UBSEC_LIBNAME(const char *name) | ||
323 | { | ||
324 | free_UBSEC_LIBNAME(); | ||
325 | return (((UBSEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); | ||
326 | } | ||
327 | static const char *UBSEC_F1 = "ubsec_bytes_to_bits"; | ||
328 | static const char *UBSEC_F2 = "ubsec_bits_to_bytes"; | ||
329 | static const char *UBSEC_F3 = "ubsec_open"; | ||
330 | static const char *UBSEC_F4 = "ubsec_close"; | ||
331 | #ifndef OPENSSL_NO_DH | ||
332 | static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl"; | ||
333 | static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl"; | ||
334 | #endif | ||
335 | /* #ifndef OPENSSL_NO_RSA */ | ||
336 | static const char *UBSEC_F7 = "rsa_mod_exp_ioctl"; | ||
337 | static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl"; | ||
338 | /* #endif */ | ||
339 | #ifndef OPENSSL_NO_DSA | ||
340 | static const char *UBSEC_F9 = "dsa_sign_ioctl"; | ||
341 | static const char *UBSEC_F10 = "dsa_verify_ioctl"; | ||
342 | #endif | ||
343 | static const char *UBSEC_F11 = "math_accelerate_ioctl"; | ||
344 | static const char *UBSEC_F12 = "rng_ioctl"; | ||
345 | static const char *UBSEC_F13 = "ubsec_max_key_len_ioctl"; | ||
346 | |||
347 | /* Destructor (complements the "ENGINE_ubsec()" constructor) */ | ||
348 | static int ubsec_destroy(ENGINE *e) | ||
349 | { | ||
350 | free_UBSEC_LIBNAME(); | ||
351 | ERR_unload_UBSEC_strings(); | ||
352 | return 1; | ||
353 | } | ||
354 | |||
355 | /* (de)initialisation functions. */ | ||
356 | static int ubsec_init(ENGINE *e) | ||
357 | { | ||
358 | t_UBSEC_ubsec_bytes_to_bits *p1; | ||
359 | t_UBSEC_ubsec_bits_to_bytes *p2; | ||
360 | t_UBSEC_ubsec_open *p3; | ||
361 | t_UBSEC_ubsec_close *p4; | ||
362 | #ifndef OPENSSL_NO_DH | ||
363 | t_UBSEC_diffie_hellman_generate_ioctl *p5; | ||
364 | t_UBSEC_diffie_hellman_agree_ioctl *p6; | ||
365 | #endif | ||
366 | /* #ifndef OPENSSL_NO_RSA */ | ||
367 | t_UBSEC_rsa_mod_exp_ioctl *p7; | ||
368 | t_UBSEC_rsa_mod_exp_crt_ioctl *p8; | ||
369 | /* #endif */ | ||
370 | #ifndef OPENSSL_NO_DSA | ||
371 | t_UBSEC_dsa_sign_ioctl *p9; | ||
372 | t_UBSEC_dsa_verify_ioctl *p10; | ||
373 | #endif | ||
374 | t_UBSEC_math_accelerate_ioctl *p11; | ||
375 | t_UBSEC_rng_ioctl *p12; | ||
376 | t_UBSEC_max_key_len_ioctl *p13; | ||
377 | int fd = 0; | ||
378 | |||
379 | if(ubsec_dso != NULL) | ||
380 | { | ||
381 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_ALREADY_LOADED); | ||
382 | goto err; | ||
383 | } | ||
384 | /* | ||
385 | * Attempt to load libubsec.so/ubsec.dll/whatever. | ||
386 | */ | ||
387 | ubsec_dso = DSO_load(NULL, get_UBSEC_LIBNAME(), NULL, 0); | ||
388 | if(ubsec_dso == NULL) | ||
389 | { | ||
390 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE); | ||
391 | goto err; | ||
392 | } | ||
393 | |||
394 | if ( | ||
395 | !(p1 = (t_UBSEC_ubsec_bytes_to_bits *) DSO_bind_func(ubsec_dso, UBSEC_F1)) || | ||
396 | !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) DSO_bind_func(ubsec_dso, UBSEC_F2)) || | ||
397 | !(p3 = (t_UBSEC_ubsec_open *) DSO_bind_func(ubsec_dso, UBSEC_F3)) || | ||
398 | !(p4 = (t_UBSEC_ubsec_close *) DSO_bind_func(ubsec_dso, UBSEC_F4)) || | ||
399 | #ifndef OPENSSL_NO_DH | ||
400 | !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *) | ||
401 | DSO_bind_func(ubsec_dso, UBSEC_F5)) || | ||
402 | !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *) | ||
403 | DSO_bind_func(ubsec_dso, UBSEC_F6)) || | ||
404 | #endif | ||
405 | /* #ifndef OPENSSL_NO_RSA */ | ||
406 | !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F7)) || | ||
407 | !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F8)) || | ||
408 | /* #endif */ | ||
409 | #ifndef OPENSSL_NO_DSA | ||
410 | !(p9 = (t_UBSEC_dsa_sign_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F9)) || | ||
411 | !(p10 = (t_UBSEC_dsa_verify_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F10)) || | ||
412 | #endif | ||
413 | !(p11 = (t_UBSEC_math_accelerate_ioctl *) | ||
414 | DSO_bind_func(ubsec_dso, UBSEC_F11)) || | ||
415 | !(p12 = (t_UBSEC_rng_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F12)) || | ||
416 | !(p13 = (t_UBSEC_max_key_len_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F13))) | ||
417 | { | ||
418 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE); | ||
419 | goto err; | ||
420 | } | ||
421 | |||
422 | /* Copy the pointers */ | ||
423 | p_UBSEC_ubsec_bytes_to_bits = p1; | ||
424 | p_UBSEC_ubsec_bits_to_bytes = p2; | ||
425 | p_UBSEC_ubsec_open = p3; | ||
426 | p_UBSEC_ubsec_close = p4; | ||
427 | #ifndef OPENSSL_NO_DH | ||
428 | p_UBSEC_diffie_hellman_generate_ioctl = p5; | ||
429 | p_UBSEC_diffie_hellman_agree_ioctl = p6; | ||
430 | #endif | ||
431 | #ifndef OPENSSL_NO_RSA | ||
432 | p_UBSEC_rsa_mod_exp_ioctl = p7; | ||
433 | p_UBSEC_rsa_mod_exp_crt_ioctl = p8; | ||
434 | #endif | ||
435 | #ifndef OPENSSL_NO_DSA | ||
436 | p_UBSEC_dsa_sign_ioctl = p9; | ||
437 | p_UBSEC_dsa_verify_ioctl = p10; | ||
438 | #endif | ||
439 | p_UBSEC_math_accelerate_ioctl = p11; | ||
440 | p_UBSEC_rng_ioctl = p12; | ||
441 | p_UBSEC_max_key_len_ioctl = p13; | ||
442 | |||
443 | /* Perform an open to see if there's actually any unit running. */ | ||
444 | if (((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) > 0) && (p_UBSEC_max_key_len_ioctl(fd, &max_key_len) == 0)) | ||
445 | { | ||
446 | p_UBSEC_ubsec_close(fd); | ||
447 | return 1; | ||
448 | } | ||
449 | else | ||
450 | { | ||
451 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
452 | } | ||
453 | |||
454 | err: | ||
455 | if(ubsec_dso) | ||
456 | DSO_free(ubsec_dso); | ||
457 | p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
458 | p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
459 | p_UBSEC_ubsec_open = NULL; | ||
460 | p_UBSEC_ubsec_close = NULL; | ||
461 | #ifndef OPENSSL_NO_DH | ||
462 | p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
463 | p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
464 | #endif | ||
465 | #ifndef OPENSSL_NO_RSA | ||
466 | p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
467 | p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
468 | #endif | ||
469 | #ifndef OPENSSL_NO_DSA | ||
470 | p_UBSEC_dsa_sign_ioctl = NULL; | ||
471 | p_UBSEC_dsa_verify_ioctl = NULL; | ||
472 | #endif | ||
473 | p_UBSEC_math_accelerate_ioctl = NULL; | ||
474 | p_UBSEC_rng_ioctl = NULL; | ||
475 | p_UBSEC_max_key_len_ioctl = NULL; | ||
476 | |||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | static int ubsec_finish(ENGINE *e) | ||
481 | { | ||
482 | free_UBSEC_LIBNAME(); | ||
483 | if(ubsec_dso == NULL) | ||
484 | { | ||
485 | UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED); | ||
486 | return 0; | ||
487 | } | ||
488 | if(!DSO_free(ubsec_dso)) | ||
489 | { | ||
490 | UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_DSO_FAILURE); | ||
491 | return 0; | ||
492 | } | ||
493 | ubsec_dso = NULL; | ||
494 | p_UBSEC_ubsec_bytes_to_bits = NULL; | ||
495 | p_UBSEC_ubsec_bits_to_bytes = NULL; | ||
496 | p_UBSEC_ubsec_open = NULL; | ||
497 | p_UBSEC_ubsec_close = NULL; | ||
498 | #ifndef OPENSSL_NO_DH | ||
499 | p_UBSEC_diffie_hellman_generate_ioctl = NULL; | ||
500 | p_UBSEC_diffie_hellman_agree_ioctl = NULL; | ||
501 | #endif | ||
502 | #ifndef OPENSSL_NO_RSA | ||
503 | p_UBSEC_rsa_mod_exp_ioctl = NULL; | ||
504 | p_UBSEC_rsa_mod_exp_crt_ioctl = NULL; | ||
505 | #endif | ||
506 | #ifndef OPENSSL_NO_DSA | ||
507 | p_UBSEC_dsa_sign_ioctl = NULL; | ||
508 | p_UBSEC_dsa_verify_ioctl = NULL; | ||
509 | #endif | ||
510 | p_UBSEC_math_accelerate_ioctl = NULL; | ||
511 | p_UBSEC_rng_ioctl = NULL; | ||
512 | p_UBSEC_max_key_len_ioctl = NULL; | ||
513 | return 1; | ||
514 | } | ||
515 | |||
516 | static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)()) | ||
517 | { | ||
518 | int initialised = ((ubsec_dso == NULL) ? 0 : 1); | ||
519 | switch(cmd) | ||
520 | { | ||
521 | case UBSEC_CMD_SO_PATH: | ||
522 | if(p == NULL) | ||
523 | { | ||
524 | UBSECerr(UBSEC_F_UBSEC_CTRL,ERR_R_PASSED_NULL_PARAMETER); | ||
525 | return 0; | ||
526 | } | ||
527 | if(initialised) | ||
528 | { | ||
529 | UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED); | ||
530 | return 0; | ||
531 | } | ||
532 | return set_UBSEC_LIBNAME((const char *)p); | ||
533 | default: | ||
534 | break; | ||
535 | } | ||
536 | UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED); | ||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
541 | const BIGNUM *m, BN_CTX *ctx) | ||
542 | { | ||
543 | int y_len = 0; | ||
544 | int fd; | ||
545 | |||
546 | if(ubsec_dso == NULL) | ||
547 | { | ||
548 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_NOT_LOADED); | ||
549 | return 0; | ||
550 | } | ||
551 | |||
552 | /* Check if hardware can't handle this argument. */ | ||
553 | y_len = BN_num_bits(m); | ||
554 | if (y_len > max_key_len) { | ||
555 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
556 | return BN_mod_exp(r, a, p, m, ctx); | ||
557 | } | ||
558 | |||
559 | if(!bn_wexpand(r, m->top)) | ||
560 | { | ||
561 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_BN_EXPAND_FAIL); | ||
562 | return 0; | ||
563 | } | ||
564 | |||
565 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
566 | fd = 0; | ||
567 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
568 | return BN_mod_exp(r, a, p, m, ctx); | ||
569 | } | ||
570 | |||
571 | if (p_UBSEC_rsa_mod_exp_ioctl(fd, (unsigned char *)a->d, BN_num_bits(a), | ||
572 | (unsigned char *)m->d, BN_num_bits(m), (unsigned char *)p->d, | ||
573 | BN_num_bits(p), (unsigned char *)r->d, &y_len) != 0) | ||
574 | { | ||
575 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED); | ||
576 | p_UBSEC_ubsec_close(fd); | ||
577 | |||
578 | return BN_mod_exp(r, a, p, m, ctx); | ||
579 | } | ||
580 | |||
581 | p_UBSEC_ubsec_close(fd); | ||
582 | |||
583 | r->top = (BN_num_bits(m)+BN_BITS2-1)/BN_BITS2; | ||
584 | return 1; | ||
585 | } | ||
586 | |||
587 | #ifndef OPENSSL_NO_RSA | ||
588 | static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | ||
589 | { | ||
590 | BN_CTX *ctx; | ||
591 | int to_return = 0; | ||
592 | |||
593 | if((ctx = BN_CTX_new()) == NULL) | ||
594 | goto err; | ||
595 | |||
596 | if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) | ||
597 | { | ||
598 | UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS); | ||
599 | goto err; | ||
600 | } | ||
601 | |||
602 | to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1, | ||
603 | rsa->dmq1, rsa->iqmp, ctx); | ||
604 | if (to_return == FAIL_TO_SOFTWARE) | ||
605 | { | ||
606 | /* | ||
607 | * Do in software as hardware failed. | ||
608 | */ | ||
609 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
610 | to_return = (*meth->rsa_mod_exp)(r0, I, rsa); | ||
611 | } | ||
612 | err: | ||
613 | if(ctx) | ||
614 | BN_CTX_free(ctx); | ||
615 | return to_return; | ||
616 | } | ||
617 | #endif | ||
618 | |||
619 | static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
620 | const BIGNUM *q, const BIGNUM *dp, | ||
621 | const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx) | ||
622 | { | ||
623 | int y_len, | ||
624 | m_len, | ||
625 | fd; | ||
626 | |||
627 | m_len = BN_num_bytes(p) + BN_num_bytes(q) + 1; | ||
628 | y_len = BN_num_bits(p) + BN_num_bits(q); | ||
629 | |||
630 | /* Check if hardware can't handle this argument. */ | ||
631 | if (y_len > max_key_len) { | ||
632 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL); | ||
633 | return FAIL_TO_SOFTWARE; | ||
634 | } | ||
635 | |||
636 | if (!bn_wexpand(r, p->top + q->top + 1)) { | ||
637 | UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT, UBSEC_R_BN_EXPAND_FAIL); | ||
638 | return 0; | ||
639 | } | ||
640 | |||
641 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
642 | fd = 0; | ||
643 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
644 | return FAIL_TO_SOFTWARE; | ||
645 | } | ||
646 | |||
647 | if (p_UBSEC_rsa_mod_exp_crt_ioctl(fd, | ||
648 | (unsigned char *)a->d, BN_num_bits(a), | ||
649 | (unsigned char *)qinv->d, BN_num_bits(qinv), | ||
650 | (unsigned char *)dp->d, BN_num_bits(dp), | ||
651 | (unsigned char *)p->d, BN_num_bits(p), | ||
652 | (unsigned char *)dq->d, BN_num_bits(dq), | ||
653 | (unsigned char *)q->d, BN_num_bits(q), | ||
654 | (unsigned char *)r->d, &y_len) != 0) { | ||
655 | UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED); | ||
656 | p_UBSEC_ubsec_close(fd); | ||
657 | return FAIL_TO_SOFTWARE; | ||
658 | } | ||
659 | |||
660 | p_UBSEC_ubsec_close(fd); | ||
661 | |||
662 | r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2; | ||
663 | return 1; | ||
664 | } | ||
665 | |||
666 | #ifndef OPENSSL_NO_DSA | ||
667 | #ifdef NOT_USED | ||
668 | static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, | ||
669 | BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m, | ||
670 | BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
671 | { | ||
672 | BIGNUM t; | ||
673 | int to_return = 0; | ||
674 | |||
675 | BN_init(&t); | ||
676 | /* let rr = a1 ^ p1 mod m */ | ||
677 | if (!ubsec_mod_exp(rr,a1,p1,m,ctx)) goto end; | ||
678 | /* let t = a2 ^ p2 mod m */ | ||
679 | if (!ubsec_mod_exp(&t,a2,p2,m,ctx)) goto end; | ||
680 | /* let rr = rr * t mod m */ | ||
681 | if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end; | ||
682 | to_return = 1; | ||
683 | end: | ||
684 | BN_free(&t); | ||
685 | return to_return; | ||
686 | } | ||
687 | |||
688 | static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a, | ||
689 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
690 | BN_MONT_CTX *m_ctx) | ||
691 | { | ||
692 | return ubsec_mod_exp(r, a, p, m, ctx); | ||
693 | } | ||
694 | #endif | ||
695 | #endif | ||
696 | |||
697 | /* | ||
698 | * This function is aliased to mod_exp (with the mont stuff dropped). | ||
699 | */ | ||
700 | static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
701 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) | ||
702 | { | ||
703 | int ret = 0; | ||
704 | |||
705 | #ifndef OPENSSL_NO_RSA | ||
706 | /* Do in software if the key is too large for the hardware. */ | ||
707 | if (BN_num_bits(m) > max_key_len) | ||
708 | { | ||
709 | const RSA_METHOD *meth = RSA_PKCS1_SSLeay(); | ||
710 | ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx); | ||
711 | } | ||
712 | else | ||
713 | #endif | ||
714 | { | ||
715 | ret = ubsec_mod_exp(r, a, p, m, ctx); | ||
716 | } | ||
717 | |||
718 | return ret; | ||
719 | } | ||
720 | |||
721 | #ifndef OPENSSL_NO_DH | ||
722 | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | ||
723 | static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
724 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
725 | BN_MONT_CTX *m_ctx) | ||
726 | { | ||
727 | return ubsec_mod_exp(r, a, p, m, ctx); | ||
728 | } | ||
729 | #endif | ||
730 | |||
731 | #ifndef OPENSSL_NO_DSA | ||
732 | static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
733 | { | ||
734 | DSA_SIG *to_return = NULL; | ||
735 | int s_len = 160, r_len = 160, d_len, fd; | ||
736 | BIGNUM m, *r=NULL, *s=NULL; | ||
737 | |||
738 | BN_init(&m); | ||
739 | |||
740 | s = BN_new(); | ||
741 | r = BN_new(); | ||
742 | if ((s == NULL) || (r==NULL)) | ||
743 | goto err; | ||
744 | |||
745 | d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dlen); | ||
746 | |||
747 | if(!bn_wexpand(r, (160+BN_BITS2-1)/BN_BITS2) || | ||
748 | (!bn_wexpand(s, (160+BN_BITS2-1)/BN_BITS2))) { | ||
749 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
750 | goto err; | ||
751 | } | ||
752 | |||
753 | if (BN_bin2bn(dgst,dlen,&m) == NULL) { | ||
754 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
755 | goto err; | ||
756 | } | ||
757 | |||
758 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
759 | const DSA_METHOD *meth; | ||
760 | fd = 0; | ||
761 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
762 | meth = DSA_OpenSSL(); | ||
763 | to_return = meth->dsa_do_sign(dgst, dlen, dsa); | ||
764 | goto err; | ||
765 | } | ||
766 | |||
767 | if (p_UBSEC_dsa_sign_ioctl(fd, 0, /* compute hash before signing */ | ||
768 | (unsigned char *)dgst, d_len, | ||
769 | NULL, 0, /* compute random value */ | ||
770 | (unsigned char *)dsa->p->d, BN_num_bits(dsa->p), | ||
771 | (unsigned char *)dsa->q->d, BN_num_bits(dsa->q), | ||
772 | (unsigned char *)dsa->g->d, BN_num_bits(dsa->g), | ||
773 | (unsigned char *)dsa->priv_key->d, BN_num_bits(dsa->priv_key), | ||
774 | (unsigned char *)r->d, &r_len, | ||
775 | (unsigned char *)s->d, &s_len ) != 0) { | ||
776 | const DSA_METHOD *meth; | ||
777 | |||
778 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_REQUEST_FAILED); | ||
779 | p_UBSEC_ubsec_close(fd); | ||
780 | meth = DSA_OpenSSL(); | ||
781 | to_return = meth->dsa_do_sign(dgst, dlen, dsa); | ||
782 | |||
783 | goto err; | ||
784 | } | ||
785 | |||
786 | p_UBSEC_ubsec_close(fd); | ||
787 | |||
788 | r->top = (160+BN_BITS2-1)/BN_BITS2; | ||
789 | s->top = (160+BN_BITS2-1)/BN_BITS2; | ||
790 | |||
791 | to_return = DSA_SIG_new(); | ||
792 | if(to_return == NULL) { | ||
793 | UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL); | ||
794 | goto err; | ||
795 | } | ||
796 | |||
797 | to_return->r = r; | ||
798 | to_return->s = s; | ||
799 | |||
800 | err: | ||
801 | if (!to_return) { | ||
802 | if (r) BN_free(r); | ||
803 | if (s) BN_free(s); | ||
804 | } | ||
805 | BN_clear_free(&m); | ||
806 | return to_return; | ||
807 | } | ||
808 | |||
809 | static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len, | ||
810 | DSA_SIG *sig, DSA *dsa) | ||
811 | { | ||
812 | int v_len, d_len; | ||
813 | int to_return = 0; | ||
814 | int fd; | ||
815 | BIGNUM v; | ||
816 | |||
817 | BN_init(&v); | ||
818 | |||
819 | if(!bn_wexpand(&v, dsa->p->top)) { | ||
820 | UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY ,UBSEC_R_BN_EXPAND_FAIL); | ||
821 | goto err; | ||
822 | } | ||
823 | |||
824 | v_len = BN_num_bits(dsa->p); | ||
825 | |||
826 | d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dgst_len); | ||
827 | |||
828 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) { | ||
829 | const DSA_METHOD *meth; | ||
830 | fd = 0; | ||
831 | UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
832 | meth = DSA_OpenSSL(); | ||
833 | to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
834 | goto err; | ||
835 | } | ||
836 | |||
837 | if (p_UBSEC_dsa_verify_ioctl(fd, 0, /* compute hash before signing */ | ||
838 | (unsigned char *)dgst, d_len, | ||
839 | (unsigned char *)dsa->p->d, BN_num_bits(dsa->p), | ||
840 | (unsigned char *)dsa->q->d, BN_num_bits(dsa->q), | ||
841 | (unsigned char *)dsa->g->d, BN_num_bits(dsa->g), | ||
842 | (unsigned char *)dsa->pub_key->d, BN_num_bits(dsa->pub_key), | ||
843 | (unsigned char *)sig->r->d, BN_num_bits(sig->r), | ||
844 | (unsigned char *)sig->s->d, BN_num_bits(sig->s), | ||
845 | (unsigned char *)v.d, &v_len) != 0) { | ||
846 | const DSA_METHOD *meth; | ||
847 | UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY , UBSEC_R_REQUEST_FAILED); | ||
848 | p_UBSEC_ubsec_close(fd); | ||
849 | |||
850 | meth = DSA_OpenSSL(); | ||
851 | to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
852 | |||
853 | goto err; | ||
854 | } | ||
855 | |||
856 | p_UBSEC_ubsec_close(fd); | ||
857 | |||
858 | to_return = 1; | ||
859 | err: | ||
860 | BN_clear_free(&v); | ||
861 | return to_return; | ||
862 | } | ||
863 | #endif | ||
864 | |||
865 | #ifndef OPENSSL_NO_DH | ||
866 | static int ubsec_dh_compute_key (unsigned char *key,const BIGNUM *pub_key,DH *dh) | ||
867 | { | ||
868 | int ret = -1, | ||
869 | k_len, | ||
870 | fd; | ||
871 | |||
872 | k_len = BN_num_bits(dh->p); | ||
873 | |||
874 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
875 | { | ||
876 | const DH_METHOD *meth; | ||
877 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
878 | meth = DH_OpenSSL(); | ||
879 | ret = meth->compute_key(key, pub_key, dh); | ||
880 | goto err; | ||
881 | } | ||
882 | |||
883 | if (p_UBSEC_diffie_hellman_agree_ioctl(fd, | ||
884 | (unsigned char *)dh->priv_key->d, BN_num_bits(dh->priv_key), | ||
885 | (unsigned char *)pub_key->d, BN_num_bits(pub_key), | ||
886 | (unsigned char *)dh->p->d, BN_num_bits(dh->p), | ||
887 | key, &k_len) != 0) | ||
888 | { | ||
889 | /* Hardware's a no go, failover to software */ | ||
890 | const DH_METHOD *meth; | ||
891 | ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED); | ||
892 | p_UBSEC_ubsec_close(fd); | ||
893 | |||
894 | meth = DH_OpenSSL(); | ||
895 | ret = meth->compute_key(key, pub_key, dh); | ||
896 | |||
897 | goto err; | ||
898 | } | ||
899 | |||
900 | p_UBSEC_ubsec_close(fd); | ||
901 | |||
902 | ret = p_UBSEC_ubsec_bits_to_bytes(k_len); | ||
903 | err: | ||
904 | return ret; | ||
905 | } | ||
906 | |||
907 | static int ubsec_dh_generate_key (DH *dh) | ||
908 | { | ||
909 | int ret = 0, | ||
910 | random_bits = 0, | ||
911 | pub_key_len = 0, | ||
912 | priv_key_len = 0, | ||
913 | fd; | ||
914 | BIGNUM *pub_key = NULL; | ||
915 | BIGNUM *priv_key = NULL; | ||
916 | |||
917 | /* | ||
918 | * How many bits should Random x be? dh_key.c | ||
919 | * sets the range from 0 to num_bits(modulus) ??? | ||
920 | */ | ||
921 | |||
922 | if (dh->priv_key == NULL) | ||
923 | { | ||
924 | priv_key = BN_new(); | ||
925 | if (priv_key == NULL) goto err; | ||
926 | priv_key_len = BN_num_bits(dh->p); | ||
927 | bn_wexpand(priv_key, dh->p->top); | ||
928 | do | ||
929 | if (!BN_rand_range(priv_key, dh->p)) goto err; | ||
930 | while (BN_is_zero(priv_key)); | ||
931 | random_bits = BN_num_bits(priv_key); | ||
932 | } | ||
933 | else | ||
934 | { | ||
935 | priv_key = dh->priv_key; | ||
936 | } | ||
937 | |||
938 | if (dh->pub_key == NULL) | ||
939 | { | ||
940 | pub_key = BN_new(); | ||
941 | pub_key_len = BN_num_bits(dh->p); | ||
942 | bn_wexpand(pub_key, dh->p->top); | ||
943 | if(pub_key == NULL) goto err; | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | pub_key = dh->pub_key; | ||
948 | } | ||
949 | |||
950 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
951 | { | ||
952 | const DH_METHOD *meth; | ||
953 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
954 | meth = DH_OpenSSL(); | ||
955 | ret = meth->generate_key(dh); | ||
956 | goto err; | ||
957 | } | ||
958 | |||
959 | if (p_UBSEC_diffie_hellman_generate_ioctl(fd, | ||
960 | (unsigned char *)priv_key->d, &priv_key_len, | ||
961 | (unsigned char *)pub_key->d, &pub_key_len, | ||
962 | (unsigned char *)dh->g->d, BN_num_bits(dh->g), | ||
963 | (unsigned char *)dh->p->d, BN_num_bits(dh->p), | ||
964 | 0, 0, random_bits) != 0) | ||
965 | { | ||
966 | /* Hardware's a no go, failover to software */ | ||
967 | const DH_METHOD *meth; | ||
968 | |||
969 | ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED); | ||
970 | p_UBSEC_ubsec_close(fd); | ||
971 | |||
972 | meth = DH_OpenSSL(); | ||
973 | ret = meth->generate_key(dh); | ||
974 | |||
975 | goto err; | ||
976 | } | ||
977 | |||
978 | p_UBSEC_ubsec_close(fd); | ||
979 | |||
980 | dh->pub_key = pub_key; | ||
981 | dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2; | ||
982 | dh->priv_key = priv_key; | ||
983 | dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2; | ||
984 | |||
985 | ret = 1; | ||
986 | err: | ||
987 | return ret; | ||
988 | } | ||
989 | #endif | ||
990 | |||
991 | #ifdef NOT_USED | ||
992 | static int ubsec_rand_bytes(unsigned char * buf, | ||
993 | int num) | ||
994 | { | ||
995 | int ret = 0, | ||
996 | fd; | ||
997 | |||
998 | if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) | ||
999 | { | ||
1000 | const RAND_METHOD *meth; | ||
1001 | ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE); | ||
1002 | num = p_UBSEC_ubsec_bits_to_bytes(num); | ||
1003 | meth = RAND_SSLeay(); | ||
1004 | meth->seed(buf, num); | ||
1005 | ret = meth->bytes(buf, num); | ||
1006 | goto err; | ||
1007 | } | ||
1008 | |||
1009 | num *= 8; /* bytes to bits */ | ||
1010 | |||
1011 | if (p_UBSEC_rng_ioctl(fd, | ||
1012 | UBSEC_RNG_DIRECT, | ||
1013 | buf, | ||
1014 | &num) != 0) | ||
1015 | { | ||
1016 | /* Hardware's a no go, failover to software */ | ||
1017 | const RAND_METHOD *meth; | ||
1018 | |||
1019 | ENGINEerr(UBSEC_F_UBSEC_RNG_BYTES, UBSEC_R_REQUEST_FAILED); | ||
1020 | p_UBSEC_ubsec_close(fd); | ||
1021 | |||
1022 | num = p_UBSEC_ubsec_bits_to_bytes(num); | ||
1023 | meth = RAND_SSLeay(); | ||
1024 | meth->seed(buf, num); | ||
1025 | ret = meth->bytes(buf, num); | ||
1026 | |||
1027 | goto err; | ||
1028 | } | ||
1029 | |||
1030 | p_UBSEC_ubsec_close(fd); | ||
1031 | |||
1032 | ret = 1; | ||
1033 | err: | ||
1034 | return(ret); | ||
1035 | } | ||
1036 | |||
1037 | |||
1038 | static int ubsec_rand_status(void) | ||
1039 | { | ||
1040 | return 0; | ||
1041 | } | ||
1042 | #endif | ||
1043 | |||
1044 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
1045 | * shared-library. */ | ||
1046 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
1047 | static int bind_fn(ENGINE *e, const char *id) | ||
1048 | { | ||
1049 | if(id && (strcmp(id, engine_ubsec_id) != 0)) | ||
1050 | return 0; | ||
1051 | if(!bind_helper(e)) | ||
1052 | return 0; | ||
1053 | return 1; | ||
1054 | } | ||
1055 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
1056 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
1057 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
1058 | |||
1059 | #endif /* !OPENSSL_NO_HW_UBSEC */ | ||
1060 | #endif /* !OPENSSL_NO_HW */ | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.c b/src/lib/libcrypto/engine/hw_ubsec_err.c new file mode 100644 index 0000000000..d707331fc2 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ubsec_err.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* hw_ubsec_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include "hw_ubsec_err.h" | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA UBSEC_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"}, | ||
70 | {ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"}, | ||
71 | {ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"}, | ||
72 | {ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"}, | ||
73 | {ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"}, | ||
74 | {ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"}, | ||
75 | {ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"}, | ||
76 | {ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"}, | ||
77 | {ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"}, | ||
78 | {ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"}, | ||
79 | {0,NULL} | ||
80 | }; | ||
81 | |||
82 | static ERR_STRING_DATA UBSEC_str_reasons[]= | ||
83 | { | ||
84 | {UBSEC_R_ALREADY_LOADED ,"already loaded"}, | ||
85 | {UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"}, | ||
86 | {UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"}, | ||
87 | {UBSEC_R_DSO_FAILURE ,"dso failure"}, | ||
88 | {UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"}, | ||
89 | {UBSEC_R_NOT_LOADED ,"not loaded"}, | ||
90 | {UBSEC_R_REQUEST_FAILED ,"request failed"}, | ||
91 | {UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"}, | ||
92 | {UBSEC_R_UNIT_FAILURE ,"unit failure"}, | ||
93 | {0,NULL} | ||
94 | }; | ||
95 | |||
96 | #endif | ||
97 | |||
98 | #ifdef UBSEC_LIB_NAME | ||
99 | static ERR_STRING_DATA UBSEC_lib_name[]= | ||
100 | { | ||
101 | {0 ,UBSEC_LIB_NAME}, | ||
102 | {0,NULL} | ||
103 | }; | ||
104 | #endif | ||
105 | |||
106 | |||
107 | static int UBSEC_lib_error_code=0; | ||
108 | static int UBSEC_error_init=1; | ||
109 | |||
110 | static void ERR_load_UBSEC_strings(void) | ||
111 | { | ||
112 | if (UBSEC_lib_error_code == 0) | ||
113 | UBSEC_lib_error_code=ERR_get_next_error_library(); | ||
114 | |||
115 | if (UBSEC_error_init) | ||
116 | { | ||
117 | UBSEC_error_init=0; | ||
118 | #ifndef OPENSSL_NO_ERR | ||
119 | ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_functs); | ||
120 | ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_reasons); | ||
121 | #endif | ||
122 | |||
123 | #ifdef UBSEC_LIB_NAME | ||
124 | UBSEC_lib_name->error = ERR_PACK(UBSEC_lib_error_code,0,0); | ||
125 | ERR_load_strings(0,UBSEC_lib_name); | ||
126 | #endif | ||
127 | } | ||
128 | } | ||
129 | |||
130 | static void ERR_unload_UBSEC_strings(void) | ||
131 | { | ||
132 | if (UBSEC_error_init == 0) | ||
133 | { | ||
134 | #ifndef OPENSSL_NO_ERR | ||
135 | ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_functs); | ||
136 | ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_reasons); | ||
137 | #endif | ||
138 | |||
139 | #ifdef UBSEC_LIB_NAME | ||
140 | ERR_unload_strings(0,UBSEC_lib_name); | ||
141 | #endif | ||
142 | UBSEC_error_init=1; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | static void ERR_UBSEC_error(int function, int reason, char *file, int line) | ||
147 | { | ||
148 | if (UBSEC_lib_error_code == 0) | ||
149 | UBSEC_lib_error_code=ERR_get_next_error_library(); | ||
150 | ERR_PUT_error(UBSEC_lib_error_code,function,reason,file,line); | ||
151 | } | ||
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.h b/src/lib/libcrypto/engine/hw_ubsec_err.h new file mode 100644 index 0000000000..023d3be771 --- /dev/null +++ b/src/lib/libcrypto/engine/hw_ubsec_err.h | |||
@@ -0,0 +1,95 @@ | |||
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 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_UBSEC_ERR_H | ||
56 | #define HEADER_UBSEC_ERR_H | ||
57 | |||
58 | /* BEGIN ERROR CODES */ | ||
59 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
60 | * made after this point may be overwritten when the script is next run. | ||
61 | */ | ||
62 | static void ERR_load_UBSEC_strings(void); | ||
63 | static void ERR_unload_UBSEC_strings(void); | ||
64 | static void ERR_UBSEC_error(int function, int reason, char *file, int line); | ||
65 | #define UBSECerr(f,r) ERR_UBSEC_error((f),(r),__FILE__,__LINE__) | ||
66 | |||
67 | /* Error codes for the UBSEC functions. */ | ||
68 | |||
69 | /* Function codes. */ | ||
70 | #define UBSEC_F_UBSEC_CTRL 100 | ||
71 | #define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101 | ||
72 | #define UBSEC_F_UBSEC_DSA_SIGN 102 | ||
73 | #define UBSEC_F_UBSEC_DSA_VERIFY 103 | ||
74 | #define UBSEC_F_UBSEC_FINISH 104 | ||
75 | #define UBSEC_F_UBSEC_INIT 105 | ||
76 | #define UBSEC_F_UBSEC_MOD_EXP 106 | ||
77 | #define UBSEC_F_UBSEC_RNG_BYTES 107 | ||
78 | #define UBSEC_F_UBSEC_RSA_MOD_EXP 108 | ||
79 | #define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109 | ||
80 | |||
81 | /* Reason codes. */ | ||
82 | #define UBSEC_R_ALREADY_LOADED 100 | ||
83 | #define UBSEC_R_BN_EXPAND_FAIL 101 | ||
84 | #define UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED 102 | ||
85 | #define UBSEC_R_DSO_FAILURE 103 | ||
86 | #define UBSEC_R_MISSING_KEY_COMPONENTS 104 | ||
87 | #define UBSEC_R_NOT_LOADED 105 | ||
88 | #define UBSEC_R_REQUEST_FAILED 106 | ||
89 | #define UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107 | ||
90 | #define UBSEC_R_UNIT_FAILURE 108 | ||
91 | |||
92 | #ifdef __cplusplus | ||
93 | } | ||
94 | #endif | ||
95 | #endif | ||
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c index 7efe181927..80170591f2 100644 --- a/src/lib/libcrypto/engine/tb_dsa.c +++ b/src/lib/libcrypto/engine/tb_dsa.c | |||
@@ -94,7 +94,7 @@ int ENGINE_set_default_DSA(ENGINE *e) | |||
94 | { | 94 | { |
95 | if(e->dsa_meth) | 95 | if(e->dsa_meth) |
96 | return engine_table_register(&dsa_table, | 96 | return engine_table_register(&dsa_table, |
97 | engine_unregister_all_DSA, e, &dummy_nid, 1, 1); | 97 | engine_unregister_all_DSA, e, &dummy_nid, 1, 0); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/aep.h b/src/lib/libcrypto/engine/vendor_defns/aep.h new file mode 100644 index 0000000000..2b2792d2d6 --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/aep.h | |||
@@ -0,0 +1,178 @@ | |||
1 | /* This header declares the necessary definitions for using the exponentiation | ||
2 | * acceleration capabilities, and rnd number generation of the AEP card. | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | /* | ||
7 | * | ||
8 | * Some AEP defines | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /*Successful return value*/ | ||
13 | #define AEP_R_OK 0x00000000 | ||
14 | |||
15 | /*Miscelleanous unsuccessful return value*/ | ||
16 | #define AEP_R_GENERAL_ERROR 0x10000001 | ||
17 | |||
18 | /*Insufficient host memory*/ | ||
19 | #define AEP_R_HOST_MEMORY 0x10000002 | ||
20 | |||
21 | #define AEP_R_FUNCTION_FAILED 0x10000006 | ||
22 | |||
23 | /*Invalid arguments in function call*/ | ||
24 | #define AEP_R_ARGUMENTS_BAD 0x10020000 | ||
25 | |||
26 | #define AEP_R_NO_TARGET_RESOURCES 0x10030000 | ||
27 | |||
28 | /*Error occuring on socket operation*/ | ||
29 | #define AEP_R_SOCKERROR 0x10000010 | ||
30 | |||
31 | /*Socket has been closed from the other end*/ | ||
32 | #define AEP_R_SOCKEOF 0x10000011 | ||
33 | |||
34 | /*Invalid handles*/ | ||
35 | #define AEP_R_CONNECTION_HANDLE_INVALID 0x100000B3 | ||
36 | |||
37 | #define AEP_R_TRANSACTION_HANDLE_INVALID 0x10040000 | ||
38 | |||
39 | /*Transaction has not yet returned from accelerator*/ | ||
40 | #define AEP_R_TRANSACTION_NOT_READY 0x00010000 | ||
41 | |||
42 | /*There is already a thread waiting on this transaction*/ | ||
43 | #define AEP_R_TRANSACTION_CLAIMED 0x10050000 | ||
44 | |||
45 | /*The transaction timed out*/ | ||
46 | #define AEP_R_TIMED_OUT 0x10060000 | ||
47 | |||
48 | #define AEP_R_FXN_NOT_IMPLEMENTED 0x10070000 | ||
49 | |||
50 | #define AEP_R_TARGET_ERROR 0x10080000 | ||
51 | |||
52 | /*Error in the AEP daemon process*/ | ||
53 | #define AEP_R_DAEMON_ERROR 0x10090000 | ||
54 | |||
55 | /*Invalid ctx id*/ | ||
56 | #define AEP_R_INVALID_CTX_ID 0x10009000 | ||
57 | |||
58 | #define AEP_R_NO_KEY_MANAGER 0x1000a000 | ||
59 | |||
60 | /*Error obtaining a mutex*/ | ||
61 | #define AEP_R_MUTEX_BAD 0x000001A0 | ||
62 | |||
63 | /*Fxn call before AEP_Initialise ot after AEP_Finialise*/ | ||
64 | #define AEP_R_AEPAPI_NOT_INITIALIZED 0x10000190 | ||
65 | |||
66 | /*AEP_Initialise has already been called*/ | ||
67 | #define AEP_R_AEPAPI_ALREADY_INITIALIZED 0x10000191 | ||
68 | |||
69 | /*Maximum number of connections to daemon reached*/ | ||
70 | #define AEP_R_NO_MORE_CONNECTION_HNDLS 0x10000200 | ||
71 | |||
72 | /* | ||
73 | * | ||
74 | * Some AEP Type definitions | ||
75 | * | ||
76 | */ | ||
77 | |||
78 | /* an unsigned 8-bit value */ | ||
79 | typedef unsigned char AEP_U8; | ||
80 | |||
81 | /* an unsigned 8-bit character */ | ||
82 | typedef char AEP_CHAR; | ||
83 | |||
84 | /* a BYTE-sized Boolean flag */ | ||
85 | typedef AEP_U8 AEP_BBOOL; | ||
86 | |||
87 | /*Unsigned value, at least 16 bits long*/ | ||
88 | typedef unsigned short AEP_U16; | ||
89 | |||
90 | /* an unsigned value, at least 32 bits long */ | ||
91 | #ifdef SIXTY_FOUR_BIT_LONG | ||
92 | typedef unsigned int AEP_U32; | ||
93 | #else | ||
94 | typedef unsigned long AEP_U32; | ||
95 | #endif | ||
96 | |||
97 | #ifdef SIXTY_FOUR_BIT_LONG | ||
98 | typedef unsigned long AEP_U64; | ||
99 | #else | ||
100 | typedef struct { unsigned long l1, l2; } AEP_U64; | ||
101 | #endif | ||
102 | |||
103 | /* at least 32 bits; each bit is a Boolean flag */ | ||
104 | typedef AEP_U32 AEP_FLAGS; | ||
105 | |||
106 | typedef AEP_U8 *AEP_U8_PTR; | ||
107 | typedef AEP_CHAR *AEP_CHAR_PTR; | ||
108 | typedef AEP_U32 *AEP_U32_PTR; | ||
109 | typedef AEP_U64 *AEP_U64_PTR; | ||
110 | typedef void *AEP_VOID_PTR; | ||
111 | |||
112 | /* Pointer to a AEP_VOID_PTR-- i.e., pointer to pointer to void */ | ||
113 | typedef AEP_VOID_PTR *AEP_VOID_PTR_PTR; | ||
114 | |||
115 | /*Used to identify an AEP connection handle*/ | ||
116 | typedef AEP_U32 AEP_CONNECTION_HNDL; | ||
117 | |||
118 | /*Pointer to an AEP connection handle*/ | ||
119 | typedef AEP_CONNECTION_HNDL *AEP_CONNECTION_HNDL_PTR; | ||
120 | |||
121 | /*Used by an application (in conjunction with the apps process id) to | ||
122 | identify an individual transaction*/ | ||
123 | typedef AEP_U32 AEP_TRANSACTION_ID; | ||
124 | |||
125 | /*Pointer to an applications transaction identifier*/ | ||
126 | typedef AEP_TRANSACTION_ID *AEP_TRANSACTION_ID_PTR; | ||
127 | |||
128 | /*Return value type*/ | ||
129 | typedef AEP_U32 AEP_RV; | ||
130 | |||
131 | #define MAX_PROCESS_CONNECTIONS 256 | ||
132 | |||
133 | #define RAND_BLK_SIZE 1024 | ||
134 | |||
135 | typedef enum{ | ||
136 | NotConnected= 0, | ||
137 | Connected= 1, | ||
138 | InUse= 2 | ||
139 | } AEP_CONNECTION_STATE; | ||
140 | |||
141 | |||
142 | typedef struct AEP_CONNECTION_ENTRY{ | ||
143 | AEP_CONNECTION_STATE conn_state; | ||
144 | AEP_CONNECTION_HNDL conn_hndl; | ||
145 | } AEP_CONNECTION_ENTRY; | ||
146 | |||
147 | |||
148 | typedef AEP_RV t_AEP_OpenConnection(AEP_CONNECTION_HNDL_PTR phConnection); | ||
149 | typedef AEP_RV t_AEP_CloseConnection(AEP_CONNECTION_HNDL hConnection); | ||
150 | |||
151 | typedef AEP_RV t_AEP_ModExp(AEP_CONNECTION_HNDL hConnection, | ||
152 | AEP_VOID_PTR pA, AEP_VOID_PTR pP, | ||
153 | AEP_VOID_PTR pN, | ||
154 | AEP_VOID_PTR pResult, | ||
155 | AEP_TRANSACTION_ID* pidTransID); | ||
156 | |||
157 | typedef AEP_RV t_AEP_ModExpCrt(AEP_CONNECTION_HNDL hConnection, | ||
158 | AEP_VOID_PTR pA, AEP_VOID_PTR pP, | ||
159 | AEP_VOID_PTR pQ, | ||
160 | AEP_VOID_PTR pDmp1, AEP_VOID_PTR pDmq1, | ||
161 | AEP_VOID_PTR pIqmp, | ||
162 | AEP_VOID_PTR pResult, | ||
163 | AEP_TRANSACTION_ID* pidTransID); | ||
164 | |||
165 | #ifdef AEPRAND | ||
166 | typedef AEP_RV t_AEP_GenRandom(AEP_CONNECTION_HNDL hConnection, | ||
167 | AEP_U32 Len, | ||
168 | AEP_U32 Type, | ||
169 | AEP_VOID_PTR pResult, | ||
170 | AEP_TRANSACTION_ID* pidTransID); | ||
171 | #endif | ||
172 | |||
173 | typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs); | ||
174 | typedef AEP_RV t_AEP_Finalize(); | ||
175 | typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(), | ||
176 | AEP_RV (*MakeAEPBigNumFunc)(), | ||
177 | AEP_RV (*ConverAEPBigNumFunc)()); | ||
178 | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/atalla.h b/src/lib/libcrypto/engine/vendor_defns/atalla.h new file mode 100644 index 0000000000..149970d441 --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/atalla.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /* This header declares the necessary definitions for using the exponentiation | ||
2 | * acceleration capabilities of Atalla cards. The only cryptographic operation | ||
3 | * is performed by "ASI_RSAPrivateKeyOpFn" and this takes a structure that | ||
4 | * defines an "RSA private key". However, it is really only performing a | ||
5 | * regular mod_exp using the supplied modulus and exponent - no CRT form is | ||
6 | * being used. Hence, it is a generic mod_exp function in disguise, and we use | ||
7 | * it as such. | ||
8 | * | ||
9 | * Thanks to the people at Atalla for letting me know these definitions are | ||
10 | * fine and that they can be reproduced here. | ||
11 | * | ||
12 | * Geoff. | ||
13 | */ | ||
14 | |||
15 | typedef struct ItemStr | ||
16 | { | ||
17 | unsigned char *data; | ||
18 | int len; | ||
19 | } Item; | ||
20 | |||
21 | typedef struct RSAPrivateKeyStr | ||
22 | { | ||
23 | void *reserved; | ||
24 | Item version; | ||
25 | Item modulus; | ||
26 | Item publicExponent; | ||
27 | Item privateExponent; | ||
28 | Item prime[2]; | ||
29 | Item exponent[2]; | ||
30 | Item coefficient; | ||
31 | } RSAPrivateKey; | ||
32 | |||
33 | /* Predeclare the function pointer types that we dynamically load from the DSO. | ||
34 | * These use the same names and form that Ben's original support code had (in | ||
35 | * crypto/bn/bn_exp.c) unless of course I've inadvertently changed the style | ||
36 | * somewhere along the way! | ||
37 | */ | ||
38 | |||
39 | typedef int tfnASI_GetPerformanceStatistics(int reset_flag, | ||
40 | unsigned int *ret_buf); | ||
41 | |||
42 | typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf); | ||
43 | |||
44 | typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey, | ||
45 | unsigned char *output, | ||
46 | unsigned char *input, | ||
47 | unsigned int modulus_len); | ||
48 | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/cswift.h b/src/lib/libcrypto/engine/vendor_defns/cswift.h new file mode 100644 index 0000000000..60079326bb --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/cswift.h | |||
@@ -0,0 +1,234 @@ | |||
1 | /* Attribution notice: Rainbow have generously allowed me to reproduce | ||
2 | * the necessary definitions here from their API. This means the support | ||
3 | * can build independently of whether application builders have the | ||
4 | * API or hardware. This will allow developers to easily produce software | ||
5 | * that has latent hardware support for any users that have accelertors | ||
6 | * installed, without the developers themselves needing anything extra. | ||
7 | * | ||
8 | * I have only clipped the parts from the CryptoSwift header files that | ||
9 | * are (or seem) relevant to the CryptoSwift support code. This is | ||
10 | * simply to keep the file sizes reasonable. | ||
11 | * [Geoff] | ||
12 | */ | ||
13 | |||
14 | |||
15 | /* NB: These type widths do *not* seem right in general, in particular | ||
16 | * they're not terribly friendly to 64-bit architectures (unsigned long) | ||
17 | * will be 64-bit on IA-64 for a start. I'm leaving these alone as they | ||
18 | * agree with Rainbow's API and this will only be called into question | ||
19 | * on platforms with Rainbow support anyway! ;-) */ | ||
20 | |||
21 | #ifdef __cplusplus | ||
22 | extern "C" { | ||
23 | #endif /* __cplusplus */ | ||
24 | |||
25 | typedef long SW_STATUS; /* status */ | ||
26 | typedef unsigned char SW_BYTE; /* 8 bit byte */ | ||
27 | typedef unsigned short SW_U16; /* 16 bit number */ | ||
28 | #if defined(_IRIX) | ||
29 | #include <sgidefs.h> | ||
30 | typedef __uint32_t SW_U32; | ||
31 | #else | ||
32 | typedef unsigned long SW_U32; /* 32 bit integer */ | ||
33 | #endif | ||
34 | |||
35 | #if defined(OPENSSL_SYS_WIN32) | ||
36 | typedef struct _SW_U64 { | ||
37 | SW_U32 low32; | ||
38 | SW_U32 high32; | ||
39 | } SW_U64; /* 64 bit integer */ | ||
40 | #elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) | ||
41 | typedef longlong SW_U64 | ||
42 | #else /* Unix variants */ | ||
43 | typedef struct _SW_U64 { | ||
44 | SW_U32 low32; | ||
45 | SW_U32 high32; | ||
46 | } SW_U64; /* 64 bit integer */ | ||
47 | #endif | ||
48 | |||
49 | /* status codes */ | ||
50 | #define SW_OK (0L) | ||
51 | #define SW_ERR_BASE (-10000L) | ||
52 | #define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */ | ||
53 | #define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */ | ||
54 | /* up yet */ | ||
55 | #define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */ | ||
56 | /* time out */ | ||
57 | #define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */ | ||
58 | /* execute the command */ | ||
59 | #define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */ | ||
60 | /* NULL */ | ||
61 | #define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */ | ||
62 | /* small, too large. */ | ||
63 | #define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */ | ||
64 | /* handle */ | ||
65 | #define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */ | ||
66 | /* standing at this */ | ||
67 | /* context handle */ | ||
68 | #define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */ | ||
69 | #define SW_ERR_NO_PENDING (SW_ERR_BASE-10)/* No request is pending. */ | ||
70 | #define SW_ERR_NO_MEMORY (SW_ERR_BASE-11)/* Not enough memory */ | ||
71 | #define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12)/* Invalid algorithm type */ | ||
72 | /* in SW_PARAM structure */ | ||
73 | #define SW_ERR_MISSING_KEY (SW_ERR_BASE-13)/* No key is associated with */ | ||
74 | /* context. */ | ||
75 | /* swAttachKeyParam() is */ | ||
76 | /* not called. */ | ||
77 | #define SW_ERR_KEY_CMD_MISMATCH \ | ||
78 | (SW_ERR_BASE-14)/* Cannot perform requested */ | ||
79 | /* SW_COMMAND_CODE since */ | ||
80 | /* key attached via */ | ||
81 | /* swAttachKeyParam() */ | ||
82 | /* cannot be used for this*/ | ||
83 | /* SW_COMMAND_CODE. */ | ||
84 | #define SW_ERR_NOT_IMPLEMENTED \ | ||
85 | (SW_ERR_BASE-15)/* Not implemented */ | ||
86 | #define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16)/* Bad command code */ | ||
87 | #define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17)/* too small or too large in */ | ||
88 | /* the "initems" or */ | ||
89 | /* "outitems". */ | ||
90 | #define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18)/* Bad accelerator number */ | ||
91 | #define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19)/* At least one of the self */ | ||
92 | /* test fail, look at the */ | ||
93 | /* selfTestBitmap in */ | ||
94 | /* SW_ACCELERATOR_INFO for*/ | ||
95 | /* details. */ | ||
96 | #define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/ | ||
97 | /* key materials aligned */ | ||
98 | /* in certain order, e.g. */ | ||
99 | /* 128 bit for CRT */ | ||
100 | #define SW_ERR_OUTPUT_NULL_PTR \ | ||
101 | (SW_ERR_BASE-21)/* a required pointer is */ | ||
102 | /* NULL */ | ||
103 | #define SW_ERR_OUTPUT_SIZE \ | ||
104 | (SW_ERR_BASE-22)/* size is invalid, too */ | ||
105 | /* small, too large. */ | ||
106 | #define SW_ERR_FIRMWARE_CHECKSUM \ | ||
107 | (SW_ERR_BASE-23)/* firmware checksum mismatch*/ | ||
108 | /* download failed. */ | ||
109 | #define SW_ERR_UNKNOWN_FIRMWARE \ | ||
110 | (SW_ERR_BASE-24)/* unknown firmware error */ | ||
111 | #define SW_ERR_INTERRUPT (SW_ERR_BASE-25)/* request is abort when */ | ||
112 | /* it's waiting to be */ | ||
113 | /* completed. */ | ||
114 | #define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26)/* error in writing to Non- */ | ||
115 | /* volatile memory */ | ||
116 | #define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27)/* out of range error in */ | ||
117 | /* writing to NV memory */ | ||
118 | #define SW_ERR_RNG_ERROR (SW_ERR_BASE-28)/* Random Number Generation */ | ||
119 | /* failure */ | ||
120 | #define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29)/* DSS Sign or Verify failure*/ | ||
121 | #define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30)/* Failure in various math */ | ||
122 | /* calculations */ | ||
123 | #define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */ | ||
124 | /* board memory */ | ||
125 | #define SW_ERR_FIRMWARE_VERSION \ | ||
126 | (SW_ERR_BASE-32)/* Wrong version in firmware */ | ||
127 | /* update */ | ||
128 | #define SW_ERR_ZERO_WORKING_ACCELERATOR \ | ||
129 | (SW_ERR_BASE-44)/* All accelerators are bad */ | ||
130 | |||
131 | |||
132 | /* algorithm type */ | ||
133 | #define SW_ALG_CRT 1 | ||
134 | #define SW_ALG_EXP 2 | ||
135 | #define SW_ALG_DSA 3 | ||
136 | #define SW_ALG_NVDATA 4 | ||
137 | |||
138 | /* command code */ | ||
139 | #define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */ | ||
140 | /* Chinese Remainder Theorem (CRT) */ | ||
141 | #define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */ | ||
142 | #define SW_CMD_DSS_SIGN 3 /* perform DSS sign */ | ||
143 | #define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */ | ||
144 | #define SW_CMD_RAND 5 /* perform random number generation */ | ||
145 | #define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */ | ||
146 | #define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */ | ||
147 | |||
148 | typedef SW_U32 SW_ALGTYPE; /* alogrithm type */ | ||
149 | typedef SW_U32 SW_STATE; /* state */ | ||
150 | typedef SW_U32 SW_COMMAND_CODE; /* command code */ | ||
151 | typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */ | ||
152 | |||
153 | typedef struct _SW_LARGENUMBER { | ||
154 | SW_U32 nbytes; /* number of bytes in the buffer "value" */ | ||
155 | SW_BYTE* value; /* the large integer as a string of */ | ||
156 | /* bytes in network (big endian) order */ | ||
157 | } SW_LARGENUMBER; | ||
158 | |||
159 | #if defined(OPENSSL_SYS_WIN32) | ||
160 | #include <windows.h> | ||
161 | typedef HANDLE SW_OSHANDLE; /* handle to kernel object */ | ||
162 | #define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE | ||
163 | #define SW_CALLCONV _stdcall | ||
164 | #elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC) | ||
165 | /* async callback mechanisms */ | ||
166 | /* swiftCallbackLevel */ | ||
167 | #define SW_MAC_CALLBACK_LEVEL_NO 0 | ||
168 | #define SW_MAC_CALLBACK_LEVEL_HARDWARE 1 /* from the hardware ISR */ | ||
169 | #define SW_MAC_CALLBACK_LEVEL_SECONDARY 2 /* as secondary ISR */ | ||
170 | typedef int SW_MAC_CALLBACK_LEVEL; | ||
171 | typedef int SW_OSHANDLE; | ||
172 | #define SW_OS_INVALID_HANDLE (-1) | ||
173 | #define SW_CALLCONV | ||
174 | #else /* Unix variants */ | ||
175 | typedef int SW_OSHANDLE; /* handle to driver */ | ||
176 | #define SW_OS_INVALID_HANDLE (-1) | ||
177 | #define SW_CALLCONV | ||
178 | #endif | ||
179 | |||
180 | typedef struct _SW_CRT { | ||
181 | SW_LARGENUMBER p; /* prime number p */ | ||
182 | SW_LARGENUMBER q; /* prime number q */ | ||
183 | SW_LARGENUMBER dmp1; /* exponent1 */ | ||
184 | SW_LARGENUMBER dmq1; /* exponent2 */ | ||
185 | SW_LARGENUMBER iqmp; /* CRT coefficient */ | ||
186 | } SW_CRT; | ||
187 | |||
188 | typedef struct _SW_EXP { | ||
189 | SW_LARGENUMBER modulus; /* modulus */ | ||
190 | SW_LARGENUMBER exponent;/* exponent */ | ||
191 | } SW_EXP; | ||
192 | |||
193 | typedef struct _SW_DSA { | ||
194 | SW_LARGENUMBER p; /* */ | ||
195 | SW_LARGENUMBER q; /* */ | ||
196 | SW_LARGENUMBER g; /* */ | ||
197 | SW_LARGENUMBER key; /* private/public key */ | ||
198 | } SW_DSA; | ||
199 | |||
200 | typedef struct _SW_NVDATA { | ||
201 | SW_U32 accnum; /* accelerator board number */ | ||
202 | SW_U32 offset; /* offset in byte */ | ||
203 | } SW_NVDATA; | ||
204 | |||
205 | typedef struct _SW_PARAM { | ||
206 | SW_ALGTYPE type; /* type of the alogrithm */ | ||
207 | union { | ||
208 | SW_CRT crt; | ||
209 | SW_EXP exp; | ||
210 | SW_DSA dsa; | ||
211 | SW_NVDATA nvdata; | ||
212 | } up; | ||
213 | } SW_PARAM; | ||
214 | |||
215 | typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */ | ||
216 | |||
217 | |||
218 | /* Now the OpenSSL bits, these function types are the for the function | ||
219 | * pointers that will bound into the Rainbow shared libraries. */ | ||
220 | typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac); | ||
221 | typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac, | ||
222 | SW_PARAM *key_params); | ||
223 | typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac, | ||
224 | SW_COMMAND_CODE cmd, | ||
225 | SW_LARGENUMBER pin[], | ||
226 | SW_U32 pin_count, | ||
227 | SW_LARGENUMBER pout[], | ||
228 | SW_U32 pout_count); | ||
229 | typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE hac); | ||
230 | |||
231 | #ifdef __cplusplus | ||
232 | } | ||
233 | #endif /* __cplusplus */ | ||
234 | |||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h new file mode 100644 index 0000000000..296636e81a --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /**********************************************************************/ | ||
2 | /* */ | ||
3 | /* Prototypes of the CCA verbs used by the 4758 CCA openssl driver */ | ||
4 | /* */ | ||
5 | /* Maurice Gittens <maurice@gittens.nl> */ | ||
6 | /* */ | ||
7 | /**********************************************************************/ | ||
8 | |||
9 | #ifndef __HW_4758_CCA__ | ||
10 | #define __HW_4758_CCA__ | ||
11 | |||
12 | /* | ||
13 | * Only WIN32 support for now | ||
14 | */ | ||
15 | #if defined(WIN32) | ||
16 | |||
17 | #define CCA_LIB_NAME "CSUNSAPI" | ||
18 | |||
19 | #define CSNDPKX "CSNDPKX_32" | ||
20 | #define CSNDKRR "CSNDKRR_32" | ||
21 | #define CSNDPKE "CSNDPKE_32" | ||
22 | #define CSNDPKD "CSNDPKD_32" | ||
23 | #define CSNDDSV "CSNDDSV_32" | ||
24 | #define CSNDDSG "CSNDDSG_32" | ||
25 | #define CSNBRNG "CSNBRNG_32" | ||
26 | |||
27 | #define SECURITYAPI __stdcall | ||
28 | #else | ||
29 | /* Fixme!! | ||
30 | Find out the values of these constants for other platforms. | ||
31 | */ | ||
32 | #define CCA_LIB_NAME "CSUNSAPI" | ||
33 | |||
34 | #define CSNDPKX "CSNDPKX" | ||
35 | #define CSNDKRR "CSNDKRR" | ||
36 | #define CSNDPKE "CSNDPKE" | ||
37 | #define CSNDPKD "CSNDPKD" | ||
38 | #define CSNDDSV "CSNDDSV" | ||
39 | #define CSNDDSG "CSNDDSG" | ||
40 | #define CSNBRNG "CSNBRNG" | ||
41 | |||
42 | #define SECURITYAPI | ||
43 | #endif | ||
44 | |||
45 | /* | ||
46 | * security API prototypes | ||
47 | */ | ||
48 | |||
49 | /* PKA Key Record Read */ | ||
50 | typedef void (SECURITYAPI *F_KEYRECORDREAD) | ||
51 | (long * return_code, | ||
52 | long * reason_code, | ||
53 | long * exit_data_length, | ||
54 | unsigned char * exit_data, | ||
55 | long * rule_array_count, | ||
56 | unsigned char * rule_array, | ||
57 | unsigned char * key_label, | ||
58 | long * key_token_length, | ||
59 | unsigned char * key_token); | ||
60 | |||
61 | /* Random Number Generate */ | ||
62 | typedef void (SECURITYAPI *F_RANDOMNUMBERGENERATE) | ||
63 | (long * return_code, | ||
64 | long * reason_code, | ||
65 | long * exit_data_length, | ||
66 | unsigned char * exit_data, | ||
67 | unsigned char * form, | ||
68 | unsigned char * random_number); | ||
69 | |||
70 | /* Digital Signature Generate */ | ||
71 | typedef void (SECURITYAPI *F_DIGITALSIGNATUREGENERATE) | ||
72 | (long * return_code, | ||
73 | long * reason_code, | ||
74 | long * exit_data_length, | ||
75 | unsigned char * exit_data, | ||
76 | long * rule_array_count, | ||
77 | unsigned char * rule_array, | ||
78 | long * PKA_private_key_id_length, | ||
79 | unsigned char * PKA_private_key_id, | ||
80 | long * hash_length, | ||
81 | unsigned char * hash, | ||
82 | long * signature_field_length, | ||
83 | long * signature_bit_length, | ||
84 | unsigned char * signature_field); | ||
85 | |||
86 | /* Digital Signature Verify */ | ||
87 | typedef void (SECURITYAPI *F_DIGITALSIGNATUREVERIFY)( | ||
88 | long * return_code, | ||
89 | long * reason_code, | ||
90 | long * exit_data_length, | ||
91 | unsigned char * exit_data, | ||
92 | long * rule_array_count, | ||
93 | unsigned char * rule_array, | ||
94 | long * PKA_public_key_id_length, | ||
95 | unsigned char * PKA_public_key_id, | ||
96 | long * hash_length, | ||
97 | unsigned char * hash, | ||
98 | long * signature_field_length, | ||
99 | unsigned char * signature_field); | ||
100 | |||
101 | /* PKA Public Key Extract */ | ||
102 | typedef void (SECURITYAPI *F_PUBLICKEYEXTRACT)( | ||
103 | long * return_code, | ||
104 | long * reason_code, | ||
105 | long * exit_data_length, | ||
106 | unsigned char * exit_data, | ||
107 | long * rule_array_count, | ||
108 | unsigned char * rule_array, | ||
109 | long * source_key_identifier_length, | ||
110 | unsigned char * source_key_identifier, | ||
111 | long * target_key_token_length, | ||
112 | unsigned char * target_key_token); | ||
113 | |||
114 | /* PKA Encrypt */ | ||
115 | typedef void (SECURITYAPI *F_PKAENCRYPT) | ||
116 | (long * return_code, | ||
117 | long * reason_code, | ||
118 | long * exit_data_length, | ||
119 | unsigned char * exit_data, | ||
120 | long * rule_array_count, | ||
121 | unsigned char * rule_array, | ||
122 | long * key_value_length, | ||
123 | unsigned char * key_value, | ||
124 | long * data_struct_length, | ||
125 | unsigned char * data_struct, | ||
126 | long * RSA_public_key_length, | ||
127 | unsigned char * RSA_public_key, | ||
128 | long * RSA_encipher_length, | ||
129 | unsigned char * RSA_encipher ); | ||
130 | |||
131 | /* PKA Decrypt */ | ||
132 | typedef void (SECURITYAPI *F_PKADECRYPT) | ||
133 | (long * return_code, | ||
134 | long * reason_code, | ||
135 | long * exit_data_length, | ||
136 | unsigned char * exit_data, | ||
137 | long * rule_array_count, | ||
138 | unsigned char * rule_array, | ||
139 | long * enciphered_key_length, | ||
140 | unsigned char * enciphered_key, | ||
141 | long * data_struct_length, | ||
142 | unsigned char * data_struct, | ||
143 | long * RSA_private_key_length, | ||
144 | unsigned char * RSA_private_key, | ||
145 | long * key_value_length, | ||
146 | unsigned char * key_value ); | ||
147 | |||
148 | |||
149 | #endif | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h b/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h new file mode 100644 index 0000000000..b6619d40f2 --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright 2000 | ||
4 | * Broadcom Corporation | ||
5 | * 16215 Alton Parkway | ||
6 | * PO Box 57013 | ||
7 | * Irvine CA 92619-7013 | ||
8 | * | ||
9 | *****************************************************************************/ | ||
10 | /* | ||
11 | * Broadcom Corporation uBSec SDK | ||
12 | */ | ||
13 | /* | ||
14 | * Character device header file. | ||
15 | */ | ||
16 | /* | ||
17 | * Revision History: | ||
18 | * | ||
19 | * October 2000 JTT Created. | ||
20 | */ | ||
21 | |||
22 | #define MAX_PUBLIC_KEY_BITS (1024) | ||
23 | #define MAX_PUBLIC_KEY_BYTES (1024/8) | ||
24 | #define SHA_BIT_SIZE (160) | ||
25 | #define MAX_CRYPTO_KEY_LENGTH 24 | ||
26 | #define MAX_MAC_KEY_LENGTH 64 | ||
27 | #define UBSEC_CRYPTO_DEVICE_NAME ((unsigned char *)"/dev/ubscrypt") | ||
28 | #define UBSEC_KEY_DEVICE_NAME ((unsigned char *)"/dev/ubskey") | ||
29 | |||
30 | /* Math command types. */ | ||
31 | #define UBSEC_MATH_MODADD 0x0001 | ||
32 | #define UBSEC_MATH_MODSUB 0x0002 | ||
33 | #define UBSEC_MATH_MODMUL 0x0004 | ||
34 | #define UBSEC_MATH_MODEXP 0x0008 | ||
35 | #define UBSEC_MATH_MODREM 0x0010 | ||
36 | #define UBSEC_MATH_MODINV 0x0020 | ||
37 | |||
38 | typedef long ubsec_MathCommand_t; | ||
39 | typedef long ubsec_RNGCommand_t; | ||
40 | |||
41 | typedef struct ubsec_crypto_context_s { | ||
42 | unsigned int flags; | ||
43 | unsigned char crypto[MAX_CRYPTO_KEY_LENGTH]; | ||
44 | unsigned char auth[MAX_MAC_KEY_LENGTH]; | ||
45 | } ubsec_crypto_context_t, *ubsec_crypto_context_p; | ||
46 | |||
47 | /* | ||
48 | * Predeclare the function pointer types that we dynamically load from the DSO. | ||
49 | */ | ||
50 | |||
51 | typedef int t_UBSEC_ubsec_bytes_to_bits(unsigned char *n, int bytes); | ||
52 | |||
53 | typedef int t_UBSEC_ubsec_bits_to_bytes(int bits); | ||
54 | |||
55 | typedef int t_UBSEC_ubsec_open(unsigned char *device); | ||
56 | |||
57 | typedef int t_UBSEC_ubsec_close(int fd); | ||
58 | |||
59 | typedef int t_UBSEC_diffie_hellman_generate_ioctl (int fd, | ||
60 | unsigned char *x, int *x_len, unsigned char *y, int *y_len, | ||
61 | unsigned char *g, int g_len, unsigned char *m, int m_len, | ||
62 | unsigned char *userX, int userX_len, int random_bits); | ||
63 | |||
64 | typedef int t_UBSEC_diffie_hellman_agree_ioctl (int fd, | ||
65 | unsigned char *x, int x_len, unsigned char *y, int y_len, | ||
66 | unsigned char *m, int m_len, unsigned char *k, int *k_len); | ||
67 | |||
68 | typedef int t_UBSEC_rsa_mod_exp_ioctl (int fd, | ||
69 | unsigned char *x, int x_len, unsigned char *m, int m_len, | ||
70 | unsigned char *e, int e_len, unsigned char *y, int *y_len); | ||
71 | |||
72 | typedef int t_UBSEC_rsa_mod_exp_crt_ioctl (int fd, | ||
73 | unsigned char *x, int x_len, unsigned char *qinv, int qinv_len, | ||
74 | unsigned char *edq, int edq_len, unsigned char *q, int q_len, | ||
75 | unsigned char *edp, int edp_len, unsigned char *p, int p_len, | ||
76 | unsigned char *y, int *y_len); | ||
77 | |||
78 | typedef int t_UBSEC_dsa_sign_ioctl (int fd, | ||
79 | int hash, unsigned char *data, int data_len, | ||
80 | unsigned char *rndom, int random_len, | ||
81 | unsigned char *p, int p_len, unsigned char *q, int q_len, | ||
82 | unsigned char *g, int g_len, unsigned char *key, int key_len, | ||
83 | unsigned char *r, int *r_len, unsigned char *s, int *s_len); | ||
84 | |||
85 | typedef int t_UBSEC_dsa_verify_ioctl (int fd, | ||
86 | int hash, unsigned char *data, int data_len, | ||
87 | unsigned char *p, int p_len, unsigned char *q, int q_len, | ||
88 | unsigned char *g, int g_len, unsigned char *key, int key_len, | ||
89 | unsigned char *r, int r_len, unsigned char *s, int s_len, | ||
90 | unsigned char *v, int *v_len); | ||
91 | |||
92 | typedef int t_UBSEC_math_accelerate_ioctl(int fd, ubsec_MathCommand_t command, | ||
93 | unsigned char *ModN, int *ModN_len, unsigned char *ExpE, int *ExpE_len, | ||
94 | unsigned char *ParamA, int *ParamA_len, unsigned char *ParamB, int *ParamB_len, | ||
95 | unsigned char *Result, int *Result_len); | ||
96 | |||
97 | typedef int t_UBSEC_rng_ioctl(int fd, ubsec_RNGCommand_t command, | ||
98 | unsigned char *Result, int *Result_len); | ||
99 | |||
100 | typedef int t_UBSEC_max_key_len_ioctl(int fd, int *max_key_len); | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h b/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h new file mode 100644 index 0000000000..aaa4d4575e --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h | |||
@@ -0,0 +1,486 @@ | |||
1 | /* | ||
2 | * ModExp / RSA (with/without KM) plugin API | ||
3 | * | ||
4 | * The application will load a dynamic library which | ||
5 | * exports entrypoint(s) defined in this file. | ||
6 | * | ||
7 | * This set of entrypoints provides only a multithreaded, | ||
8 | * synchronous-within-each-thread, facility. | ||
9 | * | ||
10 | * | ||
11 | * This file is Copyright 1998-2000 nCipher Corporation Limited. | ||
12 | * | ||
13 | * Redistribution and use in source and binary forms, with opr without | ||
14 | * modification, are permitted provided that the following conditions | ||
15 | * are met: | ||
16 | * | ||
17 | * 1. Redistributions of source code must retain the copyright notice, | ||
18 | * this list of conditions, and the following disclaimer. | ||
19 | * | ||
20 | * 2. Redistributions in binary form must reproduce the above | ||
21 | * copyright notice, this list of conditions, and the following | ||
22 | * disclaimer, in the documentation and/or other materials provided | ||
23 | * with the distribution | ||
24 | * | ||
25 | * IN NO EVENT SHALL NCIPHER CORPORATION LIMITED (`NCIPHER') AND/OR | ||
26 | * ANY OTHER AUTHORS OR DISTRIBUTORS OF THIS FILE BE LIABLE for any | ||
27 | * damages arising directly or indirectly from this file, its use or | ||
28 | * this licence. Without prejudice to the generality of the | ||
29 | * foregoing: all liability shall be excluded for direct, indirect, | ||
30 | * special, incidental, consequential or other damages or any loss of | ||
31 | * profits, business, revenue goodwill or anticipated savings; | ||
32 | * liability shall be excluded even if nCipher or anyone else has been | ||
33 | * advised of the possibility of damage. In any event, if the | ||
34 | * exclusion of liability is not effective, the liability of nCipher | ||
35 | * or any author or distributor shall be limited to the lesser of the | ||
36 | * price paid and 1,000 pounds sterling. This licence only fails to | ||
37 | * exclude or limit liability for death or personal injury arising out | ||
38 | * of negligence, and only to the extent that such an exclusion or | ||
39 | * limitation is not effective. | ||
40 | * | ||
41 | * NCIPHER AND THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ALL | ||
42 | * AND ANY WARRANTIES (WHETHER EXPRESS OR IMPLIED), including, but not | ||
43 | * limited to, any implied warranties of merchantability, fitness for | ||
44 | * a particular purpose, satisfactory quality, and/or non-infringement | ||
45 | * of any third party rights. | ||
46 | * | ||
47 | * US Government use: This software and documentation is Commercial | ||
48 | * Computer Software and Computer Software Documentation, as defined in | ||
49 | * sub-paragraphs (a)(1) and (a)(5) of DFAR 252.227-7014, "Rights in | ||
50 | * Noncommercial Computer Software and Noncommercial Computer Software | ||
51 | * Documentation." Use, duplication or disclosure by the Government is | ||
52 | * subject to the terms and conditions specified here. | ||
53 | * | ||
54 | * By using or distributing this file you will be accepting these | ||
55 | * terms and conditions, including the limitation of liability and | ||
56 | * lack of warranty. If you do not wish to accept these terms and | ||
57 | * conditions, DO NOT USE THE FILE. | ||
58 | * | ||
59 | * | ||
60 | * The actual dynamically loadable plugin, and the library files for | ||
61 | * static linking, which are also provided in some distributions, are | ||
62 | * not covered by the licence described above. You should have | ||
63 | * received a separate licence with terms and conditions for these | ||
64 | * library files; if you received the library files without a licence, | ||
65 | * please contact nCipher. | ||
66 | * | ||
67 | * | ||
68 | * $Id: hwcryptohook.h,v 1.1.1.1 2003/05/11 21:35:16 markus Exp $ | ||
69 | */ | ||
70 | |||
71 | #ifndef HWCRYPTOHOOK_H | ||
72 | #define HWCRYPTOHOOK_H | ||
73 | |||
74 | #include <sys/types.h> | ||
75 | #include <stdio.h> | ||
76 | |||
77 | #ifndef HWCRYPTOHOOK_DECLARE_APPTYPES | ||
78 | #define HWCRYPTOHOOK_DECLARE_APPTYPES 1 | ||
79 | #endif | ||
80 | |||
81 | #define HWCRYPTOHOOK_ERROR_FAILED -1 | ||
82 | #define HWCRYPTOHOOK_ERROR_FALLBACK -2 | ||
83 | #define HWCRYPTOHOOK_ERROR_MPISIZE -3 | ||
84 | |||
85 | #if HWCRYPTOHOOK_DECLARE_APPTYPES | ||
86 | |||
87 | /* These structs are defined by the application and opaque to the | ||
88 | * crypto plugin. The application may define these as it sees fit. | ||
89 | * Default declarations are provided here, but the application may | ||
90 | * #define HWCRYPTOHOOK_DECLARE_APPTYPES 0 | ||
91 | * to prevent these declarations, and instead provide its own | ||
92 | * declarations of these types. (Pointers to them must still be | ||
93 | * ordinary pointers to structs or unions, or the resulting combined | ||
94 | * program will have a type inconsistency.) | ||
95 | */ | ||
96 | typedef struct HWCryptoHook_MutexValue HWCryptoHook_Mutex; | ||
97 | typedef struct HWCryptoHook_CondVarValue HWCryptoHook_CondVar; | ||
98 | typedef struct HWCryptoHook_PassphraseContextValue HWCryptoHook_PassphraseContext; | ||
99 | typedef struct HWCryptoHook_CallerContextValue HWCryptoHook_CallerContext; | ||
100 | |||
101 | #endif /* HWCRYPTOHOOK_DECLARE_APPTYPES */ | ||
102 | |||
103 | /* These next two structs are opaque to the application. The crypto | ||
104 | * plugin will return pointers to them; the caller simply manipulates | ||
105 | * the pointers. | ||
106 | */ | ||
107 | typedef struct HWCryptoHook_Context *HWCryptoHook_ContextHandle; | ||
108 | typedef struct HWCryptoHook_RSAKey *HWCryptoHook_RSAKeyHandle; | ||
109 | |||
110 | typedef struct { | ||
111 | char *buf; | ||
112 | size_t size; | ||
113 | } HWCryptoHook_ErrMsgBuf; | ||
114 | /* Used for error reporting. When a HWCryptoHook function fails it | ||
115 | * will return a sentinel value (0 for pointer-valued functions, or a | ||
116 | * negative number, usually HWCRYPTOHOOK_ERROR_FAILED, for | ||
117 | * integer-valued ones). It will, if an ErrMsgBuf is passed, also put | ||
118 | * an error message there. | ||
119 | * | ||
120 | * size is the size of the buffer, and will not be modified. If you | ||
121 | * pass 0 for size you must pass 0 for buf, and nothing will be | ||
122 | * recorded (just as if you passed 0 for the struct pointer). | ||
123 | * Messages written to the buffer will always be null-terminated, even | ||
124 | * when truncated to fit within size bytes. | ||
125 | * | ||
126 | * The contents of the buffer are not defined if there is no error. | ||
127 | */ | ||
128 | |||
129 | typedef struct HWCryptoHook_MPIStruct { | ||
130 | unsigned char *buf; | ||
131 | size_t size; | ||
132 | } HWCryptoHook_MPI; | ||
133 | /* When one of these is returned, a pointer is passed to the function. | ||
134 | * At call, size is the space available. Afterwards it is updated to | ||
135 | * be set to the actual length (which may be more than the space available, | ||
136 | * if there was not enough room and the result was truncated). | ||
137 | * buf (the pointer) is not updated. | ||
138 | * | ||
139 | * size is in bytes and may be zero at call or return, but must be a | ||
140 | * multiple of the limb size. Zero limbs at the MS end are not | ||
141 | * permitted. | ||
142 | */ | ||
143 | |||
144 | #define HWCryptoHook_InitFlags_FallbackModExp 0x0002UL | ||
145 | #define HWCryptoHook_InitFlags_FallbackRSAImmed 0x0004UL | ||
146 | /* Enable requesting fallback to software in case of problems with the | ||
147 | * hardware support. This indicates to the crypto provider that the | ||
148 | * application is prepared to fall back to software operation if the | ||
149 | * ModExp* or RSAImmed* functions return HWCRYPTOHOOK_ERROR_FALLBACK. | ||
150 | * Without this flag those calls will never return | ||
151 | * HWCRYPTOHOOK_ERROR_FALLBACK. The flag will also cause the crypto | ||
152 | * provider to avoid repeatedly attempting to contact dead hardware | ||
153 | * within a short interval, if appropriate. | ||
154 | */ | ||
155 | |||
156 | #define HWCryptoHook_InitFlags_SimpleForkCheck 0x0010UL | ||
157 | /* Without _SimpleForkCheck the library is allowed to assume that the | ||
158 | * application will not fork and call the library in the child(ren). | ||
159 | * | ||
160 | * When it is specified, this is allowed. However, after a fork | ||
161 | * neither parent nor child may unload any loaded keys or call | ||
162 | * _Finish. Instead, they should call exit (or die with a signal) | ||
163 | * without calling _Finish. After all the children have died the | ||
164 | * parent may unload keys or call _Finish. | ||
165 | * | ||
166 | * This flag only has any effect on UN*X platforms. | ||
167 | */ | ||
168 | |||
169 | typedef struct { | ||
170 | unsigned long flags; | ||
171 | void *logstream; /* usually a FILE*. See below. */ | ||
172 | |||
173 | size_t limbsize; /* bignum format - size of radix type, must be power of 2 */ | ||
174 | int mslimbfirst; /* 0 or 1 */ | ||
175 | int msbytefirst; /* 0 or 1; -1 = native */ | ||
176 | |||
177 | /* All the callback functions should return 0 on success, or a | ||
178 | * nonzero integer (whose value will be visible in the error message | ||
179 | * put in the buffer passed to the call). | ||
180 | * | ||
181 | * If a callback is not available pass a null function pointer. | ||
182 | * | ||
183 | * The callbacks may not call down again into the crypto plugin. | ||
184 | */ | ||
185 | |||
186 | /* For thread-safety. Set everything to 0 if you promise only to be | ||
187 | * singlethreaded. maxsimultaneous is the number of calls to | ||
188 | * ModExp[Crt]/RSAImmed{Priv,Pub}/RSA. If you don't know what to | ||
189 | * put there then say 0 and the hook library will use a default. | ||
190 | * | ||
191 | * maxmutexes is a small limit on the number of simultaneous mutexes | ||
192 | * which will be requested by the library. If there is no small | ||
193 | * limit, set it to 0. If the crypto plugin cannot create the | ||
194 | * advertised number of mutexes the calls to its functions may fail. | ||
195 | * If a low number of mutexes is advertised the plugin will try to | ||
196 | * do the best it can. Making larger numbers of mutexes available | ||
197 | * may improve performance and parallelism by reducing contention | ||
198 | * over critical sections. Unavailability of any mutexes, implying | ||
199 | * single-threaded operation, should be indicated by the setting | ||
200 | * mutex_init et al to 0. | ||
201 | */ | ||
202 | int maxmutexes; | ||
203 | int maxsimultaneous; | ||
204 | size_t mutexsize; | ||
205 | int (*mutex_init)(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext *cactx); | ||
206 | int (*mutex_acquire)(HWCryptoHook_Mutex*); | ||
207 | void (*mutex_release)(HWCryptoHook_Mutex*); | ||
208 | void (*mutex_destroy)(HWCryptoHook_Mutex*); | ||
209 | |||
210 | /* For greater efficiency, can use condition vars internally for | ||
211 | * synchronisation. In this case maxsimultaneous is ignored, but | ||
212 | * the other mutex stuff must be available. In singlethreaded | ||
213 | * programs, set everything to 0. | ||
214 | */ | ||
215 | size_t condvarsize; | ||
216 | int (*condvar_init)(HWCryptoHook_CondVar*, HWCryptoHook_CallerContext *cactx); | ||
217 | int (*condvar_wait)(HWCryptoHook_CondVar*, HWCryptoHook_Mutex*); | ||
218 | void (*condvar_signal)(HWCryptoHook_CondVar*); | ||
219 | void (*condvar_broadcast)(HWCryptoHook_CondVar*); | ||
220 | void (*condvar_destroy)(HWCryptoHook_CondVar*); | ||
221 | |||
222 | /* The semantics of acquiring and releasing mutexes and broadcasting | ||
223 | * and waiting on condition variables are expected to be those from | ||
224 | * POSIX threads (pthreads). The mutexes may be (in pthread-speak) | ||
225 | * fast mutexes, recursive mutexes, or nonrecursive ones. | ||
226 | * | ||
227 | * The _release/_signal/_broadcast and _destroy functions must | ||
228 | * always succeed when given a valid argument; if they are given an | ||
229 | * invalid argument then the program (crypto plugin + application) | ||
230 | * has an internal error, and they should abort the program. | ||
231 | */ | ||
232 | |||
233 | int (*getpassphrase)(const char *prompt_info, | ||
234 | int *len_io, char *buf, | ||
235 | HWCryptoHook_PassphraseContext *ppctx, | ||
236 | HWCryptoHook_CallerContext *cactx); | ||
237 | /* Passphrases and the prompt_info, if they contain high-bit-set | ||
238 | * characters, are UTF-8. The prompt_info may be a null pointer if | ||
239 | * no prompt information is available (it should not be an empty | ||
240 | * string). It will not contain text like `enter passphrase'; | ||
241 | * instead it might say something like `Operator Card for John | ||
242 | * Smith' or `SmartCard in nFast Module #1, Slot #1'. | ||
243 | * | ||
244 | * buf points to a buffer in which to return the passphrase; on | ||
245 | * entry *len_io is the length of the buffer. It should be updated | ||
246 | * by the callback. The returned passphrase should not be | ||
247 | * null-terminated by the callback. | ||
248 | */ | ||
249 | |||
250 | int (*getphystoken)(const char *prompt_info, | ||
251 | const char *wrong_info, | ||
252 | HWCryptoHook_PassphraseContext *ppctx, | ||
253 | HWCryptoHook_CallerContext *cactx); | ||
254 | /* Requests that the human user physically insert a different | ||
255 | * smartcard, DataKey, etc. The plugin should check whether the | ||
256 | * currently inserted token(s) are appropriate, and if they are it | ||
257 | * should not make this call. | ||
258 | * | ||
259 | * prompt_info is as before. wrong_info is a description of the | ||
260 | * currently inserted token(s) so that the user is told what | ||
261 | * something is. wrong_info, like prompt_info, may be null, but | ||
262 | * should not be an empty string. Its contents should be | ||
263 | * syntactically similar to that of prompt_info. | ||
264 | */ | ||
265 | |||
266 | /* Note that a single LoadKey operation might cause several calls to | ||
267 | * getpassphrase and/or requestphystoken. If requestphystoken is | ||
268 | * not provided (ie, a null pointer is passed) then the plugin may | ||
269 | * not support loading keys for which authorisation by several cards | ||
270 | * is required. If getpassphrase is not provided then cards with | ||
271 | * passphrases may not be supported. | ||
272 | * | ||
273 | * getpassphrase and getphystoken do not need to check that the | ||
274 | * passphrase has been entered correctly or the correct token | ||
275 | * inserted; the crypto plugin will do that. If this is not the | ||
276 | * case then the crypto plugin is responsible for calling these | ||
277 | * routines again as appropriate until the correct token(s) and | ||
278 | * passphrase(s) are supplied as required, or until any retry limits | ||
279 | * implemented by the crypto plugin are reached. | ||
280 | * | ||
281 | * In either case, the application must allow the user to say `no' | ||
282 | * or `cancel' to indicate that they do not know the passphrase or | ||
283 | * have the appropriate token; this should cause the callback to | ||
284 | * return nonzero indicating error. | ||
285 | */ | ||
286 | |||
287 | void (*logmessage)(void *logstream, const char *message); | ||
288 | /* A log message will be generated at least every time something goes | ||
289 | * wrong and an ErrMsgBuf is filled in (or would be if one was | ||
290 | * provided). Other diagnostic information may be written there too, | ||
291 | * including more detailed reasons for errors which are reported in an | ||
292 | * ErrMsgBuf. | ||
293 | * | ||
294 | * When a log message is generated, this callback is called. It | ||
295 | * should write a message to the relevant logging arrangements. | ||
296 | * | ||
297 | * The message string passed will be null-terminated and may be of arbitrary | ||
298 | * length. It will not be prefixed by the time and date, nor by the | ||
299 | * name of the library that is generating it - if this is required, | ||
300 | * the logmessage callback must do it. The message will not have a | ||
301 | * trailing newline (though it may contain internal newlines). | ||
302 | * | ||
303 | * If a null pointer is passed for logmessage a default function is | ||
304 | * used. The default function treats logstream as a FILE* which has | ||
305 | * been converted to a void*. If logstream is 0 it does nothing. | ||
306 | * Otherwise it prepends the date and time and library name and | ||
307 | * writes the message to logstream. Each line will be prefixed by a | ||
308 | * descriptive string containing the date, time and identity of the | ||
309 | * crypto plugin. Errors on the logstream are not reported | ||
310 | * anywhere, and the default function doesn't flush the stream, so | ||
311 | * the application must set the buffering how it wants it. | ||
312 | * | ||
313 | * The crypto plugin may also provide a facility to have copies of | ||
314 | * log messages sent elsewhere, and or for adjusting the verbosity | ||
315 | * of the log messages; any such facilities will be configured by | ||
316 | * external means. | ||
317 | */ | ||
318 | |||
319 | } HWCryptoHook_InitInfo; | ||
320 | |||
321 | typedef | ||
322 | HWCryptoHook_ContextHandle HWCryptoHook_Init_t(const HWCryptoHook_InitInfo *initinfo, | ||
323 | size_t initinfosize, | ||
324 | const HWCryptoHook_ErrMsgBuf *errors, | ||
325 | HWCryptoHook_CallerContext *cactx); | ||
326 | extern HWCryptoHook_Init_t HWCryptoHook_Init; | ||
327 | |||
328 | /* Caller should set initinfosize to the size of the HWCryptoHook struct, | ||
329 | * so it can be extended later. | ||
330 | * | ||
331 | * On success, a message for display or logging by the server, | ||
332 | * including the name and version number of the plugin, will be filled | ||
333 | * in into *errors; on failure *errors is used for error handling, as | ||
334 | * usual. | ||
335 | */ | ||
336 | |||
337 | /* All these functions return 0 on success, HWCRYPTOHOOK_ERROR_FAILED | ||
338 | * on most failures. HWCRYPTOHOOK_ERROR_MPISIZE means at least one of | ||
339 | * the output MPI buffer(s) was too small; the sizes of all have been | ||
340 | * set to the desired size (and for those where the buffer was large | ||
341 | * enough, the value may have been copied in), and no error message | ||
342 | * has been recorded. | ||
343 | * | ||
344 | * You may pass 0 for the errors struct. In any case, unless you set | ||
345 | * _NoStderr at init time then messages may be reported to stderr. | ||
346 | */ | ||
347 | |||
348 | /* The RSAImmed* functions (and key managed RSA) only work with | ||
349 | * modules which have an RSA patent licence - currently that means KM | ||
350 | * units; the ModExp* ones work with all modules, so you need a patent | ||
351 | * licence in the software in the US. They are otherwise identical. | ||
352 | */ | ||
353 | |||
354 | typedef | ||
355 | void HWCryptoHook_Finish_t(HWCryptoHook_ContextHandle hwctx); | ||
356 | extern HWCryptoHook_Finish_t HWCryptoHook_Finish; | ||
357 | /* You must not have any calls going or keys loaded when you call this. */ | ||
358 | |||
359 | typedef | ||
360 | int HWCryptoHook_RandomBytes_t(HWCryptoHook_ContextHandle hwctx, | ||
361 | unsigned char *buf, size_t len, | ||
362 | const HWCryptoHook_ErrMsgBuf *errors); | ||
363 | extern HWCryptoHook_RandomBytes_t HWCryptoHook_RandomBytes; | ||
364 | |||
365 | typedef | ||
366 | int HWCryptoHook_ModExp_t(HWCryptoHook_ContextHandle hwctx, | ||
367 | HWCryptoHook_MPI a, | ||
368 | HWCryptoHook_MPI p, | ||
369 | HWCryptoHook_MPI n, | ||
370 | HWCryptoHook_MPI *r, | ||
371 | const HWCryptoHook_ErrMsgBuf *errors); | ||
372 | extern HWCryptoHook_ModExp_t HWCryptoHook_ModExp; | ||
373 | |||
374 | typedef | ||
375 | int HWCryptoHook_RSAImmedPub_t(HWCryptoHook_ContextHandle hwctx, | ||
376 | HWCryptoHook_MPI m, | ||
377 | HWCryptoHook_MPI e, | ||
378 | HWCryptoHook_MPI n, | ||
379 | HWCryptoHook_MPI *r, | ||
380 | const HWCryptoHook_ErrMsgBuf *errors); | ||
381 | extern HWCryptoHook_RSAImmedPub_t HWCryptoHook_RSAImmedPub; | ||
382 | |||
383 | typedef | ||
384 | int HWCryptoHook_ModExpCRT_t(HWCryptoHook_ContextHandle hwctx, | ||
385 | HWCryptoHook_MPI a, | ||
386 | HWCryptoHook_MPI p, | ||
387 | HWCryptoHook_MPI q, | ||
388 | HWCryptoHook_MPI dmp1, | ||
389 | HWCryptoHook_MPI dmq1, | ||
390 | HWCryptoHook_MPI iqmp, | ||
391 | HWCryptoHook_MPI *r, | ||
392 | const HWCryptoHook_ErrMsgBuf *errors); | ||
393 | extern HWCryptoHook_ModExpCRT_t HWCryptoHook_ModExpCRT; | ||
394 | |||
395 | typedef | ||
396 | int HWCryptoHook_RSAImmedPriv_t(HWCryptoHook_ContextHandle hwctx, | ||
397 | HWCryptoHook_MPI m, | ||
398 | HWCryptoHook_MPI p, | ||
399 | HWCryptoHook_MPI q, | ||
400 | HWCryptoHook_MPI dmp1, | ||
401 | HWCryptoHook_MPI dmq1, | ||
402 | HWCryptoHook_MPI iqmp, | ||
403 | HWCryptoHook_MPI *r, | ||
404 | const HWCryptoHook_ErrMsgBuf *errors); | ||
405 | extern HWCryptoHook_RSAImmedPriv_t HWCryptoHook_RSAImmedPriv; | ||
406 | |||
407 | /* The RSAImmed* and ModExp* functions may return E_FAILED or | ||
408 | * E_FALLBACK for failure. | ||
409 | * | ||
410 | * E_FAILED means the failure is permanent and definite and there | ||
411 | * should be no attempt to fall back to software. (Eg, for some | ||
412 | * applications, which support only the acceleration-only | ||
413 | * functions, the `key material' may actually be an encoded key | ||
414 | * identifier, and doing the operation in software would give wrong | ||
415 | * answers.) | ||
416 | * | ||
417 | * E_FALLBACK means that doing the computation in software would seem | ||
418 | * reasonable. If an application pays attention to this and is | ||
419 | * able to fall back, it should also set the Fallback init flags. | ||
420 | */ | ||
421 | |||
422 | typedef | ||
423 | int HWCryptoHook_RSALoadKey_t(HWCryptoHook_ContextHandle hwctx, | ||
424 | const char *key_ident, | ||
425 | HWCryptoHook_RSAKeyHandle *keyhandle_r, | ||
426 | const HWCryptoHook_ErrMsgBuf *errors, | ||
427 | HWCryptoHook_PassphraseContext *ppctx); | ||
428 | extern HWCryptoHook_RSALoadKey_t HWCryptoHook_RSALoadKey; | ||
429 | /* The key_ident is a null-terminated string configured by the | ||
430 | * user via the application's usual configuration mechanisms. | ||
431 | * It is provided to the user by the crypto provider's key management | ||
432 | * system. The user must be able to enter at least any string of between | ||
433 | * 1 and 1023 characters inclusive, consisting of printable 7-bit | ||
434 | * ASCII characters. The provider should avoid using | ||
435 | * any characters except alphanumerics and the punctuation | ||
436 | * characters _ - + . / @ ~ (the user is expected to be able | ||
437 | * to enter these without quoting). The string may be case-sensitive. | ||
438 | * The application may allow the user to enter other NULL-terminated strings, | ||
439 | * and the provider must cope (returning an error if the string is not | ||
440 | * valid). | ||
441 | * | ||
442 | * If the key does not exist, no error is recorded and 0 is returned; | ||
443 | * keyhandle_r will be set to 0 instead of to a key handle. | ||
444 | */ | ||
445 | |||
446 | typedef | ||
447 | int HWCryptoHook_RSAGetPublicKey_t(HWCryptoHook_RSAKeyHandle k, | ||
448 | HWCryptoHook_MPI *n, | ||
449 | HWCryptoHook_MPI *e, | ||
450 | const HWCryptoHook_ErrMsgBuf *errors); | ||
451 | extern HWCryptoHook_RSAGetPublicKey_t HWCryptoHook_RSAGetPublicKey; | ||
452 | /* The crypto plugin will not store certificates. | ||
453 | * | ||
454 | * Although this function for acquiring the public key value is | ||
455 | * provided, it is not the purpose of this API to deal fully with the | ||
456 | * handling of the public key. | ||
457 | * | ||
458 | * It is expected that the crypto supplier's key generation program | ||
459 | * will provide general facilities for producing X.509 | ||
460 | * self-certificates and certificate requests in PEM format. These | ||
461 | * will be given to the user so that they can configure them in the | ||
462 | * application, send them to CAs, or whatever. | ||
463 | * | ||
464 | * In case this kind of certificate handling is not appropriate, the | ||
465 | * crypto supplier's key generation program should be able to be | ||
466 | * configured not to generate such a self-certificate or certificate | ||
467 | * request. Then the application will need to do all of this, and | ||
468 | * will need to store and handle the public key and certificates | ||
469 | * itself. | ||
470 | */ | ||
471 | |||
472 | typedef | ||
473 | int HWCryptoHook_RSAUnloadKey_t(HWCryptoHook_RSAKeyHandle k, | ||
474 | const HWCryptoHook_ErrMsgBuf *errors); | ||
475 | extern HWCryptoHook_RSAUnloadKey_t HWCryptoHook_RSAUnloadKey; | ||
476 | /* Might fail due to locking problems, or other serious internal problems. */ | ||
477 | |||
478 | typedef | ||
479 | int HWCryptoHook_RSA_t(HWCryptoHook_MPI m, | ||
480 | HWCryptoHook_RSAKeyHandle k, | ||
481 | HWCryptoHook_MPI *r, | ||
482 | const HWCryptoHook_ErrMsgBuf *errors); | ||
483 | extern HWCryptoHook_RSA_t HWCryptoHook_RSA; | ||
484 | /* RSA private key operation (sign or decrypt) - raw, unpadded. */ | ||
485 | |||
486 | #endif /*HWCRYPTOHOOK_H*/ | ||
diff --git a/src/lib/libcrypto/engine/vendor_defns/sureware.h b/src/lib/libcrypto/engine/vendor_defns/sureware.h new file mode 100644 index 0000000000..4bc22027f9 --- /dev/null +++ b/src/lib/libcrypto/engine/vendor_defns/sureware.h | |||
@@ -0,0 +1,239 @@ | |||
1 | /* | ||
2 | * Written by Corinne Dive-Reclus(cdive@baltimore.com) | ||
3 | * | ||
4 | * Copyright@2001 Baltimore Technologies Ltd. | ||
5 | * * | ||
6 | * THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND * | ||
7 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * | ||
8 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * | ||
9 | * ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE * | ||
10 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * | ||
11 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * | ||
12 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * | ||
13 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * | ||
14 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * | ||
15 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * | ||
16 | * SUCH DAMAGE. * | ||
17 | * | ||
18 | * | ||
19 | */ | ||
20 | #ifdef WIN32 | ||
21 | #define SW_EXPORT __declspec ( dllexport ) | ||
22 | #else | ||
23 | #define SW_EXPORT | ||
24 | #endif | ||
25 | |||
26 | /* | ||
27 | * List of exposed SureWare errors | ||
28 | */ | ||
29 | #define SUREWAREHOOK_ERROR_FAILED -1 | ||
30 | #define SUREWAREHOOK_ERROR_FALLBACK -2 | ||
31 | #define SUREWAREHOOK_ERROR_UNIT_FAILURE -3 | ||
32 | #define SUREWAREHOOK_ERROR_DATA_SIZE -4 | ||
33 | #define SUREWAREHOOK_ERROR_INVALID_PAD -5 | ||
34 | /* | ||
35 | * -----------------WARNING----------------------------------- | ||
36 | * In all the following functions: | ||
37 | * msg is a string with at least 24 bytes free. | ||
38 | * A 24 bytes string will be concatenated to the existing content of msg. | ||
39 | */ | ||
40 | /* | ||
41 | * SureWare Initialisation function | ||
42 | * in param threadsafe, if !=0, thread safe enabled | ||
43 | * return SureWareHOOK_ERROR_UNIT_FAILURE if failure, 1 if success | ||
44 | */ | ||
45 | typedef int SureWareHook_Init_t(char*const msg,int threadsafe); | ||
46 | extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init; | ||
47 | /* | ||
48 | * SureWare Finish function | ||
49 | */ | ||
50 | typedef void SureWareHook_Finish_t(); | ||
51 | extern SW_EXPORT SureWareHook_Finish_t SureWareHook_Finish; | ||
52 | /* | ||
53 | * PRE_CONDITION: | ||
54 | * DO NOT CALL ANY OF THE FOLLOWING FUNCTIONS IN CASE OF INIT FAILURE | ||
55 | */ | ||
56 | /* | ||
57 | * SureWare RAND Bytes function | ||
58 | * In case of failure, the content of buf is unpredictable. | ||
59 | * return 1 if success | ||
60 | * SureWareHOOK_ERROR_FALLBACK if function not available in hardware | ||
61 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
62 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
63 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
64 | * | ||
65 | * in/out param buf : a num bytes long buffer where random bytes will be put | ||
66 | * in param num : the number of bytes into buf | ||
67 | */ | ||
68 | typedef int SureWareHook_Rand_Bytes_t(char*const msg,unsigned char *buf, int num); | ||
69 | extern SW_EXPORT SureWareHook_Rand_Bytes_t SureWareHook_Rand_Bytes; | ||
70 | |||
71 | /* | ||
72 | * SureWare RAND Seed function | ||
73 | * Adds some seed to the Hardware Random Number Generator | ||
74 | * return 1 if success | ||
75 | * SureWareHOOK_ERROR_FALLBACK if function not available in hardware | ||
76 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
77 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
78 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
79 | * | ||
80 | * in param buf : the seed to add into the HRNG | ||
81 | * in param num : the number of bytes into buf | ||
82 | */ | ||
83 | typedef int SureWareHook_Rand_Seed_t(char*const msg,const void *buf, int num); | ||
84 | extern SW_EXPORT SureWareHook_Rand_Seed_t SureWareHook_Rand_Seed; | ||
85 | |||
86 | /* | ||
87 | * SureWare Load Private Key function | ||
88 | * return 1 if success | ||
89 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
90 | * No hardware is contact for this function. | ||
91 | * | ||
92 | * in param key_id :the name of the private protected key file without the extension | ||
93 | ".sws" | ||
94 | * out param hptr : a pointer to a buffer allocated by SureWare_Hook | ||
95 | * out param num: the effective key length in bytes | ||
96 | * out param keytype: 1 if RSA 2 if DSA | ||
97 | */ | ||
98 | typedef int SureWareHook_Load_Privkey_t(char*const msg,const char *key_id,char **hptr,unsigned long *num,char *keytype); | ||
99 | extern SW_EXPORT SureWareHook_Load_Privkey_t SureWareHook_Load_Privkey; | ||
100 | |||
101 | /* | ||
102 | * SureWare Info Public Key function | ||
103 | * return 1 if success | ||
104 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
105 | * No hardware is contact for this function. | ||
106 | * | ||
107 | * in param key_id :the name of the private protected key file without the extension | ||
108 | ".swp" | ||
109 | * out param hptr : a pointer to a buffer allocated by SureWare_Hook | ||
110 | * out param num: the effective key length in bytes | ||
111 | * out param keytype: 1 if RSA 2 if DSA | ||
112 | */ | ||
113 | typedef int SureWareHook_Info_Pubkey_t(char*const msg,const char *key_id,unsigned long *num, | ||
114 | char *keytype); | ||
115 | extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey; | ||
116 | |||
117 | /* | ||
118 | * SureWare Load Public Key function | ||
119 | * return 1 if success | ||
120 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
121 | * No hardware is contact for this function. | ||
122 | * | ||
123 | * in param key_id :the name of the public protected key file without the extension | ||
124 | ".swp" | ||
125 | * in param num : the bytes size of n and e | ||
126 | * out param n: where to write modulus in bn format | ||
127 | * out param e: where to write exponent in bn format | ||
128 | */ | ||
129 | typedef int SureWareHook_Load_Rsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num, | ||
130 | unsigned long *n, unsigned long *e); | ||
131 | extern SW_EXPORT SureWareHook_Load_Rsa_Pubkey_t SureWareHook_Load_Rsa_Pubkey; | ||
132 | |||
133 | /* | ||
134 | * SureWare Load DSA Public Key function | ||
135 | * return 1 if success | ||
136 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
137 | * No hardware is contact for this function. | ||
138 | * | ||
139 | * in param key_id :the name of the public protected key file without the extension | ||
140 | ".swp" | ||
141 | * in param num : the bytes size of n and e | ||
142 | * out param pub: where to write pub key in bn format | ||
143 | * out param p: where to write prime in bn format | ||
144 | * out param q: where to write sunprime (length 20 bytes) in bn format | ||
145 | * out param g: where to write base in bn format | ||
146 | */ | ||
147 | typedef int SureWareHook_Load_Dsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num, | ||
148 | unsigned long *pub, unsigned long *p,unsigned long*q, | ||
149 | unsigned long *g); | ||
150 | extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey; | ||
151 | |||
152 | /* | ||
153 | * SureWare Free function | ||
154 | * Destroy the key into the hardware if destroy==1 | ||
155 | */ | ||
156 | typedef void SureWareHook_Free_t(char *p,int destroy); | ||
157 | extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free; | ||
158 | |||
159 | #define SUREWARE_PKCS1_PAD 1 | ||
160 | #define SUREWARE_ISO9796_PAD 2 | ||
161 | #define SUREWARE_NO_PAD 0 | ||
162 | /* | ||
163 | * SureWare RSA Private Decryption | ||
164 | * return 1 if success | ||
165 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
166 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
167 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
168 | * | ||
169 | * in param flen : byte size of from and to | ||
170 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
171 | * out param tlen: byte size of decrypted data, if error, unexpected value | ||
172 | * out param to : decrypted data buffer, should be a not-null valid pointer | ||
173 | * in param prsa: a protected key pointer, should be a not-null valid pointer | ||
174 | * int padding: padding id as follow | ||
175 | * SUREWARE_PKCS1_PAD | ||
176 | * SUREWARE_NO_PAD | ||
177 | * | ||
178 | */ | ||
179 | typedef int SureWareHook_Rsa_Priv_Dec_t(char*const msg,int flen,unsigned char *from, | ||
180 | int *tlen,unsigned char *to, | ||
181 | char *prsa,int padding); | ||
182 | extern SW_EXPORT SureWareHook_Rsa_Priv_Dec_t SureWareHook_Rsa_Priv_Dec; | ||
183 | /* | ||
184 | * SureWare RSA Signature | ||
185 | * return 1 if success | ||
186 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
187 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
188 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
189 | * | ||
190 | * in param flen : byte size of from and to | ||
191 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
192 | * out param tlen: byte size of decrypted data, if error, unexpected value | ||
193 | * out param to : decrypted data buffer, should be a not-null valid pointer | ||
194 | * in param prsa: a protected key pointer, should be a not-null valid pointer | ||
195 | * int padding: padding id as follow | ||
196 | * SUREWARE_PKCS1_PAD | ||
197 | * SUREWARE_ISO9796_PAD | ||
198 | * | ||
199 | */ | ||
200 | typedef int SureWareHook_Rsa_Sign_t(char*const msg,int flen,unsigned char *from, | ||
201 | int *tlen,unsigned char *to, | ||
202 | char *prsa,int padding); | ||
203 | extern SW_EXPORT SureWareHook_Rsa_Sign_t SureWareHook_Rsa_Sign; | ||
204 | /* | ||
205 | * SureWare DSA Signature | ||
206 | * return 1 if success | ||
207 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
208 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
209 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
210 | * | ||
211 | * in param flen : byte size of from and to | ||
212 | * in param from : encrypted data buffer, should be a not-null valid pointer | ||
213 | * out param to : decrypted data buffer, should be a 40bytes valid pointer | ||
214 | * in param pdsa: a protected key pointer, should be a not-null valid pointer | ||
215 | * | ||
216 | */ | ||
217 | typedef int SureWareHook_Dsa_Sign_t(char*const msg,int flen,const unsigned char *from, | ||
218 | unsigned long *r,unsigned long *s,char *pdsa); | ||
219 | extern SW_EXPORT SureWareHook_Dsa_Sign_t SureWareHook_Dsa_Sign; | ||
220 | |||
221 | |||
222 | /* | ||
223 | * SureWare Mod Exp | ||
224 | * return 1 if success | ||
225 | * SureWareHOOK_ERROR_FAILED if error while processing | ||
226 | * SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure | ||
227 | * SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf | ||
228 | * | ||
229 | * mod and res are mlen bytes long. | ||
230 | * exp is elen bytes long | ||
231 | * data is dlen bytes long | ||
232 | * mlen,elen and dlen are all multiple of sizeof(unsigned long) | ||
233 | */ | ||
234 | typedef int SureWareHook_Mod_Exp_t(char*const msg,int mlen,const unsigned long *mod, | ||
235 | int elen,const unsigned long *exponent, | ||
236 | int dlen,unsigned long *data, | ||
237 | unsigned long *res); | ||
238 | extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp; | ||
239 | |||