Use randombytes_uint32
Better name. Says what you are getting.
This commit is contained in:
parent
3c8d54d87b
commit
97ee4bbdcf
@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
- Implement enacl:randombytes_int32/0. Returns a random 32bit unsigned
|
- Implement enacl:randombytes_uint32/0. Returns a random 32bit unsigned
|
||||||
integer, by means of the underlying random source.
|
integer, by means of the underlying random source.
|
||||||
- Implement enacl:randombytes_uniform/1. Takes up to a 32bit unsigned
|
- Implement enacl:randombytes_uniform/1. Takes up to a 32bit unsigned
|
||||||
integer and produces a uniform integer in the range [0..N). Note
|
integer and produces a uniform integer in the range [0..N). Note
|
||||||
|
@ -1029,8 +1029,8 @@ static ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc,
|
|||||||
return enif_make_binary(env, &result);
|
return enif_make_binary(env, &result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ERL_NIF_TERM enif_randombytes_int32(ErlNifEnv *env, int argc,
|
static ERL_NIF_TERM enif_randombytes_uint32(ErlNifEnv *env, int argc,
|
||||||
ERL_NIF_TERM const argv[]) {
|
ERL_NIF_TERM const argv[]) {
|
||||||
ErlNifUInt64 result;
|
ErlNifUInt64 result;
|
||||||
|
|
||||||
if (argc != 0) {
|
if (argc != 0) {
|
||||||
@ -1770,8 +1770,8 @@ static ErlNifFunc nif_funcs[] = {
|
|||||||
// main scheduler. Otherwise, it it would probably be fine to run on the
|
// main scheduler. Otherwise, it it would probably be fine to run on the
|
||||||
// main scheduler. This plays it safe, albeit with a performance hit.
|
// main scheduler. This plays it safe, albeit with a performance hit.
|
||||||
erl_nif_dirty_job_cpu_bound_macro("randombytes", 1, enif_randombytes),
|
erl_nif_dirty_job_cpu_bound_macro("randombytes", 1, enif_randombytes),
|
||||||
erl_nif_dirty_job_cpu_bound_macro("randombytes_int32", 0,
|
erl_nif_dirty_job_cpu_bound_macro("randombytes_uint32", 0,
|
||||||
enif_randombytes_int32),
|
enif_randombytes_uint32),
|
||||||
erl_nif_dirty_job_cpu_bound_macro("randombytes_uniform", 1,
|
erl_nif_dirty_job_cpu_bound_macro("randombytes_uniform", 1,
|
||||||
enif_randombytes_uniform),
|
enif_randombytes_uniform),
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@
|
|||||||
-export([
|
-export([
|
||||||
%% EQC
|
%% EQC
|
||||||
randombytes/1,
|
randombytes/1,
|
||||||
randombytes_int32/0,
|
randombytes_uint32/0,
|
||||||
randombytes_uniform/1
|
randombytes_uniform/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
@ -1124,11 +1124,11 @@ aead_chacha20poly1305_MESSAGEBYTES_MAX() ->
|
|||||||
randombytes(N) ->
|
randombytes(N) ->
|
||||||
enacl_nif:randombytes(N).
|
enacl_nif:randombytes(N).
|
||||||
|
|
||||||
%% @doc randombytes_int32/0 produces an integer in the 32bit range
|
%% @doc randombytes_uint32/0 produces an integer in the 32bit range
|
||||||
%% @end
|
%% @end
|
||||||
-spec randombytes_int32() -> integer().
|
-spec randombytes_uint32() -> integer().
|
||||||
randombytes_int32() ->
|
randombytes_uint32() ->
|
||||||
enacl_nif:randombytes_int32().
|
enacl_nif:randombytes_uint32().
|
||||||
|
|
||||||
%% @doc randombytes_uniform/1 produces a random integer in the space [0..N)
|
%% @doc randombytes_uniform/1 produces a random integer in the space [0..N)
|
||||||
%% That is with the upper bound excluded. Fails for integers above 32bit size
|
%% That is with the upper bound excluded. Fails for integers above 32bit size
|
||||||
|
@ -154,7 +154,7 @@
|
|||||||
%% Access to the RNG
|
%% Access to the RNG
|
||||||
-export([
|
-export([
|
||||||
randombytes/1,
|
randombytes/1,
|
||||||
randombytes_int32/0,
|
randombytes_uint32/0,
|
||||||
randombytes_uniform/1
|
randombytes_uniform/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ crypto_kx_PUBLICKEYBYTES() -> erlang:nif_error(nif_not_loaded).
|
|||||||
crypto_kx_SECRETKEYBYTES() -> erlang:nif_error(nif_not_loaded).
|
crypto_kx_SECRETKEYBYTES() -> erlang:nif_error(nif_not_loaded).
|
||||||
|
|
||||||
randombytes(_RequestedSize) -> erlang:nif_error(nif_not_loaded).
|
randombytes(_RequestedSize) -> erlang:nif_error(nif_not_loaded).
|
||||||
randombytes_int32() -> erlang:nif_error(nif_not_loaded).
|
randombytes_uint32() -> erlang:nif_error(nif_not_loaded).
|
||||||
randombytes_uniform(_UpperBound) -> erlang:nif_error(nif_not_loaded).
|
randombytes_uniform(_UpperBound) -> erlang:nif_error(nif_not_loaded).
|
||||||
|
|
||||||
scramble_block_16(_Block, _Key) -> erlang:nif_error(nif_not_loaded).
|
scramble_block_16(_Block, _Key) -> erlang:nif_error(nif_not_loaded).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user