|null */ private static $digestAlgos; /** * List of hash algorithms we support and OpenSSL's names for them. * * We include only the algorithms that make sense to support, rather than * all potentially available algorithms. In particular, we do not include: * * - Broken algorithms, such as "md5" and "sha1" * - Algorithms no longer available by default, such as "whirlpool" * - Algorithms that perform especially poorly on server CPUs relative * to other available hardware (as of 2022, this includes "sha3-512"; * see ) * - Variants for which there is no reason for use, such as "sha384" * (a truncated "sha512" that starts with a different initial state) * * The array keys should match the algorithm names known to hash_pbkdf2(). */ private const DIGEST_ALGOS = [ 'sha256' => 'sha256', 'sha512' => 'sha512', ]; protected function getDigestAlgo( string $algo ): ?string { if ( self::$digestAlgos === null ) { self::$digestAlgos = array_intersect( self::DIGEST_ALGOS, openssl_get_md_methods() ); } return self::$digestAlgos[$algo] ?? null; } protected function pbkdf2( string $digestAlgo, string $password, string $salt, int $rounds, int $length ): string { // Clear error string while ( openssl_error_string() !== false ); $hash = openssl_pbkdf2( $password, $salt, $length, $rounds, $digestAlgo ); if ( !is_string( $hash ) ) { throw new PasswordError( 'Error when hashing password: ' . openssl_error_string() ); } return $hash; } } /** @deprecated since 1.43 use MediaWiki\\Password\\Pbkdf2PasswordUsingOpenSSL */ class_alias( Pbkdf2PasswordUsingOpenSSL::class, 'Pbkdf2PasswordUsingOpenSSL' );