aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2019-03-14 19:56:51 +0100
committerHans Nilsson <[email protected]>2019-03-19 12:45:56 +0100
commit86cd8b95b704ac236d02f31a92545ca996816c2c (patch)
tree6e14b636d8876239d18af457da00ccb868c1fa91 /lib/crypto/c_src
parent7281dd92eb48280c25a8342547d70c867f6d731a (diff)
downloadotp-86cd8b95b704ac236d02f31a92545ca996816c2c.tar.gz
otp-86cd8b95b704ac236d02f31a92545ca996816c2c.tar.bz2
otp-86cd8b95b704ac236d02f31a92545ca996816c2c.zip
crypto: Fix bug in ng_api
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r--lib/crypto/c_src/api_ng.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/crypto/c_src/api_ng.c b/lib/crypto/c_src/api_ng.c
index 2823b2714b..f727b5e90f 100644
--- a/lib/crypto/c_src/api_ng.c
+++ b/lib/crypto/c_src/api_ng.c
@@ -218,18 +218,22 @@ static int get_init_args(ErlNifEnv* env,
goto err;
}
}
-
- if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, NULL, -1)) {
- *return_term = EXCP_ERROR(env, "Can't initialize key");
- goto err;
- }
-
- if (ivec_arg != atom_undefined) {
- if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, NULL, ivec_bin.data, -1)) {
- *return_term = EXCP_ERROR(env, "Can't initialize iv");
- goto err;
+ // enif_fprintf(stderr, "%s:%u %T %T %u\r\n", __FILE__, __LINE__, cipher_arg, ivec_arg, ivec_len);
+ if (ivec_arg == atom_undefined || ivec_len == 0)
+ {
+ if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, NULL, -1)) {
+ *return_term = EXCP_ERROR(env, "Can't initialize key");
+ goto err;
+ }
}
- }
+ else
+ if (!EVP_CipherInit_ex(ctx_res->ctx, NULL, NULL, key_bin.data, ivec_bin.data, -1))
+ {
+ *return_term = EXCP_ERROR(env, "Can't initialize key or iv");
+ goto err;
+ }
+
+ // enif_fprintf(stderr, "%s:%u\r\n", __FILE__, __LINE__);
EVP_CIPHER_CTX_set_padding(ctx_res->ctx, 0);