Skip to content

Commit b7f2f93

Browse files
MichaIngbackportbot[bot]
authored andcommitted
Fix Argon2 options checks
The minimum for memory cost is 8 KiB per thread. Threads must be checked and set first to allow checking against the correct memory cost mimimum. Options are now applied the following way: - If config.php contains the setting with an integer higher or equal to the minimum, it is applied. - If config.php contains the setting with an integer lower than the minimum, the minimum is applied. - If config.php does not contain the setting or with no integer value, the PHP default is applied. Signed-off-by: MichaIng <micha@dietpi.com> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 4e334dd commit b7f2f93

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/private/Security/Hasher.php

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

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

7873
$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
@@ -102,6 +102,11 @@ protected function setUp() {
102102

103103
$this->config = $this->createMock(IConfig::class);
104104

105+
$this->config->method('getSystemValueInt')
106+
->willReturnCallback(function ($name, $default) {
107+
return $default;
108+
});
109+
105110
$this->hasher = new Hasher($this->config);
106111
}
107112

0 commit comments

Comments
 (0)