diff options
author | Doug Hogan <[email protected]> | 2019-01-07 18:45:58 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:58 -0800 |
commit | a2e0b92ca13984a89f261aa1e10820252e505e84 (patch) | |
tree | b773d50634ef4fdb38b34c717de95178dae61433 /lib/crypto/c_src | |
parent | 3838f0a85cb0fd299dd2460673b64cd4e319b387 (diff) | |
download | otp-a2e0b92ca13984a89f261aa1e10820252e505e84.tar.gz otp-a2e0b92ca13984a89f261aa1e10820252e505e84.tar.bz2 otp-a2e0b92ca13984a89f261aa1e10820252e505e84.zip |
Revamp ec_key_generate
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r-- | lib/crypto/c_src/ec.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/lib/crypto/c_src/ec.c b/lib/crypto/c_src/ec.c index 78bdee318c..6da262e6a5 100644 --- a/lib/crypto/c_src/ec.c +++ b/lib/crypto/c_src/ec.c @@ -373,31 +373,41 @@ ERL_NIF_TERM ec_key_generate(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] const EC_GROUP *group; const EC_POINT *public_key; ERL_NIF_TERM priv_key; - ERL_NIF_TERM pub_key = atom_undefined; + ERL_NIF_TERM pub_key; + ERL_NIF_TERM ret; if (!get_ec_key(env, argv[0], argv[1], atom_undefined, &key)) - goto badarg; + goto bad_arg; if (argv[1] == atom_undefined) { if (!EC_KEY_generate_key(key)) - goto badarg; + goto err; } group = EC_KEY_get0_group(key); public_key = EC_KEY_get0_public_key(key); - if (group && public_key) { - pub_key = point2term(env, group, public_key, - EC_KEY_get_conv_form(key)); + if (group == NULL || public_key == NULL) { + pub_key = atom_undefined; + + } else { + pub_key = point2term(env, group, public_key, + EC_KEY_get_conv_form(key)); } + priv_key = bn2term(env, EC_KEY_get0_private_key(key)); - EC_KEY_free(key); - return enif_make_tuple2(env, pub_key, priv_key); + ret = enif_make_tuple2(env, pub_key, priv_key); + goto done; -badarg: + err: + bad_arg: + ret = make_badarg_maybe(env); + + done: if (key) - EC_KEY_free(key); - return make_badarg_maybe(env); + EC_KEY_free(key); + return ret; + #else return atom_notsup; #endif |