diff options
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r-- | lib/crypto/c_src/aead.c | 7 | ||||
-rw-r--r-- | lib/crypto/c_src/aes.c | 31 | ||||
-rw-r--r-- | lib/crypto/c_src/block.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/bn.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/chacha20.c | 8 | ||||
-rw-r--r-- | lib/crypto/c_src/cmac.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/dh.c | 6 | ||||
-rw-r--r-- | lib/crypto/c_src/ecdh.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/engine.c | 58 | ||||
-rw-r--r-- | lib/crypto/c_src/evp.c | 6 | ||||
-rw-r--r-- | lib/crypto/c_src/hash.c | 28 | ||||
-rw-r--r-- | lib/crypto/c_src/hmac.c | 15 | ||||
-rw-r--r-- | lib/crypto/c_src/info.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/math.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/pkey.c | 7 | ||||
-rw-r--r-- | lib/crypto/c_src/poly1305.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/rand.c | 16 | ||||
-rw-r--r-- | lib/crypto/c_src/rc4.c | 8 | ||||
-rw-r--r-- | lib/crypto/c_src/rsa.c | 4 | ||||
-rw-r--r-- | lib/crypto/c_src/srp.c | 11 |
20 files changed, 109 insertions, 124 deletions
diff --git a/lib/crypto/c_src/aead.c b/lib/crypto/c_src/aead.c index f33056b74c..c6f4cf52b1 100644 --- a/lib/crypto/c_src/aead.c +++ b/lib/crypto/c_src/aead.c @@ -34,8 +34,8 @@ ERL_NIF_TERM aead_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) type = argv[0]; - if (argc != 6) - goto bad_arg; + ASSERT(argc == 6); + if (!enif_is_atom(env, type)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &key)) @@ -197,8 +197,7 @@ ERL_NIF_TERM aead_decrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) ERL_NIF_TERM type, out, ret; int len, ctx_ctrl_set_ivlen, ctx_ctrl_set_tag; - if (argc != 6) - goto bad_arg; + ASSERT(argc == 6); type = argv[0]; #if defined(HAVE_GCM_EVP_DECRYPT_BUG) diff --git a/lib/crypto/c_src/aes.c b/lib/crypto/c_src/aes.c index 205cb8b058..2df123e44e 100644 --- a/lib/crypto/c_src/aes.c +++ b/lib/crypto/c_src/aes.c @@ -32,8 +32,7 @@ ERL_NIF_TERM aes_cfb_8_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] CHECK_NO_FIPS_MODE(); - if (argc != 4) - goto bad_arg; + ASSERT(argc == 4); if (!enif_inspect_iolist_as_binary(env, argv[0], &key)) goto bad_arg; @@ -74,8 +73,8 @@ ERL_NIF_TERM aes_cfb_128_crypt_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ERL_NIF_TERM ret; unsigned char *outp; - if (argc != 4) - goto bad_arg; + ASSERT(argc == 4); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key)) goto bad_arg; if (key.size != 16 && key.size != 24 && key.size != 32) @@ -119,8 +118,8 @@ ERL_NIF_TERM aes_ige_crypt_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv CHECK_NO_FIPS_MODE(); - if (argc != 4) - goto bad_arg; + ASSERT(argc == 4); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key_bin)) goto bad_arg; if (key_bin.size != 16 && key_bin.size != 32) @@ -177,8 +176,8 @@ ERL_NIF_TERM aes_ctr_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar const EVP_CIPHER *cipher; ERL_NIF_TERM ret; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key_bin)) goto bad_arg; if (!enif_inspect_binary(env, argv[1], &ivec_bin)) @@ -236,8 +235,8 @@ ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char *out; int outl = 0; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], evp_cipher_ctx_rtype, (void**)&ctx)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &data_bin)) @@ -284,8 +283,8 @@ ERL_NIF_TERM aes_ctr_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar ERL_NIF_TERM ecount_bin; unsigned char *outp; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key_bin)) goto bad_arg; if (key_bin.size != 16 && key_bin.size != 24 && key_bin.size != 32) @@ -319,8 +318,8 @@ ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char * ecount2_buf; unsigned char *outp; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_tuple(env, argv[0], &state_arity, &state_term)) goto bad_arg; if (state_arity != 4) @@ -382,8 +381,8 @@ ERL_NIF_TERM aes_gcm_decrypt_NO_EVP(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char *outp; ERL_NIF_TERM out, ret; - if (argc != 6) - goto bad_arg; + ASSERT(argc == 6); + if (!enif_inspect_iolist_as_binary(env, argv[1], &key)) goto bad_arg; if (key.size > INT_MAX / 8) diff --git a/lib/crypto/c_src/block.c b/lib/crypto/c_src/block.c index 3399b7b974..d88ee8dba7 100644 --- a/lib/crypto/c_src/block.c +++ b/lib/crypto/c_src/block.c @@ -33,8 +33,8 @@ ERL_NIF_TERM block_crypt_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] int ivec_size, out_size = 0; int cipher_len; - if (argc != 4 && argc != 5) - goto bad_arg; + ASSERT(argc == 4 || argc == 5); + if (!enif_inspect_iolist_as_binary(env, argv[1], &key)) goto bad_arg; if (key.size > INT_MAX) diff --git a/lib/crypto/c_src/bn.c b/lib/crypto/c_src/bn.c index d884a75f80..34ed4f7ebc 100644 --- a/lib/crypto/c_src/bn.c +++ b/lib/crypto/c_src/bn.c @@ -103,8 +103,8 @@ ERL_NIF_TERM mod_exp_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) unsigned extra_byte; ERL_NIF_TERM ret; - if (argc != 4) - goto bad_arg; + ASSERT(argc == 4); + if (!get_bn_from_bin(env, argv[0], &bn_base)) goto bad_arg; if (!get_bn_from_bin(env, argv[1], &bn_exponent)) diff --git a/lib/crypto/c_src/chacha20.c b/lib/crypto/c_src/chacha20.c index 51a24a43e9..5761383c95 100644 --- a/lib/crypto/c_src/chacha20.c +++ b/lib/crypto/c_src/chacha20.c @@ -29,8 +29,8 @@ ERL_NIF_TERM chacha20_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM a const EVP_CIPHER *cipher; ERL_NIF_TERM ret; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key_bin)) goto bad_arg; if (key_bin.size != 32) @@ -81,8 +81,8 @@ ERL_NIF_TERM chacha20_stream_crypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char *out; int outl = 0; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], evp_cipher_ctx_rtype, (void**)&ctx)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &data_bin)) diff --git a/lib/crypto/c_src/cmac.c b/lib/crypto/c_src/cmac.c index 303b7af6eb..196b7476e3 100644 --- a/lib/crypto/c_src/cmac.c +++ b/lib/crypto/c_src/cmac.c @@ -34,8 +34,8 @@ ERL_NIF_TERM cmac_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) unsigned char *outp; int cipher_len; - if (argc != 3) - goto bad_arg; + ASSERT(argc == 3); + if (!enif_inspect_iolist_as_binary(env, argv[1], &key)) goto bad_arg; if ((cipherp = get_cipher_type(argv[0], key.size)) == NULL) diff --git a/lib/crypto/c_src/dh.c b/lib/crypto/c_src/dh.c index d077007a52..38eb534d99 100644 --- a/lib/crypto/c_src/dh.c +++ b/lib/crypto/c_src/dh.c @@ -40,8 +40,7 @@ ERL_NIF_TERM dh_generate_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar EVP_PKEY *dhkey = NULL, *params = NULL; #endif - if (argc != 4) - goto bad_arg; + ASSERT(argc == 4); if (argv[0] != atom_undefined) { if (!get_bn_from_bin(env, argv[0], &priv_key_in)) @@ -209,8 +208,7 @@ ERL_NIF_TERM dh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM arg the peer's public key (other_pub_key), the parameters p & q */ - if (argc != 3) - goto bad_arg; + ASSERT(argc == 3); if (!get_bn_from_bin(env, argv[0], &other_pub_key)) goto bad_arg; diff --git a/lib/crypto/c_src/ecdh.c b/lib/crypto/c_src/ecdh.c index ee4b352730..9e3f460519 100644 --- a/lib/crypto/c_src/ecdh.c +++ b/lib/crypto/c_src/ecdh.c @@ -39,8 +39,8 @@ ERL_NIF_TERM ecdh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a EC_POINT *my_ecpoint = NULL; EC_KEY *other_ecdh = NULL; - if (argc != 3) - goto bad_arg; + ASSERT(argc == 3); + if (!get_ec_key(env, argv[1], argv[2], atom_undefined, &key)) goto bad_arg; if ((group = EC_GROUP_dup(EC_KEY_get0_group(key))) == NULL) diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c index 715d9bed40..6692ccd734 100644 --- a/lib/crypto/c_src/engine.c +++ b/lib/crypto/c_src/engine.c @@ -124,8 +124,8 @@ ERL_NIF_TERM engine_by_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ struct engine_ctx *ctx = NULL; // Get Engine Id - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_inspect_binary(env, argv[0], &engine_id_bin)) goto bad_arg; @@ -173,8 +173,8 @@ ERL_NIF_TERM engine_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -197,8 +197,8 @@ ERL_NIF_TERM engine_free_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -220,8 +220,8 @@ ERL_NIF_TERM engine_finish_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -241,8 +241,7 @@ ERL_NIF_TERM engine_finish_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv ERL_NIF_TERM engine_load_dynamic_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* () */ #ifdef HAS_ENGINE_SUPPORT - if (argc != 0) - return enif_make_badarg(env); + ASSERT(argc == 0); ENGINE_load_dynamic(); return atom_ok; @@ -263,8 +262,8 @@ ERL_NIF_TERM engine_ctrl_cmd_strings_nif(ErlNifEnv* env, int argc, const ERL_NIF int cmds_loaded = 0; // Get Engine - if (argc != 3) - goto bad_arg; + ASSERT(argc == 3); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -331,8 +330,8 @@ ERL_NIF_TERM engine_add_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -358,8 +357,8 @@ ERL_NIF_TERM engine_remove_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -385,8 +384,8 @@ ERL_NIF_TERM engine_register_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar unsigned int method; // Get Engine - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; if (!enif_get_uint(env, argv[1], &method)) @@ -490,8 +489,8 @@ ERL_NIF_TERM engine_unregister_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned int method; // Get Engine - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; if (!enif_get_uint(env, argv[1], &method)) @@ -581,8 +580,7 @@ ERL_NIF_TERM engine_get_first_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a ErlNifBinary engine_bin; struct engine_ctx *ctx = NULL; - if (argc != 0) - goto bad_arg; + ASSERT(argc == 0); if ((engine = ENGINE_get_first()) == NULL) { if (!enif_alloc_binary(0, &engine_bin)) @@ -600,7 +598,6 @@ ERL_NIF_TERM engine_get_first_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a ret = enif_make_tuple2(env, atom_ok, result); goto done; - bad_arg: err: ret = enif_make_badarg(env); @@ -623,8 +620,8 @@ ERL_NIF_TERM engine_get_next_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar struct engine_ctx *ctx, *next_ctx = NULL; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -667,8 +664,8 @@ ERL_NIF_TERM engine_get_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv struct engine_ctx *ctx = NULL; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -705,8 +702,8 @@ ERL_NIF_TERM engine_get_name_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar struct engine_ctx *ctx; // Get Engine - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -796,8 +793,7 @@ ERL_NIF_TERM engine_get_all_methods_nif(ErlNifEnv* env, int argc, const ERL_NIF_ ERL_NIF_TERM method_array[12]; unsigned int i = 0; - if (argc != 0) - return enif_make_badarg(env); + ASSERT(argc == 0); #ifdef ENGINE_METHOD_RSA method_array[i++] = atom_engine_method_rsa; diff --git a/lib/crypto/c_src/evp.c b/lib/crypto/c_src/evp.c index 7aa4be1f9f..3bf66bfffe 100644 --- a/lib/crypto/c_src/evp.c +++ b/lib/crypto/c_src/evp.c @@ -32,8 +32,7 @@ ERL_NIF_TERM evp_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar size_t max_size; int key_bin_alloc = 0; - if (argc != 3) - goto bad_arg; + ASSERT(argc == 3); if (argv[0] == atom_x25519) type = EVP_PKEY_X25519; @@ -110,8 +109,7 @@ ERL_NIF_TERM evp_generate_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a size_t key_len; unsigned char *out_pub = NULL, *out_priv = NULL; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); if (argv[0] == atom_x25519) type = EVP_PKEY_X25519; diff --git a/lib/crypto/c_src/hash.c b/lib/crypto/c_src/hash.c index 000eae047a..d67e68f857 100644 --- a/lib/crypto/c_src/hash.c +++ b/lib/crypto/c_src/hash.c @@ -68,8 +68,8 @@ ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) unsigned ret_size; unsigned char *outp; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if ((digp = get_digest_type(argv[0])) == NULL) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) @@ -106,8 +106,8 @@ ERL_NIF_TERM hash_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) struct evp_md_ctx *ctx = NULL; ERL_NIF_TERM ret; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if ((digp = get_digest_type(argv[0])) == NULL) goto bad_arg; if (digp->md.p == NULL) @@ -141,8 +141,8 @@ ERL_NIF_TERM hash_update_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] ErlNifBinary data; ERL_NIF_TERM ret; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], evp_md_ctx_rtype, (void**)&ctx)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) @@ -181,8 +181,8 @@ ERL_NIF_TERM hash_final_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) unsigned ret_size; unsigned char *outp; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_resource(env, argv[0], evp_md_ctx_rtype, (void**)&ctx)) goto bad_arg; @@ -224,8 +224,8 @@ ERL_NIF_TERM hash_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) init_fun ctx_init = 0; unsigned char *outp; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if ((digp = get_digest_type(argv[0])) == NULL) goto bad_arg; if (digp->md.p == NULL) @@ -306,8 +306,8 @@ ERL_NIF_TERM hash_update_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] size_t ctx_size = 0; update_fun ctx_update = 0; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_tuple(env, argv[0], &arity, &tuple)) goto bad_arg; if (arity != 2) @@ -404,8 +404,8 @@ ERL_NIF_TERM hash_final_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) final_fun ctx_final = 0; unsigned char *outp; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_tuple(env, argv[0], &arity, &tuple)) goto bad_arg; if (arity != 2) diff --git a/lib/crypto/c_src/hmac.c b/lib/crypto/c_src/hmac.c index 9418e7950e..c41e50eb35 100644 --- a/lib/crypto/c_src/hmac.c +++ b/lib/crypto/c_src/hmac.c @@ -56,8 +56,7 @@ ERL_NIF_TERM hmac_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) ERL_NIF_TERM ret; unsigned char *outp; - if (argc != 3 && argc != 4) - goto bad_arg; + ASSERT(argc == 3 || argc == 4); if ((digp = get_digest_type(argv[0])) == NULL) goto bad_arg; @@ -125,8 +124,8 @@ ERL_NIF_TERM hmac_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) ERL_NIF_TERM ret; struct hmac_context *obj = NULL; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if ((digp = get_digest_type(argv[0])) == NULL) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &key)) @@ -180,8 +179,8 @@ ERL_NIF_TERM hmac_update_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] ErlNifBinary data; struct hmac_context *obj = NULL; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_resource(env, argv[0], hmac_context_rtype, (void**)&obj)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &data)) @@ -223,8 +222,8 @@ ERL_NIF_TERM hmac_final_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) unsigned int req_len = 0; unsigned int mac_len; - if (argc != 1 && argc != 2) - goto bad_arg; + ASSERT(argc == 1 || argc == 2); + if (!enif_get_resource(env, argv[0], hmac_context_rtype, (void**)&obj)) goto bad_arg; if (argc == 2) { diff --git a/lib/crypto/c_src/info.c b/lib/crypto/c_src/info.c index 2411968b95..42f477fead 100644 --- a/lib/crypto/c_src/info.c +++ b/lib/crypto/c_src/info.c @@ -74,8 +74,7 @@ ERL_NIF_TERM info_lib(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) int ver_num; unsigned char *out_name, *out_ver; - if (argc != 0) - goto bad_arg; + ASSERT(argc == 0); name_sz = strlen(libname); ver = SSLeay_version(SSLEAY_VERSION); @@ -103,7 +102,6 @@ ERL_NIF_TERM info_lib(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) enif_make_int(env, ver_num), ver_term)); - bad_arg: err: return enif_make_badarg(env); } diff --git a/lib/crypto/c_src/math.c b/lib/crypto/c_src/math.c index a7a385e404..85494bbc93 100644 --- a/lib/crypto/c_src/math.c +++ b/lib/crypto/c_src/math.c @@ -27,8 +27,8 @@ ERL_NIF_TERM do_exor(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) size_t i; ERL_NIF_TERM ret; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_iolist_as_binary(env, argv[0], &d1)) goto bad_arg; if (!enif_inspect_iolist_as_binary(env, argv[1], &d2)) diff --git a/lib/crypto/c_src/pkey.c b/lib/crypto/c_src/pkey.c index 33905e7753..4e76f817bc 100644 --- a/lib/crypto/c_src/pkey.c +++ b/lib/crypto/c_src/pkey.c @@ -1033,8 +1033,7 @@ ERL_NIF_TERM pkey_crypt_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) int algo_init = 0; unsigned char *label_copy = NULL; - if (argc != 6) - goto bad_arg; + ASSERT(argc == 6); is_private = (argv[4] == atom_true); is_encrypt = (argv[5] == atom_true); @@ -1345,8 +1344,8 @@ ERL_NIF_TERM privkey_to_pubkey_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM DSA *dsa = NULL; ERL_NIF_TERM result[8]; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (get_pkey_private_key(env, argv[0], argv[1], &pkey) != PKEY_OK) goto bad_arg; diff --git a/lib/crypto/c_src/poly1305.c b/lib/crypto/c_src/poly1305.c index da434e4eb9..db3433dce3 100644 --- a/lib/crypto/c_src/poly1305.c +++ b/lib/crypto/c_src/poly1305.c @@ -33,8 +33,8 @@ ERL_NIF_TERM poly1305_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) size_t size; int ret_bin_alloc = 0; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_binary(env, argv[0], &key_bin)) goto bad_arg; if (key_bin.size != 32) diff --git a/lib/crypto/c_src/rand.c b/lib/crypto/c_src/rand.c index cf793a7aac..3812ae0991 100644 --- a/lib/crypto/c_src/rand.c +++ b/lib/crypto/c_src/rand.c @@ -27,8 +27,8 @@ ERL_NIF_TERM strong_rand_bytes_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char* data; ERL_NIF_TERM ret; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_get_uint(env, argv[0], &bytes)) goto bad_arg; if (bytes > INT_MAX) @@ -54,8 +54,8 @@ ERL_NIF_TERM strong_rand_range_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM BIGNUM *bn_range = NULL, *bn_rand = NULL; ERL_NIF_TERM ret; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!get_bn_from_bin(env, argv[0], &bn_range)) goto bad_arg; @@ -89,8 +89,8 @@ ERL_NIF_TERM rand_uniform_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ int dlen; ERL_NIF_TERM ret; - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!get_bn_from_mpint(env, argv[0], &bn_from)) goto bad_arg; if (!get_bn_from_mpint(env, argv[1], &bn_rand)) @@ -134,8 +134,8 @@ ERL_NIF_TERM rand_seed_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* (Seed) */ ErlNifBinary seed_bin; - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_inspect_binary(env, argv[0], &seed_bin)) goto bad_arg; if (seed_bin.size > INT_MAX) diff --git a/lib/crypto/c_src/rc4.c b/lib/crypto/c_src/rc4.c index 63f8000839..e423661097 100644 --- a/lib/crypto/c_src/rc4.c +++ b/lib/crypto/c_src/rc4.c @@ -29,8 +29,8 @@ ERL_NIF_TERM rc4_set_key(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) CHECK_NO_FIPS_MODE(); - if (argc != 1) - goto bad_arg; + ASSERT(argc == 1); + if (!enif_inspect_iolist_as_binary(env, argv[0], &key)) goto bad_arg; if (key.size > INT_MAX) @@ -61,8 +61,8 @@ ERL_NIF_TERM rc4_encrypt_with_state(ErlNifEnv* env, int argc, const ERL_NIF_TERM CHECK_NO_FIPS_MODE(); - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_inspect_iolist_as_binary(env, argv[0], &state)) goto bad_arg; if (state.size != sizeof(RC4_KEY)) diff --git a/lib/crypto/c_src/rsa.c b/lib/crypto/c_src/rsa.c index 540bc1b54d..e9f29aa496 100644 --- a/lib/crypto/c_src/rsa.c +++ b/lib/crypto/c_src/rsa.c @@ -214,8 +214,8 @@ static ERL_NIF_TERM rsa_generate_key(ErlNifEnv* env, int argc, const ERL_NIF_TER BN_GENCB intr_cb_buf; #endif - if (argc != 2) - goto bad_arg; + ASSERT(argc == 2); + if (!enif_get_int(env, argv[0], &modulus_bits)) goto bad_arg; if (modulus_bits < 256) diff --git a/lib/crypto/c_src/srp.c b/lib/crypto/c_src/srp.c index 5a49a1c1b4..2979048006 100644 --- a/lib/crypto/c_src/srp.c +++ b/lib/crypto/c_src/srp.c @@ -32,8 +32,7 @@ ERL_NIF_TERM srp_value_B_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] CHECK_NO_FIPS_MODE(); - if (argc != 5) - goto bad_arg; + ASSERT(argc == 5); if (!get_bn_from_bin(env, argv[0], &bn_multiplier)) goto bad_arg; @@ -124,8 +123,8 @@ ERL_NIF_TERM srp_user_secret_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar CHECK_NO_FIPS_MODE(); - if (argc != 7) - goto bad_arg; + ASSERT(argc == 7); + if (!get_bn_from_bin(env, argv[0], &bn_a)) goto bad_arg; if (!get_bn_from_bin(env, argv[1], &bn_u)) @@ -232,8 +231,8 @@ ERL_NIF_TERM srp_host_secret_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar CHECK_NO_FIPS_MODE(); - if (argc != 5) - goto bad_arg; + ASSERT(argc == 5); + if (!get_bn_from_bin(env, argv[0], &bn_verifier)) goto bad_arg; if (!get_bn_from_bin(env, argv[1], &bn_b)) |