summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rsa')
-rw-r--r--src/lib/libcrypto/rsa/Makefile244
-rw-r--r--src/lib/libcrypto/rsa/Makefile.ssl241
-rw-r--r--src/lib/libcrypto/rsa/rsa.h39
-rw-r--r--src/lib/libcrypto/rsa/rsa_asn1.c2
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c24
-rw-r--r--src/lib/libcrypto/rsa/rsa_eng.c348
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c10
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c3
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c272
-rw-r--r--src/lib/libcrypto/rsa/rsa_null.c151
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c2
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c24
-rw-r--r--src/lib/libcrypto/rsa/rsa_test.c340
-rw-r--r--src/lib/libcrypto/rsa/rsa_x931g.c255
14 files changed, 1863 insertions, 92 deletions
diff --git a/src/lib/libcrypto/rsa/Makefile b/src/lib/libcrypto/rsa/Makefile
new file mode 100644
index 0000000000..8f1c611800
--- /dev/null
+++ b/src/lib/libcrypto/rsa/Makefile
@@ -0,0 +1,244 @@
1#
2# OpenSSL/crypto/rsa/Makefile
3#
4
5DIR= rsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=rsa_test.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
21 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \
22 rsa_pss.c rsa_x931.c rsa_asn1.c rsa_depr.c
23LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
24 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \
25 rsa_pss.o rsa_x931.o rsa_asn1.o rsa_depr.o
26
27SRC= $(LIBSRC)
28
29EXHEADER= rsa.h
30HEADER= $(EXHEADER)
31
32ALL= $(GENERAL) $(SRC) $(HEADER)
33
34top:
35 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
36
37all: lib
38
39lib: $(LIBOBJ)
40 $(AR) $(LIB) $(LIBOBJ)
41 $(RANLIB) $(LIB) || echo Never mind.
42 @touch lib
43
44files:
45 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
46
47links:
48 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51
52install:
53 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
54 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
55 do \
56 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done;
59
60tags:
61 ctags $(SRC)
62
63tests:
64
65lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff
67
68depend:
69 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
70 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
71
72dclean:
73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
74 mv -f Makefile.new $(MAKEFILE)
75
76clean:
77 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
78
79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
82rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
83rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
84rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
85rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
86rsa_asn1.o: ../../include/openssl/opensslconf.h
87rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
88rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
89rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
90rsa_asn1.o: ../cryptlib.h rsa_asn1.c
91rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
92rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
93rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
95rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
97rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98rsa_chk.o: rsa_chk.c
99rsa_depr.o: ../../e_os.h ../../include/openssl/asn1.h
100rsa_depr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101rsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102rsa_depr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
103rsa_depr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
104rsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105rsa_depr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
106rsa_depr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
107rsa_depr.o: ../cryptlib.h rsa_depr.c
108rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h
109rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
110rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
111rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
112rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
113rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
115rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c
117rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
118rsa_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
119rsa_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
120rsa_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
121rsa_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
122rsa_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123rsa_err.o: ../../include/openssl/symhacks.h rsa_err.c
124rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h
125rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
126rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
127rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
128rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
129rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
132rsa_gen.o: ../cryptlib.h rsa_gen.c
133rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
134rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
135rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
136rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
137rsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
138rsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
139rsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
140rsa_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
141rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
142rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
143rsa_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
144rsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
145rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
146rsa_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
147rsa_lib.o: ../cryptlib.h rsa_lib.c
148rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h
149rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
150rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
151rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
152rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
153rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
154rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
155rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
156rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c
157rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h
158rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
159rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
160rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
161rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
162rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
163rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
164rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
165rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c
166rsa_oaep.o: ../../e_os.h ../../include/openssl/asn1.h
167rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
168rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
169rsa_oaep.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
170rsa_oaep.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
171rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
172rsa_oaep.o: ../../include/openssl/opensslconf.h
173rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
174rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
175rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
176rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
177rsa_oaep.o: ../cryptlib.h rsa_oaep.c
178rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h
179rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
180rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
181rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
182rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
183rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
184rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
185rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
186rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c
187rsa_pss.o: ../../e_os.h ../../include/openssl/asn1.h
188rsa_pss.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
189rsa_pss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
190rsa_pss.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
191rsa_pss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
192rsa_pss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
193rsa_pss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
194rsa_pss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
195rsa_pss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
196rsa_pss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
197rsa_pss.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pss.c
198rsa_saos.o: ../../e_os.h ../../include/openssl/asn1.h
199rsa_saos.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
200rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
201rsa_saos.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
202rsa_saos.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
203rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
204rsa_saos.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
205rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
206rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
207rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
208rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
209rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
210rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
211rsa_saos.o: ../cryptlib.h rsa_saos.c
212rsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
213rsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
214rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
215rsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
216rsa_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
217rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
218rsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
219rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
220rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
221rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
222rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
223rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
224rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
225rsa_sign.o: ../cryptlib.h rsa_sign.c
226rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h
227rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
228rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
229rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
230rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
231rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
232rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
233rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
234rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_ssl.c
235rsa_x931.o: ../../e_os.h ../../include/openssl/asn1.h
236rsa_x931.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
237rsa_x931.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
238rsa_x931.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
239rsa_x931.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
240rsa_x931.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
241rsa_x931.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
242rsa_x931.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
243rsa_x931.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
244rsa_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
5DIR= rsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=rsa_test.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= 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
29LIBOBJ= 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
33SRC= $(LIBSRC)
34
35EXHEADER= rsa.h
36HEADER= $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
52
53links:
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
59install:
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
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
76
77dclean:
78 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
79 mv -f Makefile.new $(MAKEFILE)
80
81clean:
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
86rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
87rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
88rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
89rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
90rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
91rsa_asn1.o: ../../include/openssl/opensslconf.h
92rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
94rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
95rsa_asn1.o: ../cryptlib.h rsa_asn1.c
96rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
97rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
98rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
99rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
100rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
102rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
103rsa_chk.o: rsa_chk.c
104rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h
105rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
106rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
107rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
110rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
111rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
112rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c
113rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
114rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
115rsa_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
116rsa_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
117rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
118rsa_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119rsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
120rsa_err.o: rsa_err.c
121rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h
122rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
123rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
124rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
125rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
126rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
127rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
128rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
129rsa_gen.o: ../cryptlib.h rsa_gen.c
130rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
131rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
132rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
133rsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
134rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
135rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
136rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
137rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
138rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
139rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
140rsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h rsa_lib.c
141rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h
142rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
143rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
144rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
145rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
146rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
147rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
148rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
149rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c
150rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h
151rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
152rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
153rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
154rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
155rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
156rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
157rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c
159rsa_oaep.o: ../../e_os.h ../../include/openssl/aes.h
160rsa_oaep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
161rsa_oaep.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
162rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
163rsa_oaep.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
164rsa_oaep.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
165rsa_oaep.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
166rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/evp.h
167rsa_oaep.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
168rsa_oaep.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
169rsa_oaep.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
170rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
171rsa_oaep.o: ../../include/openssl/opensslconf.h
172rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
173rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
174rsa_oaep.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
175rsa_oaep.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
176rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
177rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
178rsa_oaep.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
179rsa_oaep.o: ../cryptlib.h rsa_oaep.c
180rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h
181rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
182rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
183rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
184rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
185rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
186rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
187rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
188rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c
189rsa_saos.o: ../../e_os.h ../../include/openssl/aes.h
190rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
191rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
192rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
193rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
194rsa_saos.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
195rsa_saos.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
196rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
197rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
198rsa_saos.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
199rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
200rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
201rsa_saos.o: ../../include/openssl/opensslconf.h
202rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
203rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
204rsa_saos.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
205rsa_saos.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
206rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
207rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
208rsa_saos.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
209rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
210rsa_saos.o: ../cryptlib.h rsa_saos.c
211rsa_sign.o: ../../e_os.h ../../include/openssl/aes.h
212rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
213rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
214rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
215rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
216rsa_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
217rsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
218rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
219rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
220rsa_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
221rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
222rsa_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
223rsa_sign.o: ../../include/openssl/opensslconf.h
224rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
225rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
226rsa_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
227rsa_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
228rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
229rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
230rsa_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
231rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
232rsa_sign.o: ../cryptlib.h rsa_sign.c
233rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h
234rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
235rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
236rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
237rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
238rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
239rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
240rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
241rsa_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 5bb932ae15..3699afaaaf 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -74,25 +74,6 @@
74#error RSA is disabled. 74#error RSA is disabled.
75#endif 75#endif
76 76
77/* If this flag is set the RSA method is FIPS compliant and can be used
78 * in FIPS mode. This is set in the validated module method. If an
79 * application sets this flag in its own methods it is its reposibility
80 * to ensure the result is compliant.
81 */
82
83#define RSA_FLAG_FIPS_METHOD 0x0400
84
85/* If this flag is set the operations normally disabled in FIPS mode are
86 * permitted it is then the applications responsibility to ensure that the
87 * usage is compliant.
88 */
89
90#define RSA_FLAG_NON_FIPS_ALLOW 0x0400
91
92#ifdef OPENSSL_FIPS
93#define FIPS_RSA_SIZE_T int
94#endif
95
96#ifdef __cplusplus 77#ifdef __cplusplus
97extern "C" { 78extern "C" {
98#endif 79#endif
@@ -182,8 +163,6 @@ struct rsa_st
182# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 163# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
183#endif 164#endif
184 165
185#define OPENSSL_RSA_FIPS_MIN_MODULUS_BITS 1024
186
187#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS 166#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
188# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 167# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
189#endif 168#endif
@@ -261,11 +240,6 @@ RSA * RSA_generate_key(int bits, unsigned long e,void
261 240
262/* New version */ 241/* New version */
263int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb); 242int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
264int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
265 const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
266 const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
267 const BIGNUM *e, BN_GENCB *cb);
268int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb);
269 243
270int RSA_check_key(const RSA *); 244int RSA_check_key(const RSA *);
271 /* next 4 return -1 on error */ 245 /* next 4 return -1 on error */
@@ -283,11 +257,6 @@ int RSA_up_ref(RSA *r);
283 257
284int RSA_flags(const RSA *r); 258int RSA_flags(const RSA *r);
285 259
286#ifdef OPENSSL_FIPS
287RSA *FIPS_rsa_new(void);
288void FIPS_rsa_free(RSA *r);
289#endif
290
291void RSA_set_default_method(const RSA_METHOD *meth); 260void RSA_set_default_method(const RSA_METHOD *meth);
292const RSA_METHOD *RSA_get_default_method(void); 261const RSA_METHOD *RSA_get_default_method(void);
293const RSA_METHOD *RSA_get_method(const RSA *rsa); 262const RSA_METHOD *RSA_get_method(const RSA *rsa);
@@ -401,8 +370,6 @@ void ERR_load_RSA_strings(void);
401/* Error codes for the RSA functions. */ 370/* Error codes for the RSA functions. */
402 371
403/* Function codes. */ 372/* Function codes. */
404#define RSA_F_FIPS_RSA_SIGN 140
405#define RSA_F_FIPS_RSA_VERIFY 141
406#define RSA_F_MEMORY_LOCK 100 373#define RSA_F_MEMORY_LOCK 100
407#define RSA_F_RSA_BUILTIN_KEYGEN 129 374#define RSA_F_RSA_BUILTIN_KEYGEN 129
408#define RSA_F_RSA_CHECK_KEY 123 375#define RSA_F_RSA_CHECK_KEY 123
@@ -434,11 +401,7 @@ void ERR_load_RSA_strings(void);
434#define RSA_F_RSA_PADDING_CHECK_X931 128 401#define RSA_F_RSA_PADDING_CHECK_X931 128
435#define RSA_F_RSA_PRINT 115 402#define RSA_F_RSA_PRINT 115
436#define RSA_F_RSA_PRINT_FP 116 403#define RSA_F_RSA_PRINT_FP 116
437#define RSA_F_RSA_PRIVATE_ENCRYPT 137
438#define RSA_F_RSA_PUBLIC_DECRYPT 138
439#define RSA_F_RSA_SETUP_BLINDING 136 404#define RSA_F_RSA_SETUP_BLINDING 136
440#define RSA_F_RSA_SET_DEFAULT_METHOD 139
441#define RSA_F_RSA_SET_METHOD 142
442#define RSA_F_RSA_SIGN 117 405#define RSA_F_RSA_SIGN 117
443#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 406#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
444#define RSA_F_RSA_VERIFY 119 407#define RSA_F_RSA_VERIFY 119
@@ -472,12 +435,10 @@ void ERR_load_RSA_strings(void);
472#define RSA_R_KEY_SIZE_TOO_SMALL 120 435#define RSA_R_KEY_SIZE_TOO_SMALL 120
473#define RSA_R_LAST_OCTET_INVALID 134 436#define RSA_R_LAST_OCTET_INVALID 134
474#define RSA_R_MODULUS_TOO_LARGE 105 437#define RSA_R_MODULUS_TOO_LARGE 105
475#define RSA_R_NON_FIPS_METHOD 141
476#define RSA_R_NO_PUBLIC_EXPONENT 140 438#define RSA_R_NO_PUBLIC_EXPONENT 140
477#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 439#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
478#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 440#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
479#define RSA_R_OAEP_DECODING_ERROR 121 441#define RSA_R_OAEP_DECODING_ERROR 121
480#define RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE 142
481#define RSA_R_PADDING_CHECK_FAILED 114 442#define RSA_R_PADDING_CHECK_FAILED 114
482#define RSA_R_P_NOT_PRIME 128 443#define RSA_R_P_NOT_PRIME 128
483#define RSA_R_Q_NOT_PRIME 129 444#define RSA_R_Q_NOT_PRIME 129
diff --git a/src/lib/libcrypto/rsa/rsa_asn1.c b/src/lib/libcrypto/rsa/rsa_asn1.c
index 6e8a803e81..bbbf26d50e 100644
--- a/src/lib/libcrypto/rsa/rsa_asn1.c
+++ b/src/lib/libcrypto/rsa/rsa_asn1.c
@@ -1,5 +1,5 @@
1/* rsa_asn1.c */ 1/* rsa_asn1.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 0ac6418449..5a6eda7961 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -115,7 +115,7 @@
115#include <openssl/rsa.h> 115#include <openssl/rsa.h>
116#include <openssl/rand.h> 116#include <openssl/rand.h>
117 117
118#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS) 118#ifndef RSA_NULL
119 119
120static int RSA_eay_public_encrypt(int flen, const unsigned char *from, 120static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
121 unsigned char *to, RSA *rsa,int padding); 121 unsigned char *to, RSA *rsa,int padding);
@@ -353,6 +353,28 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
353 int local_blinding = 0; 353 int local_blinding = 0;
354 BN_BLINDING *blinding = NULL; 354 BN_BLINDING *blinding = NULL;
355 355
356 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
357 {
358 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
359 return -1;
360 }
361
362 if (BN_ucmp(rsa->n, rsa->e) <= 0)
363 {
364 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
365 return -1;
366 }
367
368 /* for large moduli, enforce exponent limit */
369 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
370 {
371 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
372 {
373 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
374 return -1;
375 }
376 }
377
356 if ((ctx=BN_CTX_new()) == NULL) goto err; 378 if ((ctx=BN_CTX_new()) == NULL) goto err;
357 BN_CTX_start(ctx); 379 BN_CTX_start(ctx);
358 f = BN_CTX_get(ctx); 380 f = BN_CTX_get(ctx);
diff --git a/src/lib/libcrypto/rsa/rsa_eng.c b/src/lib/libcrypto/rsa/rsa_eng.c
new file mode 100644
index 0000000000..383a7045b2
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_eng.c
@@ -0,0 +1,348 @@
1/* crypto/rsa/rsa_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/lhash.h>
63#include <openssl/bn.h>
64#include <openssl/rsa.h>
65#include <openssl/rand.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT;
71
72static const RSA_METHOD *default_RSA_meth=NULL;
73
74RSA *RSA_new(void)
75 {
76 RSA *r=RSA_new_method(NULL);
77
78 return r;
79 }
80
81void RSA_set_default_method(const RSA_METHOD *meth)
82 {
83#ifdef OPENSSL_FIPS
84 if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD))
85 {
86 RSAerr(RSA_F_RSA_SET_DEFAULT_METHOD, RSA_R_NON_FIPS_METHOD);
87 return;
88 }
89#endif
90 default_RSA_meth = meth;
91 }
92
93const RSA_METHOD *RSA_get_default_method(void)
94 {
95 if (default_RSA_meth == NULL)
96 {
97#ifdef RSA_NULL
98 default_RSA_meth=RSA_null_method();
99#else
100#if 0 /* was: #ifdef RSAref */
101 default_RSA_meth=RSA_PKCS1_RSAref();
102#else
103 default_RSA_meth=RSA_PKCS1_SSLeay();
104#endif
105#endif
106 }
107
108 return default_RSA_meth;
109 }
110
111const RSA_METHOD *RSA_get_method(const RSA *rsa)
112 {
113 return rsa->meth;
114 }
115
116int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
117 {
118 /* NB: The caller is specifically setting a method, so it's not up to us
119 * to deal with which ENGINE it comes from. */
120 const RSA_METHOD *mtmp;
121#ifdef OPENSSL_FIPS
122 if (FIPS_mode() && !(meth->flags & RSA_FLAG_FIPS_METHOD))
123 {
124 RSAerr(RSA_F_RSA_SET_METHOD, RSA_R_NON_FIPS_METHOD);
125 return 0;
126 }
127#endif
128 mtmp = rsa->meth;
129 if (mtmp->finish) mtmp->finish(rsa);
130#ifndef OPENSSL_NO_ENGINE
131 if (rsa->engine)
132 {
133 ENGINE_finish(rsa->engine);
134 rsa->engine = NULL;
135 }
136#endif
137 rsa->meth = meth;
138 if (meth->init) meth->init(rsa);
139 return 1;
140 }
141
142RSA *RSA_new_method(ENGINE *engine)
143 {
144 RSA *ret;
145
146 ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
147 if (ret == NULL)
148 {
149 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
150 return NULL;
151 }
152
153 ret->meth = RSA_get_default_method();
154#ifndef OPENSSL_NO_ENGINE
155 if (engine)
156 {
157 if (!ENGINE_init(engine))
158 {
159 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
160 OPENSSL_free(ret);
161 return NULL;
162 }
163 ret->engine = engine;
164 }
165 else
166 ret->engine = ENGINE_get_default_RSA();
167 if(ret->engine)
168 {
169 ret->meth = ENGINE_get_RSA(ret->engine);
170 if(!ret->meth)
171 {
172 RSAerr(RSA_F_RSA_NEW_METHOD,
173 ERR_R_ENGINE_LIB);
174 ENGINE_finish(ret->engine);
175 OPENSSL_free(ret);
176 return NULL;
177 }
178 }
179#endif
180#ifdef OPENSSL_FIPS
181 if (FIPS_mode() && !(ret->meth->flags & RSA_FLAG_FIPS_METHOD))
182 {
183 RSAerr(RSA_F_RSA_NEW_METHOD, RSA_R_NON_FIPS_METHOD);
184#ifndef OPENSSL_NO_ENGINE
185 if (ret->engine)
186 ENGINE_finish(ret->engine);
187#endif
188 OPENSSL_free(ret);
189 return NULL;
190 }
191#endif
192
193 ret->pad=0;
194 ret->version=0;
195 ret->n=NULL;
196 ret->e=NULL;
197 ret->d=NULL;
198 ret->p=NULL;
199 ret->q=NULL;
200 ret->dmp1=NULL;
201 ret->dmq1=NULL;
202 ret->iqmp=NULL;
203 ret->references=1;
204 ret->_method_mod_n=NULL;
205 ret->_method_mod_p=NULL;
206 ret->_method_mod_q=NULL;
207 ret->blinding=NULL;
208 ret->mt_blinding=NULL;
209 ret->bignum_data=NULL;
210 ret->flags=ret->meth->flags;
211 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
212 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
213 {
214#ifndef OPENSSL_NO_ENGINE
215 if (ret->engine)
216 ENGINE_finish(ret->engine);
217#endif
218 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
219 OPENSSL_free(ret);
220 ret=NULL;
221 }
222 return(ret);
223 }
224
225void RSA_free(RSA *r)
226 {
227 int i;
228
229 if (r == NULL) return;
230
231 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
232#ifdef REF_PRINT
233 REF_PRINT("RSA",r);
234#endif
235 if (i > 0) return;
236#ifdef REF_CHECK
237 if (i < 0)
238 {
239 fprintf(stderr,"RSA_free, bad reference count\n");
240 abort();
241 }
242#endif
243
244 if (r->meth->finish)
245 r->meth->finish(r);
246#ifndef OPENSSL_NO_ENGINE
247 if (r->engine)
248 ENGINE_finish(r->engine);
249#endif
250
251 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
252
253 if (r->n != NULL) BN_clear_free(r->n);
254 if (r->e != NULL) BN_clear_free(r->e);
255 if (r->d != NULL) BN_clear_free(r->d);
256 if (r->p != NULL) BN_clear_free(r->p);
257 if (r->q != NULL) BN_clear_free(r->q);
258 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
259 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
260 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
261 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
262 if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
263 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
264 OPENSSL_free(r);
265 }
266
267int RSA_up_ref(RSA *r)
268 {
269 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
270#ifdef REF_PRINT
271 REF_PRINT("RSA",r);
272#endif
273#ifdef REF_CHECK
274 if (i < 2)
275 {
276 fprintf(stderr, "RSA_up_ref, bad reference count\n");
277 abort();
278 }
279#endif
280 return ((i > 1) ? 1 : 0);
281 }
282
283int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
284 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
285 {
286 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
287 new_func, dup_func, free_func);
288 }
289
290int RSA_set_ex_data(RSA *r, int idx, void *arg)
291 {
292 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
293 }
294
295void *RSA_get_ex_data(const RSA *r, int idx)
296 {
297 return(CRYPTO_get_ex_data(&r->ex_data,idx));
298 }
299
300int RSA_flags(const RSA *r)
301 {
302 return((r == NULL)?0:r->meth->flags);
303 }
304
305int RSA_memory_lock(RSA *r)
306 {
307 int i,j,k,off;
308 char *p;
309 BIGNUM *bn,**t[6],*b;
310 BN_ULONG *ul;
311
312 if (r->d == NULL) return(1);
313 t[0]= &r->d;
314 t[1]= &r->p;
315 t[2]= &r->q;
316 t[3]= &r->dmp1;
317 t[4]= &r->dmq1;
318 t[5]= &r->iqmp;
319 k=sizeof(BIGNUM)*6;
320 off=k/sizeof(BN_ULONG)+1;
321 j=1;
322 for (i=0; i<6; i++)
323 j+= (*t[i])->top;
324 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
325 {
326 RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
327 return(0);
328 }
329 bn=(BIGNUM *)p;
330 ul=(BN_ULONG *)&(p[off]);
331 for (i=0; i<6; i++)
332 {
333 b= *(t[i]);
334 *(t[i])= &(bn[i]);
335 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
336 bn[i].flags=BN_FLG_STATIC_DATA;
337 bn[i].d=ul;
338 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
339 ul+=b->top;
340 BN_clear_free(b);
341 }
342
343 /* I should fix this so it can still be done */
344 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
345
346 r->bignum_data=p;
347 return(1);
348 }
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
index 501f5ea389..fe3ba1b44b 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-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -70,8 +70,6 @@
70 70
71static ERR_STRING_DATA RSA_str_functs[]= 71static ERR_STRING_DATA RSA_str_functs[]=
72 { 72 {
73{ERR_FUNC(RSA_F_FIPS_RSA_SIGN), "FIPS_RSA_SIGN"},
74{ERR_FUNC(RSA_F_FIPS_RSA_VERIFY), "FIPS_RSA_VERIFY"},
75{ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"}, 73{ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"},
76{ERR_FUNC(RSA_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"}, 74{ERR_FUNC(RSA_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"},
77{ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"}, 75{ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"},
@@ -103,11 +101,7 @@ static ERR_STRING_DATA RSA_str_functs[]=
103{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"}, 101{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"},
104{ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"}, 102{ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"},
105{ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"}, 103{ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"},
106{ERR_FUNC(RSA_F_RSA_PRIVATE_ENCRYPT), "RSA_private_encrypt"},
107{ERR_FUNC(RSA_F_RSA_PUBLIC_DECRYPT), "RSA_public_decrypt"},
108{ERR_FUNC(RSA_F_RSA_SETUP_BLINDING), "RSA_setup_blinding"}, 104{ERR_FUNC(RSA_F_RSA_SETUP_BLINDING), "RSA_setup_blinding"},
109{ERR_FUNC(RSA_F_RSA_SET_DEFAULT_METHOD), "RSA_set_default_method"},
110{ERR_FUNC(RSA_F_RSA_SET_METHOD), "RSA_set_method"},
111{ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"}, 105{ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"},
112{ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"}, 106{ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"},
113{ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"}, 107{ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"},
@@ -144,12 +138,10 @@ static ERR_STRING_DATA RSA_str_reasons[]=
144{ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"}, 138{ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"},
145{ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"}, 139{ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"},
146{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, 140{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
147{ERR_REASON(RSA_R_NON_FIPS_METHOD) ,"non fips method"},
148{ERR_REASON(RSA_R_NO_PUBLIC_EXPONENT) ,"no public exponent"}, 141{ERR_REASON(RSA_R_NO_PUBLIC_EXPONENT) ,"no public exponent"},
149{ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"}, 142{ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"},
150{ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"}, 143{ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"},
151{ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"}, 144{ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"},
152{ERR_REASON(RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE),"operation not allowed in fips mode"},
153{ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"}, 145{ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"},
154{ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"}, 146{ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"},
155{ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"}, 147{ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"},
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index 41278f83c6..767f7ab682 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -68,8 +68,6 @@
68#include <openssl/bn.h> 68#include <openssl/bn.h>
69#include <openssl/rsa.h> 69#include <openssl/rsa.h>
70 70
71#ifndef OPENSSL_FIPS
72
73static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb); 71static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb);
74 72
75/* NB: this wrapper would normally be placed in rsa_lib.c and the static 73/* NB: this wrapper would normally be placed in rsa_lib.c and the static
@@ -219,4 +217,3 @@ err:
219 return ok; 217 return ok;
220 } 218 }
221 219
222#endif
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 5714841f4c..104aa4c1f2 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -67,6 +67,215 @@
67#include <openssl/engine.h> 67#include <openssl/engine.h>
68#endif 68#endif
69 69
70const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT;
71
72static const RSA_METHOD *default_RSA_meth=NULL;
73
74RSA *RSA_new(void)
75 {
76 RSA *r=RSA_new_method(NULL);
77
78 return r;
79 }
80
81void RSA_set_default_method(const RSA_METHOD *meth)
82 {
83 default_RSA_meth = meth;
84 }
85
86const RSA_METHOD *RSA_get_default_method(void)
87 {
88 if (default_RSA_meth == NULL)
89 {
90#ifdef RSA_NULL
91 default_RSA_meth=RSA_null_method();
92#else
93#if 0 /* was: #ifdef RSAref */
94 default_RSA_meth=RSA_PKCS1_RSAref();
95#else
96 default_RSA_meth=RSA_PKCS1_SSLeay();
97#endif
98#endif
99 }
100
101 return default_RSA_meth;
102 }
103
104const RSA_METHOD *RSA_get_method(const RSA *rsa)
105 {
106 return rsa->meth;
107 }
108
109int RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
110 {
111 /* NB: The caller is specifically setting a method, so it's not up to us
112 * to deal with which ENGINE it comes from. */
113 const RSA_METHOD *mtmp;
114 mtmp = rsa->meth;
115 if (mtmp->finish) mtmp->finish(rsa);
116#ifndef OPENSSL_NO_ENGINE
117 if (rsa->engine)
118 {
119 ENGINE_finish(rsa->engine);
120 rsa->engine = NULL;
121 }
122#endif
123 rsa->meth = meth;
124 if (meth->init) meth->init(rsa);
125 return 1;
126 }
127
128RSA *RSA_new_method(ENGINE *engine)
129 {
130 RSA *ret;
131
132 ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
133 if (ret == NULL)
134 {
135 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 ret->meth = RSA_get_default_method();
140#ifndef OPENSSL_NO_ENGINE
141 if (engine)
142 {
143 if (!ENGINE_init(engine))
144 {
145 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
146 OPENSSL_free(ret);
147 return NULL;
148 }
149 ret->engine = engine;
150 }
151 else
152 ret->engine = ENGINE_get_default_RSA();
153 if(ret->engine)
154 {
155 ret->meth = ENGINE_get_RSA(ret->engine);
156 if(!ret->meth)
157 {
158 RSAerr(RSA_F_RSA_NEW_METHOD,
159 ERR_R_ENGINE_LIB);
160 ENGINE_finish(ret->engine);
161 OPENSSL_free(ret);
162 return NULL;
163 }
164 }
165#endif
166
167 ret->pad=0;
168 ret->version=0;
169 ret->n=NULL;
170 ret->e=NULL;
171 ret->d=NULL;
172 ret->p=NULL;
173 ret->q=NULL;
174 ret->dmp1=NULL;
175 ret->dmq1=NULL;
176 ret->iqmp=NULL;
177 ret->references=1;
178 ret->_method_mod_n=NULL;
179 ret->_method_mod_p=NULL;
180 ret->_method_mod_q=NULL;
181 ret->blinding=NULL;
182 ret->mt_blinding=NULL;
183 ret->bignum_data=NULL;
184 ret->flags=ret->meth->flags;
185 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
186 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
187 {
188#ifndef OPENSSL_NO_ENGINE
189 if (ret->engine)
190 ENGINE_finish(ret->engine);
191#endif
192 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
193 OPENSSL_free(ret);
194 ret=NULL;
195 }
196 return(ret);
197 }
198
199void RSA_free(RSA *r)
200 {
201 int i;
202
203 if (r == NULL) return;
204
205 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA);
206#ifdef REF_PRINT
207 REF_PRINT("RSA",r);
208#endif
209 if (i > 0) return;
210#ifdef REF_CHECK
211 if (i < 0)
212 {
213 fprintf(stderr,"RSA_free, bad reference count\n");
214 abort();
215 }
216#endif
217
218 if (r->meth->finish)
219 r->meth->finish(r);
220#ifndef OPENSSL_NO_ENGINE
221 if (r->engine)
222 ENGINE_finish(r->engine);
223#endif
224
225 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
226
227 if (r->n != NULL) BN_clear_free(r->n);
228 if (r->e != NULL) BN_clear_free(r->e);
229 if (r->d != NULL) BN_clear_free(r->d);
230 if (r->p != NULL) BN_clear_free(r->p);
231 if (r->q != NULL) BN_clear_free(r->q);
232 if (r->dmp1 != NULL) BN_clear_free(r->dmp1);
233 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
234 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
235 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
236 if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
237 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
238 OPENSSL_free(r);
239 }
240
241int RSA_up_ref(RSA *r)
242 {
243 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
244#ifdef REF_PRINT
245 REF_PRINT("RSA",r);
246#endif
247#ifdef REF_CHECK
248 if (i < 2)
249 {
250 fprintf(stderr, "RSA_up_ref, bad reference count\n");
251 abort();
252 }
253#endif
254 return ((i > 1) ? 1 : 0);
255 }
256
257int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
258 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
259 {
260 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_RSA, argl, argp,
261 new_func, dup_func, free_func);
262 }
263
264int RSA_set_ex_data(RSA *r, int idx, void *arg)
265 {
266 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
267 }
268
269void *RSA_get_ex_data(const RSA *r, int idx)
270 {
271 return(CRYPTO_get_ex_data(&r->ex_data,idx));
272 }
273
274int RSA_size(const RSA *r)
275 {
276 return(BN_num_bytes(r->n));
277 }
278
70int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to, 279int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
71 RSA *rsa, int padding) 280 RSA *rsa, int padding)
72 { 281 {
@@ -76,13 +285,6 @@ int RSA_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
76int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to, 285int RSA_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
77 RSA *rsa, int padding) 286 RSA *rsa, int padding)
78 { 287 {
79#ifdef OPENSSL_FIPS
80 if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
81 {
82 RSAerr(RSA_F_RSA_PRIVATE_ENCRYPT, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
83 return 0;
84 }
85#endif
86 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); 288 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
87 } 289 }
88 290
@@ -95,19 +297,12 @@ int RSA_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
95int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, 297int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
96 RSA *rsa, int padding) 298 RSA *rsa, int padding)
97 { 299 {
98#ifdef OPENSSL_FIPS
99 if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
100 {
101 RSAerr(RSA_F_RSA_PUBLIC_DECRYPT, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
102 return 0;
103 }
104#endif
105 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); 300 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
106 } 301 }
107 302
108int RSA_size(const RSA *r) 303int RSA_flags(const RSA *r)
109 { 304 {
110 return(BN_num_bytes(r->n)); 305 return((r == NULL)?0:r->meth->flags);
111 } 306 }
112 307
113void RSA_blinding_off(RSA *rsa) 308void RSA_blinding_off(RSA *rsa)
@@ -232,3 +427,48 @@ err:
232 427
233 return ret; 428 return ret;
234} 429}
430
431int RSA_memory_lock(RSA *r)
432 {
433 int i,j,k,off;
434 char *p;
435 BIGNUM *bn,**t[6],*b;
436 BN_ULONG *ul;
437
438 if (r->d == NULL) return(1);
439 t[0]= &r->d;
440 t[1]= &r->p;
441 t[2]= &r->q;
442 t[3]= &r->dmp1;
443 t[4]= &r->dmq1;
444 t[5]= &r->iqmp;
445 k=sizeof(BIGNUM)*6;
446 off=k/sizeof(BN_ULONG)+1;
447 j=1;
448 for (i=0; i<6; i++)
449 j+= (*t[i])->top;
450 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
451 {
452 RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
453 return(0);
454 }
455 bn=(BIGNUM *)p;
456 ul=(BN_ULONG *)&(p[off]);
457 for (i=0; i<6; i++)
458 {
459 b= *(t[i]);
460 *(t[i])= &(bn[i]);
461 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
462 bn[i].flags=BN_FLG_STATIC_DATA;
463 bn[i].d=ul;
464 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
465 ul+=b->top;
466 BN_clear_free(b);
467 }
468
469 /* I should fix this so it can still be done */
470 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
471
472 r->bignum_data=p;
473 return(1);
474 }
diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c
new file mode 100644
index 0000000000..491572c82b
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_null.c
@@ -0,0 +1,151 @@
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
72static int RSA_null_public_encrypt(int flen, const unsigned char *from,
73 unsigned char *to, RSA *rsa,int padding);
74static int RSA_null_private_encrypt(int flen, const unsigned char *from,
75 unsigned char *to, RSA *rsa,int padding);
76static int RSA_null_public_decrypt(int flen, const unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static 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 */
81static int RSA_null_mod_exp(const BIGNUM *r0, const BIGNUM *i, RSA *rsa);
82#endif
83static int RSA_null_init(RSA *rsa);
84static int RSA_null_finish(RSA *rsa);
85static 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 NULL,
98 NULL,
99 NULL
100 };
101
102const RSA_METHOD *RSA_null_method(void)
103 {
104 return(&rsa_null_meth);
105 }
106
107static int RSA_null_public_encrypt(int flen, const unsigned char *from,
108 unsigned char *to, RSA *rsa, int padding)
109 {
110 RSAerr(RSA_F_RSA_NULL_PUBLIC_ENCRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
111 return -1;
112 }
113
114static int RSA_null_private_encrypt(int flen, const unsigned char *from,
115 unsigned char *to, RSA *rsa, int padding)
116 {
117 RSAerr(RSA_F_RSA_NULL_PRIVATE_ENCRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
118 return -1;
119 }
120
121static int RSA_null_private_decrypt(int flen, const unsigned char *from,
122 unsigned char *to, RSA *rsa, int padding)
123 {
124 RSAerr(RSA_F_RSA_NULL_PRIVATE_DECRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
125 return -1;
126 }
127
128static int RSA_null_public_decrypt(int flen, const unsigned char *from,
129 unsigned char *to, RSA *rsa, int padding)
130 {
131 RSAerr(RSA_F_RSA_NULL_PUBLIC_DECRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
132 return -1;
133 }
134
135#if 0 /* not currently used */
136static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
137 {
138 ...err(RSA_F_RSA_NULL_MOD_EXP, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
139 return -1;
140 }
141#endif
142
143static int RSA_null_init(RSA *rsa)
144 {
145 return(1);
146 }
147
148static int RSA_null_finish(RSA *rsa)
149 {
150 return(1);
151 }
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index 4d30c9d2d3..3652677a99 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -187,7 +187,7 @@ int PKCS1_MGF1(unsigned char *mask, long len,
187 int mdlen; 187 int mdlen;
188 188
189 EVP_MD_CTX_init(&c); 189 EVP_MD_CTX_init(&c);
190 mdlen = M_EVP_MD_size(dgst); 190 mdlen = EVP_MD_size(dgst);
191 for (i = 0; outlen < len; i++) 191 for (i = 0; outlen < len; i++)
192 { 192 {
193 cnt[0] = (unsigned char)((i >> 24) & 255); 193 cnt[0] = (unsigned char)((i >> 24) & 255);
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 5488c06f6d..71aabeea1b 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -90,14 +90,6 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
90 i = SSL_SIG_LENGTH; 90 i = SSL_SIG_LENGTH;
91 s = m; 91 s = m;
92 } else { 92 } else {
93 /* NB: in FIPS mode block anything that isn't a TLS signature */
94#ifdef OPENSSL_FIPS
95 if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
96 {
97 RSAerr(RSA_F_RSA_SIGN, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
98 return 0;
99 }
100#endif
101 sig.algor= &algor; 93 sig.algor= &algor;
102 sig.algor->algorithm=OBJ_nid2obj(type); 94 sig.algor->algorithm=OBJ_nid2obj(type);
103 if (sig.algor->algorithm == NULL) 95 if (sig.algor->algorithm == NULL)
@@ -175,22 +167,10 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
175 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); 167 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
176 goto err; 168 goto err;
177 } 169 }
178 if(dtype == NID_md5_sha1) 170 if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) {
179 {
180 if (m_len != SSL_SIG_LENGTH)
181 {
182 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH); 171 RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH);
183 goto err; 172 goto err;
184 } 173 }
185 }
186 /* NB: in FIPS mode block anything that isn't a TLS signature */
187#ifdef OPENSSL_FIPS
188 else if(FIPS_mode() && !(rsa->flags & RSA_FLAG_NON_FIPS_ALLOW))
189 {
190 RSAerr(RSA_F_RSA_VERIFY, RSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
191 return 0;
192 }
193#endif
194 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); 174 i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING);
195 175
196 if (i <= 0) goto err; 176 if (i <= 0) goto err;
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c
new file mode 100644
index 0000000000..4080de8bcf
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_test.c
@@ -0,0 +1,340 @@
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#include <openssl/bn.h>
12#ifdef OPENSSL_NO_RSA
13int main(int argc, char *argv[])
14{
15 printf("No RSA support\n");
16 return(0);
17}
18#else
19#include <openssl/rsa.h>
20
21#define SetKey \
22 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
23 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
24 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
25 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
26 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
27 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
28 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
29 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
30 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
31 return (sizeof(ctext_ex) - 1);
32
33static int key1(RSA *key, unsigned char *c)
34 {
35 static unsigned char n[] =
36"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
37"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
38"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
39"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
40"\xF5";
41
42 static unsigned char e[] = "\x11";
43
44 static unsigned char d[] =
45"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
46"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
47"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
48"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
49
50 static unsigned char p[] =
51"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
52"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
53"\x0D";
54
55 static unsigned char q[] =
56"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
57"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
58"\x89";
59
60 static unsigned char dmp1[] =
61"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
62"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
63
64 static unsigned char dmq1[] =
65"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
66"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
67"\x51";
68
69 static unsigned char iqmp[] =
70"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
71"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
72
73 static unsigned char ctext_ex[] =
74"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
75"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
76"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
77"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
78
79 SetKey;
80 }
81
82static int key2(RSA *key, unsigned char *c)
83 {
84 static unsigned char n[] =
85"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
86"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
87"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
88"\x34\x77\xCF";
89
90 static unsigned char e[] = "\x3";
91
92 static unsigned char d[] =
93"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
94"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
95"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
96"\xE5\xEB";
97
98 static unsigned char p[] =
99"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
100"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
101
102 static unsigned char q[] =
103"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
104"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
105
106 static unsigned char dmp1[] =
107"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
108"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
109
110 static unsigned char dmq1[] =
111"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
112"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
113
114 static unsigned char iqmp[] =
115"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
116"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
117
118 static unsigned char ctext_ex[] =
119"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
120"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
121"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
122"\x62\x51";
123
124 SetKey;
125 }
126
127static int key3(RSA *key, unsigned char *c)
128 {
129 static unsigned char n[] =
130"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
131"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
132"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
133"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
134"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
135"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
136"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
137"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
138"\xCB";
139
140 static unsigned char e[] = "\x11";
141
142 static unsigned char d[] =
143"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
144"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
145"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
146"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
147"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
148"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
149"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
150"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
151"\xC1";
152
153 static unsigned char p[] =
154"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
155"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
156"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
157"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
158"\x99";
159
160 static unsigned char q[] =
161"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
162"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
163"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
164"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
165"\x03";
166
167 static unsigned char dmp1[] =
168"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
169"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
170"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
171"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
172
173 static unsigned char dmq1[] =
174"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
175"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
176"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
177"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
178
179 static unsigned char iqmp[] =
180"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
181"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
182"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
183"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
184"\xF7";
185
186 static unsigned char ctext_ex[] =
187"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
188"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
189"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
190"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
191"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
192"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
193"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
194"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
195
196 SetKey;
197 }
198
199static int pad_unknown(void)
200{
201 unsigned long l;
202 while ((l = ERR_get_error()) != 0)
203 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
204 return(1);
205 return(0);
206}
207
208static const char rnd_seed[] = "string to make the random number generator think it has entropy";
209
210int main(int argc, char *argv[])
211 {
212 int err=0;
213 int v;
214 RSA *key;
215 unsigned char ptext[256];
216 unsigned char ctext[256];
217 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
218 unsigned char ctext_ex[256];
219 int plen;
220 int clen = 0;
221 int num;
222 int n;
223
224 CRYPTO_malloc_debug_init();
225 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
226 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
227
228 RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
229
230 plen = sizeof(ptext_ex) - 1;
231
232 for (v = 0; v < 6; v++)
233 {
234 key = RSA_new();
235 switch (v%3) {
236 case 0:
237 clen = key1(key, ctext_ex);
238 break;
239 case 1:
240 clen = key2(key, ctext_ex);
241 break;
242 case 2:
243 clen = key3(key, ctext_ex);
244 break;
245 }
246 if (v/3 >= 1) key->flags |= RSA_FLAG_NO_CONSTTIME;
247
248 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
249 RSA_PKCS1_PADDING);
250 if (num != clen)
251 {
252 printf("PKCS#1 v1.5 encryption failed!\n");
253 err=1;
254 goto oaep;
255 }
256
257 num = RSA_private_decrypt(num, ctext, ptext, key,
258 RSA_PKCS1_PADDING);
259 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
260 {
261 printf("PKCS#1 v1.5 decryption failed!\n");
262 err=1;
263 }
264 else
265 printf("PKCS #1 v1.5 encryption/decryption ok\n");
266
267 oaep:
268 ERR_clear_error();
269 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
270 RSA_PKCS1_OAEP_PADDING);
271 if (num == -1 && pad_unknown())
272 {
273 printf("No OAEP support\n");
274 goto next;
275 }
276 if (num != clen)
277 {
278 printf("OAEP encryption failed!\n");
279 err=1;
280 goto next;
281 }
282
283 num = RSA_private_decrypt(num, ctext, ptext, key,
284 RSA_PKCS1_OAEP_PADDING);
285 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
286 {
287 printf("OAEP decryption (encrypted data) failed!\n");
288 err=1;
289 }
290 else if (memcmp(ctext, ctext_ex, num) == 0)
291 printf("OAEP test vector %d passed!\n", v);
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
307 /* Try decrypting corrupted ciphertexts */
308 for(n = 0 ; n < clen ; ++n)
309 {
310 int b;
311 unsigned char saved = ctext[n];
312 for(b = 0 ; b < 256 ; ++b)
313 {
314 if(b == saved)
315 continue;
316 ctext[n] = b;
317 num = RSA_private_decrypt(num, ctext, ptext, key,
318 RSA_PKCS1_OAEP_PADDING);
319 if(num > 0)
320 {
321 printf("Corrupt data decrypted!\n");
322 err = 1;
323 }
324 }
325 }
326 next:
327 RSA_free(key);
328 }
329
330 CRYPTO_cleanup_all_ex_data();
331 ERR_remove_state(0);
332
333 CRYPTO_mem_leaks_fp(stderr);
334
335#ifdef OPENSSL_SYS_NETWARE
336 if (err) printf("ERROR: %d\n", err);
337#endif
338 return err;
339 }
340#endif
diff --git a/src/lib/libcrypto/rsa/rsa_x931g.c b/src/lib/libcrypto/rsa/rsa_x931g.c
new file mode 100644
index 0000000000..c640cc2ec9
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_x931g.c
@@ -0,0 +1,255 @@
1/* crypto/rsa/rsa_gen.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <time.h>
62#include <openssl/err.h>
63#include <openssl/bn.h>
64#include <openssl/rsa.h>
65
66#ifndef OPENSSL_FIPS
67
68/* X9.31 RSA key derivation and generation */
69
70int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
71 const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
72 const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
73 const BIGNUM *e, BN_GENCB *cb)
74 {
75 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL;
76 BN_CTX *ctx=NULL,*ctx2=NULL;
77
78 if (!rsa)
79 goto err;
80
81 ctx = BN_CTX_new();
82 BN_CTX_start(ctx);
83 if (!ctx)
84 goto err;
85
86 r0 = BN_CTX_get(ctx);
87 r1 = BN_CTX_get(ctx);
88 r2 = BN_CTX_get(ctx);
89 r3 = BN_CTX_get(ctx);
90
91 if (r3 == NULL)
92 goto err;
93 if (!rsa->e)
94 {
95 rsa->e = BN_dup(e);
96 if (!rsa->e)
97 goto err;
98 }
99 else
100 e = rsa->e;
101
102 /* If not all parameters present only calculate what we can.
103 * This allows test programs to output selective parameters.
104 */
105
106 if (Xp && !rsa->p)
107 {
108 rsa->p = BN_new();
109 if (!rsa->p)
110 goto err;
111
112 if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,
113 Xp, Xp1, Xp2, e, ctx, cb))
114 goto err;
115 }
116
117 if (Xq && !rsa->q)
118 {
119 rsa->q = BN_new();
120 if (!rsa->q)
121 goto err;
122 if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,
123 Xq, Xq1, Xq2, e, ctx, cb))
124 goto err;
125 }
126
127 if (!rsa->p || !rsa->q)
128 {
129 BN_CTX_end(ctx);
130 BN_CTX_free(ctx);
131 return 2;
132 }
133
134 /* Since both primes are set we can now calculate all remaining
135 * components.
136 */
137
138 /* calculate n */
139 rsa->n=BN_new();
140 if (rsa->n == NULL)
141 goto err;
142 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx))
143 goto err;
144
145 /* calculate d */
146 if (!BN_sub(r1,rsa->p,BN_value_one()))
147 goto err; /* p-1 */
148 if (!BN_sub(r2,rsa->q,BN_value_one()))
149 goto err; /* q-1 */
150 if (!BN_mul(r0,r1,r2,ctx))
151 goto err; /* (p-1)(q-1) */
152
153 if (!BN_gcd(r3, r1, r2, ctx))
154 goto err;
155
156 if (!BN_div(r0, NULL, r0, r3, ctx))
157 goto err; /* LCM((p-1)(q-1)) */
158
159 ctx2 = BN_CTX_new();
160 if (!ctx2)
161 goto err;
162
163 rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */
164 if (rsa->d == NULL)
165 goto err;
166
167 /* calculate d mod (p-1) */
168 rsa->dmp1=BN_new();
169 if (rsa->dmp1 == NULL)
170 goto err;
171 if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx))
172 goto err;
173
174 /* calculate d mod (q-1) */
175 rsa->dmq1=BN_new();
176 if (rsa->dmq1 == NULL)
177 goto err;
178 if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx))
179 goto err;
180
181 /* calculate inverse of q mod p */
182 rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
183
184 err:
185 if (ctx)
186 {
187 BN_CTX_end(ctx);
188 BN_CTX_free(ctx);
189 }
190 if (ctx2)
191 BN_CTX_free(ctx2);
192 /* If this is set all calls successful */
193 if (rsa->iqmp != NULL)
194 return 1;
195
196 return 0;
197
198 }
199
200int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb)
201 {
202 int ok = 0;
203 BIGNUM *Xp = NULL, *Xq = NULL;
204 BN_CTX *ctx = NULL;
205
206 ctx = BN_CTX_new();
207 if (!ctx)
208 goto error;
209
210 BN_CTX_start(ctx);
211 Xp = BN_CTX_get(ctx);
212 Xq = BN_CTX_get(ctx);
213 if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))
214 goto error;
215
216 rsa->p = BN_new();
217 rsa->q = BN_new();
218 if (!rsa->p || !rsa->q)
219 goto error;
220
221 /* Generate two primes from Xp, Xq */
222
223 if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,
224 e, ctx, cb))
225 goto error;
226
227 if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,
228 e, ctx, cb))
229 goto error;
230
231 /* Since rsa->p and rsa->q are valid this call will just derive
232 * remaining RSA components.
233 */
234
235 if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,
236 NULL, NULL, NULL, NULL, NULL, NULL, e, cb))
237 goto error;
238
239 ok = 1;
240
241 error:
242 if (ctx)
243 {
244 BN_CTX_end(ctx);
245 BN_CTX_free(ctx);
246 }
247
248 if (ok)
249 return 1;
250
251 return 0;
252
253 }
254
255#endif