wiki.techinc.nl/tests/phpunit/unit/includes/password/LayeredParameterizedPasswordTest.php
Kevin Israel 47241a3520 Use OpenSSL if available for PBKDF2 password hashing
This at least doubles the speed, which would allow the number of
iterations to be doubled and computation of the password hash to
complete in the same amount of time as before, or maybe even a
slight bit less.

The doubling in speed is due to an optimization[1] that so far has not
been accepted into PHP's hash extension.[2] In addition, OpenSSL has
optimized assembly-language hash function implementations for several
common CPU architectures. These provide a further, yet more slight,
performance improvement.

While OpenSSL's PKCS5_PBKDF2_HMAC() is not the fastest implementation
around, using it does not add a new library dependency. And although
better password hashing functions exist, PBKDF2 is still the default
in MediaWiki. For these reasons, I think this change makes sense.

[1]: https://github.com/openssl/openssl/commit/c10e3f0cffb3820d
[2]: https://github.com/php/php-src/issues/9604

Change-Id: I7b06590d4c42581f8749336f9c17777f973a506c
2022-10-04 19:46:14 -04:00

62 lines
1.7 KiB
PHP

<?php
/**
* @covers LayeredParameterizedPassword
* @covers Password
*/
class LayeredParameterizedPasswordTest extends PasswordTestCase {
protected function getTypeConfigs() {
return [
'testLargeLayeredTop' => [
'class' => LayeredParameterizedPassword::class,
'types' => [
'testLargeLayeredBottom',
'testLargeLayeredBottom',
'testLargeLayeredBottom',
'testLargeLayeredBottom',
'testLargeLayeredFinal',
],
],
'testLargeLayeredBottom' => [
'class' => Pbkdf2PasswordUsingHashExtension::class,
'algo' => 'sha512',
'cost' => 1024,
'length' => 512,
],
'testLargeLayeredFinal' => [
'class' => BcryptPassword::class,
'cost' => 5,
]
];
}
protected function getValidTypes() {
return [ 'testLargeLayeredFinal' ];
}
public static function providePasswordTests() {
return [
[
true,
':testLargeLayeredTop:sha512:1024:512!sha512:1024:512!sha512:1024:512!sha512:1024:512!5!vnRy+2SrSA0fHt3dwhTP5g==!AVnwfZsAQjn+gULv7FSGjA==!xvHUX3WcpkeSn1lvjWcvBg==!It+OC/N9tu+d3ByHhuB0BQ==!Tb.gqUOiD.aWktVwHM.Q/O!7CcyMfXUPky5ptyATJsR2nq3vUqtnBC',
'testPassword123'
],
];
// phpcs:enable
}
/**
* @covers LayeredParameterizedPassword::partialCrypt
*/
public function testLargeLayeredPartialUpdate() {
/** @var ParameterizedPassword $partialPassword */
$partialPassword = $this->passwordFactory->newFromType( 'testLargeLayeredBottom' );
$partialPassword->crypt( 'testPassword123' );
/** @var LayeredParameterizedPassword $totalPassword */
$totalPassword = $this->passwordFactory->newFromType( 'testLargeLayeredTop' );
$totalPassword->partialCrypt( $partialPassword );
$this->assertTrue( $totalPassword->verify( 'testPassword123' ) );
}
}