diff options
Diffstat (limited to 'src/lib/libcrypto/rsa')
-rw-r--r-- | src/lib/libcrypto/rsa/Makefile | 269 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/Makefile.ssl | 241 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa.h | 67 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 247 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_err.c | 135 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_gen.c | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_null.c | 150 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_oaep.c | 32 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_test.c | 317 |
9 files changed, 1164 insertions, 297 deletions
diff --git a/src/lib/libcrypto/rsa/Makefile b/src/lib/libcrypto/rsa/Makefile new file mode 100644 index 0000000000..8851825250 --- /dev/null +++ b/src/lib/libcrypto/rsa/Makefile | |||
@@ -0,0 +1,269 @@ | |||
1 | # | ||
2 | # OpenSSL/crypto/rsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rsa | ||
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=rsa_test.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \ | ||
26 | rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \ | ||
27 | rsa_pss.c rsa_x931.c rsa_asn1.c | ||
28 | LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \ | ||
29 | rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \ | ||
30 | rsa_pss.o rsa_x931.o rsa_asn1.o | ||
31 | |||
32 | SRC= $(LIBSRC) | ||
33 | |||
34 | EXHEADER= rsa.h | ||
35 | HEADER= $(EXHEADER) | ||
36 | |||
37 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
38 | |||
39 | top: | ||
40 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
41 | |||
42 | all: lib | ||
43 | |||
44 | lib: $(LIBOBJ) | ||
45 | $(AR) $(LIB) $(LIBOBJ) | ||
46 | $(RANLIB) $(LIB) || echo Never mind. | ||
47 | @touch lib | ||
48 | |||
49 | files: | ||
50 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
51 | |||
52 | links: | ||
53 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
54 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
55 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
56 | |||
57 | install: | ||
58 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
59 | do \ | ||
60 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
61 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
62 | done; | ||
63 | |||
64 | tags: | ||
65 | ctags $(SRC) | ||
66 | |||
67 | tests: | ||
68 | |||
69 | lint: | ||
70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
71 | |||
72 | depend: | ||
73 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
74 | |||
75 | dclean: | ||
76 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
77 | mv -f Makefile.new $(MAKEFILE) | ||
78 | |||
79 | clean: | ||
80 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
81 | |||
82 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
83 | |||
84 | rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h | ||
85 | rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
86 | rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
87 | rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
88 | rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
89 | rsa_asn1.o: ../../include/openssl/opensslconf.h | ||
90 | rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
91 | rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
92 | rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
93 | rsa_asn1.o: ../cryptlib.h rsa_asn1.c | ||
94 | rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
95 | rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
96 | rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
97 | rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
98 | rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
99 | rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
100 | rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
101 | rsa_chk.o: rsa_chk.c | ||
102 | rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h | ||
103 | rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
104 | rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
105 | rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
106 | rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
107 | rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
108 | rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
109 | rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
110 | rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c | ||
111 | rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
112 | rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
113 | rsa_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
114 | rsa_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
115 | rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
116 | rsa_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
117 | rsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
118 | rsa_err.o: rsa_err.c | ||
119 | rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h | ||
120 | rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
121 | rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
122 | rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
123 | rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
124 | rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
125 | rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
126 | rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
127 | rsa_gen.o: ../cryptlib.h rsa_gen.c | ||
128 | rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
129 | rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
130 | rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
131 | rsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
132 | rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
133 | rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
134 | rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
135 | rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
136 | rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
137 | rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
138 | rsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h rsa_lib.c | ||
139 | rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h | ||
140 | rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
141 | rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
142 | rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
143 | rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
144 | rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
145 | rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
146 | rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
147 | rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c | ||
148 | rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h | ||
149 | rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
150 | rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
151 | rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
152 | rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
153 | rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
154 | rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
155 | rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
156 | rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c | ||
157 | rsa_oaep.o: ../../e_os.h ../../include/openssl/aes.h | ||
158 | rsa_oaep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
159 | rsa_oaep.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
160 | rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
161 | rsa_oaep.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
162 | rsa_oaep.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
163 | rsa_oaep.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
164 | rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
165 | rsa_oaep.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
166 | rsa_oaep.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
167 | rsa_oaep.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
168 | rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
169 | rsa_oaep.o: ../../include/openssl/opensslconf.h | ||
170 | rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
171 | rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
172 | rsa_oaep.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
173 | rsa_oaep.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
174 | rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
175 | rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
176 | rsa_oaep.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
177 | rsa_oaep.o: ../cryptlib.h rsa_oaep.c | ||
178 | rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h | ||
179 | rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
180 | rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
181 | rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
182 | rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
183 | rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
184 | rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
185 | rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
186 | rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c | ||
187 | rsa_pss.o: ../../e_os.h ../../include/openssl/aes.h | ||
188 | rsa_pss.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
189 | rsa_pss.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
190 | rsa_pss.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
191 | rsa_pss.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
192 | rsa_pss.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
193 | rsa_pss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
194 | rsa_pss.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
195 | rsa_pss.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
196 | rsa_pss.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
197 | rsa_pss.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
198 | rsa_pss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
199 | rsa_pss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
200 | rsa_pss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
201 | rsa_pss.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
202 | rsa_pss.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
203 | rsa_pss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
204 | rsa_pss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
205 | rsa_pss.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
206 | rsa_pss.o: ../../include/openssl/ui_compat.h ../cryptlib.h rsa_pss.c | ||
207 | rsa_saos.o: ../../e_os.h ../../include/openssl/aes.h | ||
208 | rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
209 | rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
210 | rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
211 | rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
212 | rsa_saos.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
213 | rsa_saos.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
214 | rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
215 | rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
216 | rsa_saos.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
217 | rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
218 | rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
219 | rsa_saos.o: ../../include/openssl/opensslconf.h | ||
220 | rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
221 | rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
222 | rsa_saos.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
223 | rsa_saos.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
224 | rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
225 | rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
226 | rsa_saos.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
227 | rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
228 | rsa_saos.o: ../cryptlib.h rsa_saos.c | ||
229 | rsa_sign.o: ../../e_os.h ../../include/openssl/aes.h | ||
230 | rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
231 | rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
232 | rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
233 | rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
234 | rsa_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
235 | rsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
236 | rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
237 | rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
238 | rsa_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
239 | rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
240 | rsa_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
241 | rsa_sign.o: ../../include/openssl/opensslconf.h | ||
242 | rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
243 | rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
244 | rsa_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
245 | rsa_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
246 | rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
247 | rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
248 | rsa_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
249 | rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
250 | rsa_sign.o: ../cryptlib.h rsa_sign.c | ||
251 | rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
252 | rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
253 | rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
254 | rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
255 | rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
256 | rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
257 | rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
258 | rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
259 | rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_ssl.c | ||
260 | rsa_x931.o: ../../e_os.h ../../include/openssl/asn1.h | ||
261 | rsa_x931.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
262 | rsa_x931.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
263 | rsa_x931.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
264 | rsa_x931.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
265 | rsa_x931.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
266 | rsa_x931.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
267 | rsa_x931.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
268 | rsa_x931.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
269 | rsa_x931.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_x931.c | ||
diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl new file mode 100644 index 0000000000..8089344a04 --- /dev/null +++ b/src/lib/libcrypto/rsa/Makefile.ssl | |||
@@ -0,0 +1,241 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rsa/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rsa | ||
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=rsa_test.c | ||
23 | APPS= | ||
24 | |||
25 | LIB=$(TOP)/libcrypto.a | ||
26 | LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \ | ||
27 | rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \ | ||
28 | rsa_asn1.c | ||
29 | LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \ | ||
30 | rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \ | ||
31 | rsa_asn1.o | ||
32 | |||
33 | SRC= $(LIBSRC) | ||
34 | |||
35 | EXHEADER= rsa.h | ||
36 | HEADER= $(EXHEADER) | ||
37 | |||
38 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
39 | |||
40 | top: | ||
41 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
42 | |||
43 | all: lib | ||
44 | |||
45 | lib: $(LIBOBJ) | ||
46 | $(AR) $(LIB) $(LIBOBJ) | ||
47 | $(RANLIB) $(LIB) || echo Never mind. | ||
48 | @touch lib | ||
49 | |||
50 | files: | ||
51 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
52 | |||
53 | links: | ||
54 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
55 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
56 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
57 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
58 | |||
59 | install: | ||
60 | @for i in $(EXHEADER) ; \ | ||
61 | do \ | ||
62 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
63 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
64 | done; | ||
65 | |||
66 | tags: | ||
67 | ctags $(SRC) | ||
68 | |||
69 | tests: | ||
70 | |||
71 | lint: | ||
72 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
73 | |||
74 | depend: | ||
75 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
76 | |||
77 | dclean: | ||
78 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
79 | mv -f Makefile.new $(MAKEFILE) | ||
80 | |||
81 | clean: | ||
82 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
83 | |||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
85 | |||
86 | rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h | ||
87 | rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | ||
88 | rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h | ||
89 | rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
90 | rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
91 | rsa_asn1.o: ../../include/openssl/opensslconf.h | ||
92 | rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
93 | rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
94 | rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
95 | rsa_asn1.o: ../cryptlib.h rsa_asn1.c | ||
96 | rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
97 | rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
98 | rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
99 | rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
100 | rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
101 | rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
102 | rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
103 | rsa_chk.o: rsa_chk.c | ||
104 | rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h | ||
105 | rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
106 | rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
107 | rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
108 | rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
109 | rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
110 | rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
111 | rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
112 | rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c | ||
113 | rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
114 | rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h | ||
115 | rsa_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
116 | rsa_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
117 | rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
118 | rsa_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
119 | rsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
120 | rsa_err.o: rsa_err.c | ||
121 | rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h | ||
122 | rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
123 | rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
124 | rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
125 | rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
126 | rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
127 | rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
128 | rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
129 | rsa_gen.o: ../cryptlib.h rsa_gen.c | ||
130 | rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
131 | rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
132 | rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
133 | rsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
134 | rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
135 | rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
136 | rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
137 | rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
138 | rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
139 | rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
140 | rsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h rsa_lib.c | ||
141 | rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h | ||
142 | rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
143 | rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
144 | rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
145 | rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
146 | rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
147 | rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
148 | rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
149 | rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c | ||
150 | rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h | ||
151 | rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
152 | rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
153 | rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
154 | rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
155 | rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
156 | rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
157 | rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
158 | rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c | ||
159 | rsa_oaep.o: ../../e_os.h ../../include/openssl/aes.h | ||
160 | rsa_oaep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
161 | rsa_oaep.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
162 | rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
163 | rsa_oaep.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
164 | rsa_oaep.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
165 | rsa_oaep.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
166 | rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
167 | rsa_oaep.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
168 | rsa_oaep.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
169 | rsa_oaep.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
170 | rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
171 | rsa_oaep.o: ../../include/openssl/opensslconf.h | ||
172 | rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
173 | rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
174 | rsa_oaep.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
175 | rsa_oaep.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
176 | rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
177 | rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
178 | rsa_oaep.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
179 | rsa_oaep.o: ../cryptlib.h rsa_oaep.c | ||
180 | rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h | ||
181 | rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
182 | rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
183 | rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
184 | rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
185 | rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
186 | rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
187 | rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
188 | rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c | ||
189 | rsa_saos.o: ../../e_os.h ../../include/openssl/aes.h | ||
190 | rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
191 | rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
192 | rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
193 | rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
194 | rsa_saos.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
195 | rsa_saos.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
196 | rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
197 | rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
198 | rsa_saos.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
199 | rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
200 | rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
201 | rsa_saos.o: ../../include/openssl/opensslconf.h | ||
202 | rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
203 | rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
204 | rsa_saos.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
205 | rsa_saos.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
206 | rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
207 | rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
208 | rsa_saos.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
209 | rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
210 | rsa_saos.o: ../cryptlib.h rsa_saos.c | ||
211 | rsa_sign.o: ../../e_os.h ../../include/openssl/aes.h | ||
212 | rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
213 | rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
214 | rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
215 | rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
216 | rsa_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
217 | rsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
218 | rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
219 | rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
220 | rsa_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
221 | rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
222 | rsa_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
223 | rsa_sign.o: ../../include/openssl/opensslconf.h | ||
224 | rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
225 | rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h | ||
226 | rsa_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
227 | rsa_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
228 | rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
229 | rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
230 | rsa_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
231 | rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
232 | rsa_sign.o: ../cryptlib.h rsa_sign.c | ||
233 | rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h | ||
234 | rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
235 | rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
236 | rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
237 | rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
238 | rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
239 | rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
240 | rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
241 | rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_ssl.c | ||
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h index 0b639cd37f..fc3bb5f86d 100644 --- a/src/lib/libcrypto/rsa/rsa.h +++ b/src/lib/libcrypto/rsa/rsa.h | |||
@@ -157,41 +157,33 @@ struct rsa_st | |||
157 | #define RSA_3 0x3L | 157 | #define RSA_3 0x3L |
158 | #define RSA_F4 0x10001L | 158 | #define RSA_F4 0x10001L |
159 | 159 | ||
160 | #define RSA_METHOD_FLAG_NO_CHECK 0x0001 /* don't check pub/private match */ | 160 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ |
161 | 161 | ||
162 | #define RSA_FLAG_CACHE_PUBLIC 0x0002 | 162 | #define RSA_FLAG_CACHE_PUBLIC 0x02 |
163 | #define RSA_FLAG_CACHE_PRIVATE 0x0004 | 163 | #define RSA_FLAG_CACHE_PRIVATE 0x04 |
164 | #define RSA_FLAG_BLINDING 0x0008 | 164 | #define RSA_FLAG_BLINDING 0x08 |
165 | #define RSA_FLAG_THREAD_SAFE 0x0010 | 165 | #define RSA_FLAG_THREAD_SAFE 0x10 |
166 | /* This flag means the private key operations will be handled by rsa_mod_exp | 166 | /* This flag means the private key operations will be handled by rsa_mod_exp |
167 | * and that they do not depend on the private key components being present: | 167 | * and that they do not depend on the private key components being present: |
168 | * for example a key stored in external hardware. Without this flag bn_mod_exp | 168 | * for example a key stored in external hardware. Without this flag bn_mod_exp |
169 | * gets called when private key components are absent. | 169 | * gets called when private key components are absent. |
170 | */ | 170 | */ |
171 | #define RSA_FLAG_EXT_PKEY 0x0020 | 171 | #define RSA_FLAG_EXT_PKEY 0x20 |
172 | 172 | ||
173 | /* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions. | 173 | /* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions. |
174 | */ | 174 | */ |
175 | #define RSA_FLAG_SIGN_VER 0x0040 | 175 | #define RSA_FLAG_SIGN_VER 0x40 |
176 | 176 | ||
177 | #define RSA_FLAG_NO_BLINDING 0x0080 /* new with 0.9.6j and 0.9.7b; the built-in | 177 | #define RSA_FLAG_NO_BLINDING 0x80 /* new with 0.9.6j and 0.9.7b; the built-in |
178 | * RSA implementation now uses blinding by | 178 | * RSA implementation now uses blinding by |
179 | * default (ignoring RSA_FLAG_BLINDING), | 179 | * default (ignoring RSA_FLAG_BLINDING), |
180 | * but other engines might not need it | 180 | * but other engines might not need it |
181 | */ | 181 | */ |
182 | #define RSA_FLAG_NO_EXP_CONSTTIME 0x0100 /* new with 0.9.7h; the built-in RSA | ||
183 | * implementation now uses constant time | ||
184 | * modular exponentiation for secret exponents | ||
185 | * by default. This flag causes the | ||
186 | * faster variable sliding window method to | ||
187 | * be used for all exponents. | ||
188 | */ | ||
189 | 182 | ||
190 | #define RSA_PKCS1_PADDING 1 | 183 | #define RSA_PKCS1_PADDING 1 |
191 | #define RSA_SSLV23_PADDING 2 | 184 | #define RSA_SSLV23_PADDING 2 |
192 | #define RSA_NO_PADDING 3 | 185 | #define RSA_NO_PADDING 3 |
193 | #define RSA_PKCS1_OAEP_PADDING 4 | 186 | #define RSA_PKCS1_OAEP_PADDING 4 |
194 | #define RSA_X931_PADDING 5 | ||
195 | 187 | ||
196 | #define RSA_PKCS1_PADDING_SIZE 11 | 188 | #define RSA_PKCS1_PADDING_SIZE 11 |
197 | 189 | ||
@@ -204,15 +196,6 @@ int RSA_size(const RSA *); | |||
204 | RSA * RSA_generate_key(int bits, unsigned long e,void | 196 | RSA * RSA_generate_key(int bits, unsigned long e,void |
205 | (*callback)(int,int,void *),void *cb_arg); | 197 | (*callback)(int,int,void *),void *cb_arg); |
206 | int RSA_check_key(const RSA *); | 198 | int RSA_check_key(const RSA *); |
207 | #ifdef OPENSSL_FIPS | ||
208 | int RSA_X931_derive(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2, | ||
209 | void (*cb)(int, int, void *), void *cb_arg, | ||
210 | const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp, | ||
211 | const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq, | ||
212 | const BIGNUM *e); | ||
213 | RSA *RSA_X931_generate_key(int bits, const BIGNUM *e, | ||
214 | void (*cb)(int,int,void *), void *cb_arg); | ||
215 | #endif | ||
216 | /* next 4 return -1 on error */ | 199 | /* next 4 return -1 on error */ |
217 | int RSA_public_encrypt(int flen, const unsigned char *from, | 200 | int RSA_public_encrypt(int flen, const unsigned char *from, |
218 | unsigned char *to, RSA *rsa,int padding); | 201 | unsigned char *to, RSA *rsa,int padding); |
@@ -285,8 +268,6 @@ int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, | |||
285 | const unsigned char *f,int fl); | 268 | const unsigned char *f,int fl); |
286 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, | 269 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, |
287 | const unsigned char *f,int fl,int rsa_len); | 270 | const unsigned char *f,int fl,int rsa_len); |
288 | int PKCS1_MGF1(unsigned char *mask, long len, | ||
289 | const unsigned char *seed, long seedlen, const EVP_MD *dgst); | ||
290 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, | 271 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, |
291 | const unsigned char *f,int fl, | 272 | const unsigned char *f,int fl, |
292 | const unsigned char *p,int pl); | 273 | const unsigned char *p,int pl); |
@@ -301,17 +282,6 @@ int RSA_padding_add_none(unsigned char *to,int tlen, | |||
301 | const unsigned char *f,int fl); | 282 | const unsigned char *f,int fl); |
302 | int RSA_padding_check_none(unsigned char *to,int tlen, | 283 | int RSA_padding_check_none(unsigned char *to,int tlen, |
303 | const unsigned char *f,int fl,int rsa_len); | 284 | const unsigned char *f,int fl,int rsa_len); |
304 | int RSA_padding_add_X931(unsigned char *to,int tlen, | ||
305 | const unsigned char *f,int fl); | ||
306 | int RSA_padding_check_X931(unsigned char *to,int tlen, | ||
307 | const unsigned char *f,int fl,int rsa_len); | ||
308 | int RSA_X931_hash_id(int nid); | ||
309 | |||
310 | int RSA_verify_PKCS1_PSS(RSA *rsa, const unsigned char *mHash, | ||
311 | const EVP_MD *Hash, const unsigned char *EM, int sLen); | ||
312 | int RSA_padding_add_PKCS1_PSS(RSA *rsa, unsigned char *EM, | ||
313 | const unsigned char *mHash, | ||
314 | const EVP_MD *Hash, int sLen); | ||
315 | 285 | ||
316 | int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 286 | int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, |
317 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 287 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); |
@@ -341,24 +311,20 @@ void ERR_load_RSA_strings(void); | |||
341 | #define RSA_F_RSA_NULL 124 | 311 | #define RSA_F_RSA_NULL 124 |
342 | #define RSA_F_RSA_PADDING_ADD_NONE 107 | 312 | #define RSA_F_RSA_PADDING_ADD_NONE 107 |
343 | #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 | 313 | #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 |
344 | #define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 | ||
345 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 | 314 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 |
346 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 | 315 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 |
347 | #define RSA_F_RSA_PADDING_ADD_SSLV23 110 | 316 | #define RSA_F_RSA_PADDING_ADD_SSLV23 110 |
348 | #define RSA_F_RSA_PADDING_ADD_X931 127 | ||
349 | #define RSA_F_RSA_PADDING_CHECK_NONE 111 | 317 | #define RSA_F_RSA_PADDING_CHECK_NONE 111 |
350 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 | 318 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 |
351 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 | 319 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 |
352 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 | 320 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 |
353 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 114 | 321 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 114 |
354 | #define RSA_F_RSA_PADDING_CHECK_X931 128 | ||
355 | #define RSA_F_RSA_PRINT 115 | 322 | #define RSA_F_RSA_PRINT 115 |
356 | #define RSA_F_RSA_PRINT_FP 116 | 323 | #define RSA_F_RSA_PRINT_FP 116 |
357 | #define RSA_F_RSA_SIGN 117 | 324 | #define RSA_F_RSA_SIGN 117 |
358 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 | 325 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 |
359 | #define RSA_F_RSA_VERIFY 119 | 326 | #define RSA_F_RSA_VERIFY 119 |
360 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 | 327 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 |
361 | #define RSA_F_RSA_VERIFY_PKCS1_PSS 126 | ||
362 | 328 | ||
363 | /* Reason codes. */ | 329 | /* Reason codes. */ |
364 | #define RSA_R_ALGORITHM_MISMATCH 100 | 330 | #define RSA_R_ALGORITHM_MISMATCH 100 |
@@ -378,14 +344,9 @@ void ERR_load_RSA_strings(void); | |||
378 | #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 | 344 | #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 |
379 | #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 | 345 | #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 |
380 | #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 | 346 | #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 |
381 | #define RSA_R_FIRST_OCTET_INVALID 133 | ||
382 | #define RSA_R_INVALID_HEADER 137 | ||
383 | #define RSA_R_INVALID_MESSAGE_LENGTH 131 | 347 | #define RSA_R_INVALID_MESSAGE_LENGTH 131 |
384 | #define RSA_R_INVALID_PADDING 138 | ||
385 | #define RSA_R_INVALID_TRAILER 139 | ||
386 | #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 | 348 | #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 |
387 | #define RSA_R_KEY_SIZE_TOO_SMALL 120 | 349 | #define RSA_R_KEY_SIZE_TOO_SMALL 120 |
388 | #define RSA_R_LAST_OCTET_INVALID 134 | ||
389 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 | 350 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 |
390 | #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 | 351 | #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 |
391 | #define RSA_R_OAEP_DECODING_ERROR 121 | 352 | #define RSA_R_OAEP_DECODING_ERROR 121 |
@@ -393,8 +354,6 @@ void ERR_load_RSA_strings(void); | |||
393 | #define RSA_R_P_NOT_PRIME 128 | 354 | #define RSA_R_P_NOT_PRIME 128 |
394 | #define RSA_R_Q_NOT_PRIME 129 | 355 | #define RSA_R_Q_NOT_PRIME 129 |
395 | #define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 | 356 | #define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 |
396 | #define RSA_R_SLEN_CHECK_FAILED 136 | ||
397 | #define RSA_R_SLEN_RECOVERY_FAILED 135 | ||
398 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 | 357 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 |
399 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 | 358 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 |
400 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 | 359 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 |
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index be4ac96ce3..d4caab3f95 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c | |||
@@ -55,59 +55,6 @@ | |||
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | 58 | ||
112 | #include <stdio.h> | 59 | #include <stdio.h> |
113 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
@@ -198,13 +145,30 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from, | |||
198 | goto err; | 145 | goto err; |
199 | } | 146 | } |
200 | 147 | ||
201 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) | 148 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) |
202 | { | 149 | { |
203 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, | 150 | BN_MONT_CTX* bn_mont_ctx; |
204 | CRYPTO_LOCK_RSA, rsa->n, ctx)) | 151 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) |
152 | goto err; | ||
153 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) | ||
154 | { | ||
155 | BN_MONT_CTX_free(bn_mont_ctx); | ||
205 | goto err; | 156 | goto err; |
157 | } | ||
158 | if (rsa->_method_mod_n == NULL) /* other thread may have finished first */ | ||
159 | { | ||
160 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
161 | if (rsa->_method_mod_n == NULL) | ||
162 | { | ||
163 | rsa->_method_mod_n = bn_mont_ctx; | ||
164 | bn_mont_ctx = NULL; | ||
165 | } | ||
166 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
167 | } | ||
168 | if (bn_mont_ctx) | ||
169 | BN_MONT_CTX_free(bn_mont_ctx); | ||
206 | } | 170 | } |
207 | 171 | ||
208 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | 172 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, |
209 | rsa->_method_mod_n)) goto err; | 173 | rsa->_method_mod_n)) goto err; |
210 | 174 | ||
@@ -285,7 +249,7 @@ err: | |||
285 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | 249 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, |
286 | unsigned char *to, RSA *rsa, int padding) | 250 | unsigned char *to, RSA *rsa, int padding) |
287 | { | 251 | { |
288 | BIGNUM f,ret, *res; | 252 | BIGNUM f,ret; |
289 | int i,j,k,num=0,r= -1; | 253 | int i,j,k,num=0,r= -1; |
290 | unsigned char *buf=NULL; | 254 | unsigned char *buf=NULL; |
291 | BN_CTX *ctx=NULL; | 255 | BN_CTX *ctx=NULL; |
@@ -367,43 +331,19 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
367 | (rsa->dmp1 != NULL) && | 331 | (rsa->dmp1 != NULL) && |
368 | (rsa->dmq1 != NULL) && | 332 | (rsa->dmq1 != NULL) && |
369 | (rsa->iqmp != NULL)) ) | 333 | (rsa->iqmp != NULL)) ) |
370 | { | 334 | { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } |
371 | if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; | ||
372 | } | ||
373 | else | 335 | else |
374 | { | 336 | { |
375 | BIGNUM local_d; | 337 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err; |
376 | BIGNUM *d = NULL; | ||
377 | |||
378 | if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME)) | ||
379 | { | ||
380 | BN_init(&local_d); | ||
381 | d = &local_d; | ||
382 | BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME); | ||
383 | } | ||
384 | else | ||
385 | d = rsa->d; | ||
386 | if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL)) goto err; | ||
387 | } | 338 | } |
388 | 339 | ||
389 | if (blinding) | 340 | if (blinding) |
390 | if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err; | 341 | if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err; |
391 | 342 | ||
392 | if (padding == RSA_X931_PADDING) | ||
393 | { | ||
394 | BN_sub(&f, rsa->n, &ret); | ||
395 | if (BN_cmp(&ret, &f)) | ||
396 | res = &f; | ||
397 | else | ||
398 | res = &ret; | ||
399 | } | ||
400 | else | ||
401 | res = &ret; | ||
402 | |||
403 | /* put in leading 0 bytes if the number is less than the | 343 | /* put in leading 0 bytes if the number is less than the |
404 | * length of the modulus */ | 344 | * length of the modulus */ |
405 | j=BN_num_bytes(res); | 345 | j=BN_num_bytes(&ret); |
406 | i=BN_bn2bin(res,&(to[num-j])); | 346 | i=BN_bn2bin(&ret,&(to[num-j])); |
407 | for (k=0; k<(num-i); k++) | 347 | for (k=0; k<(num-i); k++) |
408 | to[k]=0; | 348 | to[k]=0; |
409 | 349 | ||
@@ -504,22 +444,10 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
504 | (rsa->dmp1 != NULL) && | 444 | (rsa->dmp1 != NULL) && |
505 | (rsa->dmq1 != NULL) && | 445 | (rsa->dmq1 != NULL) && |
506 | (rsa->iqmp != NULL)) ) | 446 | (rsa->iqmp != NULL)) ) |
507 | { | 447 | { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } |
508 | if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; | ||
509 | } | ||
510 | else | 448 | else |
511 | { | 449 | { |
512 | BIGNUM local_d; | 450 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) |
513 | BIGNUM *d = NULL; | ||
514 | |||
515 | if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME)) | ||
516 | { | ||
517 | d = &local_d; | ||
518 | BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME); | ||
519 | } | ||
520 | else | ||
521 | d = rsa->d; | ||
522 | if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL)) | ||
523 | goto err; | 451 | goto err; |
524 | } | 452 | } |
525 | 453 | ||
@@ -606,20 +534,33 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from, | |||
606 | } | 534 | } |
607 | 535 | ||
608 | /* do the decrypt */ | 536 | /* do the decrypt */ |
609 | 537 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) | |
610 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) | ||
611 | { | 538 | { |
612 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, | 539 | BN_MONT_CTX* bn_mont_ctx; |
613 | CRYPTO_LOCK_RSA, rsa->n, ctx)) | 540 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) |
541 | goto err; | ||
542 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) | ||
543 | { | ||
544 | BN_MONT_CTX_free(bn_mont_ctx); | ||
614 | goto err; | 545 | goto err; |
546 | } | ||
547 | if (rsa->_method_mod_n == NULL) /* other thread may have finished first */ | ||
548 | { | ||
549 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
550 | if (rsa->_method_mod_n == NULL) | ||
551 | { | ||
552 | rsa->_method_mod_n = bn_mont_ctx; | ||
553 | bn_mont_ctx = NULL; | ||
554 | } | ||
555 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
556 | } | ||
557 | if (bn_mont_ctx) | ||
558 | BN_MONT_CTX_free(bn_mont_ctx); | ||
615 | } | 559 | } |
616 | 560 | ||
617 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | 561 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, |
618 | rsa->_method_mod_n)) goto err; | 562 | rsa->_method_mod_n)) goto err; |
619 | 563 | ||
620 | if ((padding == RSA_X931_PADDING) && ((ret.d[0] & 0xf) != 12)) | ||
621 | BN_sub(&ret, rsa->n, &ret); | ||
622 | |||
623 | p=buf; | 564 | p=buf; |
624 | i=BN_bn2bin(&ret,p); | 565 | i=BN_bn2bin(&ret,p); |
625 | 566 | ||
@@ -653,8 +594,6 @@ err: | |||
653 | static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | 594 | static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) |
654 | { | 595 | { |
655 | BIGNUM r1,m1,vrfy; | 596 | BIGNUM r1,m1,vrfy; |
656 | BIGNUM local_dmp1, local_dmq1; | ||
657 | BIGNUM *dmp1, *dmq1; | ||
658 | int ret=0; | 597 | int ret=0; |
659 | BN_CTX *ctx; | 598 | BN_CTX *ctx; |
660 | 599 | ||
@@ -665,34 +604,61 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | |||
665 | 604 | ||
666 | if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) | 605 | if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) |
667 | { | 606 | { |
668 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p, | 607 | if (rsa->_method_mod_p == NULL) |
669 | CRYPTO_LOCK_RSA, rsa->p, ctx)) | 608 | { |
670 | goto err; | 609 | BN_MONT_CTX* bn_mont_ctx; |
671 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q, | 610 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) |
672 | CRYPTO_LOCK_RSA, rsa->q, ctx)) | 611 | goto err; |
673 | goto err; | 612 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->p,ctx)) |
674 | } | 613 | { |
614 | BN_MONT_CTX_free(bn_mont_ctx); | ||
615 | goto err; | ||
616 | } | ||
617 | if (rsa->_method_mod_p == NULL) /* other thread may have finished first */ | ||
618 | { | ||
619 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
620 | if (rsa->_method_mod_p == NULL) | ||
621 | { | ||
622 | rsa->_method_mod_p = bn_mont_ctx; | ||
623 | bn_mont_ctx = NULL; | ||
624 | } | ||
625 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
626 | } | ||
627 | if (bn_mont_ctx) | ||
628 | BN_MONT_CTX_free(bn_mont_ctx); | ||
629 | } | ||
675 | 630 | ||
676 | if (!BN_mod(&r1,I,rsa->q,ctx)) goto err; | 631 | if (rsa->_method_mod_q == NULL) |
677 | if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME)) | 632 | { |
678 | { | 633 | BN_MONT_CTX* bn_mont_ctx; |
679 | dmq1 = &local_dmq1; | 634 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) |
680 | BN_with_flags(dmq1, rsa->dmq1, BN_FLG_EXP_CONSTTIME); | 635 | goto err; |
636 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->q,ctx)) | ||
637 | { | ||
638 | BN_MONT_CTX_free(bn_mont_ctx); | ||
639 | goto err; | ||
640 | } | ||
641 | if (rsa->_method_mod_q == NULL) /* other thread may have finished first */ | ||
642 | { | ||
643 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
644 | if (rsa->_method_mod_q == NULL) | ||
645 | { | ||
646 | rsa->_method_mod_q = bn_mont_ctx; | ||
647 | bn_mont_ctx = NULL; | ||
648 | } | ||
649 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
650 | } | ||
651 | if (bn_mont_ctx) | ||
652 | BN_MONT_CTX_free(bn_mont_ctx); | ||
653 | } | ||
681 | } | 654 | } |
682 | else | 655 | |
683 | dmq1 = rsa->dmq1; | 656 | if (!BN_mod(&r1,I,rsa->q,ctx)) goto err; |
684 | if (!rsa->meth->bn_mod_exp(&m1,&r1,dmq1,rsa->q,ctx, | 657 | if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx, |
685 | rsa->_method_mod_q)) goto err; | 658 | rsa->_method_mod_q)) goto err; |
686 | 659 | ||
687 | if (!BN_mod(&r1,I,rsa->p,ctx)) goto err; | 660 | if (!BN_mod(&r1,I,rsa->p,ctx)) goto err; |
688 | if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME)) | 661 | if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx, |
689 | { | ||
690 | dmp1 = &local_dmp1; | ||
691 | BN_with_flags(dmp1, rsa->dmp1, BN_FLG_EXP_CONSTTIME); | ||
692 | } | ||
693 | else | ||
694 | dmp1 = rsa->dmp1; | ||
695 | if (!rsa->meth->bn_mod_exp(r0,&r1,dmp1,rsa->p,ctx, | ||
696 | rsa->_method_mod_p)) goto err; | 662 | rsa->_method_mod_p)) goto err; |
697 | 663 | ||
698 | if (!BN_sub(r0,r0,&m1)) goto err; | 664 | if (!BN_sub(r0,r0,&m1)) goto err; |
@@ -727,23 +693,10 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) | |||
727 | if (vrfy.neg) | 693 | if (vrfy.neg) |
728 | if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err; | 694 | if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err; |
729 | if (!BN_is_zero(&vrfy)) | 695 | if (!BN_is_zero(&vrfy)) |
730 | { | ||
731 | /* 'I' and 'vrfy' aren't congruent mod n. Don't leak | 696 | /* 'I' and 'vrfy' aren't congruent mod n. Don't leak |
732 | * miscalculated CRT output, just do a raw (slower) | 697 | * miscalculated CRT output, just do a raw (slower) |
733 | * mod_exp and return that instead. */ | 698 | * mod_exp and return that instead. */ |
734 | 699 | if (!rsa->meth->bn_mod_exp(r0,I,rsa->d,rsa->n,ctx,NULL)) goto err; | |
735 | BIGNUM local_d; | ||
736 | BIGNUM *d = NULL; | ||
737 | |||
738 | if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME)) | ||
739 | { | ||
740 | d = &local_d; | ||
741 | BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME); | ||
742 | } | ||
743 | else | ||
744 | d = rsa->d; | ||
745 | if (!rsa->meth->bn_mod_exp(r0,I,d,rsa->n,ctx,NULL)) goto err; | ||
746 | } | ||
747 | } | 700 | } |
748 | ret=1; | 701 | ret=1; |
749 | err: | 702 | err: |
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c index 2ec4b30ff7..a7766c3b76 100644 --- a/src/lib/libcrypto/rsa/rsa_err.c +++ b/src/lib/libcrypto/rsa/rsa_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/rsa/rsa_err.c */ | 1 | /* crypto/rsa/rsa_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999 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,85 +64,70 @@ | |||
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_RSA,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RSA,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA RSA_str_functs[]= | 67 | static ERR_STRING_DATA RSA_str_functs[]= |
72 | { | 68 | { |
73 | {ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"}, | 69 | {ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"}, |
74 | {ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"}, | 70 | {ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"}, |
75 | {ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"}, | 71 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, |
76 | {ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"}, | 72 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, |
77 | {ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"}, | 73 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, |
78 | {ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"}, | 74 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"}, |
79 | {ERR_FUNC(RSA_F_RSA_GENERATE_KEY), "RSA_generate_key"}, | 75 | {ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, |
80 | {ERR_FUNC(RSA_F_RSA_NEW_METHOD), "RSA_new_method"}, | 76 | {ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, |
81 | {ERR_FUNC(RSA_F_RSA_NULL), "RSA_NULL"}, | 77 | {ERR_PACK(0,RSA_F_RSA_NULL,0), "RSA_NULL"}, |
82 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_NONE), "RSA_padding_add_none"}, | 78 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, |
83 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP), "RSA_padding_add_PKCS1_OAEP"}, | 79 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"}, |
84 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS), "RSA_padding_add_PKCS1_PSS"}, | 80 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, |
85 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1), "RSA_padding_add_PKCS1_type_1"}, | 81 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, |
86 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2), "RSA_padding_add_PKCS1_type_2"}, | 82 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, |
87 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_SSLV23), "RSA_padding_add_SSLv23"}, | 83 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, |
88 | {ERR_FUNC(RSA_F_RSA_PADDING_ADD_X931), "RSA_padding_add_X931"}, | 84 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"}, |
89 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_NONE), "RSA_padding_check_none"}, | 85 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, |
90 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP), "RSA_padding_check_PKCS1_OAEP"}, | 86 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, |
91 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1), "RSA_padding_check_PKCS1_type_1"}, | 87 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, |
92 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2), "RSA_padding_check_PKCS1_type_2"}, | 88 | {ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"}, |
93 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_SSLV23), "RSA_padding_check_SSLv23"}, | 89 | {ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"}, |
94 | {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"}, | 90 | {ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"}, |
95 | {ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"}, | 91 | {ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, |
96 | {ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"}, | 92 | {ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, |
97 | {ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"}, | 93 | {ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, |
98 | {ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"}, | ||
99 | {ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"}, | ||
100 | {ERR_FUNC(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING), "RSA_verify_ASN1_OCTET_STRING"}, | ||
101 | {ERR_FUNC(RSA_F_RSA_VERIFY_PKCS1_PSS), "RSA_verify_PKCS1_PSS"}, | ||
102 | {0,NULL} | 94 | {0,NULL} |
103 | }; | 95 | }; |
104 | 96 | ||
105 | static ERR_STRING_DATA RSA_str_reasons[]= | 97 | static ERR_STRING_DATA RSA_str_reasons[]= |
106 | { | 98 | { |
107 | {ERR_REASON(RSA_R_ALGORITHM_MISMATCH) ,"algorithm mismatch"}, | 99 | {RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"}, |
108 | {ERR_REASON(RSA_R_BAD_E_VALUE) ,"bad e value"}, | 100 | {RSA_R_BAD_E_VALUE ,"bad e value"}, |
109 | {ERR_REASON(RSA_R_BAD_FIXED_HEADER_DECRYPT),"bad fixed header decrypt"}, | 101 | {RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, |
110 | {ERR_REASON(RSA_R_BAD_PAD_BYTE_COUNT) ,"bad pad byte count"}, | 102 | {RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, |
111 | {ERR_REASON(RSA_R_BAD_SIGNATURE) ,"bad signature"}, | 103 | {RSA_R_BAD_SIGNATURE ,"bad signature"}, |
112 | {ERR_REASON(RSA_R_BLOCK_TYPE_IS_NOT_01) ,"block type is not 01"}, | 104 | {RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, |
113 | {ERR_REASON(RSA_R_BLOCK_TYPE_IS_NOT_02) ,"block type is not 02"}, | 105 | {RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, |
114 | {ERR_REASON(RSA_R_DATA_GREATER_THAN_MOD_LEN),"data greater than mod len"}, | 106 | {RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, |
115 | {ERR_REASON(RSA_R_DATA_TOO_LARGE) ,"data too large"}, | 107 | {RSA_R_DATA_TOO_LARGE ,"data too large"}, |
116 | {ERR_REASON(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"}, | 108 | {RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, |
117 | {ERR_REASON(RSA_R_DATA_TOO_LARGE_FOR_MODULUS),"data too large for modulus"}, | 109 | {RSA_R_DATA_TOO_LARGE_FOR_MODULUS ,"data too large for modulus"}, |
118 | {ERR_REASON(RSA_R_DATA_TOO_SMALL) ,"data too small"}, | 110 | {RSA_R_DATA_TOO_SMALL ,"data too small"}, |
119 | {ERR_REASON(RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE),"data too small for key size"}, | 111 | {RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"}, |
120 | {ERR_REASON(RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY),"digest too big for rsa key"}, | 112 | {RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, |
121 | {ERR_REASON(RSA_R_DMP1_NOT_CONGRUENT_TO_D),"dmp1 not congruent to d"}, | 113 | {RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"}, |
122 | {ERR_REASON(RSA_R_DMQ1_NOT_CONGRUENT_TO_D),"dmq1 not congruent to d"}, | 114 | {RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"}, |
123 | {ERR_REASON(RSA_R_D_E_NOT_CONGRUENT_TO_1),"d e not congruent to 1"}, | 115 | {RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"}, |
124 | {ERR_REASON(RSA_R_FIRST_OCTET_INVALID) ,"first octet invalid"}, | 116 | {RSA_R_INVALID_MESSAGE_LENGTH ,"invalid message length"}, |
125 | {ERR_REASON(RSA_R_INVALID_HEADER) ,"invalid header"}, | 117 | {RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"}, |
126 | {ERR_REASON(RSA_R_INVALID_MESSAGE_LENGTH),"invalid message length"}, | 118 | {RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"}, |
127 | {ERR_REASON(RSA_R_INVALID_PADDING) ,"invalid padding"}, | 119 | {RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, |
128 | {ERR_REASON(RSA_R_INVALID_TRAILER) ,"invalid trailer"}, | 120 | {RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"}, |
129 | {ERR_REASON(RSA_R_IQMP_NOT_INVERSE_OF_Q) ,"iqmp not inverse of q"}, | 121 | {RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"}, |
130 | {ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"}, | 122 | {RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, |
131 | {ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"}, | 123 | {RSA_R_P_NOT_PRIME ,"p not prime"}, |
132 | {ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"}, | 124 | {RSA_R_Q_NOT_PRIME ,"q not prime"}, |
133 | {ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"}, | 125 | {RSA_R_RSA_OPERATIONS_NOT_SUPPORTED ,"rsa operations not supported"}, |
134 | {ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"}, | 126 | {RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, |
135 | {ERR_REASON(RSA_R_SLEN_RECOVERY_FAILED) ,"salt length recovery failed"}, | 127 | {RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, |
136 | {ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"}, | 128 | {RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, |
137 | {ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"}, | 129 | {RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, |
138 | {ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"}, | 130 | {RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, |
139 | {ERR_REASON(RSA_R_RSA_OPERATIONS_NOT_SUPPORTED),"rsa operations not supported"}, | ||
140 | {ERR_REASON(RSA_R_SSLV3_ROLLBACK_ATTACK) ,"sslv3 rollback attack"}, | ||
141 | {ERR_REASON(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"}, | ||
142 | {ERR_REASON(RSA_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"}, | ||
143 | {ERR_REASON(RSA_R_UNKNOWN_PADDING_TYPE) ,"unknown padding type"}, | ||
144 | {ERR_REASON(RSA_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"}, | ||
145 | {ERR_REASON(RSA_R_SLEN_CHECK_FAILED) ,"salt length check failed"}, | ||
146 | {0,NULL} | 131 | {0,NULL} |
147 | }; | 132 | }; |
148 | 133 | ||
@@ -156,8 +141,8 @@ void ERR_load_RSA_strings(void) | |||
156 | { | 141 | { |
157 | init=0; | 142 | init=0; |
158 | #ifndef OPENSSL_NO_ERR | 143 | #ifndef OPENSSL_NO_ERR |
159 | ERR_load_strings(0,RSA_str_functs); | 144 | ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); |
160 | ERR_load_strings(0,RSA_str_reasons); | 145 | ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons); |
161 | #endif | 146 | #endif |
162 | 147 | ||
163 | } | 148 | } |
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c index dd1422cc98..adb5e34da5 100644 --- a/src/lib/libcrypto/rsa/rsa_gen.c +++ b/src/lib/libcrypto/rsa/rsa_gen.c | |||
@@ -184,8 +184,7 @@ err: | |||
184 | RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); | 184 | RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); |
185 | ok=0; | 185 | ok=0; |
186 | } | 186 | } |
187 | if (ctx != NULL) | 187 | BN_CTX_end(ctx); |
188 | BN_CTX_end(ctx); | ||
189 | BN_CTX_free(ctx); | 188 | BN_CTX_free(ctx); |
190 | BN_CTX_free(ctx2); | 189 | BN_CTX_free(ctx2); |
191 | 190 | ||
diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c new file mode 100644 index 0000000000..64057fbdcf --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_null.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /* rsa_null.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | /* This is a dummy RSA implementation that just returns errors when called. | ||
66 | * It is designed to allow some RSA functions to work while stopping those | ||
67 | * covered by the RSA patent. That is RSA, encryption, decryption, signing | ||
68 | * and verify is not allowed but RSA key generation, key checking and other | ||
69 | * operations (like storing RSA keys) are permitted. | ||
70 | */ | ||
71 | |||
72 | static int RSA_null_public_encrypt(int flen, const unsigned char *from, | ||
73 | unsigned char *to, RSA *rsa,int padding); | ||
74 | static int RSA_null_private_encrypt(int flen, const unsigned char *from, | ||
75 | unsigned char *to, RSA *rsa,int padding); | ||
76 | static int RSA_null_public_decrypt(int flen, const unsigned char *from, | ||
77 | unsigned char *to, RSA *rsa,int padding); | ||
78 | static int RSA_null_private_decrypt(int flen, const unsigned char *from, | ||
79 | unsigned char *to, RSA *rsa,int padding); | ||
80 | #if 0 /* not currently used */ | ||
81 | static int RSA_null_mod_exp(const BIGNUM *r0, const BIGNUM *i, RSA *rsa); | ||
82 | #endif | ||
83 | static int RSA_null_init(RSA *rsa); | ||
84 | static int RSA_null_finish(RSA *rsa); | ||
85 | static RSA_METHOD rsa_null_meth={ | ||
86 | "Null RSA", | ||
87 | RSA_null_public_encrypt, | ||
88 | RSA_null_public_decrypt, | ||
89 | RSA_null_private_encrypt, | ||
90 | RSA_null_private_decrypt, | ||
91 | NULL, | ||
92 | NULL, | ||
93 | RSA_null_init, | ||
94 | RSA_null_finish, | ||
95 | 0, | ||
96 | NULL, | ||
97 | }; | ||
98 | |||
99 | const RSA_METHOD *RSA_null_method(void) | ||
100 | { | ||
101 | return(&rsa_null_meth); | ||
102 | } | ||
103 | |||
104 | static int RSA_null_public_encrypt(int flen, const unsigned char *from, | ||
105 | unsigned char *to, RSA *rsa, int padding) | ||
106 | { | ||
107 | RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); | ||
108 | return -1; | ||
109 | } | ||
110 | |||
111 | static int RSA_null_private_encrypt(int flen, const unsigned char *from, | ||
112 | unsigned char *to, RSA *rsa, int padding) | ||
113 | { | ||
114 | RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); | ||
115 | return -1; | ||
116 | } | ||
117 | |||
118 | static int RSA_null_private_decrypt(int flen, const unsigned char *from, | ||
119 | unsigned char *to, RSA *rsa, int padding) | ||
120 | { | ||
121 | RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); | ||
122 | return -1; | ||
123 | } | ||
124 | |||
125 | static int RSA_null_public_decrypt(int flen, const unsigned char *from, | ||
126 | unsigned char *to, RSA *rsa, int padding) | ||
127 | { | ||
128 | RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); | ||
129 | return -1; | ||
130 | } | ||
131 | |||
132 | #if 0 /* not currently used */ | ||
133 | static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) | ||
134 | { | ||
135 | RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); | ||
136 | return -1; | ||
137 | } | ||
138 | #endif | ||
139 | |||
140 | static int RSA_null_init(RSA *rsa) | ||
141 | { | ||
142 | return(1); | ||
143 | } | ||
144 | |||
145 | static int RSA_null_finish(RSA *rsa) | ||
146 | { | ||
147 | return(1); | ||
148 | } | ||
149 | |||
150 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c index d43ecaca63..e3f7c608ec 100644 --- a/src/lib/libcrypto/rsa/rsa_oaep.c +++ b/src/lib/libcrypto/rsa/rsa_oaep.c | |||
@@ -28,6 +28,9 @@ | |||
28 | #include <openssl/rand.h> | 28 | #include <openssl/rand.h> |
29 | #include <openssl/sha.h> | 29 | #include <openssl/sha.h> |
30 | 30 | ||
31 | int MGF1(unsigned char *mask, long len, | ||
32 | const unsigned char *seed, long seedlen); | ||
33 | |||
31 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | 34 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, |
32 | const unsigned char *from, int flen, | 35 | const unsigned char *from, int flen, |
33 | const unsigned char *param, int plen) | 36 | const unsigned char *param, int plen) |
@@ -73,13 +76,11 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | |||
73 | 20); | 76 | 20); |
74 | #endif | 77 | #endif |
75 | 78 | ||
76 | PKCS1_MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH, | 79 | MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); |
77 | EVP_sha1()); | ||
78 | for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) | 80 | for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) |
79 | db[i] ^= dbmask[i]; | 81 | db[i] ^= dbmask[i]; |
80 | 82 | ||
81 | PKCS1_MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH, | 83 | MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); |
82 | EVP_sha1()); | ||
83 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) | 84 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) |
84 | seed[i] ^= seedmask[i]; | 85 | seed[i] ^= seedmask[i]; |
85 | 86 | ||
@@ -125,11 +126,11 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, | |||
125 | return -1; | 126 | return -1; |
126 | } | 127 | } |
127 | 128 | ||
128 | PKCS1_MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen, EVP_sha1()); | 129 | MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen); |
129 | for (i = lzero; i < SHA_DIGEST_LENGTH; i++) | 130 | for (i = lzero; i < SHA_DIGEST_LENGTH; i++) |
130 | seed[i] ^= from[i - lzero]; | 131 | seed[i] ^= from[i - lzero]; |
131 | 132 | ||
132 | PKCS1_MGF1(db, dblen, seed, SHA_DIGEST_LENGTH, EVP_sha1()); | 133 | MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); |
133 | for (i = 0; i < dblen; i++) | 134 | for (i = 0; i < dblen; i++) |
134 | db[i] ^= maskeddb[i]; | 135 | db[i] ^= maskeddb[i]; |
135 | 136 | ||
@@ -169,30 +170,28 @@ decoding_err: | |||
169 | return -1; | 170 | return -1; |
170 | } | 171 | } |
171 | 172 | ||
172 | int PKCS1_MGF1(unsigned char *mask, long len, | 173 | int MGF1(unsigned char *mask, long len, |
173 | const unsigned char *seed, long seedlen, const EVP_MD *dgst) | 174 | const unsigned char *seed, long seedlen) |
174 | { | 175 | { |
175 | long i, outlen = 0; | 176 | long i, outlen = 0; |
176 | unsigned char cnt[4]; | 177 | unsigned char cnt[4]; |
177 | EVP_MD_CTX c; | 178 | EVP_MD_CTX c; |
178 | unsigned char md[EVP_MAX_MD_SIZE]; | 179 | unsigned char md[SHA_DIGEST_LENGTH]; |
179 | int mdlen; | ||
180 | 180 | ||
181 | EVP_MD_CTX_init(&c); | 181 | EVP_MD_CTX_init(&c); |
182 | mdlen = EVP_MD_size(dgst); | ||
183 | for (i = 0; outlen < len; i++) | 182 | for (i = 0; outlen < len; i++) |
184 | { | 183 | { |
185 | cnt[0] = (unsigned char)((i >> 24) & 255); | 184 | cnt[0] = (unsigned char)((i >> 24) & 255); |
186 | cnt[1] = (unsigned char)((i >> 16) & 255); | 185 | cnt[1] = (unsigned char)((i >> 16) & 255); |
187 | cnt[2] = (unsigned char)((i >> 8)) & 255; | 186 | cnt[2] = (unsigned char)((i >> 8)) & 255; |
188 | cnt[3] = (unsigned char)(i & 255); | 187 | cnt[3] = (unsigned char)(i & 255); |
189 | EVP_DigestInit_ex(&c,dgst, NULL); | 188 | EVP_DigestInit_ex(&c,EVP_sha1(), NULL); |
190 | EVP_DigestUpdate(&c, seed, seedlen); | 189 | EVP_DigestUpdate(&c, seed, seedlen); |
191 | EVP_DigestUpdate(&c, cnt, 4); | 190 | EVP_DigestUpdate(&c, cnt, 4); |
192 | if (outlen + mdlen <= len) | 191 | if (outlen + SHA_DIGEST_LENGTH <= len) |
193 | { | 192 | { |
194 | EVP_DigestFinal_ex(&c, mask + outlen, NULL); | 193 | EVP_DigestFinal_ex(&c, mask + outlen, NULL); |
195 | outlen += mdlen; | 194 | outlen += SHA_DIGEST_LENGTH; |
196 | } | 195 | } |
197 | else | 196 | else |
198 | { | 197 | { |
@@ -204,9 +203,4 @@ int PKCS1_MGF1(unsigned char *mask, long len, | |||
204 | EVP_MD_CTX_cleanup(&c); | 203 | EVP_MD_CTX_cleanup(&c); |
205 | return 0; | 204 | return 0; |
206 | } | 205 | } |
207 | |||
208 | int MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen) | ||
209 | { | ||
210 | return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1()); | ||
211 | } | ||
212 | #endif | 206 | #endif |
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c new file mode 100644 index 0000000000..924e9ad1f6 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_test.c | |||
@@ -0,0 +1,317 @@ | |||
1 | /* test vectors from p1ovect1.txt */ | ||
2 | |||
3 | #include <stdio.h> | ||
4 | #include <string.h> | ||
5 | |||
6 | #include "e_os.h" | ||
7 | |||
8 | #include <openssl/crypto.h> | ||
9 | #include <openssl/err.h> | ||
10 | #include <openssl/rand.h> | ||
11 | #ifdef OPENSSL_NO_RSA | ||
12 | int main(int argc, char *argv[]) | ||
13 | { | ||
14 | printf("No RSA support\n"); | ||
15 | return(0); | ||
16 | } | ||
17 | #else | ||
18 | #include <openssl/rsa.h> | ||
19 | |||
20 | #define SetKey \ | ||
21 | key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \ | ||
22 | key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \ | ||
23 | key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \ | ||
24 | key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \ | ||
25 | key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \ | ||
26 | key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \ | ||
27 | key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \ | ||
28 | key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \ | ||
29 | memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \ | ||
30 | return (sizeof(ctext_ex) - 1); | ||
31 | |||
32 | static int key1(RSA *key, unsigned char *c) | ||
33 | { | ||
34 | static unsigned char n[] = | ||
35 | "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" | ||
36 | "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" | ||
37 | "\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93" | ||
38 | "\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1" | ||
39 | "\xF5"; | ||
40 | |||
41 | static unsigned char e[] = "\x11"; | ||
42 | |||
43 | static unsigned char d[] = | ||
44 | "\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44" | ||
45 | "\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64" | ||
46 | "\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9" | ||
47 | "\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51"; | ||
48 | |||
49 | static unsigned char p[] = | ||
50 | "\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
51 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12" | ||
52 | "\x0D"; | ||
53 | |||
54 | static unsigned char q[] = | ||
55 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
56 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
57 | "\x89"; | ||
58 | |||
59 | static unsigned char dmp1[] = | ||
60 | "\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF" | ||
61 | "\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05"; | ||
62 | |||
63 | static unsigned char dmq1[] = | ||
64 | "\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99" | ||
65 | "\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D" | ||
66 | "\x51"; | ||
67 | |||
68 | static unsigned char iqmp[] = | ||
69 | "\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8" | ||
70 | "\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26"; | ||
71 | |||
72 | static unsigned char ctext_ex[] = | ||
73 | "\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89" | ||
74 | "\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52" | ||
75 | "\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44" | ||
76 | "\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2"; | ||
77 | |||
78 | SetKey; | ||
79 | } | ||
80 | |||
81 | static int key2(RSA *key, unsigned char *c) | ||
82 | { | ||
83 | static unsigned char n[] = | ||
84 | "\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8" | ||
85 | "\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26" | ||
86 | "\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8" | ||
87 | "\x34\x77\xCF"; | ||
88 | |||
89 | static unsigned char e[] = "\x3"; | ||
90 | |||
91 | static unsigned char d[] = | ||
92 | "\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2" | ||
93 | "\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41" | ||
94 | "\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21" | ||
95 | "\xE5\xEB"; | ||
96 | |||
97 | static unsigned char p[] = | ||
98 | "\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92" | ||
99 | "\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91"; | ||
100 | |||
101 | static unsigned char q[] = | ||
102 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
103 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F"; | ||
104 | |||
105 | static unsigned char dmp1[] = | ||
106 | "\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61" | ||
107 | "\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B"; | ||
108 | |||
109 | static unsigned char dmq1[] = | ||
110 | "\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90" | ||
111 | "\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F"; | ||
112 | |||
113 | static unsigned char iqmp[] = | ||
114 | "\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13" | ||
115 | "\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D"; | ||
116 | |||
117 | static unsigned char ctext_ex[] = | ||
118 | "\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a" | ||
119 | "\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4" | ||
120 | "\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52" | ||
121 | "\x62\x51"; | ||
122 | |||
123 | SetKey; | ||
124 | } | ||
125 | |||
126 | static int key3(RSA *key, unsigned char *c) | ||
127 | { | ||
128 | static unsigned char n[] = | ||
129 | "\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" | ||
130 | "\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" | ||
131 | "\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD" | ||
132 | "\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80" | ||
133 | "\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25" | ||
134 | "\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39" | ||
135 | "\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68" | ||
136 | "\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD" | ||
137 | "\xCB"; | ||
138 | |||
139 | static unsigned char e[] = "\x11"; | ||
140 | |||
141 | static unsigned char d[] = | ||
142 | "\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD" | ||
143 | "\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41" | ||
144 | "\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69" | ||
145 | "\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA" | ||
146 | "\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94" | ||
147 | "\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A" | ||
148 | "\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94" | ||
149 | "\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3" | ||
150 | "\xC1"; | ||
151 | |||
152 | static unsigned char p[] = | ||
153 | "\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60" | ||
154 | "\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6" | ||
155 | "\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A" | ||
156 | "\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65" | ||
157 | "\x99"; | ||
158 | |||
159 | static unsigned char q[] = | ||
160 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
161 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
162 | "\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
163 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15" | ||
164 | "\x03"; | ||
165 | |||
166 | static unsigned char dmp1[] = | ||
167 | "\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A" | ||
168 | "\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E" | ||
169 | "\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E" | ||
170 | "\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81"; | ||
171 | |||
172 | static unsigned char dmq1[] = | ||
173 | "\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9" | ||
174 | "\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7" | ||
175 | "\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D" | ||
176 | "\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D"; | ||
177 | |||
178 | static unsigned char iqmp[] = | ||
179 | "\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23" | ||
180 | "\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11" | ||
181 | "\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E" | ||
182 | "\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39" | ||
183 | "\xF7"; | ||
184 | |||
185 | static unsigned char ctext_ex[] = | ||
186 | "\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7" | ||
187 | "\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce" | ||
188 | "\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3" | ||
189 | "\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06" | ||
190 | "\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86" | ||
191 | "\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4" | ||
192 | "\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a" | ||
193 | "\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1"; | ||
194 | |||
195 | SetKey; | ||
196 | } | ||
197 | |||
198 | static int pad_unknown(void) | ||
199 | { | ||
200 | unsigned long l; | ||
201 | while ((l = ERR_get_error()) != 0) | ||
202 | if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE) | ||
203 | return(1); | ||
204 | return(0); | ||
205 | } | ||
206 | |||
207 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
208 | |||
209 | int main(int argc, char *argv[]) | ||
210 | { | ||
211 | int err=0; | ||
212 | int v; | ||
213 | RSA *key; | ||
214 | unsigned char ptext[256]; | ||
215 | unsigned char ctext[256]; | ||
216 | static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a"; | ||
217 | unsigned char ctext_ex[256]; | ||
218 | int plen; | ||
219 | int clen = 0; | ||
220 | int num; | ||
221 | |||
222 | CRYPTO_malloc_debug_init(); | ||
223 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
224 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
225 | |||
226 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */ | ||
227 | |||
228 | plen = sizeof(ptext_ex) - 1; | ||
229 | |||
230 | for (v = 0; v < 3; v++) | ||
231 | { | ||
232 | key = RSA_new(); | ||
233 | switch (v) { | ||
234 | case 0: | ||
235 | clen = key1(key, ctext_ex); | ||
236 | break; | ||
237 | case 1: | ||
238 | clen = key2(key, ctext_ex); | ||
239 | break; | ||
240 | case 2: | ||
241 | clen = key3(key, ctext_ex); | ||
242 | break; | ||
243 | } | ||
244 | |||
245 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
246 | RSA_PKCS1_PADDING); | ||
247 | if (num != clen) | ||
248 | { | ||
249 | printf("PKCS#1 v1.5 encryption failed!\n"); | ||
250 | err=1; | ||
251 | goto oaep; | ||
252 | } | ||
253 | |||
254 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
255 | RSA_PKCS1_PADDING); | ||
256 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
257 | { | ||
258 | printf("PKCS#1 v1.5 decryption failed!\n"); | ||
259 | err=1; | ||
260 | } | ||
261 | else | ||
262 | printf("PKCS #1 v1.5 encryption/decryption ok\n"); | ||
263 | |||
264 | oaep: | ||
265 | ERR_clear_error(); | ||
266 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
267 | RSA_PKCS1_OAEP_PADDING); | ||
268 | if (num == -1 && pad_unknown()) | ||
269 | { | ||
270 | printf("No OAEP support\n"); | ||
271 | goto next; | ||
272 | } | ||
273 | if (num != clen) | ||
274 | { | ||
275 | printf("OAEP encryption failed!\n"); | ||
276 | err=1; | ||
277 | goto next; | ||
278 | } | ||
279 | |||
280 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
281 | RSA_PKCS1_OAEP_PADDING); | ||
282 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
283 | { | ||
284 | printf("OAEP decryption (encrypted data) failed!\n"); | ||
285 | err=1; | ||
286 | } | ||
287 | else if (memcmp(ctext, ctext_ex, num) == 0) | ||
288 | { | ||
289 | printf("OAEP test vector %d passed!\n", v); | ||
290 | goto next; | ||
291 | } | ||
292 | |||
293 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). | ||
294 | Try decrypting ctext_ex */ | ||
295 | |||
296 | num = RSA_private_decrypt(clen, ctext_ex, ptext, key, | ||
297 | RSA_PKCS1_OAEP_PADDING); | ||
298 | |||
299 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
300 | { | ||
301 | printf("OAEP decryption (test vector data) failed!\n"); | ||
302 | err=1; | ||
303 | } | ||
304 | else | ||
305 | printf("OAEP encryption/decryption ok\n"); | ||
306 | next: | ||
307 | RSA_free(key); | ||
308 | } | ||
309 | |||
310 | CRYPTO_cleanup_all_ex_data(); | ||
311 | ERR_remove_state(0); | ||
312 | |||
313 | CRYPTO_mem_leaks_fp(stderr); | ||
314 | |||
315 | return err; | ||
316 | } | ||
317 | #endif | ||