diff --git a/crypto/engine/engine.c b/crypto/engine/engine.c index 5b8cf1c5d..6c3300d35 100644 --- a/crypto/engine/engine.c +++ b/crypto/engine/engine.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -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); diff --git a/include/openssl/engine.h b/include/openssl/engine.h index 4a4f37de5..da242f6b8 100644 --- a/include/openssl/engine.h +++ b/include/openssl/engine.h @@ -78,12 +78,14 @@ OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine); * These functions take a void* type but actually operate on all method * structures. */ -/* METHOD_ref increments the reference count of |method|. */ -OPENSSL_EXPORT void METHOD_ref(void *method); +/* METHOD_ref increments the reference count of |method|. This is a no-op for + * now because all methods are currently static. */ +void METHOD_ref(void *method); /* METHOD_unref decrements the reference count of |method| and frees it if the - * reference count drops to zero. */ -OPENSSL_EXPORT void METHOD_unref(void *method); + * reference count drops to zero. This is a no-op for now because all methods + * are currently static. */ +void METHOD_unref(void *method); /* Private functions. */