Merge pull request #48 from kuon/patch-0

Add pwhash_SALTBYTES/0
This commit is contained in:
Jesper Louis Andersen 2020-06-09 11:56:18 +02:00 committed by GitHub
commit a45d3863e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 0 deletions

View File

@ -287,6 +287,7 @@ static ErlNifFunc nif_funcs[] = {
{"crypto_verify_32", 2, enacl_crypto_verify_32},
{"sodium_memzero", 1, enif_sodium_memzero},
{"crypto_pwhash_SALTBYTES", 0, enacl_crypto_pwhash_SALTBYTES},
erl_nif_dirty_job_cpu_bound_macro("crypto_pwhash", 4, enacl_crypto_pwhash),
erl_nif_dirty_job_cpu_bound_macro("crypto_pwhash_str", 3,
enacl_crypto_pwhash_str),

View File

@ -57,6 +57,12 @@ static size_t enacl_pwhash_memlimit(ErlNifEnv *env, ERL_NIF_TERM arg) {
return 0;
}
ERL_NIF_TERM enacl_crypto_pwhash_SALTBYTES(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]) {
return enif_make_int64(env, crypto_pwhash_SALTBYTES);
}
ERL_NIF_TERM enacl_crypto_pwhash(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]) {
ErlNifBinary h, p, s;

View File

@ -3,6 +3,9 @@
#include <erl_nif.h>
ERL_NIF_TERM enacl_crypto_pwhash_SALTBYTES(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]);
ERL_NIF_TERM enacl_crypto_pwhash(ErlNifEnv *env, int argc,
ERL_NIF_TERM const argv[]);

View File

@ -116,6 +116,7 @@
shorthash_size/0,
shorthash/2,
pwhash_SALTBYTES/0,
pwhash/4,
pwhash_str/3,
@ -395,6 +396,13 @@ generichash_final(State) ->
enacl_nif:crypto_generichash_final(State).
-type pwhash_limit() :: interactive | moderate | sensitive | pos_integer().
%% @doc pwhash_SALTBYTES/0 returns the number of bytes required for salt.
%% @end
-spec pwhash_SALTBYTES() -> pos_integer().
pwhash_SALTBYTES() ->
enacl_nif:crypto_pwhash_SALTBYTES().
%% @doc pwhash/2 hash a password
%%
%% This function generates a fixed size salted hash of a user defined password.

View File

@ -147,6 +147,7 @@
%% Password Hashing - Argon2 Algorithm
-export([
crypto_pwhash_SALTBYTES/0,
crypto_pwhash/4,
crypto_pwhash_str/3,
crypto_pwhash_str_verify/2
@ -238,6 +239,7 @@ crypto_secretstream_xchacha20poly1305_init_pull(_Header, _Key) -> erlang:nif_err
crypto_secretstream_xchacha20poly1305_pull(_Ref, _CipherText, _AD) -> erlang:nif_error(nif_not_loaded).
crypto_secretstream_xchacha20poly1305_rekey(_Ref) -> erlang:nif_error(nif_not_loaded).
crypto_pwhash_SALTBYTES() -> erlang:nif_error(nif_not_loaded).
crypto_pwhash(_Password, _Salt, _Ops, _Mem) -> erlang:nif_error(nif_not_loaded).
crypto_pwhash_str(_Password, _Ops, _Mem) -> erlang:nif_error(nif_not_loaded).
crypto_pwhash_str_verify(_HashedPassword, _Password) -> erlang:nif_error(nif_not_loaded).

View File

@ -136,6 +136,7 @@ pwhash(_Config) ->
Str1 = enacl:pwhash_str(PW),
true = enacl:pwhash_str_verify(Str1, PW),
false = enacl:pwhash_str_verify(Str1, <<PW/binary, 1>>),
16 = enacl:pwhash_SALTBYTES(),
ok.
sign(_Config) ->