aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2018-12-21 07:58:02 -0800
committerDoug Hogan <[email protected]>2018-12-21 08:40:50 -0800
commitc1eb6e52b503fdcb7f69052e69b392ea6df3bdab (patch)
tree9004d38a476deb9884b26cf1fb8243b8a26b5417 /lib/crypto
parentbd3c0fac624c6b31ccbb8d72ae4ced958a40ddee (diff)
downloadotp-c1eb6e52b503fdcb7f69052e69b392ea6df3bdab.tar.gz
otp-c1eb6e52b503fdcb7f69052e69b392ea6df3bdab.tar.bz2
otp-c1eb6e52b503fdcb7f69052e69b392ea6df3bdab.zip
Make cipher ctx init internal to cipher.c per PR feedback
Diffstat (limited to 'lib/crypto')
-rw-r--r--lib/crypto/c_src/cipher.c17
-rw-r--r--lib/crypto/c_src/cipher.h4
-rw-r--r--lib/crypto/c_src/crypto.c11
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,