aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2018-12-21 07:53:24 -0800
committerDoug Hogan <[email protected]>2018-12-21 08:23:43 -0800
commitbd3c0fac624c6b31ccbb8d72ae4ced958a40ddee (patch)
treef6c5854ebc91bf6ca8e7e9b97afc8c171af14a76 /lib
parentda3831bbe75f68626e362fdadd653becf230cf1f (diff)
downloadotp-bd3c0fac624c6b31ccbb8d72ae4ced958a40ddee.tar.gz
otp-bd3c0fac624c6b31ccbb8d72ae4ced958a40ddee.tar.bz2
otp-bd3c0fac624c6b31ccbb8d72ae4ced958a40ddee.zip
Make hash ctx init internal to hash.c per PR feedback
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/c_src/crypto.c11
-rw-r--r--lib/crypto/c_src/hash.c23
-rw-r--r--lib/crypto/c_src/hash.h9
3 files changed, 24 insertions, 19 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 5b697ba5aa..df2e4a9f4b 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -184,17 +184,10 @@ static int initialize(ErlNifEnv* env, ERL_NIF_TERM load_info)
if (!init_hmac_ctx(env)) {
return __LINE__;
}
-
-#if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(1,0,0)
- evp_md_ctx_rtype = enif_open_resource_type(env, NULL, "EVP_MD_CTX",
- (ErlNifResourceDtor*) evp_md_ctx_dtor,
- ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
- NULL);
- if (!evp_md_ctx_rtype) {
- PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_MD_CTX'");
+ if (!init_hash_ctx(env)) {
return __LINE__;
}
-#endif
+
#ifdef HAVE_EVP_AES_CTR
evp_cipher_ctx_rtype = enif_open_resource_type(env, NULL, "EVP_CIPHER_CTX",
(ErlNifResourceDtor*) evp_cipher_ctx_dtor,
diff --git a/lib/crypto/c_src/hash.c b/lib/crypto/c_src/hash.c
index 44704329ab..52748dc933 100644
--- a/lib/crypto/c_src/hash.c
+++ b/lib/crypto/c_src/hash.c
@@ -26,14 +26,33 @@
#define RIPEMD160_CTX_LEN (sizeof(RIPEMD160_CTX))
#if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(1,0,0)
+struct evp_md_ctx {
+ EVP_MD_CTX* ctx;
+};
+
/* Define resource types for OpenSSL context structures. */
-ErlNifResourceType* evp_md_ctx_rtype;
+static ErlNifResourceType* evp_md_ctx_rtype;
-void evp_md_ctx_dtor(ErlNifEnv* env, struct evp_md_ctx *ctx) {
+static void evp_md_ctx_dtor(ErlNifEnv* env, struct evp_md_ctx *ctx) {
EVP_MD_CTX_free(ctx->ctx);
}
#endif
+int init_hash_ctx(ErlNifEnv* env) {
+#if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(1,0,0)
+ evp_md_ctx_rtype = enif_open_resource_type(env, NULL, "EVP_MD_CTX",
+ (ErlNifResourceDtor*) evp_md_ctx_dtor,
+ ERL_NIF_RT_CREATE|ERL_NIF_RT_TAKEOVER,
+ NULL);
+ if (evp_md_ctx_rtype == NULL) {
+ PRINTF_ERR0("CRYPTO: Could not open resource type 'EVP_MD_CTX'");
+ return 0;
+ }
+#endif
+
+ return 1;
+}
+
ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (Type, Data) */
struct digest_type_t *digp = NULL;
diff --git a/lib/crypto/c_src/hash.h b/lib/crypto/c_src/hash.h
index 9b82d9356c..8bae07f39a 100644
--- a/lib/crypto/c_src/hash.h
+++ b/lib/crypto/c_src/hash.h
@@ -23,14 +23,7 @@
#include "common.h"
-#if OPENSSL_VERSION_NUMBER >= PACKED_OPENSSL_VERSION_PLAIN(1,0,0)
-struct evp_md_ctx {
- EVP_MD_CTX* ctx;
-};
-extern ErlNifResourceType* evp_md_ctx_rtype;
-
-void evp_md_ctx_dtor(ErlNifEnv* env, struct evp_md_ctx *ctx);
-#endif
+int init_hash_ctx(ErlNifEnv *env);
ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM hash_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);