Add crypto_sign_ed25519_sk_to_pk/1 API.

This patch implements the enacl:crypto_sign_ed25519_sk_to_pk/1 for
generating the public key from a given Ed25519 secret key.
parent ab0e5211
......@@ -184,6 +184,27 @@ ERL_NIF_TERM enif_crypto_sign_ed25519_secret_to_curve25519(ErlNifEnv *env, int a
return enif_make_binary(env, &curve25519_sk);
}
static
ERL_NIF_TERM enif_crypto_sign_ed25519_sk_to_pk(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
ErlNifBinary ed25519_sk, ed25519_pk;
if ((argc != 1)
|| (!enif_inspect_binary(env, argv[0], &ed25519_sk))
|| (ed25519_sk.size != crypto_sign_ed25519_SECRETKEYBYTES)) {
return enif_make_badarg(env);
}
if (!enif_alloc_binary(crypto_sign_PUBLICKEYBYTES, &ed25519_pk)) {
return nacl_error_tuple(env, "alloc_failed");
}
if (crypto_sign_ed25519_sk_to_pk(ed25519_pk.data, ed25519_sk.data) != 0) {
return nacl_error_tuple(env, "crypto_sign_ed25519_sk_to_pk_failed");
}
return enif_make_binary(env, &ed25519_pk);
}
static
ERL_NIF_TERM enif_crypto_sign_ed25519_PUBLICKEYBYTES(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
return enif_make_int64(env, crypto_sign_ed25519_PUBLICKEYBYTES);
......@@ -1068,6 +1089,7 @@ static ErlNifFunc nif_funcs[] = {
{"crypto_sign_ed25519_keypair", 0, enif_crypto_sign_ed25519_keypair, ERL_NIF_DIRTY_JOB_CPU_BOUND},
{"crypto_sign_ed25519_public_to_curve25519", 1, enif_crypto_sign_ed25519_public_to_curve25519},
{"crypto_sign_ed25519_secret_to_curve25519", 1, enif_crypto_sign_ed25519_secret_to_curve25519},
{"crypto_sign_ed25519_sk_to_pk", 1, enif_crypto_sign_ed25519_sk_to_pk},
{"crypto_sign_ed25519_PUBLICKEYBYTES", 0, enif_crypto_sign_ed25519_PUBLICKEYBYTES},
{"crypto_sign_ed25519_SECRETKEYBYTES", 0, enif_crypto_sign_ed25519_SECRETKEYBYTES},
......
......@@ -75,6 +75,7 @@
crypto_sign_ed25519_keypair/0,
crypto_sign_ed25519_public_to_curve25519/1,
crypto_sign_ed25519_secret_to_curve25519/1,
crypto_sign_ed25519_sk_to_pk/1,
crypto_sign_ed25519_public_size/0,
crypto_sign_ed25519_secret_size/0
]).
......@@ -699,6 +700,13 @@ crypto_sign_ed25519_secret_to_curve25519(SecretKey) ->
erlang:bump_reductions(?ED25519_SECRET_TO_CURVE_REDS),
R.
%% @doc crypto_sign_ed25519_sk_to_pk/1 computes a given Ed 25519 public key
%% from a secret key.
%% @end
-spec crypto_sign_ed25519_sk_to_pk(SecretKey :: binary()) -> binary().
crypto_sign_ed25519_sk_to_pk(SecretKey) ->
enacl_nif:crypto_sign_ed25519_sk_to_pk(SecretKey).
-spec crypto_sign_ed25519_public_size() -> pos_integer().
crypto_sign_ed25519_public_size() ->
enacl_nif:crypto_sign_ed25519_PUBLICKEYBYTES().
......
......@@ -87,6 +87,7 @@
crypto_sign_ed25519_keypair/0,
crypto_sign_ed25519_public_to_curve25519/1,
crypto_sign_ed25519_secret_to_curve25519/1,
crypto_sign_ed25519_sk_to_pk/1,
crypto_sign_ed25519_PUBLICKEYBYTES/0,
crypto_sign_ed25519_SECRETKEYBYTES/0
]).
......@@ -189,6 +190,7 @@ crypto_curve25519_scalarmult(_Secret, _BasePoint) -> erlang:nif_error(nif_not_lo
crypto_sign_ed25519_keypair() -> erlang:nif_error(nif_not_loaded).
crypto_sign_ed25519_public_to_curve25519(_PublicKey) -> erlang:nif_error(nif_not_loaded).
crypto_sign_ed25519_secret_to_curve25519(_SecretKey) -> erlang:nif_error(nif_not_loaded).
crypto_sign_ed25519_sk_to_pk(_SecretKey) -> erlang:nif_error(nif_not_loaded).
crypto_sign_ed25519_PUBLICKEYBYTES() -> erlang:nif_error(nif_not_loaded).
crypto_sign_ed25519_SECRETKEYBYTES() -> erlang:nif_error(nif_not_loaded).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment