mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
Use openssl_digest() instead of hash() in network hot code
openssl_digest() is TWICE as fast as hash() on my machine for the same data and same algorithm. I can only guess that OpenSSL is more optimized than PHP ext/standard :)
This commit is contained in:
parent
59a51a6c75
commit
4b7300de8d
@ -78,6 +78,6 @@ class NetworkCipher{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function calculateChecksum(int $counter, string $payload) : string{
|
private function calculateChecksum(int $counter, string $payload) : string{
|
||||||
return substr(hash(self::CHECKSUM_ALGO, Binary::writeLLong($counter) . $payload . $this->key, true), 0, 8);
|
return substr(openssl_digest(Binary::writeLLong($counter) . $payload . $this->key, self::CHECKSUM_ALGO, true), 0, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class ProcessLoginTask extends AsyncTask{
|
|||||||
$salt = random_bytes(16);
|
$salt = random_bytes(16);
|
||||||
$sharedSecret = $serverPriv->createExchange($clientPub)->calculateSharedKey();
|
$sharedSecret = $serverPriv->createExchange($clientPub)->calculateSharedKey();
|
||||||
|
|
||||||
$this->aesKey = hash('sha256', $salt . hex2bin(str_pad(gmp_strval($sharedSecret, 16), 96, "0", STR_PAD_LEFT)), true);
|
$this->aesKey = openssl_digest($salt . hex2bin(str_pad(gmp_strval($sharedSecret, 16), 96, "0", STR_PAD_LEFT)), 'sha256', true);
|
||||||
$this->handshakeJwt = $this->generateServerHandshakeJwt($serverPriv, $salt);
|
$this->handshakeJwt = $this->generateServerHandshakeJwt($serverPriv, $salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user