diff options
author | Hans Nilsson <[email protected]> | 2019-02-25 10:02:04 +0100 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2019-02-25 10:02:04 +0100 |
commit | 2c06e174d6515b6a842906de9e6ebc70bd2f2ec0 (patch) | |
tree | c197e1682ecdea385f93b5bbeee540e444b84e06 /lib/crypto/c_src/aes.c | |
parent | b3dbf45fdbe8c584c89b5e061f6e9a28a5d3ea86 (diff) | |
parent | c7cab680b80ef9220832151ed2c8c23a5d590b8b (diff) | |
download | otp-2c06e174d6515b6a842906de9e6ebc70bd2f2ec0.tar.gz otp-2c06e174d6515b6a842906de9e6ebc70bd2f2ec0.tar.bz2 otp-2c06e174d6515b6a842906de9e6ebc70bd2f2ec0.zip |
Merge branch 'hans/crypto/new_api_rc1/OTP-15451'
* hans/crypto/new_api_rc1/OTP-15451:
crypto: New experimental api
Diffstat (limited to 'lib/crypto/c_src/aes.c')
-rw-r--r-- | lib/crypto/c_src/aes.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/crypto/c_src/aes.c b/lib/crypto/c_src/aes.c index 2f30ec8a58..ee2bb70fb7 100644 --- a/lib/crypto/c_src/aes.c +++ b/lib/crypto/c_src/aes.c @@ -166,8 +166,6 @@ ERL_NIF_TERM aes_ige_crypt_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv } -/* Initializes state for ctr streaming (de)encryption -*/ #ifdef HAVE_EVP_AES_CTR ERL_NIF_TERM aes_ctr_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* (Key, IVec) */ @@ -279,27 +277,31 @@ ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM ERL_NIF_TERM aes_ctr_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* (Key, IVec) */ + ASSERT(argc == 2); + + return aes_ctr_stream_init_compat(env, argv[0], argv[1]); +} + + +ERL_NIF_TERM aes_ctr_stream_init_compat(ErlNifEnv* env, const ERL_NIF_TERM key_term, const ERL_NIF_TERM iv_term) +{ ErlNifBinary key_bin, ivec_bin; ERL_NIF_TERM ecount_bin; unsigned char *outp; - - ASSERT(argc == 2); - - if (!enif_inspect_iolist_as_binary(env, argv[0], &key_bin)) + + if (!enif_inspect_iolist_as_binary(env, key_term, &key_bin)) goto bad_arg; if (key_bin.size != 16 && key_bin.size != 24 && key_bin.size != 32) goto bad_arg; - if (!enif_inspect_binary(env, argv[1], &ivec_bin)) + if (!enif_inspect_binary(env, iv_term, &ivec_bin)) goto bad_arg; if (ivec_bin.size != 16) goto bad_arg; - if ((outp = enif_make_new_binary(env, AES_BLOCK_SIZE, &ecount_bin)) == NULL) goto err; - memset(outp, 0, AES_BLOCK_SIZE); - return enif_make_tuple4(env, argv[0], argv[1], ecount_bin, enif_make_int(env, 0)); + return enif_make_tuple4(env, key_term, iv_term, ecount_bin, enif_make_int(env, 0)); bad_arg: err: @@ -307,6 +309,14 @@ ERL_NIF_TERM aes_ctr_stream_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM ar } ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ASSERT(argc == 2); + + return aes_ctr_stream_encrypt_compat(env, argv[0], argv[1]); +} + + +ERL_NIF_TERM aes_ctr_stream_encrypt_compat(ErlNifEnv* env, const ERL_NIF_TERM state_arg, const ERL_NIF_TERM data_arg) {/* ({Key, IVec, ECount, Num}, Data) */ ErlNifBinary key_bin, ivec_bin, text_bin, ecount_bin; AES_KEY aes_key; @@ -318,9 +328,7 @@ ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM unsigned char * ecount2_buf; unsigned char *outp; - ASSERT(argc == 2); - - if (!enif_get_tuple(env, argv[0], &state_arity, &state_term)) + if (!enif_get_tuple(env, state_arg, &state_arity, &state_term)) goto bad_arg; if (state_arity != 4) goto bad_arg; @@ -338,7 +346,7 @@ ERL_NIF_TERM aes_ctr_stream_encrypt(ErlNifEnv* env, int argc, const ERL_NIF_TERM goto bad_arg; if (!enif_get_uint(env, state_term[3], &num)) goto bad_arg; - if (!enif_inspect_iolist_as_binary(env, argv[1], &text_bin)) + if (!enif_inspect_iolist_as_binary(env, data_arg, &text_bin)) goto bad_arg; /* NOTE: This function returns 0 on success unlike most OpenSSL functions */ |