Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
argon2i | |
83.33% |
10 / 12 |
|
50.00% |
2 / 4 |
9.37 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
6 | |||
get_algo_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_options | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
get_prefix | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\passwords\driver; |
15 | |
16 | class argon2i extends base_native |
17 | { |
18 | /** @var int Maximum memory (in bytes) that may be used to compute the Argon2 hash */ |
19 | protected $memory_cost; |
20 | |
21 | /** @var int Number of threads to use for computing the Argon2 hash */ |
22 | protected $threads; |
23 | |
24 | /** @var int Maximum amount of time it may take to compute the Argon2 hash */ |
25 | protected $time_cost; |
26 | |
27 | /** |
28 | * Constructor of passwords driver object |
29 | * |
30 | * @param \phpbb\config\config $config phpBB config |
31 | * @param \phpbb\passwords\driver\helper $helper Password driver helper |
32 | * @param int $memory_cost Maximum memory (optional) |
33 | * @param int $threads Number of threads to use (optional) |
34 | * @param int $time_cost Maximum amount of time (optional) |
35 | */ |
36 | public function __construct(\phpbb\config\config $config, helper $helper, $memory_cost = 65536, $threads = 2, $time_cost = 4) |
37 | { |
38 | parent::__construct($config, $helper); |
39 | |
40 | /** |
41 | * For Sodium implementation of argon2 algorithm (since PHP 7.4), set special value of 1 for "threads" cost factor |
42 | * See https://wiki.php.net/rfc/sodium.argon.hash and PHPBB3-16266 |
43 | * Don't allow cost factors to be below default settings where possible |
44 | */ |
45 | $this->memory_cost = max($memory_cost, defined('PASSWORD_ARGON2_DEFAULT_MEMORY_COST') ? PASSWORD_ARGON2_DEFAULT_MEMORY_COST : 65536); |
46 | $this->time_cost = max($time_cost, defined('PASSWORD_ARGON2_DEFAULT_TIME_COST') ? PASSWORD_ARGON2_DEFAULT_TIME_COST : 4); |
47 | $this->threads = (defined('PASSWORD_ARGON2_PROVIDER') && PASSWORD_ARGON2_PROVIDER == 'sodium') ? |
48 | 1 : max($threads, defined('PASSWORD_ARGON2_DEFAULT_THREADS') ? PASSWORD_ARGON2_DEFAULT_THREADS : 1); |
49 | } |
50 | |
51 | /** |
52 | * {@inheritdoc} |
53 | */ |
54 | public function get_algo_name() |
55 | { |
56 | return 'PASSWORD_ARGON2I'; |
57 | } |
58 | |
59 | /** |
60 | * {@inheritdoc} |
61 | */ |
62 | public function get_options() |
63 | { |
64 | return [ |
65 | 'memory_cost' => $this->memory_cost, |
66 | 'time_cost' => $this->time_cost, |
67 | 'threads' => $this->threads |
68 | ]; |
69 | } |
70 | |
71 | /** |
72 | * {@inheritdoc} |
73 | */ |
74 | public function get_prefix() |
75 | { |
76 | return '$argon2i$'; |
77 | } |
78 | } |