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/Makefile.ssl121
-rw-r--r--src/lib/libcrypto/rsa/rsa.h31
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c43
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c2
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c123
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c15
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c2
9 files changed, 240 insertions, 113 deletions
diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl
index 7b3960e70d..c159eedafe 100644
--- a/src/lib/libcrypto/rsa/Makefile.ssl
+++ b/src/lib/libcrypto/rsa/Makefile.ssl
@@ -80,64 +80,97 @@ clean:
80 80
81# DO NOT DELETE THIS LINE -- make depend depends on it. 81# DO NOT DELETE THIS LINE -- make depend depends on it.
82 82
83rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h 83rsa_chk.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
84rsa_chk.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 84rsa_chk.o: ../../include/openssl/crypto.h ../../include/openssl/err.h
85rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 86rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
86rsa_chk.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 87rsa_chk.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 88rsa_chk.o: ../../include/openssl/symhacks.h
88rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 89rsa_eay.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
90rsa_eay.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
91rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
92rsa_eay.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
93rsa_eay.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
89rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 94rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
90rsa_eay.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 95rsa_eay.o: ../../include/openssl/engine.h ../../include/openssl/err.h
96rsa_eay.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
97rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
98rsa_eay.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
99rsa_eay.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
100rsa_eay.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
91rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 101rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
102rsa_eay.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
103rsa_eay.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
92rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 104rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
93rsa_eay.o: ../../include/openssl/stack.h ../cryptlib.h 105rsa_eay.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
94rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h 106rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h
95rsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 107rsa_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
108rsa_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h
109rsa_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
96rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 110rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
97rsa_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 111rsa_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
112rsa_err.o: ../../include/openssl/symhacks.h
98rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 113rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
99rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 114rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
100rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 115rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
101rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 116rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
102rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h 117rsa_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103rsa_gen.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h 118rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
104rsa_gen.o: ../cryptlib.h 120rsa_gen.o: ../cryptlib.h
105rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 121rsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
106rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 122rsa_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
123rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
124rsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
125rsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
107rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 126rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
108rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h 127rsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
109rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 128rsa_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
129rsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
130rsa_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
131rsa_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
132rsa_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
133rsa_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
134rsa_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
135rsa_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
110rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 136rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
111rsa_lib.o: ../../include/openssl/stack.h ../cryptlib.h 137rsa_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
138rsa_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h
112rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 139rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
113rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 140rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
114rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 141rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
115rsa_none.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 142rsa_none.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
143rsa_none.o: ../../include/openssl/opensslconf.h
116rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 144rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
117rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 145rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
118rsa_none.o: ../../include/openssl/stack.h ../cryptlib.h 146rsa_none.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
147rsa_none.o: ../cryptlib.h
119rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 148rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
120rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 149rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
121rsa_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 150rsa_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
122rsa_null.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 151rsa_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
152rsa_null.o: ../../include/openssl/opensslconf.h
123rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 153rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
124rsa_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 154rsa_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
125rsa_null.o: ../../include/openssl/stack.h ../cryptlib.h 155rsa_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
156rsa_null.o: ../cryptlib.h
126rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 157rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
127rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 158rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
128rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 159rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
129rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 160rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
161rsa_oaep.o: ../../include/openssl/opensslconf.h
130rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 162rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
131rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 163rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
132rsa_oaep.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 164rsa_oaep.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
133rsa_oaep.o: ../cryptlib.h 165rsa_oaep.o: ../../include/openssl/symhacks.h ../cryptlib.h
134rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 166rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
135rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 167rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
136rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 168rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
137rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 169rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
138rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 170rsa_pk1.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
139rsa_pk1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 171rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
140rsa_pk1.o: ../../include/openssl/stack.h ../cryptlib.h 172rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
173rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h
141rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 174rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
142rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 175rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
143rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 176rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
@@ -145,37 +178,43 @@ rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
145rsa_saos.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 178rsa_saos.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
146rsa_saos.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 179rsa_saos.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
147rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h 180rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
148rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 181rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
182rsa_saos.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
149rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 183rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
150rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 184rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
185rsa_saos.o: ../../include/openssl/opensslconf.h
151rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 186rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
152rsa_saos.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h 187rsa_saos.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
153rsa_saos.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h 188rsa_saos.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
154rsa_saos.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 189rsa_saos.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
155rsa_saos.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 190rsa_saos.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
156rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 191rsa_saos.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
157rsa_saos.o: ../cryptlib.h 192rsa_saos.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
158rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 193rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
159rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 194rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
160rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 195rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
161rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 196rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
162rsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h 197rsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
163rsa_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 198rsa_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
164rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h 199rsa_sign.o: ../../include/openssl/engine.h ../../include/openssl/err.h
165rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h 200rsa_sign.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
166rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h 201rsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
202rsa_sign.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
203rsa_sign.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
167rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h 204rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
168rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h 205rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
169rsa_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h 206rsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
170rsa_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h 207rsa_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
171rsa_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 208rsa_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
172rsa_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 209rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
210rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
173rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 211rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
174rsa_sign.o: ../cryptlib.h 212rsa_sign.o: ../cryptlib.h
175rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h 213rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
176rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h 214rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
177rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 215rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
178rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 216rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
179rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 217rsa_ssl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
180rsa_ssl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 218rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
181rsa_ssl.o: ../../include/openssl/stack.h ../cryptlib.h 219rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
220rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index f9f9b5cfe9..bda636a365 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -59,10 +59,9 @@
59#ifndef HEADER_RSA_H 59#ifndef HEADER_RSA_H
60#define HEADER_RSA_H 60#define HEADER_RSA_H
61 61
62#ifdef __cplusplus 62#ifndef NO_BIO
63extern "C" { 63#include <openssl/bio.h>
64#endif 64#endif
65
66#include <openssl/bn.h> 65#include <openssl/bn.h>
67#include <openssl/crypto.h> 66#include <openssl/crypto.h>
68 67
@@ -70,6 +69,10 @@ extern "C" {
70#error RSA is disabled. 69#error RSA is disabled.
71#endif 70#endif
72 71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
73typedef struct rsa_st RSA; 76typedef struct rsa_st RSA;
74 77
75typedef struct rsa_meth_st 78typedef struct rsa_meth_st
@@ -111,7 +114,11 @@ struct rsa_st
111 * this is passed instead of aEVP_PKEY, it is set to 0 */ 114 * this is passed instead of aEVP_PKEY, it is set to 0 */
112 int pad; 115 int pad;
113 int version; 116 int version;
117#if 0
114 RSA_METHOD *meth; 118 RSA_METHOD *meth;
119#else
120 struct engine_st *engine;
121#endif
115 BIGNUM *n; 122 BIGNUM *n;
116 BIGNUM *e; 123 BIGNUM *e;
117 BIGNUM *d; 124 BIGNUM *d;
@@ -165,7 +172,11 @@ struct rsa_st
165#define RSA_get_app_data(s) RSA_get_ex_data(s,0) 172#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
166 173
167RSA * RSA_new(void); 174RSA * RSA_new(void);
175#if 0
168RSA * RSA_new_method(RSA_METHOD *method); 176RSA * RSA_new_method(RSA_METHOD *method);
177#else
178RSA * RSA_new_method(struct engine_st *engine);
179#endif
169int RSA_size(RSA *); 180int RSA_size(RSA *);
170RSA * RSA_generate_key(int bits, unsigned long e,void 181RSA * RSA_generate_key(int bits, unsigned long e,void
171 (*callback)(int,int,void *),void *cb_arg); 182 (*callback)(int,int,void *),void *cb_arg);
@@ -183,10 +194,14 @@ void RSA_free (RSA *r);
183 194
184int RSA_flags(RSA *r); 195int RSA_flags(RSA *r);
185 196
186void RSA_set_default_method(RSA_METHOD *meth); 197void RSA_set_default_openssl_method(RSA_METHOD *meth);
187RSA_METHOD *RSA_get_default_method(void); 198RSA_METHOD *RSA_get_default_openssl_method(void);
188RSA_METHOD *RSA_get_method(RSA *rsa); 199RSA_METHOD *RSA_get_method(RSA *rsa);
200#if 0
189RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth); 201RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
202#else
203int RSA_set_method(RSA *rsa, struct engine_st *engine);
204#endif
190 205
191/* This function needs the memory locking malloc callbacks to be installed */ 206/* This function needs the memory locking malloc callbacks to be installed */
192int RSA_memory_lock(RSA *r); 207int RSA_memory_lock(RSA *r);
@@ -209,10 +224,14 @@ int i2d_RSAPrivateKey(RSA *a, unsigned char **pp);
209int RSA_print_fp(FILE *fp, RSA *r,int offset); 224int RSA_print_fp(FILE *fp, RSA *r,int offset);
210#endif 225#endif
211 226
212#ifdef HEADER_BIO_H 227#ifndef NO_BIO
213int RSA_print(BIO *bp, RSA *r,int offset); 228int RSA_print(BIO *bp, RSA *r,int offset);
214#endif 229#endif
215 230
231int i2d_RSA_NET(RSA *a, unsigned char **pp, int (*cb)(), int sgckey);
232RSA *d2i_RSA_NET(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey);
233RSA *d2i_RSA_NET_2(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey);
234
216int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)()); 235int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)());
217RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)()); 236RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)());
218/* Naughty internal function required elsewhere, to handle a MS structure 237/* Naughty internal function required elsewhere, to handle a MS structure
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index b7d2460754..8b8a1e279a 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -61,6 +61,7 @@
61#include <openssl/bn.h> 61#include <openssl/bn.h>
62#include <openssl/rsa.h> 62#include <openssl/rsa.h>
63#include <openssl/rand.h> 63#include <openssl/rand.h>
64#include <openssl/engine.h>
64 65
65#ifndef RSA_NULL 66#ifndef RSA_NULL
66 67
@@ -97,16 +98,18 @@ RSA_METHOD *RSA_PKCS1_SSLeay(void)
97static int RSA_eay_public_encrypt(int flen, unsigned char *from, 98static int RSA_eay_public_encrypt(int flen, unsigned char *from,
98 unsigned char *to, RSA *rsa, int padding) 99 unsigned char *to, RSA *rsa, int padding)
99 { 100 {
101 const RSA_METHOD *meth;
100 BIGNUM f,ret; 102 BIGNUM f,ret;
101 int i,j,k,num=0,r= -1; 103 int i,j,k,num=0,r= -1;
102 unsigned char *buf=NULL; 104 unsigned char *buf=NULL;
103 BN_CTX *ctx=NULL; 105 BN_CTX *ctx=NULL;
104 106
107 meth = ENGINE_get_RSA(rsa->engine);
105 BN_init(&f); 108 BN_init(&f);
106 BN_init(&ret); 109 BN_init(&ret);
107 if ((ctx=BN_CTX_new()) == NULL) goto err; 110 if ((ctx=BN_CTX_new()) == NULL) goto err;
108 num=BN_num_bytes(rsa->n); 111 num=BN_num_bytes(rsa->n);
109 if ((buf=(unsigned char *)Malloc(num)) == NULL) 112 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
110 { 113 {
111 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); 114 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
112 goto err; 115 goto err;
@@ -143,7 +146,7 @@ static int RSA_eay_public_encrypt(int flen, unsigned char *from,
143 goto err; 146 goto err;
144 } 147 }
145 148
146 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, 149 if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
147 rsa->_method_mod_n)) goto err; 150 rsa->_method_mod_n)) goto err;
148 151
149 /* put in leading 0 bytes if the number is less than the 152 /* put in leading 0 bytes if the number is less than the
@@ -161,7 +164,7 @@ err:
161 if (buf != NULL) 164 if (buf != NULL)
162 { 165 {
163 memset(buf,0,num); 166 memset(buf,0,num);
164 Free(buf); 167 OPENSSL_free(buf);
165 } 168 }
166 return(r); 169 return(r);
167 } 170 }
@@ -169,17 +172,19 @@ err:
169static int RSA_eay_private_encrypt(int flen, unsigned char *from, 172static int RSA_eay_private_encrypt(int flen, unsigned char *from,
170 unsigned char *to, RSA *rsa, int padding) 173 unsigned char *to, RSA *rsa, int padding)
171 { 174 {
175 const RSA_METHOD *meth;
172 BIGNUM f,ret; 176 BIGNUM f,ret;
173 int i,j,k,num=0,r= -1; 177 int i,j,k,num=0,r= -1;
174 unsigned char *buf=NULL; 178 unsigned char *buf=NULL;
175 BN_CTX *ctx=NULL; 179 BN_CTX *ctx=NULL;
176 180
181 meth = ENGINE_get_RSA(rsa->engine);
177 BN_init(&f); 182 BN_init(&f);
178 BN_init(&ret); 183 BN_init(&ret);
179 184
180 if ((ctx=BN_CTX_new()) == NULL) goto err; 185 if ((ctx=BN_CTX_new()) == NULL) goto err;
181 num=BN_num_bytes(rsa->n); 186 num=BN_num_bytes(rsa->n);
182 if ((buf=(unsigned char *)Malloc(num)) == NULL) 187 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
183 { 188 {
184 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE); 189 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
185 goto err; 190 goto err;
@@ -213,10 +218,10 @@ static int RSA_eay_private_encrypt(int flen, unsigned char *from,
213 (rsa->dmp1 != NULL) && 218 (rsa->dmp1 != NULL) &&
214 (rsa->dmq1 != NULL) && 219 (rsa->dmq1 != NULL) &&
215 (rsa->iqmp != NULL)) ) 220 (rsa->iqmp != NULL)) )
216 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } 221 { if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
217 else 222 else
218 { 223 {
219 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err; 224 if (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err;
220 } 225 }
221 226
222 if (rsa->flags & RSA_FLAG_BLINDING) 227 if (rsa->flags & RSA_FLAG_BLINDING)
@@ -237,7 +242,7 @@ err:
237 if (buf != NULL) 242 if (buf != NULL)
238 { 243 {
239 memset(buf,0,num); 244 memset(buf,0,num);
240 Free(buf); 245 OPENSSL_free(buf);
241 } 246 }
242 return(r); 247 return(r);
243 } 248 }
@@ -245,12 +250,14 @@ err:
245static int RSA_eay_private_decrypt(int flen, unsigned char *from, 250static int RSA_eay_private_decrypt(int flen, unsigned char *from,
246 unsigned char *to, RSA *rsa, int padding) 251 unsigned char *to, RSA *rsa, int padding)
247 { 252 {
253 const RSA_METHOD *meth;
248 BIGNUM f,ret; 254 BIGNUM f,ret;
249 int j,num=0,r= -1; 255 int j,num=0,r= -1;
250 unsigned char *p; 256 unsigned char *p;
251 unsigned char *buf=NULL; 257 unsigned char *buf=NULL;
252 BN_CTX *ctx=NULL; 258 BN_CTX *ctx=NULL;
253 259
260 meth = ENGINE_get_RSA(rsa->engine);
254 BN_init(&f); 261 BN_init(&f);
255 BN_init(&ret); 262 BN_init(&ret);
256 ctx=BN_CTX_new(); 263 ctx=BN_CTX_new();
@@ -258,7 +265,7 @@ static int RSA_eay_private_decrypt(int flen, unsigned char *from,
258 265
259 num=BN_num_bytes(rsa->n); 266 num=BN_num_bytes(rsa->n);
260 267
261 if ((buf=(unsigned char *)Malloc(num)) == NULL) 268 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
262 { 269 {
263 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE); 270 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
264 goto err; 271 goto err;
@@ -287,10 +294,10 @@ static int RSA_eay_private_decrypt(int flen, unsigned char *from,
287 (rsa->dmp1 != NULL) && 294 (rsa->dmp1 != NULL) &&
288 (rsa->dmq1 != NULL) && 295 (rsa->dmq1 != NULL) &&
289 (rsa->iqmp != NULL)) ) 296 (rsa->iqmp != NULL)) )
290 { if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } 297 { if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }
291 else 298 else
292 { 299 {
293 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) 300 if (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))
294 goto err; 301 goto err;
295 } 302 }
296 303
@@ -330,7 +337,7 @@ err:
330 if (buf != NULL) 337 if (buf != NULL)
331 { 338 {
332 memset(buf,0,num); 339 memset(buf,0,num);
333 Free(buf); 340 OPENSSL_free(buf);
334 } 341 }
335 return(r); 342 return(r);
336 } 343 }
@@ -338,19 +345,21 @@ err:
338static int RSA_eay_public_decrypt(int flen, unsigned char *from, 345static int RSA_eay_public_decrypt(int flen, unsigned char *from,
339 unsigned char *to, RSA *rsa, int padding) 346 unsigned char *to, RSA *rsa, int padding)
340 { 347 {
348 const RSA_METHOD *meth;
341 BIGNUM f,ret; 349 BIGNUM f,ret;
342 int i,num=0,r= -1; 350 int i,num=0,r= -1;
343 unsigned char *p; 351 unsigned char *p;
344 unsigned char *buf=NULL; 352 unsigned char *buf=NULL;
345 BN_CTX *ctx=NULL; 353 BN_CTX *ctx=NULL;
346 354
355 meth = ENGINE_get_RSA(rsa->engine);
347 BN_init(&f); 356 BN_init(&f);
348 BN_init(&ret); 357 BN_init(&ret);
349 ctx=BN_CTX_new(); 358 ctx=BN_CTX_new();
350 if (ctx == NULL) goto err; 359 if (ctx == NULL) goto err;
351 360
352 num=BN_num_bytes(rsa->n); 361 num=BN_num_bytes(rsa->n);
353 buf=(unsigned char *)Malloc(num); 362 buf=(unsigned char *)OPENSSL_malloc(num);
354 if (buf == NULL) 363 if (buf == NULL)
355 { 364 {
356 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); 365 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
@@ -374,7 +383,7 @@ static int RSA_eay_public_decrypt(int flen, unsigned char *from,
374 goto err; 383 goto err;
375 } 384 }
376 385
377 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, 386 if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
378 rsa->_method_mod_n)) goto err; 387 rsa->_method_mod_n)) goto err;
379 388
380 p=buf; 389 p=buf;
@@ -402,17 +411,19 @@ err:
402 if (buf != NULL) 411 if (buf != NULL)
403 { 412 {
404 memset(buf,0,num); 413 memset(buf,0,num);
405 Free(buf); 414 OPENSSL_free(buf);
406 } 415 }
407 return(r); 416 return(r);
408 } 417 }
409 418
410static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) 419static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
411 { 420 {
421 const RSA_METHOD *meth;
412 BIGNUM r1,m1; 422 BIGNUM r1,m1;
413 int ret=0; 423 int ret=0;
414 BN_CTX *ctx; 424 BN_CTX *ctx;
415 425
426 meth = ENGINE_get_RSA(rsa->engine);
416 if ((ctx=BN_CTX_new()) == NULL) goto err; 427 if ((ctx=BN_CTX_new()) == NULL) goto err;
417 BN_init(&m1); 428 BN_init(&m1);
418 BN_init(&r1); 429 BN_init(&r1);
@@ -436,11 +447,11 @@ static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
436 } 447 }
437 448
438 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err; 449 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
439 if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx, 450 if (!meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,
440 rsa->_method_mod_q)) goto err; 451 rsa->_method_mod_q)) goto err;
441 452
442 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err; 453 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
443 if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx, 454 if (!meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,
444 rsa->_method_mod_p)) goto err; 455 rsa->_method_mod_p)) goto err;
445 456
446 if (!BN_sub(r0,r0,&m1)) goto err; 457 if (!BN_sub(r0,r0,&m1)) goto err;
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index 95e636d3f0..00c25adbc5 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -95,7 +95,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
95 * unsigned long can be larger */ 95 * unsigned long can be larger */
96 for (i=0; i<sizeof(unsigned long)*8; i++) 96 for (i=0; i<sizeof(unsigned long)*8; i++)
97 { 97 {
98 if (e_value & (1<<i)) 98 if (e_value & (1UL<<i))
99 BN_set_bit(rsa->e,i); 99 BN_set_bit(rsa->e,i);
100 } 100 }
101#else 101#else
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 074a4f5074..5e1e8fcdf3 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -62,6 +62,7 @@
62#include <openssl/lhash.h> 62#include <openssl/lhash.h>
63#include <openssl/bn.h> 63#include <openssl/bn.h>
64#include <openssl/rsa.h> 64#include <openssl/rsa.h>
65#include <openssl/engine.h>
65 66
66const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; 67const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
67 68
@@ -74,21 +75,49 @@ RSA *RSA_new(void)
74 return(RSA_new_method(NULL)); 75 return(RSA_new_method(NULL));
75 } 76 }
76 77
77void RSA_set_default_method(RSA_METHOD *meth) 78void RSA_set_default_openssl_method(RSA_METHOD *meth)
78 { 79 {
79 default_RSA_meth=meth; 80 ENGINE *e;
81 /* We'll need to notify the "openssl" ENGINE of this
82 * change too. We won't bother locking things down at
83 * our end as there was never any locking in these
84 * functions! */
85 if(default_RSA_meth != meth)
86 {
87 default_RSA_meth = meth;
88 e = ENGINE_by_id("openssl");
89 if(e)
90 {
91 ENGINE_set_RSA(e, meth);
92 ENGINE_free(e);
93 }
94 }
80 } 95 }
81 96
82RSA_METHOD *RSA_get_default_method(void) 97RSA_METHOD *RSA_get_default_openssl_method(void)
83{ 98{
99 if (default_RSA_meth == NULL)
100 {
101#ifdef RSA_NULL
102 default_RSA_meth=RSA_null_method();
103#else
104#ifdef RSAref
105 default_RSA_meth=RSA_PKCS1_RSAref();
106#else
107 default_RSA_meth=RSA_PKCS1_SSLeay();
108#endif
109#endif
110 }
111
84 return default_RSA_meth; 112 return default_RSA_meth;
85} 113}
86 114
87RSA_METHOD *RSA_get_method(RSA *rsa) 115RSA_METHOD *RSA_get_method(RSA *rsa)
88{ 116{
89 return rsa->meth; 117 return ENGINE_get_RSA(rsa->engine);
90} 118}
91 119
120#if 0
92RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth) 121RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth)
93{ 122{
94 RSA_METHOD *mtmp; 123 RSA_METHOD *mtmp;
@@ -98,34 +127,52 @@ RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth)
98 if (meth->init) meth->init(rsa); 127 if (meth->init) meth->init(rsa);
99 return mtmp; 128 return mtmp;
100} 129}
130#else
131int RSA_set_method(RSA *rsa, ENGINE *engine)
132{
133 ENGINE *mtmp;
134 RSA_METHOD *meth;
135 mtmp = rsa->engine;
136 meth = ENGINE_get_RSA(mtmp);
137 if (!ENGINE_init(engine))
138 return 0;
139 if (meth->finish) meth->finish(rsa);
140 rsa->engine = engine;
141 meth = ENGINE_get_RSA(engine);
142 if (meth->init) meth->init(rsa);
143 /* SHOULD ERROR CHECK THIS!!! */
144 ENGINE_finish(mtmp);
145 return 1;
146}
147#endif
101 148
149#if 0
102RSA *RSA_new_method(RSA_METHOD *meth) 150RSA *RSA_new_method(RSA_METHOD *meth)
151#else
152RSA *RSA_new_method(ENGINE *engine)
153#endif
103 { 154 {
155 RSA_METHOD *meth;
104 RSA *ret; 156 RSA *ret;
105 157
106 if (default_RSA_meth == NULL) 158 ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
107 {
108#ifdef RSA_NULL
109 default_RSA_meth=RSA_null_method();
110#else
111#ifdef RSAref
112 default_RSA_meth=RSA_PKCS1_RSAref();
113#else
114 default_RSA_meth=RSA_PKCS1_SSLeay();
115#endif
116#endif
117 }
118 ret=(RSA *)Malloc(sizeof(RSA));
119 if (ret == NULL) 159 if (ret == NULL)
120 { 160 {
121 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); 161 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
122 return(NULL); 162 return(NULL);
123 } 163 }
124 164
125 if (meth == NULL) 165 if (engine == NULL)
126 ret->meth=default_RSA_meth; 166 {
167 if((ret->engine=ENGINE_get_default_RSA()) == NULL)
168 {
169 OPENSSL_free(ret);
170 return NULL;
171 }
172 }
127 else 173 else
128 ret->meth=meth; 174 ret->engine=engine;
175 meth = ENGINE_get_RSA(ret->engine);
129 176
130 ret->pad=0; 177 ret->pad=0;
131 ret->version=0; 178 ret->version=0;
@@ -143,10 +190,10 @@ RSA *RSA_new_method(RSA_METHOD *meth)
143 ret->_method_mod_q=NULL; 190 ret->_method_mod_q=NULL;
144 ret->blinding=NULL; 191 ret->blinding=NULL;
145 ret->bignum_data=NULL; 192 ret->bignum_data=NULL;
146 ret->flags=ret->meth->flags; 193 ret->flags=meth->flags;
147 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 194 if ((meth->init != NULL) && !meth->init(ret))
148 { 195 {
149 Free(ret); 196 OPENSSL_free(ret);
150 ret=NULL; 197 ret=NULL;
151 } 198 }
152 else 199 else
@@ -156,6 +203,7 @@ RSA *RSA_new_method(RSA_METHOD *meth)
156 203
157void RSA_free(RSA *r) 204void RSA_free(RSA *r)
158 { 205 {
206 RSA_METHOD *meth;
159 int i; 207 int i;
160 208
161 if (r == NULL) return; 209 if (r == NULL) return;
@@ -175,8 +223,10 @@ void RSA_free(RSA *r)
175 223
176 CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data); 224 CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data);
177 225
178 if (r->meth->finish != NULL) 226 meth = ENGINE_get_RSA(r->engine);
179 r->meth->finish(r); 227 if (meth->finish != NULL)
228 meth->finish(r);
229 ENGINE_finish(r->engine);
180 230
181 if (r->n != NULL) BN_clear_free(r->n); 231 if (r->n != NULL) BN_clear_free(r->n);
182 if (r->e != NULL) BN_clear_free(r->e); 232 if (r->e != NULL) BN_clear_free(r->e);
@@ -187,8 +237,8 @@ void RSA_free(RSA *r)
187 if (r->dmq1 != NULL) BN_clear_free(r->dmq1); 237 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
188 if (r->iqmp != NULL) BN_clear_free(r->iqmp); 238 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
189 if (r->blinding != NULL) BN_BLINDING_free(r->blinding); 239 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
190 if (r->bignum_data != NULL) Free_locked(r->bignum_data); 240 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
191 Free(r); 241 OPENSSL_free(r);
192 } 242 }
193 243
194int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 244int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
@@ -217,30 +267,34 @@ int RSA_size(RSA *r)
217int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, 267int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to,
218 RSA *rsa, int padding) 268 RSA *rsa, int padding)
219 { 269 {
220 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); 270 return(ENGINE_get_RSA(rsa->engine)->rsa_pub_enc(flen,
271 from, to, rsa, padding));
221 } 272 }
222 273
223int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to, 274int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to,
224 RSA *rsa, int padding) 275 RSA *rsa, int padding)
225 { 276 {
226 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); 277 return(ENGINE_get_RSA(rsa->engine)->rsa_priv_enc(flen,
278 from, to, rsa, padding));
227 } 279 }
228 280
229int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to, 281int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to,
230 RSA *rsa, int padding) 282 RSA *rsa, int padding)
231 { 283 {
232 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); 284 return(ENGINE_get_RSA(rsa->engine)->rsa_priv_dec(flen,
285 from, to, rsa, padding));
233 } 286 }
234 287
235int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to, 288int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to,
236 RSA *rsa, int padding) 289 RSA *rsa, int padding)
237 { 290 {
238 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); 291 return(ENGINE_get_RSA(rsa->engine)->rsa_pub_dec(flen,
292 from, to, rsa, padding));
239 } 293 }
240 294
241int RSA_flags(RSA *r) 295int RSA_flags(RSA *r)
242 { 296 {
243 return((r == NULL)?0:r->meth->flags); 297 return((r == NULL)?0:ENGINE_get_RSA(r->engine)->flags);
244 } 298 }
245 299
246void RSA_blinding_off(RSA *rsa) 300void RSA_blinding_off(RSA *rsa)
@@ -274,7 +328,8 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
274 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; 328 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
275 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; 329 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
276 330
277 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) 331 if (!ENGINE_get_RSA(rsa->engine)->bn_mod_exp(A,A,
332 rsa->e,rsa->n,ctx,rsa->_method_mod_n))
278 goto err; 333 goto err;
279 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); 334 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
280 rsa->flags|=RSA_FLAG_BLINDING; 335 rsa->flags|=RSA_FLAG_BLINDING;
@@ -305,7 +360,7 @@ int RSA_memory_lock(RSA *r)
305 j=1; 360 j=1;
306 for (i=0; i<6; i++) 361 for (i=0; i<6; i++)
307 j+= (*t[i])->top; 362 j+= (*t[i])->top;
308 if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) 363 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
309 { 364 {
310 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); 365 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
311 return(0); 366 return(0);
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index 1465c01f4f..fd0b7f361f 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -34,7 +34,7 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
34 return (0); 34 return (0);
35 } 35 }
36 36
37 dbmask = Malloc(emlen - SHA_DIGEST_LENGTH); 37 dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH);
38 if (dbmask == NULL) 38 if (dbmask == NULL)
39 { 39 {
40 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 40 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
@@ -66,7 +66,7 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
66 for (i = 0; i < SHA_DIGEST_LENGTH; i++) 66 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
67 seed[i] ^= seedmask[i]; 67 seed[i] ^= seedmask[i];
68 68
69 Free(dbmask); 69 OPENSSL_free(dbmask);
70 return (1); 70 return (1);
71 } 71 }
72 72
@@ -86,7 +86,7 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
86 } 86 }
87 87
88 dblen = num - SHA_DIGEST_LENGTH; 88 dblen = num - SHA_DIGEST_LENGTH;
89 db = Malloc(dblen); 89 db = OPENSSL_malloc(dblen);
90 if (db == NULL) 90 if (db == NULL)
91 { 91 {
92 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 92 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
@@ -128,7 +128,7 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
128 memcpy(to, db + i, mlen); 128 memcpy(to, db + i, mlen);
129 } 129 }
130 } 130 }
131 Free(db); 131 OPENSSL_free(db);
132 return (mlen); 132 return (mlen);
133 } 133 }
134 134
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index 61efb0b00f..c77f4381ff 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -81,7 +81,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
81 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); 81 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
82 return(0); 82 return(0);
83 } 83 }
84 s=(unsigned char *)Malloc((unsigned int)j+1); 84 s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
85 if (s == NULL) 85 if (s == NULL)
86 { 86 {
87 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); 87 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
@@ -96,7 +96,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
96 *siglen=i; 96 *siglen=i;
97 97
98 memset(s,0,(unsigned int)j+1); 98 memset(s,0,(unsigned int)j+1);
99 Free(s); 99 OPENSSL_free(s);
100 return(ret); 100 return(ret);
101 } 101 }
102 102
@@ -114,7 +114,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m,
114 return(0); 114 return(0);
115 } 115 }
116 116
117 s=(unsigned char *)Malloc((unsigned int)siglen); 117 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
118 if (s == NULL) 118 if (s == NULL)
119 { 119 {
120 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); 120 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
@@ -138,7 +138,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m,
138err: 138err:
139 if (sig != NULL) M_ASN1_OCTET_STRING_free(sig); 139 if (sig != NULL) M_ASN1_OCTET_STRING_free(sig);
140 memset(s,0,(unsigned int)siglen); 140 memset(s,0,(unsigned int)siglen);
141 Free(s); 141 OPENSSL_free(s);
142 return(ret); 142 return(ret);
143 } 143 }
144 144
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 05bb7fb74a..cf00876292 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -62,6 +62,7 @@
62#include <openssl/rsa.h> 62#include <openssl/rsa.h>
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/engine.h>
65 66
66/* Size of an SSL signature: MD5+SHA1 */ 67/* Size of an SSL signature: MD5+SHA1 */
67#define SSL_SIG_LENGTH 36 68#define SSL_SIG_LENGTH 36
@@ -76,7 +77,8 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len,
76 X509_ALGOR algor; 77 X509_ALGOR algor;
77 ASN1_OCTET_STRING digest; 78 ASN1_OCTET_STRING digest;
78 if(rsa->flags & RSA_FLAG_SIGN_VER) 79 if(rsa->flags & RSA_FLAG_SIGN_VER)
79 return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa); 80 return ENGINE_get_RSA(rsa->engine)->rsa_sign(type,
81 m, m_len, sigret, siglen, rsa);
80 /* Special case: SSL signature, just check the length */ 82 /* Special case: SSL signature, just check the length */
81 if(type == NID_md5_sha1) { 83 if(type == NID_md5_sha1) {
82 if(m_len != SSL_SIG_LENGTH) { 84 if(m_len != SSL_SIG_LENGTH) {
@@ -115,7 +117,7 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len,
115 return(0); 117 return(0);
116 } 118 }
117 if(type != NID_md5_sha1) { 119 if(type != NID_md5_sha1) {
118 s=(unsigned char *)Malloc((unsigned int)j+1); 120 s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1);
119 if (s == NULL) 121 if (s == NULL)
120 { 122 {
121 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); 123 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
@@ -132,7 +134,7 @@ int RSA_sign(int type, unsigned char *m, unsigned int m_len,
132 134
133 if(type != NID_md5_sha1) { 135 if(type != NID_md5_sha1) {
134 memset(s,0,(unsigned int)j+1); 136 memset(s,0,(unsigned int)j+1);
135 Free(s); 137 OPENSSL_free(s);
136 } 138 }
137 return(ret); 139 return(ret);
138 } 140 }
@@ -151,9 +153,10 @@ int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
151 } 153 }
152 154
153 if(rsa->flags & RSA_FLAG_SIGN_VER) 155 if(rsa->flags & RSA_FLAG_SIGN_VER)
154 return rsa->meth->rsa_verify(dtype, m, m_len, sigbuf, siglen, rsa); 156 return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype,
157 m, m_len, sigbuf, siglen, rsa);
155 158
156 s=(unsigned char *)Malloc((unsigned int)siglen); 159 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen);
157 if (s == NULL) 160 if (s == NULL)
158 { 161 {
159 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); 162 RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
@@ -215,7 +218,7 @@ int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
215err: 218err:
216 if (sig != NULL) X509_SIG_free(sig); 219 if (sig != NULL) X509_SIG_free(sig);
217 memset(s,0,(unsigned int)siglen); 220 memset(s,0,(unsigned int)siglen);
218 Free(s); 221 OPENSSL_free(s);
219 return(ret); 222 return(ret);
220 } 223 }
221 224
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
index 81a857c813..482f4a8273 100644
--- a/src/lib/libcrypto/rsa/rsa_ssl.c
+++ b/src/lib/libcrypto/rsa/rsa_ssl.c
@@ -134,7 +134,7 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from,
134 { 134 {
135 if (p[k] != 0x03) break; 135 if (p[k] != 0x03) break;
136 } 136 }
137 if (k == 0) 137 if (k == -1)
138 { 138 {
139 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK); 139 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK);
140 return(-1); 140 return(-1);