aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2018-06-14 09:48:45 +0200
committerHans Nilsson <[email protected]>2018-06-14 14:39:20 +0200
commit5c2f4277badf33a518683c44617a64863f606726 (patch)
treeb7859dd8bfa7fe2e2e307d4628376a8f52e0378d /lib/crypto/c_src
parent4f5e7a82943eaca6453953cb028a9fb00c3c48a1 (diff)
downloadotp-5c2f4277badf33a518683c44617a64863f606726.tar.gz
otp-5c2f4277badf33a518683c44617a64863f606726.tar.bz2
otp-5c2f4277badf33a518683c44617a64863f606726.zip
crypto: Remove EVP_PKEY from dh_compute_key_nif
According to valgrind, there is a memory leak. When fixing that there is a core-dump instead. Since generate_key is the part that is important for the quality of the key we keep the old compute_key part to avoid memory leakage.
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r--lib/crypto/c_src/crypto.c72
1 files changed, 0 insertions, 72 deletions
diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c
index 1c746b2ee1..0a2a235209 100644
--- a/lib/crypto/c_src/crypto.c
+++ b/lib/crypto/c_src/crypto.c
@@ -3230,77 +3230,6 @@ static ERL_NIF_TERM dh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_T
return enif_make_badarg(env);
}
}
-#ifdef HAS_EVP_PKEY_CTX
- {
- EVP_PKEY_CTX *ctx = NULL;
- /* Prepare my private key dh_priv and assign to CTX */
- {
- EVP_PKEY *my_priv_key = EVP_PKEY_new();
- if (!EVP_PKEY_set1_DH(my_priv_key, dh_priv)) { /* set the key referenced by my_priv_key to dh_priv.
- dh_priv (and my_priv_key) must be freed by us */
- DH_free(dh_priv);
- EVP_PKEY_free(my_priv_key);
- return atom_error;
- }
- DH_free(dh_priv);
- ctx = EVP_PKEY_CTX_new(my_priv_key, NULL);
- EVP_PKEY_free(my_priv_key);
- }
- /* Prepare derivation */
- EVP_PKEY_derive_init(ctx);
-
- /* Prepare the peers public key other_pub_key and assign to CTX */
- {
- EVP_PKEY *peer_pub_key = EVP_PKEY_new();
- DH *dh_pub = DH_new();
-
- if (!DH_set0_key(dh_pub, other_pub_key, NULL)
- || !DH_set0_pqg(dh_pub, dh_p, NULL, dh_g)
- || !EVP_PKEY_set1_DH(peer_pub_key, dh_pub)) {
- EVP_PKEY_CTX_free(ctx);
- return atom_error;
- }
- DH_free(dh_pub);
- if (EVP_PKEY_derive_set_peer(ctx, peer_pub_key) <= 0) {
- return atom_error;
- }
- }
-
- /* Derive the common secret and return it in an Erlang binary */
- {
- size_t maxkeylen, len;
- unsigned char *buf;
- ErlNifBinary ret_bin;
- int success;
-
- /* Get the common key MAX length: */
- if (EVP_PKEY_derive(ctx, NULL, &maxkeylen) <= 0) {
- EVP_PKEY_CTX_free(ctx);
- return atom_error;
- }
-
- buf = enif_alloc(maxkeylen);
- len = maxkeylen;
-
- success =
- (EVP_PKEY_derive(ctx, buf, &len) > 0)
- && (maxkeylen >= len);
-
- EVP_PKEY_CTX_free(ctx);
-
- if (!success) {
- enif_free(buf);
- return atom_error;
- }
-
- enif_alloc_binary(len, &ret_bin);
- memcpy(ret_bin.data, buf, ret_bin.size);
- enif_free(buf);
-
- return enif_make_binary(env, &ret_bin);
- }
- }
-#else
{
ErlNifBinary ret_bin;
int size;
@@ -3317,7 +3246,6 @@ static ERL_NIF_TERM dh_compute_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_T
if (size != ret_bin.size) enif_realloc_binary(&ret_bin, size);
return enif_make_binary(env, &ret_bin);
}
-#endif
}