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.
This commit is contained in:
Jesper Louis Andersen 2015-08-29 22:09:51 +02:00
parent 2cad66ac2a
commit b1c3e69fb5
3 changed files with 1 additions and 6 deletions

View File

@ -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}

View File

@ -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).

View File

@ -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).