Skip to content

Commit 8d5404b

Browse files
authored
Merge pull request #20710 from nextcloud/fix/argon2-options-checks
Fix Argon2 options checks
2 parents fa914f2 + ad60619 commit 8d5404b

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

lib/private/Security/Hasher.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,11 @@ public function __construct(IConfig $config) {
6767

6868
if (\defined('PASSWORD_ARGON2I')) {
6969
// password_hash fails, when the minimum values are undershot.
70-
// In this case, ignore and revert to default
71-
if ($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 8) {
72-
$this->options['memory_cost'] = $this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST);
73-
}
74-
if ($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
75-
$this->options['time_cost'] = $this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST);
76-
}
77-
if ($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_MEMORY_COST) >= 1) {
78-
$this->options['threads'] = $this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS);
79-
}
70+
// In this case, apply minimum.
71+
$this->options['threads'] = max($this->config->getSystemValueInt('hashingThreads', PASSWORD_ARGON2_DEFAULT_THREADS), 1);
72+
// The minimum memory cost is 8 KiB per thread.
73+
$this->options['memory_cost'] = max($this->config->getSystemValueInt('hashingMemoryCost', PASSWORD_ARGON2_DEFAULT_MEMORY_COST), $this->options['threads'] * 8);
74+
$this->options['time_cost'] = max($this->config->getSystemValueInt('hashingTimeCost', PASSWORD_ARGON2_DEFAULT_TIME_COST), 1);
8075
}
8176

8277
$hashingCost = $this->config->getSystemValue('hashingCost', null);

tests/lib/Security/HasherTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ protected function setUp(): void {
113113

114114
$this->config = $this->createMock(IConfig::class);
115115

116+
$this->config->method('getSystemValueInt')
117+
->willReturnCallback(function ($name, $default) {
118+
return $default;
119+
});
120+
116121
$this->hasher = new Hasher($this->config);
117122
}
118123

0 commit comments

Comments
 (0)