Skip to content
/ arrow Public
forked from apache/arrow

Commit

Permalink
Possibility to use openssl 1.0.X
Browse files Browse the repository at this point in the history
  • Loading branch information
hristov authored and ktf committed Oct 26, 2022
1 parent 2ce2cd6 commit 69f1afc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion cpp/src/gandiva/hash_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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,
Expand All @@ -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 "";
}
Expand All @@ -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 "";
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 69f1afc

Please sign in to comment.