1*4882a593SmuzhiyunFrom a801d10a081e3130e24042256a43190c9eb6c112 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Eneas Queiroz <35331380+cotequeiroz@users.noreply.github.com>
3*4882a593SmuzhiyunDate: Wed, 23 May 2018 03:09:02 -0300
4*4882a593SmuzhiyunSubject: [PATCH] ibrcommon: added openssl 1.1 compatibility (#264)
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunThis patch adds compatibility to openssl 1.1.0.
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunBackported from master branch:
9*4882a593Smuzhiyunhttps://github.com/ibrdtn/ibrdtn/commit/a801d10a081e3130e24042256a43190c9eb6c112
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunSigned-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
12*4882a593SmuzhiyunSigned-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
13*4882a593Smuzhiyun---
14*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/HMacStream.cpp      | 11 +++---
15*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/HMacStream.h        |  2 +-
16*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/RSASHA256Stream.cpp | 28 +++++++------
17*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/RSASHA256Stream.h   |  2 +-
18*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/iostreamBIO.cpp     | 44 ++++++++++++++++-----
19*4882a593Smuzhiyun ibrcommon/ibrcommon/ssl/openssl_compat.h    | 38 ++++++++++++++++++
20*4882a593Smuzhiyun 6 files changed, 95 insertions(+), 30 deletions(-)
21*4882a593Smuzhiyun create mode 100644 ibrcommon/ibrcommon/ssl/openssl_compat.h
22*4882a593Smuzhiyun
23*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/HMacStream.cpp b/ibrcommon/ssl/HMacStream.cpp
24*4882a593Smuzhiyunindex e5d317e3..66d8ce42 100644
25*4882a593Smuzhiyun--- a/ibrcommon/ssl/HMacStream.cpp
26*4882a593Smuzhiyun+++ b/ibrcommon/ssl/HMacStream.cpp
27*4882a593Smuzhiyun@@ -20,29 +20,30 @@
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include "ibrcommon/ssl/HMacStream.h"
31*4882a593Smuzhiyun+#include "openssl_compat.h"
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun namespace ibrcommon
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	HMacStream::HMacStream(const unsigned char * const key, const int key_size)
36*4882a593Smuzhiyun 	 : HashStream(EVP_MAX_MD_SIZE, BUFF_SIZE), key_(key), key_size_(key_size)
37*4882a593Smuzhiyun 	{
38*4882a593Smuzhiyun-		HMAC_CTX_init(&ctx_);
39*4882a593Smuzhiyun-		HMAC_Init_ex(&ctx_, key_, key_size_, EVP_sha1(), NULL);
40*4882a593Smuzhiyun+		ctx_ = HMAC_CTX_new();
41*4882a593Smuzhiyun+		HMAC_Init_ex(ctx_, key_, key_size_, EVP_sha1(), NULL);
42*4882a593Smuzhiyun 	}
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun 	HMacStream::~HMacStream()
45*4882a593Smuzhiyun 	{
46*4882a593Smuzhiyun-		HMAC_CTX_cleanup(&ctx_);
47*4882a593Smuzhiyun+		HMAC_CTX_free(ctx_);
48*4882a593Smuzhiyun 	}
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun 	void HMacStream::update(char *buf, const size_t size)
51*4882a593Smuzhiyun 	{
52*4882a593Smuzhiyun 		// hashing
53*4882a593Smuzhiyun-		HMAC_Update(&ctx_, (unsigned char*)buf, size);
54*4882a593Smuzhiyun+		HMAC_Update(ctx_, (unsigned char*)buf, size);
55*4882a593Smuzhiyun 	}
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun 	void HMacStream::finalize(char * hash, unsigned int &size)
58*4882a593Smuzhiyun 	{
59*4882a593Smuzhiyun-		HMAC_Final(&ctx_, (unsigned char*)hash, &size);
60*4882a593Smuzhiyun+		HMAC_Final(ctx_, (unsigned char*)hash, &size);
61*4882a593Smuzhiyun 	}
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/HMacStream.h b/ibrcommon/ssl/HMacStream.h
64*4882a593Smuzhiyunindex 7dcea168..d04bceb8 100644
65*4882a593Smuzhiyun--- a/ibrcommon/ssl/HMacStream.h
66*4882a593Smuzhiyun+++ b/ibrcommon/ssl/HMacStream.h
67*4882a593Smuzhiyun@@ -44,7 +44,7 @@ namespace ibrcommon
68*4882a593Smuzhiyun 		const unsigned char * const key_;
69*4882a593Smuzhiyun 		const int key_size_;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun-		HMAC_CTX ctx_;
72*4882a593Smuzhiyun+		HMAC_CTX* ctx_;
73*4882a593Smuzhiyun 	};
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/RSASHA256Stream.cpp b/ibrcommon/ssl/RSASHA256Stream.cpp
77*4882a593Smuzhiyunindex d94430ed..d25c5d2f 100644
78*4882a593Smuzhiyun--- a/ibrcommon/ssl/RSASHA256Stream.cpp
79*4882a593Smuzhiyun+++ b/ibrcommon/ssl/RSASHA256Stream.cpp
80*4882a593Smuzhiyun@@ -21,6 +21,7 @@
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun #include "ibrcommon/ssl/RSASHA256Stream.h"
83*4882a593Smuzhiyun #include "ibrcommon/Logger.h"
84*4882a593Smuzhiyun+#include "openssl_compat.h"
85*4882a593Smuzhiyun #include <openssl/err.h>
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun namespace ibrcommon
88*4882a593Smuzhiyun@@ -30,11 +31,11 @@ namespace ibrcommon
89*4882a593Smuzhiyun 	{
90*4882a593Smuzhiyun 		// Initialize get pointer.  This should be zero so that underflow is called upon first read.
91*4882a593Smuzhiyun 		setp(&out_buf_[0], &out_buf_[BUFF_SIZE - 1]);
92*4882a593Smuzhiyun-		EVP_MD_CTX_init(&_ctx);
93*4882a593Smuzhiyun+		_ctx = EVP_MD_CTX_new();
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun 		if (!_verify)
96*4882a593Smuzhiyun 		{
97*4882a593Smuzhiyun-			if (!EVP_SignInit_ex(&_ctx, EVP_sha256(), NULL))
98*4882a593Smuzhiyun+			if (!EVP_SignInit_ex(_ctx, EVP_sha256(), NULL))
99*4882a593Smuzhiyun 			{
100*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to initialize the signature function" << IBRCOMMON_LOGGER_ENDL;
101*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
102*4882a593Smuzhiyun@@ -42,7 +43,7 @@ namespace ibrcommon
103*4882a593Smuzhiyun 		}
104*4882a593Smuzhiyun 		else
105*4882a593Smuzhiyun 		{
106*4882a593Smuzhiyun-			if (!EVP_VerifyInit_ex(&_ctx, EVP_sha256(), NULL))
107*4882a593Smuzhiyun+			if (!EVP_VerifyInit_ex(_ctx, EVP_sha256(), NULL))
108*4882a593Smuzhiyun 			{
109*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to initialize the verification function" << IBRCOMMON_LOGGER_ENDL;
110*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
111*4882a593Smuzhiyun@@ -52,18 +53,19 @@ namespace ibrcommon
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun 	RSASHA256Stream::~RSASHA256Stream()
114*4882a593Smuzhiyun 	{
115*4882a593Smuzhiyun-		EVP_MD_CTX_cleanup(&_ctx);
116*4882a593Smuzhiyun+		EVP_MD_CTX_free(_ctx);
117*4882a593Smuzhiyun 	}
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun 	void RSASHA256Stream::reset()
120*4882a593Smuzhiyun 	{
121*4882a593Smuzhiyun-		EVP_MD_CTX_cleanup(&_ctx);
122*4882a593Smuzhiyun-
123*4882a593Smuzhiyun-		EVP_MD_CTX_init(&_ctx);
124*4882a593Smuzhiyun+#if OPENSSL_VERSION_NUMBER < 0x10100000L
125*4882a593Smuzhiyun+		EVP_MD_CTX_cleanup(_ctx);
126*4882a593Smuzhiyun+#endif
127*4882a593Smuzhiyun+		EVP_MD_CTX_init(_ctx);
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun 		if (!_verify)
130*4882a593Smuzhiyun 		{
131*4882a593Smuzhiyun-			if (!EVP_SignInit_ex(&_ctx, EVP_sha256(), NULL))
132*4882a593Smuzhiyun+			if (!EVP_SignInit_ex(_ctx, EVP_sha256(), NULL))
133*4882a593Smuzhiyun 			{
134*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to initialize the signature function" << IBRCOMMON_LOGGER_ENDL;
135*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
136*4882a593Smuzhiyun@@ -71,7 +73,7 @@ namespace ibrcommon
137*4882a593Smuzhiyun 		}
138*4882a593Smuzhiyun 		else
139*4882a593Smuzhiyun 		{
140*4882a593Smuzhiyun-			if (!EVP_VerifyInit_ex(&_ctx, EVP_sha256(), NULL))
141*4882a593Smuzhiyun+			if (!EVP_VerifyInit_ex(_ctx, EVP_sha256(), NULL))
142*4882a593Smuzhiyun 			{
143*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to initialize the verfication function" << IBRCOMMON_LOGGER_ENDL;
144*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
145*4882a593Smuzhiyun@@ -91,7 +93,7 @@ namespace ibrcommon
146*4882a593Smuzhiyun 			std::vector<unsigned char> sign(EVP_PKEY_size(_pkey));
147*4882a593Smuzhiyun 			unsigned int size = EVP_PKEY_size(_pkey);
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun-			_return_code = EVP_SignFinal(&_ctx, &sign[0], &size, _pkey);
150*4882a593Smuzhiyun+			_return_code = EVP_SignFinal(_ctx, &sign[0], &size, _pkey);
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun 			_sign = std::string((const char*)&sign[0], size);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun@@ -107,7 +109,7 @@ namespace ibrcommon
155*4882a593Smuzhiyun 		if (!_sign_valid)
156*4882a593Smuzhiyun 		{
157*4882a593Smuzhiyun 			sync();
158*4882a593Smuzhiyun-			_return_code = EVP_VerifyFinal(&_ctx, reinterpret_cast<const unsigned char *>(their_sign.c_str()), static_cast<unsigned int>(their_sign.size()), _pkey);
159*4882a593Smuzhiyun+			_return_code = EVP_VerifyFinal(_ctx, reinterpret_cast<const unsigned char *>(their_sign.c_str()), static_cast<unsigned int>(their_sign.size()), _pkey);
160*4882a593Smuzhiyun 			_sign_valid = true;
161*4882a593Smuzhiyun 		}
162*4882a593Smuzhiyun 		return _return_code;
163*4882a593Smuzhiyun@@ -145,7 +147,7 @@ namespace ibrcommon
164*4882a593Smuzhiyun 		if (!_verify)
165*4882a593Smuzhiyun 			// hashing
166*4882a593Smuzhiyun 		{
167*4882a593Smuzhiyun-			if (!EVP_SignUpdate(&_ctx, &out_buf_[0], iend - ibegin))
168*4882a593Smuzhiyun+			if (!EVP_SignUpdate(_ctx, &out_buf_[0], iend - ibegin))
169*4882a593Smuzhiyun 			{
170*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to feed data into the signature function" << IBRCOMMON_LOGGER_ENDL;
171*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
172*4882a593Smuzhiyun@@ -153,7 +155,7 @@ namespace ibrcommon
173*4882a593Smuzhiyun 		}
174*4882a593Smuzhiyun 		else
175*4882a593Smuzhiyun 		{
176*4882a593Smuzhiyun-			if (!EVP_VerifyUpdate(&_ctx, &out_buf_[0], iend - ibegin))
177*4882a593Smuzhiyun+			if (!EVP_VerifyUpdate(_ctx, &out_buf_[0], iend - ibegin))
178*4882a593Smuzhiyun 			{
179*4882a593Smuzhiyun 				IBRCOMMON_LOGGER_TAG("RSASHA256Stream", critical) << "failed to feed data into the verification function" << IBRCOMMON_LOGGER_ENDL;
180*4882a593Smuzhiyun 				ERR_print_errors_fp(stderr);
181*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/RSASHA256Stream.h b/ibrcommon/ssl/RSASHA256Stream.h
182*4882a593Smuzhiyunindex 344f8e10..6f3a1168 100644
183*4882a593Smuzhiyun--- a/ibrcommon/ssl/RSASHA256Stream.h
184*4882a593Smuzhiyun+++ b/ibrcommon/ssl/RSASHA256Stream.h
185*4882a593Smuzhiyun@@ -106,7 +106,7 @@ namespace ibrcommon
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun 		/** the context in which the streamed data will be feed into for
188*4882a593Smuzhiyun 		calculation of the hash/signature */
189*4882a593Smuzhiyun-		EVP_MD_CTX _ctx;
190*4882a593Smuzhiyun+		EVP_MD_CTX * _ctx;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun 		/** tells if the context needs to be finalized to get a valid signature or
193*4882a593Smuzhiyun 		verification */
194*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/iostreamBIO.cpp b/ibrcommon/ssl/iostreamBIO.cpp
195*4882a593Smuzhiyunindex 18c1b55c..ea6c63eb 100644
196*4882a593Smuzhiyun--- a/ibrcommon/ssl/iostreamBIO.cpp
197*4882a593Smuzhiyun+++ b/ibrcommon/ssl/iostreamBIO.cpp
198*4882a593Smuzhiyun@@ -23,6 +23,7 @@
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun #include "ibrcommon/Logger.h"
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun+#include "openssl_compat.h"
203*4882a593Smuzhiyun #include <openssl/err.h>
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun namespace ibrcommon
206*4882a593Smuzhiyun@@ -42,7 +43,20 @@ static int create(BIO *bio);
207*4882a593Smuzhiyun //static int destroy(BIO *bio);
208*4882a593Smuzhiyun //static long (*callback_ctrl)(BIO *, int, bio_info_cb *);
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun-
211*4882a593Smuzhiyun+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
212*4882a593Smuzhiyun+BIO_METHOD * BIO_iostream_method()
213*4882a593Smuzhiyun+{
214*4882a593Smuzhiyun+	static BIO_METHOD *iostream_method = NULL;
215*4882a593Smuzhiyun+	if (iostream_method) {
216*4882a593Smuzhiyun+		iostream_method = BIO_meth_new(iostreamBIO::type, iostreamBIO::name);
217*4882a593Smuzhiyun+		BIO_meth_set_write(iostream_method, bwrite);
218*4882a593Smuzhiyun+		BIO_meth_set_read(iostream_method, bread);
219*4882a593Smuzhiyun+		BIO_meth_set_ctrl(iostream_method, ctrl);
220*4882a593Smuzhiyun+		BIO_meth_set_create(iostream_method, create);
221*4882a593Smuzhiyun+	}
222*4882a593Smuzhiyun+	return iostream_method;
223*4882a593Smuzhiyun+}
224*4882a593Smuzhiyun+#else
225*4882a593Smuzhiyun static BIO_METHOD iostream_method =
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun 		iostreamBIO::type,
228*4882a593Smuzhiyun@@ -56,12 +70,17 @@ static BIO_METHOD iostream_method =
229*4882a593Smuzhiyun 		NULL,//destroy,
230*4882a593Smuzhiyun 		NULL//callback_ctrl
231*4882a593Smuzhiyun };
232*4882a593Smuzhiyun+BIO_METHOD * BIO_iostream_method()
233*4882a593Smuzhiyun+{
234*4882a593Smuzhiyun+	return &iostream_method;
235*4882a593Smuzhiyun+}
236*4882a593Smuzhiyun+#endif
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun iostreamBIO::iostreamBIO(iostream *stream)
239*4882a593Smuzhiyun 	:	_stream(stream)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	/* create BIO */
242*4882a593Smuzhiyun-	_bio = BIO_new(&iostream_method);
243*4882a593Smuzhiyun+	_bio = BIO_new(BIO_iostream_method());
244*4882a593Smuzhiyun 	if(!_bio){
245*4882a593Smuzhiyun 		/* creation failed, throw exception */
246*4882a593Smuzhiyun 		char err_buf[ERR_BUF_SIZE];
247*4882a593Smuzhiyun@@ -72,7 +91,7 @@ iostreamBIO::iostreamBIO(iostream *stream)
248*4882a593Smuzhiyun 	}
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun 	/* save the iostream in the bio object */
251*4882a593Smuzhiyun-	_bio->ptr = stream;
252*4882a593Smuzhiyun+	BIO_set_data(_bio, (void *) stream);
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun BIO * iostreamBIO::getBIO(){
256*4882a593Smuzhiyun@@ -81,10 +100,10 @@ BIO * iostreamBIO::getBIO(){
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun static int create(BIO *bio)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun-	bio->ptr = NULL;
261*4882a593Smuzhiyun-	/* (from openssl memory bio) */
262*4882a593Smuzhiyun-	bio->shutdown=1;
263*4882a593Smuzhiyun-	bio->init=1;
264*4882a593Smuzhiyun+	BIO_set_data(bio, NULL);
265*4882a593Smuzhiyun+	BIO_set_shutdown(bio, 1);
266*4882a593Smuzhiyun+	BIO_set_init(bio, 1);
267*4882a593Smuzhiyun+#if OPENSSL_VERSION_NUMBER < 0x10100000L
268*4882a593Smuzhiyun 	/* from bss_mem.c (openssl):
269*4882a593Smuzhiyun 	 * bio->num is used to hold the value to return on 'empty', if it is
270*4882a593Smuzhiyun 	 * 0, should_retry is not set
271*4882a593Smuzhiyun@@ -93,6 +112,7 @@ static int create(BIO *bio)
272*4882a593Smuzhiyun 	 * it is set to 0 since the underlying stream is blocking
273*4882a593Smuzhiyun 	 */
274*4882a593Smuzhiyun 	bio->num= 0;
275*4882a593Smuzhiyun+#endif
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun 	return 1;
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun@@ -102,7 +122,7 @@ static int create(BIO *bio)
280*4882a593Smuzhiyun static long ctrl(BIO *bio, int cmd, long  num, void *)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun 	long ret;
283*4882a593Smuzhiyun-	iostream *stream = reinterpret_cast<iostream*>(bio->ptr);
284*4882a593Smuzhiyun+	iostream *stream = reinterpret_cast<iostream*>(BIO_get_data(bio));
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun 	IBRCOMMON_LOGGER_DEBUG_TAG("iostreamBIO", 90) << "ctrl called, cmd: " << cmd << ", num: " << num << "." << IBRCOMMON_LOGGER_ENDL;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun@@ -147,8 +167,12 @@ static long ctrl(BIO *bio, int cmd, long  num, void *)
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun static int bread(BIO *bio, char *buf, int len)
291*4882a593Smuzhiyun {
292*4882a593Smuzhiyun-	iostream *stream = reinterpret_cast<iostream*>(bio->ptr);
293*4882a593Smuzhiyun+	iostream *stream = reinterpret_cast<iostream*>(BIO_get_data(bio));
294*4882a593Smuzhiyun+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
295*4882a593Smuzhiyun+	int num_bytes = 0;
296*4882a593Smuzhiyun+#else
297*4882a593Smuzhiyun 	int num_bytes = bio->num;
298*4882a593Smuzhiyun+#endif
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun 	try{
301*4882a593Smuzhiyun 		/* make sure to read at least 1 byte and then read as much as we can */
302*4882a593Smuzhiyun@@ -170,7 +194,7 @@ static int bwrite(BIO *bio, const char *buf, int len)
303*4882a593Smuzhiyun 	if(len == 0){
304*4882a593Smuzhiyun 		return 0;
305*4882a593Smuzhiyun 	}
306*4882a593Smuzhiyun-	iostream *stream = reinterpret_cast<iostream*>(bio->ptr);
307*4882a593Smuzhiyun+	iostream *stream = reinterpret_cast<iostream*>(BIO_get_data(bio));
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun 	/* write the data */
310*4882a593Smuzhiyun 	try{
311*4882a593Smuzhiyundiff --git a/ibrcommon/ssl/openssl_compat.h b/ibrcommon/ssl/openssl_compat.h
312*4882a593Smuzhiyunnew file mode 100644
313*4882a593Smuzhiyunindex 00000000..e491677f
314*4882a593Smuzhiyun--- /dev/null
315*4882a593Smuzhiyun+++ b/ibrcommon/ssl/openssl_compat.h
316*4882a593Smuzhiyun@@ -0,0 +1,38 @@
317*4882a593Smuzhiyun+#ifndef OPENSSL_COMPAT_H
318*4882a593Smuzhiyun+#define OPENSSL_COMPAT_H
319*4882a593Smuzhiyun+
320*4882a593Smuzhiyun+#include <openssl/crypto.h>
321*4882a593Smuzhiyun+#if OPENSSL_VERSION_NUMBER < 0x10100000L
322*4882a593Smuzhiyun+
323*4882a593Smuzhiyun+#include <openssl/evp.h>
324*4882a593Smuzhiyun+#include <openssl/hmac.h>
325*4882a593Smuzhiyun+
326*4882a593Smuzhiyun+static inline EVP_MD_CTX * EVP_MD_CTX_new()
327*4882a593Smuzhiyun+{
328*4882a593Smuzhiyun+	EVP_MD_CTX *ctx;
329*4882a593Smuzhiyun+
330*4882a593Smuzhiyun+	ctx = (EVP_MD_CTX *) OPENSSL_malloc(sizeof(EVP_MD_CTX));
331*4882a593Smuzhiyun+	EVP_MD_CTX_init(ctx);
332*4882a593Smuzhiyun+        return ctx;
333*4882a593Smuzhiyun+}
334*4882a593Smuzhiyun+#define EVP_MD_CTX_free(c) if (c != NULL) OPENSSL_free(c)
335*4882a593Smuzhiyun+
336*4882a593Smuzhiyun+static inline HMAC_CTX * HMAC_CTX_new()
337*4882a593Smuzhiyun+{
338*4882a593Smuzhiyun+        HMAC_CTX *ctx;
339*4882a593Smuzhiyun+
340*4882a593Smuzhiyun+        ctx = (HMAC_CTX *) OPENSSL_malloc(sizeof(HMAC_CTX));
341*4882a593Smuzhiyun+        HMAC_CTX_init(ctx);
342*4882a593Smuzhiyun+        return ctx;
343*4882a593Smuzhiyun+}
344*4882a593Smuzhiyun+#define HMAC_CTX_free(c) if (c != NULL) OPENSSL_free(c)
345*4882a593Smuzhiyun+
346*4882a593Smuzhiyun+#define BIO_get_data(b) b->ptr
347*4882a593Smuzhiyun+#define BIO_set_data(b, v) b->ptr=v
348*4882a593Smuzhiyun+#define BIO_set_shutdown(b, v) b->shutdown=v
349*4882a593Smuzhiyun+#define BIO_set_init(b, v) b->init=v
350*4882a593Smuzhiyun+
351*4882a593Smuzhiyun+#endif /* OPENSSL_VERSION_NUMBER */
352*4882a593Smuzhiyun+
353*4882a593Smuzhiyun+#endif /* OPENSSL_COMPAT_H */
354*4882a593Smuzhiyun+
355*4882a593Smuzhiyun--
356*4882a593Smuzhiyun2.18.0
357*4882a593Smuzhiyun
358