From 69f1afc0b85ae4f66d379d5a4a7606ffc6e844d8 Mon Sep 17 00:00:00 2001 From: hristov Date: Wed, 25 Aug 2021 11:28:44 +0200 Subject: [PATCH] Possibility to use openssl 1.0.X --- cpp/src/gandiva/hash_utils.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cpp/src/gandiva/hash_utils.cc b/cpp/src/gandiva/hash_utils.cc index 5019d45ca8b20..51917b7a15caf 100644 --- a/cpp/src/gandiva/hash_utils.cc +++ b/cpp/src/gandiva/hash_utils.cc @@ -20,6 +20,7 @@ #include "arrow/util/logging.h" #include "gandiva/gdv_function_stubs.h" #include "openssl/evp.h" +#include "openssl/opensslv.h" namespace gandiva { @@ -67,7 +68,11 @@ GANDIVA_EXPORT const char* gdv_hash_using_openssl(int64_t context, const void* message, size_t message_length, const EVP_MD* hash_type, uint32_t result_buf_size, int32_t* out_length) { +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX* md_ctx = EVP_MD_CTX_new(); +#else + EVP_MD_CTX* md_ctx = EVP_MD_CTX_create(); +#endif if (md_ctx == nullptr) { gdv_fn_context_set_error_msg(context, @@ -82,8 +87,11 @@ const char* gdv_hash_using_openssl(int64_t context, const void* message, EVP_DigestUpdate(md_ctx, message, message_length) != evp_success_status) { gdv_fn_context_set_error_msg(context, "Could not obtain the hash for the defined value."); +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX_free(md_ctx); - +#else + EVP_MD_CTX_destroy(md_ctx); +#endif *out_length = 0; return ""; } @@ -94,7 +102,11 @@ const char* gdv_hash_using_openssl(int64_t context, const void* message, if (result == nullptr) { gdv_fn_context_set_error_msg(context, "Could not allocate memory for SHA processing"); +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX_free(md_ctx); +#else + EVP_MD_CTX_destroy(md_ctx); +#endif *out_length = 0; return ""; } @@ -105,7 +117,11 @@ const char* gdv_hash_using_openssl(int64_t context, const void* message, if (result_length != hash_digest_size && result_buf_size != (2 * hash_digest_size)) { gdv_fn_context_set_error_msg(context, "Could not obtain the hash for the defined value"); +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX_free(md_ctx); +#else + EVP_MD_CTX_destroy(md_ctx); +#endif OPENSSL_free(result); *out_length = 0; @@ -119,7 +135,11 @@ const char* gdv_hash_using_openssl(int64_t context, const void* message, gdv_fn_context_set_error_msg(context, "Could not allocate memory for the result buffer"); // Free the resources used by the EVP +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX_free(md_ctx); +#else + EVP_MD_CTX_destroy(md_ctx); +#endif OPENSSL_free(result); *out_length = 0; @@ -136,7 +156,11 @@ const char* gdv_hash_using_openssl(int64_t context, const void* message, } // Free the resources used by the EVP to avoid memory leaks +#if OPENSSL_VERSION_NUMBER >= 0x1010000fL EVP_MD_CTX_free(md_ctx); +#else + EVP_MD_CTX_destroy(md_ctx); +#endif OPENSSL_free(result); *out_length = result_buf_size;