Commit b1c3e69f authored by Jesper Louis Andersen's avatar Jesper Louis Andersen

Change randombytes/1 so it always executes on a DS

Investigation shows erratic behaviour of the CSPRNG. It may block at times
because it needs to go to the kernel and obtain more random information in
the system. Once this happens, you are blocked for quite a long time, but
we don't generally know when this happens. So just execute these directly
on the dirty scheduler.
parent 2cad66ac
......@@ -1071,7 +1071,6 @@ static ErlNifFunc nif_funcs[] = {
{"crypto_sign_ed25519_PUBLICKEYBYTES", 0, enif_crypto_sign_ed25519_PUBLICKEYBYTES},
{"crypto_sign_ed25519_SECRETKEYBYTES", 0, enif_crypto_sign_ed25519_SECRETKEYBYTES},
{"randombytes_b", 1, enif_randombytes},
{"randombytes", 1, enif_randombytes, ERL_NIF_DIRTY_JOB_CPU_BOUND},
{"scramble_block_16", 2, enif_scramble_block_16}
......
......@@ -722,8 +722,6 @@ crypto_sign_ed25519_secret_size() ->
%% you to the underlying system implementations for random data.
%% @end
-spec randombytes(non_neg_integer()) -> binary().
randombytes(N) when N =< ?RANDOMBYTES_SIZE ->
bump(enacl_nif:randombytes_b(N), ?RANDOMBYTES_REDUCTIONS, ?RANDOMBYTES_SIZE, N);
randombytes(N) ->
enacl_nif:randombytes(N).
......
......@@ -101,8 +101,7 @@
%% Access to the RNG
-export([
randombytes/1,
randombytes_b/1
randombytes/1
]).
%% Undocumented features :>
......@@ -199,6 +198,5 @@ crypto_verify_16(_X, _Y) -> erlang:nif_error(nif_not_loaded).
crypto_verify_32(_X, _Y) -> erlang:nif_error(nif_not_loaded).
randombytes(_RequestedSize) -> erlang:nif_error(nif_not_loaded).
randombytes_b(_RequestedSize) -> erlang:nif_error(nif_not_loaded).
scramble_block_16(_Block, _Key) -> 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