diff options
author | Bernard Kolobara <[email protected]> | 2019-07-19 15:16:44 +0200 |
---|---|---|
committer | Bernard Kolobara <[email protected]> | 2019-07-22 14:36:37 +0200 |
commit | 8cc550ce03309c36e8626206b6a7b758220a9481 (patch) | |
tree | 6dd97806bec721f4033c95b5cb2131deea7f2a14 /lib/crypto/c_src/evp.c | |
parent | 9d1b3bb0db87cf95cb821af01189f6d6be072f79 (diff) | |
download | otp-8cc550ce03309c36e8626206b6a7b758220a9481.tar.gz otp-8cc550ce03309c36e8626206b6a7b758220a9481.tar.bz2 otp-8cc550ce03309c36e8626206b6a7b758220a9481.zip |
Add ED25519 & ED448 support to crypto:generate_key
Diffstat (limited to 'lib/crypto/c_src/evp.c')
-rw-r--r-- | lib/crypto/c_src/evp.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/crypto/c_src/evp.c b/lib/crypto/c_src/evp.c index 3bf66bfffe..19dbd234f6 100644 --- a/lib/crypto/c_src/evp.c +++ b/lib/crypto/c_src/evp.c @@ -106,25 +106,34 @@ ERL_NIF_TERM evp_generate_key_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM a EVP_PKEY_CTX *ctx = NULL; EVP_PKEY *pkey = NULL; ERL_NIF_TERM ret_pub, ret_prv, ret; + ErlNifBinary prv_key; size_t key_len; unsigned char *out_pub = NULL, *out_priv = NULL; - ASSERT(argc == 1); - if (argv[0] == atom_x25519) type = EVP_PKEY_X25519; else if (argv[0] == atom_x448) type = EVP_PKEY_X448; + else if (argv[0] == atom_ed25519) + type = EVP_PKEY_ED25519; + else if (argv[0] == atom_ed448) + type = EVP_PKEY_ED448; else goto bad_arg; - if ((ctx = EVP_PKEY_CTX_new_id(type, NULL)) == NULL) - goto bad_arg; - - if (EVP_PKEY_keygen_init(ctx) != 1) - goto err; - if (EVP_PKEY_keygen(ctx, &pkey) != 1) - goto err; + if (argv[1] == atom_undefined) { + if ((ctx = EVP_PKEY_CTX_new_id(type, NULL)) == NULL) + goto bad_arg; + if (EVP_PKEY_keygen_init(ctx) != 1) + goto bad_arg; + if (EVP_PKEY_keygen(ctx, &pkey) != 1) + goto bad_arg; + } else { + if (!enif_inspect_binary(env, argv[1], &prv_key)) + goto bad_arg; + if ((pkey = EVP_PKEY_new_raw_private_key(type, NULL, prv_key.data, prv_key.size)) == NULL) + goto bad_arg; + } if (EVP_PKEY_get_raw_public_key(pkey, NULL, &key_len) != 1) goto err; |