charlesportwoodii / php-argon2-ext

PHP7 extension for Argon2
Other
33 stars 4 forks source link

Feature Request: functions to use as KDF #7

Closed My1 closed 6 years ago

My1 commented 6 years ago

One thing that would totally be awesome would be having a side-function that just takes the parameters including a salt and outputs a key which then can be used for example to encrypt stuff.

especially as the description notes it as a sucessor to PBKDF, which obviously is a KDF.

charlesportwoodii commented 6 years ago
argon2_hash(string $string [, const $algorithm = HASH_ARGON2ID] [, array $options ] [, bool $raw = false ]);

The raw option outputs the KDF you're looking for per the Argon2 spec sans the salt option.

If you need a salt, use sodium, as it supersedes this library.

https://paragonie.com/book/pecl-libsodium/read/07-password-hashing.md#crypto-pwhash

$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
$out_len = SODIUM_CRYPTO_SIGN_SEEDBYTES;
$seed = sodium_crypto_pwhash(
    $out_len,
    $password,
    $salt,
    SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
    SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
My1 commented 6 years ago

well for a KDF you obviously need the salt option because you need to be able to generate that key later to access what's been crypted with it.

That they only do Argon2i for that is sad though.

charlesportwoodii commented 6 years ago

With this library, the salt is generated automatically for you. It simply doesn't provide an option to pass your own.

The default in libsodium was changed to Argon2id, so if your sodium extension is compiled against the latest, it'll use Argon2id by default. The last option however lets you specify the algorithm: https://github.com/jedisct1/libsodium-php/blob/master/libsodium.c#L1811. The constant you'd pass is SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13.

Reference the sodium extension source code for more details on how to accomplish what you're trying to do.