aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2019-01-03 22:15:38 -0800
committerDoug Hogan <[email protected]>2019-01-08 01:11:57 -0800
commit2e31e2cdcab0de8e00e4b3103a92440d81541211 (patch)
tree0a37dd1a5ee97d11d6a60d056a4b99e2967f42f7 /lib
parent35d9cb839ea0ef764d266212d7f3419c8750b59d (diff)
downloadotp-2e31e2cdcab0de8e00e4b3103a92440d81541211.tar.gz
otp-2e31e2cdcab0de8e00e4b3103a92440d81541211.tar.bz2
otp-2e31e2cdcab0de8e00e4b3103a92440d81541211.zip
Revamp hash_init_nif()
Diffstat (limited to 'lib')
-rw-r--r--lib/crypto/c_src/hash.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/lib/crypto/c_src/hash.c b/lib/crypto/c_src/hash.c
index 34e6db6b66..a2c53bcaaf 100644
--- a/lib/crypto/c_src/hash.c
+++ b/lib/crypto/c_src/hash.c
@@ -101,24 +101,33 @@ 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[])
{/* (Type) */
struct digest_type_t *digp = NULL;
- struct evp_md_ctx *ctx;
+ struct evp_md_ctx *ctx = NULL;
ERL_NIF_TERM ret;
- digp = get_digest_type(argv[0]);
- if (!digp) {
- return enif_make_badarg(env);
- }
- if (!digp->md.p) {
- return atom_notsup;
- }
+ if (argc != 1)
+ goto bad_arg;
+ if ((digp = get_digest_type(argv[0])) == NULL)
+ goto bad_arg;
+ if (digp->md.p == NULL)
+ goto err;
+
+ if ((ctx = enif_alloc_resource(evp_md_ctx_rtype, sizeof(struct evp_md_ctx))) == NULL)
+ goto err;
+ if ((ctx->ctx = EVP_MD_CTX_new()) == NULL)
+ goto err;
+ if (EVP_DigestInit(ctx->ctx, digp->md.p) != 1)
+ goto err;
- ctx = enif_alloc_resource(evp_md_ctx_rtype, sizeof(struct evp_md_ctx));
- ctx->ctx = EVP_MD_CTX_new();
- if (!EVP_DigestInit(ctx->ctx, digp->md.p)) {
- enif_release_resource(ctx);
- return atom_notsup;
- }
ret = enif_make_resource(env, ctx);
+ goto done;
+
+ bad_arg:
+ return enif_make_badarg(env);
+
+ err:
+ ret = atom_notsup;
+
+ done:
enif_release_resource(ctx);
return ret;
}