add crypto_sign_ed25519_sk_to_pk
This commit is contained in:
parent
885662c069
commit
3442655c5b
@ -203,6 +203,27 @@ ERL_NIF_TERM enif_crypto_sign_ed25519_keypair(ErlNifEnv *env, int argc, ERL_NIF_
|
||||
return enif_make_tuple2(env, enif_make_binary(env, &pk), enif_make_binary(env, &sk));
|
||||
}
|
||||
|
||||
static
|
||||
ERL_NIF_TERM enif_crypto_sign_ed25519_sk_to_pk(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
|
||||
ErlNifBinary pk, sk;
|
||||
|
||||
if ((argc != 1)
|
||||
|| (!enif_inspect_binary(env, argv[0], &sk))
|
||||
|| (sk.size != crypto_sign_ed25519_SECRETKEYBYTES)) {
|
||||
return enif_make_badarg(env);
|
||||
}
|
||||
|
||||
if (!enif_alloc_binary(crypto_sign_ed25519_PUBLICKEYBYTES, &pk)) {
|
||||
return nacl_error_tuple(env, "alloc_failed");
|
||||
}
|
||||
|
||||
if (crypto_sign_ed25519_sk_to_pk(pk.data, sk.data) != 0) {
|
||||
return nacl_error_tuple(env, "crypto_sign_ed25519_sk_to_pk_failed");
|
||||
}
|
||||
|
||||
return enif_make_binary(env, &pk);
|
||||
}
|
||||
|
||||
static
|
||||
ERL_NIF_TERM enif_crypto_sign_ed25519_public_to_curve25519(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[]) {
|
||||
ErlNifBinary curve25519_pk, ed25519_pk;
|
||||
@ -1735,6 +1756,7 @@ static ErlNifFunc nif_funcs[] = {
|
||||
erl_nif_dirty_job_cpu_bound_macro("crypto_curve25519_scalarmult_base", 1, enif_crypto_curve25519_scalarmult_base),
|
||||
|
||||
erl_nif_dirty_job_cpu_bound_macro("crypto_sign_ed25519_keypair", 0, enif_crypto_sign_ed25519_keypair),
|
||||
{"crypto_sign_ed25519_sk_to_pk", 1, enif_crypto_sign_ed25519_sk_to_pk},
|
||||
{"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_PUBLICKEYBYTES", 0, enif_crypto_sign_ed25519_PUBLICKEYBYTES},
|
||||
|
@ -137,6 +137,7 @@
|
||||
-export([
|
||||
%% No Tests!
|
||||
crypto_sign_ed25519_keypair/0,
|
||||
crypto_sign_ed25519_sk_to_pk/1,
|
||||
crypto_sign_ed25519_public_to_curve25519/1,
|
||||
crypto_sign_ed25519_secret_to_curve25519/1,
|
||||
crypto_sign_ed25519_public_size/0,
|
||||
@ -957,6 +958,12 @@ crypto_sign_ed25519_keypair() ->
|
||||
{PK, SK} = enacl_nif:crypto_sign_ed25519_keypair(),
|
||||
#{ public => PK, secret => SK }.
|
||||
|
||||
%% @doc TODO
|
||||
%% @end
|
||||
-spec crypto_sign_ed25519_sk_to_pk(Secret :: binary()) -> binary().
|
||||
crypto_sign_ed25519_sk_to_pk(Secret) ->
|
||||
enacl_nif:crypto_sign_ed25519_sk_to_pk(Secret).
|
||||
|
||||
%% @doc crypto_sign_ed25519_public_to_curve25519/1 converts a given Ed 25519 public
|
||||
%% key to a Curve 25519 public key.
|
||||
%% @end
|
||||
|
@ -105,6 +105,7 @@
|
||||
%% Ed 25519
|
||||
-export([
|
||||
crypto_sign_ed25519_keypair/0,
|
||||
crypto_sign_ed25519_sk_to_pk/1,
|
||||
crypto_sign_ed25519_public_to_curve25519/1,
|
||||
crypto_sign_ed25519_secret_to_curve25519/1,
|
||||
crypto_sign_ed25519_PUBLICKEYBYTES/0,
|
||||
@ -277,6 +278,7 @@ crypto_curve25519_scalarmult(_Secret, _BasePoint) -> erlang:nif_error(nif_not_lo
|
||||
crypto_curve25519_scalarmult_base(_Secret) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
crypto_sign_ed25519_keypair() -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_sign_ed25519_sk_to_pk(_SecretKey) -> 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_PUBLICKEYBYTES() -> erlang:nif_error(nif_not_loaded).
|
||||
|
Loading…
x
Reference in New Issue
Block a user