diff options
Diffstat (limited to 'src/crypto/engine/engine.c')
-rw-r--r-- | src/crypto/engine/engine.c | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/src/crypto/engine/engine.c b/src/crypto/engine/engine.c index 5b8cf1c..6c3300d 100644 --- a/src/crypto/engine/engine.c +++ b/src/crypto/engine/engine.c @@ -15,6 +15,7 @@ #include <openssl/engine.h> #include <string.h> +#include <assert.h> #include <openssl/dh.h> #include <openssl/dsa.h> @@ -43,33 +44,23 @@ ENGINE *ENGINE_new(void) { } void ENGINE_free(ENGINE *engine) { - if (engine->dh_method != NULL) { - METHOD_unref(engine->dh_method); - } - + /* Methods are currently required to be static so are not unref'ed. */ OPENSSL_free(engine); } /* set_method takes a pointer to a method and its given size and sets - * |*out_member| to point to a copy of it. The copy is |compiled_size| bytes - * long and has zero padding if needed. */ + * |*out_member| to point to it. This function might want to be extended in the + * future to support making a copy of the method so that a stable ABI for + * ENGINEs can be supported. But, for the moment, all *_METHODS must be + * static. */ static int set_method(void **out_member, const void *method, size_t method_size, size_t compiled_size) { - void *copy = OPENSSL_malloc(compiled_size); - if (copy == NULL) { + const struct openssl_method_common_st *common = method; + if (method_size != compiled_size || !common->is_static) { return 0; } - memset(copy, 0, compiled_size); - - if (method_size > compiled_size) { - method_size = compiled_size; - } - memcpy(copy, method, method_size); - - METHOD_unref(*out_member); - *out_member = copy; - + *out_member = (void*) method; return 1; } @@ -114,25 +105,16 @@ ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) { } void METHOD_ref(void *method_in) { - struct openssl_method_common_st *method = method_in; - - if (method->is_static) { - return; - } - - CRYPTO_add(&method->references, 1, CRYPTO_LOCK_ENGINE); + assert(((struct openssl_method_common_st*) method_in)->is_static); } void METHOD_unref(void *method_in) { struct openssl_method_common_st *method = method_in; - if (method == NULL || method->is_static) { + if (method == NULL) { return; } - - if (CRYPTO_add(&method->references, -1, CRYPTO_LOCK_ENGINE) == 0) { - OPENSSL_free(method); - } + assert(method->is_static); } OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED); |