Skip to content

Commit b5216aa

Browse files
authored
Merge pull request #45027 from remicollet/argon-sodium-threads
fix(argon2): respect max value for hashingThreads
2 parents 4841cad + eb32f1d commit b5216aa

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

lib/private/Security/Hasher.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ 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. So apply minimum/maximum.
44+
/** @psalm-suppress TypeDoesNotContainType - The constant defaults to "standard" but when sodium is installed it will be "sodium" */
45+
if (PASSWORD_ARGON2_PROVIDER === 'sodium') {
46+
$this->options['threads'] = 1;
47+
} else {
48+
// standard (libargon) or openssl
49+
$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
50+
}
4651
// The minimum memory cost is 8 KiB per thread.
4752
$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
4853
$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);

0 commit comments

Comments
 (0)