From 97ee4bbdcf900b8ee09fdec70d808da5c4b0761a Mon Sep 17 00:00:00 2001 From: Jesper Louis Andersen Date: Wed, 15 Jan 2020 14:05:25 +0100 Subject: [PATCH] Use randombytes_uint32 Better name. Says what you are getting. --- CHANGELOG.md | 2 +- c_src/enacl_nif.c | 8 ++++---- src/enacl.erl | 10 +++++----- src/enacl_nif.erl | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0d3c2..dc42b33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). ## [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. - Implement enacl:randombytes_uniform/1. Takes up to a 32bit unsigned integer and produces a uniform integer in the range [0..N). Note diff --git a/c_src/enacl_nif.c b/c_src/enacl_nif.c index c66193a..93c69a3 100644 --- a/c_src/enacl_nif.c +++ b/c_src/enacl_nif.c @@ -1029,8 +1029,8 @@ static ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc, return enif_make_binary(env, &result); } -static ERL_NIF_TERM enif_randombytes_int32(ErlNifEnv *env, int argc, - ERL_NIF_TERM const argv[]) { +static ERL_NIF_TERM enif_randombytes_uint32(ErlNifEnv *env, int argc, + ERL_NIF_TERM const argv[]) { ErlNifUInt64 result; 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. 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_int32", 0, - enif_randombytes_int32), + erl_nif_dirty_job_cpu_bound_macro("randombytes_uint32", 0, + enif_randombytes_uint32), erl_nif_dirty_job_cpu_bound_macro("randombytes_uniform", 1, enif_randombytes_uniform), diff --git a/src/enacl.erl b/src/enacl.erl index d1bd28d..3ea4ede 100644 --- a/src/enacl.erl +++ b/src/enacl.erl @@ -123,7 +123,7 @@ -export([ %% EQC randombytes/1, - randombytes_int32/0, + randombytes_uint32/0, randombytes_uniform/1 ]). @@ -1124,11 +1124,11 @@ aead_chacha20poly1305_MESSAGEBYTES_MAX() -> 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 --spec randombytes_int32() -> integer(). -randombytes_int32() -> - enacl_nif:randombytes_int32(). +-spec randombytes_uint32() -> integer(). +randombytes_uint32() -> + enacl_nif:randombytes_uint32(). %% @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 diff --git a/src/enacl_nif.erl b/src/enacl_nif.erl index 7b48252..9b4c7ce 100644 --- a/src/enacl_nif.erl +++ b/src/enacl_nif.erl @@ -154,7 +154,7 @@ %% Access to the RNG -export([ randombytes/1, - randombytes_int32/0, + randombytes_uint32/0, 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). 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). scramble_block_16(_Block, _Key) -> erlang:nif_error(nif_not_loaded).