-
Notifications
You must be signed in to change notification settings - Fork 25
Pwhash implementation #7
base: master
Are you sure you want to change the base?
Conversation
work in progress for pwhash implementation. here is the code I use to test: require Salty.Nif
### pwhash
outlen = 16
password = "thepassword"
{:ok, password_salt} = Salty.Nif.randombytes_buf(16)
opslimit = 2
memlimit = Salty.Nif.pwhash_argon2id_MEMLIMIT_INTERACTIVE
# alg can either be pwhash_ALG_ARGON2ID13 or pwhash_ALG_ARGON2I13
alg = Salty.Nif.pwhash_ALG_ARGON2ID13
# alg = Salty.Nif.pwhash_ALG_ARGON2I13
{:ok, pwhash} = Salty.Nif.pwhash(outlen, password, password_salt, opslimit, memlimit, alg) also the code for str_verify and needs_rehash is in progress as well - I pull request to reach out for help and get feedback and understand what I am missing. thanks |
Hi there, and thanks for taking the time to work on this! The approach to high level APIs in this library is to not bind them directly, but provide a method "primitive()" that returns the module that implements the default (high level) primitive. Take the secretbox API as an example. In case of Salty.PwHash, that would lead to exposing the pwhash/pwhash_str/str_verify/str_needs_rehash methods in the modules that implement the primitives (Salty.PwHash.Scrypt, Salty.PwHash.Argon2i, Salty.PwHash.Argon2id), and returning the Argon2id module from the Salty.PwHash.primitive() method. This removes the requirement to work with algorithm identifiers altogether, and lets you call the primitives' implementations directly in salty_nif.c instead. As a special case, the str_verify/str_needs_rehash methods could be implemented in the Salty.PwHash module as well, as they do not need any algorithm specific input parameters. That aside, what is the error message that you're getting? Also, which version of libsodium are you using, and on which system are you testing? On another note, in order to use pwhash within Elixir (or Erlang's VM for that matter), the methods for pwhash, str and str_verify will need to use the dirty scheduler in order for applications to be able to use it without messing up the scheduler. I hope this answers some of your questions, let me know if there is anything else. |
Hi @ArteMisc - I apologize for the delay and thanks a lot for your detailed explanation. If I try a few more times I have a segmentation fault:
I am using Hopefully that helps troubleshooting. Thanks |
Implementing primitives now @ArteMisc to respect high level API approach. |
updated the pull request - the seg fault no longer happens. outlen = 16
password = "thepassword"
{:ok, password_salt} = Salty.Nif.randombytes_buf(16)
opslimit = Salty.PwHash.Argon2i.opslimit_interactive
memlimit = Salty.PwHash.Argon2i.memlimit_interactive
alg = Salty.PwHash.Argon2i.alg
{:ok, pwhash} = Salty.PwHash.Argon2i.pwhash(outlen, password, password_salt, opslimit, memlimit, alg) |
any updates @ArteMisc ? thanks |
No description provided.