public function testHash() { if (MWCryptHash::hashAlgo() !== 'whirlpool') { $this->markTestSkipped('Hash algorithm isn\'t whirlpool'); } $data = 'foobar'; $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9'; $this->assertEquals(pack('H*', $hash), MWCryptHash::hash($data), 'Raw hash'); $this->assertEquals($hash, MWCryptHash::hash($data, false), 'Hex hash'); }
public function testHash() { if (MWCryptHash::hashAlgo() !== 'whirlpool') { $this->markTestSkipped('Hash algorithm isn\'t whirlpool'); } $data = 'foobar'; // @codingStandardsIgnoreStart Generic.Files.LineLength $hash = '9923afaec3a86f865bb231a588f453f84e8151a2deb4109aebc6de4284be5bebcff4fab82a7e51d920237340a043736e9d13bab196006dcca0fe65314d68eab9'; // @codingStandardsIgnoreEnd $this->assertEquals(hex2bin($hash), MWCryptHash::hash($data), 'Raw hash'); $this->assertEquals($hash, MWCryptHash::hash($data, false), 'Hex hash'); }
/** * Return a rolling random state initially build using data from unstable sources * @return string A new weak random state */ protected function randomState() { static $state = null; if (is_null($state)) { // Initialize the state with whatever unstable data we can find // It's important that this data is hashed right afterwards to prevent // it from being leaked into the output stream $state = MWCryptHash::hash($this->initialRandomState()); } // Generate a new random state based on the initial random state or previous // random state by combining it with clock drift $state = $this->driftHash($state); return $state; }