From: Michael Wallner Date: Mon, 12 Jul 2021 13:57:32 +0000 (+0200) Subject: libhashkit/aes: keep API compatible X-Git-Tag: 1.1.1~21 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0d7a3e0e040ddf840d656b61f41419c252debcde;p=awesomized%2Flibmemcached libhashkit/aes: keep API compatible --- diff --git a/include/libhashkit-1.0/hashkit.h b/include/libhashkit-1.0/hashkit.h index 0f67e377..09b7edeb 100644 --- a/include/libhashkit-1.0/hashkit.h +++ b/include/libhashkit-1.0/hashkit.h @@ -49,7 +49,7 @@ struct hashkit_st { bool is_allocated : 1; } options; - void *_cryptographic_context; + void *_key; }; #ifdef __cplusplus diff --git a/src/libhashkit/encrypt.cc b/src/libhashkit/encrypt.cc index e7898a6a..effa299f 100644 --- a/src/libhashkit/encrypt.cc +++ b/src/libhashkit/encrypt.cc @@ -21,44 +21,44 @@ hashkit_string_st *hashkit_encrypt(hashkit_st *kit, const char *source, size_t source_length) { #ifdef HAVE_OPENSSL_CRYPTO - return aes_encrypt((encryption_context_t *) kit->_cryptographic_context, + return aes_encrypt((encryption_context_t *) kit->_key, (const unsigned char *) source, source_length); #else - return aes_encrypt((aes_key_t *) kit->_cryptographic_context, source, + return aes_encrypt((aes_key_t *) kit->_key, source, source_length); #endif } hashkit_string_st *hashkit_decrypt(hashkit_st *kit, const char *source, size_t source_length) { #ifdef HAVE_OPENSSL_CRYPTO - return aes_decrypt((encryption_context_t *) kit->_cryptographic_context, + return aes_decrypt((encryption_context_t *) kit->_key, (const unsigned char *) source, source_length); #else - return aes_decrypt((aes_key_t *)kit->_cryptographic_context, source, source_length); + return aes_decrypt((aes_key_t *)kit->_key, source, source_length); #endif } #ifdef HAVE_OPENSSL_CRYPTO bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) { - kit->_cryptographic_context = (encryption_context_t *) malloc(sizeof(encryption_context_t)); - ((encryption_context_t *) kit->_cryptographic_context)->encryption_context = EVP_CIPHER_CTX_new(); - ((encryption_context_t *) kit->_cryptographic_context)->decryption_context = EVP_CIPHER_CTX_new(); - if (((encryption_context_t *) kit->_cryptographic_context)->encryption_context == NULL - || ((encryption_context_t *) kit->_cryptographic_context)->decryption_context == NULL) + kit->_key = (encryption_context_t *) malloc(sizeof(encryption_context_t)); + ((encryption_context_t *) kit->_key)->encryption_context = EVP_CIPHER_CTX_new(); + ((encryption_context_t *) kit->_key)->decryption_context = EVP_CIPHER_CTX_new(); + if (((encryption_context_t *) kit->_key)->encryption_context == NULL + || ((encryption_context_t *) kit->_key)->decryption_context == NULL) { return false; } return aes_initialize((const unsigned char *) key, key_length, - (encryption_context_t *) kit->_cryptographic_context); + (encryption_context_t *) kit->_key); } #else bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) { - if (kit->_cryptographic_context) { - free(kit->_cryptographic_context); + if (kit->_key) { + free(kit->_key); } - kit->_cryptographic_context = aes_create_key(key, key_length); + kit->_key = aes_create_key(key, key_length); - return bool(kit->_cryptographic_context); + return bool(kit->_key); } #endif diff --git a/src/libhashkit/hashkit.cc b/src/libhashkit/hashkit.cc index d15d7372..e61b014d 100644 --- a/src/libhashkit/hashkit.cc +++ b/src/libhashkit/hashkit.cc @@ -27,7 +27,7 @@ static inline void _hashkit_init(hashkit_st *self) { self->distribution_hash.context = NULL; self->flags.is_base_same_distributed = true; - self->_cryptographic_context = NULL; + self->_key = NULL; } static inline hashkit_st *_hashkit_create(hashkit_st *self) { @@ -66,14 +66,14 @@ static void cryptographic_context_free(encryption_context_t *context) { void hashkit_free(hashkit_st *self) { #ifdef HAVE_OPENSSL_CRYPTO - if (self and self->_cryptographic_context) { - cryptographic_context_free((encryption_context_t *)self->_cryptographic_context); - self->_cryptographic_context = NULL; + if (self and self->_key) { + cryptographic_context_free((encryption_context_t *)self->_key); + self->_key = NULL; } #else - if (self and self->_cryptographic_context) { - free(self->_cryptographic_context); - self->_cryptographic_context = NULL; + if (self and self->_key) { + free(self->_key); + self->_key = NULL; } #endif @@ -99,19 +99,19 @@ hashkit_st *hashkit_clone(hashkit_st *destination, const hashkit_st *source) { destination->distribution_hash = source->distribution_hash; destination->flags = source->flags; #ifdef HAVE_OPENSSL_CRYPTO - if (destination->_cryptographic_context) { - cryptographic_context_free((encryption_context_t *)destination->_cryptographic_context); - destination->_cryptographic_context = NULL; + if (destination->_key) { + cryptographic_context_free((encryption_context_t *)destination->_key); + destination->_key = NULL; } - if (source->_cryptographic_context) { - destination->_cryptographic_context = - aes_clone_cryptographic_context(((encryption_context_t *) source->_cryptographic_context)); - if (destination->_cryptographic_context) { + if (source->_key) { + destination->_key = + aes_clone_cryptographic_context(((encryption_context_t *) source->_key)); + if (destination->_key) { } } #else - destination->_cryptographic_context = aes_clone_key(static_cast(source->_cryptographic_context)); + destination->_key = aes_clone_key(static_cast(source->_key)); #endif return destination; diff --git a/src/libmemcached/is.h b/src/libmemcached/is.h index 3987332f..229fd9b0 100644 --- a/src/libmemcached/is.h +++ b/src/libmemcached/is.h @@ -17,7 +17,7 @@ /* These are private */ #define memcached_is_allocated(__object) ((__object)->options.is_allocated) -#define memcached_is_encrypted(__object) (!!(__object)->hashkit._cryptographic_context) +#define memcached_is_encrypted(__object) (!!(__object)->hashkit._key) #define memcached_is_initialized(__object) ((__object)->options.is_initialized) #define memcached_is_purging(__object) ((__object)->state.is_purging) #define memcached_is_processing_input(__object) ((__object)->state.is_processing_input)