Skip to content

Commit b7f446e

Browse files
committed
libhashkit/aes: make using openssl configurable
1 parent 2aab181 commit b7f446e

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

CMakeConfig.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ if(NOT DEFINED ENV{ENABLE_MEMASLAP})
6565
endif()
6666
option(ENABLE_MEMASLAP "enable memaslap client"
6767
$ENV{ENABLE_MEMASLAP})
68+
option(ENABLE_OPENSSL_CRYPTO
69+
"enable OpenSSL's libcrypto instead of bundled AES implementation"
70+
$ENV{ENABLE_OPENSSL_CRYPTO})
6871

6972
if(BUILD_TESTING)
7073
set(MEMCACHED_BINARY "$ENV{MEMCACHED_BINARY}"

src/libhashkit/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ target_include_directories(libhashkit PUBLIC
4040
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
4141
$<INSTALL_INTERFACE:include>)
4242

43-
find_package(OpenSSL)
44-
if(NOT OPENSSL_FOUND)
45-
message(WARNING "crypto library not found")
46-
else()
47-
add_compile_definitions(WITH_OPENSSL)
48-
target_link_libraries(libhashkit PUBLIC OpenSSL::Crypto)
43+
if(ENABLE_OPENSSL_CRYPTO)
44+
find_package(OpenSSL)
45+
if(OPENSSL_FOUND)
46+
if(OPENSSL_CRYPTO_LIBRARY)
47+
target_compile_definitions(libhashkit PRIVATE HAVE_OPENSSL_CRYPTO)
48+
target_link_libraries(libhashkit PUBLIC OpenSSL::Crypto)
49+
else()
50+
message(WARNING "Could not find OpenSSL::Crypto")
51+
endif()
52+
endif()
4953
endif()
5054

5155
configure_file(hashkitcon.h.in hashkitcon.h @ONLY)

src/libhashkit/aes.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <cstring>
1919

20-
#ifdef WITH_OPENSSL
20+
#ifdef HAVE_OPENSSL_CRYPTO
2121

2222
#include <openssl/evp.h>
2323

@@ -250,4 +250,4 @@ hashkit_string_st *aes_decrypt(aes_key_t *_aes_key, const char *source, size_t s
250250

251251
return destination;
252252
}
253-
#endif
253+
#endif

src/libhashkit/aes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#pragma once
1717

18-
#ifdef WITH_OPENSSL
18+
#ifdef HAVE_OPENSSL_CRYPTO
1919

2020
#include <openssl/evp.h>
2121

@@ -45,4 +45,4 @@ hashkit_string_st *aes_decrypt(aes_key_t *_aes_key, const char *source, size_t s
4545
aes_key_t *aes_create_key(const char *key, const size_t key_length);
4646

4747
aes_key_t *aes_clone_key(aes_key_t *_aes_key);
48-
#endif
48+
#endif

src/libhashkit/encrypt.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
#include "libhashkit/common.h"
1717

18-
#ifdef WITH_OPENSSL
18+
#ifdef HAVE_OPENSSL_CRYPTO
1919
# include <openssl/evp.h>
2020
#endif
2121

2222
hashkit_string_st *hashkit_encrypt(hashkit_st *kit, const char *source, size_t source_length) {
23-
#ifdef WITH_OPENSSL
23+
#ifdef HAVE_OPENSSL_CRYPTO
2424
return aes_encrypt((encryption_context_t *) kit->_cryptographic_context,
2525
(const unsigned char *) source, source_length);
2626
#else
@@ -30,15 +30,15 @@ hashkit_string_st *hashkit_encrypt(hashkit_st *kit, const char *source, size_t s
3030
}
3131

3232
hashkit_string_st *hashkit_decrypt(hashkit_st *kit, const char *source, size_t source_length) {
33-
#ifdef WITH_OPENSSL
33+
#ifdef HAVE_OPENSSL_CRYPTO
3434
return aes_decrypt((encryption_context_t *) kit->_cryptographic_context,
3535
(const unsigned char *) source, source_length);
3636
#else
3737
return aes_decrypt((aes_key_t *)kit->_cryptographic_context, source, source_length);
3838
#endif
3939
}
4040

41-
#ifdef WITH_OPENSSL
41+
#ifdef HAVE_OPENSSL_CRYPTO
4242
bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
4343
kit->_cryptographic_context = (encryption_context_t *) malloc(sizeof(encryption_context_t));
4444
((encryption_context_t *) kit->_cryptographic_context)->encryption_context = EVP_CIPHER_CTX_new();
@@ -61,4 +61,4 @@ bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
6161

6262
return bool(kit->_cryptographic_context);
6363
}
64-
#endif
64+
#endif

src/libhashkit/hashkit.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "libhashkit/common.h"
1717

18-
#ifdef WITH_OPENSSL
18+
#ifdef HAVE_OPENSSL_CRYPTO
1919
# include <openssl/evp.h>
2020
#endif
2121

@@ -56,7 +56,7 @@ hashkit_st *hashkit_create(hashkit_st *self) {
5656
return self;
5757
}
5858

59-
#ifdef WITH_OPENSSL
59+
#ifdef HAVE_OPENSSL_CRYPTO
6060
static void cryptographic_context_free(encryption_context_t *context) {
6161
EVP_CIPHER_CTX_free(context->encryption_context);
6262
EVP_CIPHER_CTX_free(context->decryption_context);
@@ -65,7 +65,7 @@ static void cryptographic_context_free(encryption_context_t *context) {
6565
#endif
6666

6767
void hashkit_free(hashkit_st *self) {
68-
#ifdef WITH_OPENSSL
68+
#ifdef HAVE_OPENSSL_CRYPTO
6969
if (self and self->_cryptographic_context) {
7070
cryptographic_context_free((encryption_context_t *)self->_cryptographic_context);
7171
self->_cryptographic_context = NULL;
@@ -98,7 +98,7 @@ hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *source) {
9898
destination->base_hash = source->base_hash;
9999
destination->distribution_hash = source->distribution_hash;
100100
destination->flags = source->flags;
101-
#ifdef WITH_OPENSSL
101+
#ifdef HAVE_OPENSSL_CRYPTO
102102
if (destination->_cryptographic_context) {
103103
cryptographic_context_free((encryption_context_t *)destination->_cryptographic_context);
104104
destination->_cryptographic_context = NULL;

0 commit comments

Comments
 (0)