antelle / argon2-browser

Argon2 library compiled for browser runtime
https://antelle.net/argon2-browser
MIT License
367 stars 79 forks source link

Optional secret data support for hashing the password. #44

Closed DomainFlag closed 3 years ago

DomainFlag commented 4 years ago

Does it have support for providing the optional secret data besides the password / salt for keyed hashing? If not, can you provide any tips how to achieve that? Thanks.

antelle commented 4 years ago

Hi! If I'm not mistaken, you can make keyed hashing from any cryptographic hash function. However Argon2 is not a hashing function per se (it is, but it's a key derivation function, which means it's designed to be computation-hard), it's not clear why you need it for keyed hashing. But it should be possible to implement. I'd suggest asking in the argon2 repo itself though, this repo is just a fork for WebAssembly, probably you'll get better advice from experts there.

DomainFlag commented 4 years ago

@antelle thanks for the quick response, I mean that I am using the Argon2 Repo the official one in Objective-C + Swift and if you have a look at the argon2_context that they use to initialize before key derivation, there is an optional secret data parameter used for keyed hashing that allows a secret key to be an extra input at hashing time. But, the argon2.hash in your repo does not support such parameter if I am not mistaken?

antelle commented 4 years ago

I see, didn't know it supported this parameter, thanks for pointing that out! It makes sense to add support indeed.

antelle commented 3 years ago

Done, now you can do this:

argon2.hash({
    ...
    secret: new Uint8Array([...]), // optional secret data
    ad: new Uint8Array([...]), // optional associated data
})