33
33
* SUCH DAMAGE.
34
34
*/
35
35
36
+ #include <openssl/opensslv.h>
37
+ #if (OPENSSL_VERSION_NUMBER >= 0x300000L )
38
+ #define IS_OPENSSL3 1
39
+ #endif
40
+
36
41
#include <openssl/x509.h>
37
42
#include <openssl/md5.h>
38
43
#include <openssl/ssl.h>
39
44
#include <openssl/err.h>
40
45
#include <openssl/pem.h>
41
46
#include <openssl/rand.h>
42
47
48
+ #include <assert.h>
43
49
#include <strings.h>
44
50
#include <string.h>
45
51
#include <syslog.h>
@@ -115,8 +121,16 @@ smtp_init_crypto(int fd, int feature, struct smtp_features* features)
115
121
116
122
/* XXX clean up on error/close */
117
123
/* Init SSL library */
124
+ #if (OPENSSL_VERSION_NUMBER >= 0x10100000L )
125
+ error = OPENSSL_init_ssl (0 , NULL );
126
+ if (error != 1 ) {
127
+ syslog (LOG_WARNING , "remote delivery deferred: SSL init failed: %s" , ssl_errstr ());
128
+ return (1 );
129
+ }
130
+ #else
118
131
SSL_library_init ();
119
132
SSL_load_error_strings ();
133
+ #endif
120
134
121
135
// Allow any possible version
122
136
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L )
@@ -225,7 +239,12 @@ void
225
239
hmac_md5 (unsigned char * text , int text_len , unsigned char * key , int key_len ,
226
240
unsigned char * digest )
227
241
{
228
- MD5_CTX context ;
242
+ #ifdef IS_OPENSSL3
243
+ EVP_MD * md ;
244
+ EVP_MD_CTX * context ;
245
+ #else
246
+ MD5_CTX context ;
247
+ #endif
229
248
unsigned char k_ipad [65 ]; /* inner padding -
230
249
* key XORd with ipad
231
250
*/
@@ -234,15 +253,23 @@ hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len,
234
253
*/
235
254
unsigned char tk [16 ];
236
255
int i ;
237
- /* if key is longer than 64 bytes reset it to key=MD5(key) */
238
- if (key_len > 64 ) {
239
-
240
- MD5_CTX tctx ;
241
256
242
- MD5_Init (& tctx );
243
- MD5_Update (& tctx , key , key_len );
244
- MD5_Final (tk , & tctx );
257
+ #ifdef IS_OPENSSL3
258
+ context = EVP_MD_CTX_new ();
259
+ assert (context != NULL );
260
+ #endif
245
261
262
+ /* if key is longer than 64 bytes reset it to key=MD5(key) */
263
+ if (key_len > 64 ) {
264
+ #ifdef IS_OPENSSL3
265
+ EVP_DigestInit_ex (context , md , NULL );
266
+ EVP_DigestUpdate (context , key , key_len );
267
+ EVP_DigestFinal_ex (context , tk , NULL );
268
+ #else
269
+ MD5_Init (& context );
270
+ MD5_Update (& context , key , key_len );
271
+ MD5_Final (tk , & context );
272
+ #endif
246
273
key = tk ;
247
274
key_len = 16 ;
248
275
}
@@ -270,14 +297,43 @@ hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len,
270
297
k_ipad [i ] ^= 0x36 ;
271
298
k_opad [i ] ^= 0x5c ;
272
299
}
300
+
301
+ #ifdef IS_OPENSSL3
302
+ /**
303
+ * Perform inner MD5.
304
+ */
305
+
306
+ /* Init context for first pass. */
307
+ EVP_DigestInit_ex (context , md , NULL );
308
+ /* Start with inner pad. */
309
+ EVP_DigestUpdate (context , k_ipad , 64 );
310
+ /* Update with text of datagram. */
311
+ EVP_DigestUpdate (context , text , text_len );
312
+ /* Finish up first pass. */
313
+ EVP_DigestFinal_ex (context , digest , NULL );
314
+
315
+ /**
316
+ * Perform outer MD5.
317
+ */
318
+
319
+ /* Re-init context for second pass. */
320
+ EVP_DigestInit_ex (context , md , NULL );
321
+ /* Start with outer pad. */
322
+ EVP_DigestUpdate (context , k_opad , 64 );
323
+ /* Update with results of first hash. */
324
+ EVP_DigestUpdate (context , digest , 16 );
325
+ /* Finish up second pass. */
326
+ EVP_DigestFinal_ex (context , digest , NULL );
327
+ #else
273
328
/*
274
329
* perform inner MD5
275
330
*/
276
331
MD5_Init (& context ); /* init context for 1st
277
332
* pass */
278
333
MD5_Update (& context , k_ipad , 64 ); /* start with inner pad */
279
334
MD5_Update (& context , text , text_len ); /* then text of datagram */
280
- MD5_Final (digest , & context ); /* finish up 1st pass */
335
+
336
+ MD5_Final (digest , & context ); /* finish up 1st pass */
281
337
/*
282
338
* perform outer MD5
283
339
*/
@@ -287,6 +343,7 @@ hmac_md5(unsigned char *text, int text_len, unsigned char *key, int key_len,
287
343
MD5_Update (& context , digest , 16 ); /* then results of 1st
288
344
* hash */
289
345
MD5_Final (digest , & context ); /* finish up 2nd pass */
346
+ #endif
290
347
}
291
348
292
349
/*
0 commit comments