X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibhashkit%2Fhashkit.cc;h=d15d73725d167aeaa6e1db74f15c138ef22c57e1;hb=b7f446e55146456e368c3926347f4c771afcea8c;hp=d74128f2d4096290f6b39944e8df8956420dadfc;hpb=1a82d708fca6b4c379dc035d05763ee80aae6d72;p=awesomized%2Flibmemcached diff --git a/src/libhashkit/hashkit.cc b/src/libhashkit/hashkit.cc index d74128f2..d15d7372 100644 --- a/src/libhashkit/hashkit.cc +++ b/src/libhashkit/hashkit.cc @@ -1,6 +1,6 @@ /* +--------------------------------------------------------------------+ - | libmemcached - C/C++ Client Library for memcached | + | libmemcached-awesome - C/C++ Client Library for memcached | +--------------------------------------------------------------------+ | Redistribution and use in source and binary forms, with or without | | modification, are permitted under the terms of the BSD license. | @@ -9,12 +9,16 @@ | the terms online at: https://opensource.org/licenses/BSD-3-Clause | +--------------------------------------------------------------------+ | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | - | Copyright (c) 2020 Michael Wallner | + | Copyright (c) 2020-2021 Michael Wallner https://awesome.co/ | +--------------------------------------------------------------------+ */ #include "libhashkit/common.h" +#ifdef HAVE_OPENSSL_CRYPTO +# include +#endif + static inline void _hashkit_init(hashkit_st *self) { self->base_hash.function = hashkit_one_at_a_time; self->base_hash.context = NULL; @@ -23,7 +27,7 @@ static inline void _hashkit_init(hashkit_st *self) { self->distribution_hash.context = NULL; self->flags.is_base_same_distributed = true; - self->_key = NULL; + self->_cryptographic_context = NULL; } static inline hashkit_st *_hashkit_create(hashkit_st *self) { @@ -52,11 +56,26 @@ hashkit_st *hashkit_create(hashkit_st *self) { return self; } +#ifdef HAVE_OPENSSL_CRYPTO +static void cryptographic_context_free(encryption_context_t *context) { + EVP_CIPHER_CTX_free(context->encryption_context); + EVP_CIPHER_CTX_free(context->decryption_context); + free(context); +} +#endif + void hashkit_free(hashkit_st *self) { - if (self and self->_key) { - free(self->_key); - self->_key = NULL; +#ifdef HAVE_OPENSSL_CRYPTO + if (self and self->_cryptographic_context) { + cryptographic_context_free((encryption_context_t *)self->_cryptographic_context); + self->_cryptographic_context = NULL; + } +#else + if (self and self->_cryptographic_context) { + free(self->_cryptographic_context); + self->_cryptographic_context = NULL; } +#endif if (hashkit_is_allocated(self)) { free(self); @@ -79,7 +98,21 @@ hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *source) { destination->base_hash = source->base_hash; destination->distribution_hash = source->distribution_hash; destination->flags = source->flags; - destination->_key = aes_clone_key(static_cast(source->_key)); +#ifdef HAVE_OPENSSL_CRYPTO + if (destination->_cryptographic_context) { + cryptographic_context_free((encryption_context_t *)destination->_cryptographic_context); + destination->_cryptographic_context = NULL; + } + if (source->_cryptographic_context) { + destination->_cryptographic_context = + aes_clone_cryptographic_context(((encryption_context_t *) source->_cryptographic_context)); + if (destination->_cryptographic_context) { + + } + } +#else + destination->_cryptographic_context = aes_clone_key(static_cast(source->_cryptographic_context)); +#endif return destination; }