Implemented nif for crypto_pwhash()
This commit is contained in:
committed by
Irina Guberman
parent
f395f65389
commit
43cae7c7ea
@@ -106,6 +106,13 @@
|
||||
kx_session_key_size/0
|
||||
]).
|
||||
|
||||
%% Password Hashing - Argon2 Algorithm
|
||||
-export([
|
||||
pwhash/2,
|
||||
pwhash_str/1,
|
||||
pwhash_str_verify/2
|
||||
]).
|
||||
|
||||
%% Libsodium specific functions (which are also part of the "undocumented" interface to NaCl
|
||||
-export([
|
||||
randombytes/1
|
||||
@@ -249,6 +256,32 @@ unsafe_memzero(X) when is_binary(X) ->
|
||||
unsafe_memzero(_) ->
|
||||
error(badarg).
|
||||
|
||||
|
||||
%% @doc pwhash/2 hash a password
|
||||
%%
|
||||
%% This function generates a fixed size salted hash of a user defined password.
|
||||
%% @end
|
||||
-spec pwhash(iodata(), binary()) -> {ok, binary()} | {error, term()}.
|
||||
pwhash(Password, Salt) ->
|
||||
enacl_nif:crypto_pwhash(Password, Salt).
|
||||
|
||||
%% @doc pwhash_str_verify/2 generates a ASCII encoded hash of a password
|
||||
%%
|
||||
%% This function generates a fixed size, salted, ASCII encoded hash of a user defined password.
|
||||
%% @end
|
||||
-spec pwhash_str(iodata()) -> {ok, iodata()} | {error, term()}.
|
||||
pwhash_str(Password) ->
|
||||
enacl_nif:crypto_pwhash_str(Password).
|
||||
|
||||
%% @doc pwhash_str_verify/2 compares a password with a hash
|
||||
%%
|
||||
%% This function verifies that the hash is generated from the password. The
|
||||
%% function returns true if the verifcate succeeds, false otherwise
|
||||
%% @end
|
||||
-spec pwhash_str_verify(binary(), iodata()) -> boolean().
|
||||
pwhash_str_verify(HashPassword, Password) ->
|
||||
enacl_nif:crypto_pwhash_str_verify(HashPassword, Password).
|
||||
|
||||
%% Public Key Crypto
|
||||
%% ---------------------
|
||||
%% @doc box_keypair/0 creates a new Public/Secret keypair.
|
||||
@@ -913,6 +946,8 @@ kx_public_key_size() ->
|
||||
kx_secret_key_size() ->
|
||||
enacl_nif:crypto_kx_SECRETKEYBYTES().
|
||||
|
||||
|
||||
|
||||
%% Obtaining random bytes
|
||||
|
||||
%% @doc randombytes/1 produces a stream of random bytes of the given size
|
||||
|
||||
@@ -122,6 +122,13 @@
|
||||
sodium_memzero/1
|
||||
]).
|
||||
|
||||
%% Password Hashing - Argon2 Algorithm
|
||||
-export([
|
||||
crypto_pwhash/2,
|
||||
crypto_pwhash_str/1,
|
||||
crypto_pwhash_str_verify/2
|
||||
]).
|
||||
|
||||
%% Access to the RNG
|
||||
-export([
|
||||
randombytes/1
|
||||
@@ -146,6 +153,10 @@ init() ->
|
||||
SoName = filename:join(Dir, atom_to_list(?MODULE)),
|
||||
erlang:load_nif(SoName, 0).
|
||||
|
||||
crypto_pwhash(Password, Salt) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_pwhash_str(Password) -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_pwhash_str_verify(HashedPassword, Password) -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
crypto_box_NONCEBYTES() -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_box_ZEROBYTES() -> erlang:nif_error(nif_not_loaded).
|
||||
crypto_box_BOXZEROBYTES() -> erlang:nif_error(nif_not_loaded).
|
||||
|
||||
Reference in New Issue
Block a user