diff options
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r-- | lib/crypto/c_src/cipher.c | 17 | ||||
-rw-r--r-- | lib/crypto/c_src/cipher.h | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/crypto.c | 11 |
3 files changed, 20 insertions, 12 deletions
diff --git a/lib/crypto/c_src/cipher.c b/lib/crypto/c_src/cipher.c index 6eba6aa49b..6580cb183f 100644 --- a/lib/crypto/c_src/cipher.c +++ b/lib/crypto/c_src/cipher.c @@ -73,11 +73,26 @@ static struct cipher_type_t cipher_types[] = #ifdef HAVE_EVP_AES_CTR ErlNifResourceType* evp_cipher_ctx_rtype; -void evp_cipher_ctx_dtor(ErlNifEnv* env, struct evp_cipher_ctx* ctx) { +static void evp_cipher_ctx_dtor(ErlNifEnv* env, struct evp_cipher_ctx* ctx) { EVP_CIPHER_CTX_free(ctx->ctx); } #endif +int init_cipher_ctx(ErlNifEnv *env) { +#ifdef HAVE_EVP_AES_CTR + evp_cipher_ctx_rtype = enif_open_resource_type(env, NULL, "EVP_CIPHER_CTX", + (ErlNifResourceDtor*) evp_cipher_ctx_dtor, + ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER, + NULL); + if (evp_cipher_ctx_rtype == NULL) { + PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_CIPHER_CTX'"); + return 0; + } +#endif + + return 1; +} + void init_cipher_types(ErlNifEnv* env) { struct cipher_type_t* p = cipher_types; diff --git a/lib/crypto/c_src/cipher.h b/lib/crypto/c_src/cipher.h index 3abaabda69..3fb27f0ba3 100644 --- a/lib/crypto/c_src/cipher.h +++ b/lib/crypto/c_src/cipher.h @@ -40,10 +40,10 @@ extern ErlNifResourceType* evp_cipher_ctx_rtype; struct evp_cipher_ctx { EVP_CIPHER_CTX* ctx; }; - -void evp_cipher_ctx_dtor(ErlNifEnv* env, struct evp_cipher_ctx* ctx); #endif +int init_cipher_ctx(ErlNifEnv *env); + void init_cipher_types(ErlNifEnv* env); struct cipher_type_t* get_cipher_type(ERL_NIF_TERM type, size_t key_len); diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c index df2e4a9f4b..5b42b976bb 100644 --- a/lib/crypto/c_src/crypto.c +++ b/lib/crypto/c_src/crypto.c @@ -187,17 +187,10 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info) if (!init_hash_ctx(env)) { return __LINE__; } - -#ifdef HAVE_EVP_AES_CTR - evp_cipher_ctx_rtype = enif_open_resource_type(env, NULL, "EVP_CIPHER_CTX", - (ErlNifResourceDtor*) evp_cipher_ctx_dtor, - ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER, - NULL); - if (!evp_cipher_ctx_rtype) { - PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_CIPHER_CTX'"); + if (!init_cipher_ctx(env)) { return __LINE__; } -#endif + #ifdef HAS_ENGINE_SUPPORT engine_ctx_rtype = enif_open_resource_type(env, NULL, "ENGINE_CTX", (ErlNifResourceDtor*) engine_ctx_dtor, |