Skip to content

Commit 2be8c3f

Browse files
remicolletAltahrim
authored andcommitted
also respect max value for hashingThreads
Signed-off-by: Remi Collet <remi@php.net>
1 parent a1fbd55 commit 2be8c3f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

lib/private/Security/Hasher.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ class Hasher implements IHasher {
3939
public function __construct(
4040
private IConfig $config,
4141
) {
42-
if (\defined('PASSWORD_ARGON2ID') || \defined('PASSWORD_ARGON2I')) {
43-
// password_hash fails, when the minimum values are undershot.
44-
// In this case, apply minimum.
45-
$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
42+
if (\defined('PASSWORD_ARGON2_PROVIDER')) {
43+
// password_hash fails, when the minimum values are undershot or maximum overshot
44+
// In this case, apply minimum/maximum.
45+
if (PASSWORD_ARGON2_PROVIDER === 'sodium') {
46+
$this->options['threads'] = 1;
47+
} else { // standard (libargon) or openssl
48+
$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
49+
}
4650
// The minimum memory cost is 8 KiB per thread.
4751
$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
4852
$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);

0 commit comments

Comments
 (0)