@@ -58,7 +58,14 @@ const char* s3fs_crypt_lib_name()
58
58
bool s3fs_init_global_ssl ()
59
59
{
60
60
ERR_load_crypto_strings ();
61
+
62
+ // [NOTE]
63
+ // OpenSSL 3.0 loads error strings automatically so these functions are not needed.
64
+ //
65
+ #ifndef USE_OPENSSL_30
61
66
ERR_load_BIO_strings ();
67
+ #endif
68
+
62
69
OpenSSL_add_all_algorithms ();
63
70
return true ;
64
71
}
@@ -245,8 +252,67 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz
245
252
return s3fs_HMAC_RAW (key, keylen, data, datalen, digest, digestlen, true );
246
253
}
247
254
255
+ #ifdef USE_OPENSSL_30
248
256
// -------------------------------------------------------------------
249
- // Utility Function for MD5
257
+ // Utility Function for MD5 (OpenSSL >= 3.0)
258
+ // -------------------------------------------------------------------
259
+ // [NOTE]
260
+ // OpenSSL 3.0 deprecated the MD5_*** low-level encryption functions,
261
+ // so we should use the high-level EVP API instead.
262
+ //
263
+ size_t get_md5_digest_length ()
264
+ {
265
+ return EVP_MD_size (EVP_md5 ());
266
+ }
267
+
268
+ unsigned char * s3fs_md5_fd (int fd, off_t start, off_t size)
269
+ {
270
+ EVP_MD_CTX* mdctx;
271
+ unsigned char * md5_digest;
272
+ unsigned int md5_digest_len = get_md5_digest_length ();
273
+ off_t bytes;
274
+
275
+ if (-1 == size){
276
+ struct stat st;
277
+ if (-1 == fstat (fd, &st)){
278
+ return NULL ;
279
+ }
280
+ size = st.st_size ;
281
+ }
282
+
283
+ // instead of MD5_Init
284
+ mdctx = EVP_MD_CTX_new ();
285
+ EVP_DigestInit_ex (mdctx, EVP_md5 (), NULL );
286
+
287
+ for (off_t total = 0 ; total < size; total += bytes){
288
+ const off_t len = 512 ;
289
+ char buf[len];
290
+ bytes = len < (size - total) ? len : (size - total);
291
+ bytes = pread (fd, buf, bytes, start + total);
292
+ if (0 == bytes){
293
+ // end of file
294
+ break ;
295
+ }else if (-1 == bytes){
296
+ // error
297
+ S3FS_PRN_ERR (" file read error(%d)" , errno);
298
+ EVP_MD_CTX_free (mdctx);
299
+ return NULL ;
300
+ }
301
+ // instead of MD5_Update
302
+ EVP_DigestUpdate (mdctx, buf, bytes);
303
+ }
304
+
305
+ // instead of MD5_Final
306
+ md5_digest = new unsigned char [md5_digest_len];
307
+ EVP_DigestFinal_ex (mdctx, md5_digest, &md5_digest_len);
308
+ EVP_MD_CTX_free (mdctx);
309
+
310
+ return md5_digest;
311
+ }
312
+
313
+ #else
314
+ // -------------------------------------------------------------------
315
+ // Utility Function for MD5 (OpenSSL < 3.0)
250
316
// -------------------------------------------------------------------
251
317
size_t get_md5_digest_length ()
252
318
{
@@ -290,6 +356,7 @@ unsigned char* s3fs_md5_fd(int fd, off_t start, off_t size)
290
356
291
357
return result;
292
358
}
359
+ #endif
293
360
294
361
// -------------------------------------------------------------------
295
362
// Utility Function for SHA256
0 commit comments