From c7cab680b80ef9220832151ed2c8c23a5d590b8b Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Thu, 31 Jan 2019 10:27:23 +0100 Subject: crypto: New experimental api The new files api_ng.h and api_ng.c implements an api using EVP. The api is not by any mean new, except for the crypto application in Erlang/OTP. The aims at using the block api in a stream manor, that is 1) call crypto_init/4 2..N) call crypto_update/{2,3} The purpose is to simplify and hopefully optimize the SSL and SSH applications. By keeping the crypto state in C in an enif_resource the costful state copying in SSL and SSH is reduced with 1-2 per message sent or received. Changes in other files are for adaptation like FIPS etc since many functions uses the central get_cipher_type() function. --- lib/crypto/c_src/engine.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/crypto/c_src/engine.c') diff --git a/lib/crypto/c_src/engine.c b/lib/crypto/c_src/engine.c index 6692ccd734..7ffbb9e70d 100644 --- a/lib/crypto/c_src/engine.c +++ b/lib/crypto/c_src/engine.c @@ -26,6 +26,9 @@ struct engine_ctx { char *id; }; +#define ERROR_Term(Env, ReasonTerm) enif_make_tuple2((Env), atom_error, (ReasonTerm)) +#define ERROR_Atom(Env, ReasonString) ERROR_Term((Env), enif_make_atom((Env),(ReasonString))) + static ErlNifResourceType* engine_ctx_rtype; static int get_engine_load_cmd_list(ErlNifEnv* env, const ERL_NIF_TERM term, char **cmds, int i); @@ -136,7 +139,7 @@ ERL_NIF_TERM engine_by_id_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ if ((engine = ENGINE_by_id(engine_id)) == NULL) { PRINTF_ERR0("engine_by_id_nif Leaved: {error, bad_engine_id}"); - ret = enif_make_tuple2(env, atom_error, atom_bad_engine_id); + ret = ERROR_Atom(env, "bad_engine_id"); goto done; } @@ -179,7 +182,7 @@ ERL_NIF_TERM engine_init_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[] goto bad_arg; if (!ENGINE_init(ctx->engine)) - return enif_make_tuple2(env, atom_error, atom_engine_init_failed); + return ERROR_Atom(env, "engine_init_failed"); return atom_ok; @@ -306,7 +309,7 @@ ERL_NIF_TERM engine_ctrl_cmd_strings_nif(ErlNifEnv* env, int argc, const ERL_NIF goto done; cmd_failed: - ret = enif_make_tuple2(env, atom_error, atom_ctrl_cmd_failed); + ret = ERROR_Atom(env, "ctrl_cmd_failed"); done: if (cmds_loaded) { @@ -344,7 +347,7 @@ ERL_NIF_TERM engine_add_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) return enif_make_badarg(env); failed: - return enif_make_tuple2(env, atom_error, atom_add_engine_failed); + return ERROR_Atom(env, "add_engine_failed"); #else return atom_notsup; @@ -371,7 +374,7 @@ ERL_NIF_TERM engine_remove_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv return enif_make_badarg(env); failed: - return enif_make_tuple2(env, atom_error, atom_remove_engine_failed); + return ERROR_Atom(env, "remove_engine_failed"); #else return atom_notsup; #endif @@ -466,7 +469,7 @@ ERL_NIF_TERM engine_register_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar break; #endif default: - return enif_make_tuple2(env, atom_error, atom_engine_method_not_supported); + return ERROR_Atom(env, "engine_method_not_supported"); } return atom_ok; @@ -475,7 +478,7 @@ ERL_NIF_TERM engine_register_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar return enif_make_badarg(env); failed: - return enif_make_tuple2(env, atom_error, atom_register_engine_failed); + return ERROR_Atom(env, "register_engine_failed"); #else return atom_notsup; -- cgit v1.2.3