Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/crypt-mhash-extension'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed May 27, 2012
3 parents 8d52ae8 + 1c05de1 + 1b6abcb commit b926b75
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Key/Derivation/SaltedS2k.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ class SaltedS2k
'md4' => MHASH_MD4,
'md5' => MHASH_MD5,
'sha1' => MHASH_SHA1,
'sha224' => MHASH_SHA224,
'sha256' => MHASH_SHA256,
'sha382' => MHASH_SHA384,
'sha512' => MHASH_SHA512,
'ripemd128' => MHASH_RIPEMD128,
'ripemd256' => MHASH_RIPEMD256,
'ripemd320' => MHASH_RIPEMD320,
'haval128,3' => MHASH_HAVAL128,
'haval160,3' => MHASH_HAVAL160,
'haval192,3' => MHASH_HAVAL192,
'haval224,3' => MHASH_HAVAL224,
'haval256,3' => MHASH_HAVAL256,
'sha224' => MHASH_SHA224,
'sha256' => MHASH_SHA256,
'sha382' => MHASH_SHA384,
'sha512' => MHASH_SHA512,
'ripemd128' => MHASH_RIPEMD128,
'ripemd256' => MHASH_RIPEMD256,
'ripemd320' => MHASH_RIPEMD320,
'haval128,3' => MHASH_HAVAL128,
'haval160,3' => MHASH_HAVAL160,
'haval192,3' => MHASH_HAVAL192,
'haval224,3' => MHASH_HAVAL224,
'haval256,3' => MHASH_HAVAL256,
'tiger128,3' => MHASH_TIGER128,
'riger160,3' => MHASH_TIGER160,
'whirpool' => MHASH_WHIRLPOOL,
Expand Down
12 changes: 12 additions & 0 deletions test/Key/Derivation/SaltedS2kTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,32 @@ public function setUp()

public function testCalc()
{
if (!extension_loaded('mhash')) {
$this->markTestSkipped('The mhash extension is not available');
return;
}
$password = SaltedS2k::calc('sha256', 'test', $this->salt, 32);
$this->assertEquals(32, strlen($password));
$this->assertEquals('qzQISUBUSP1iqYtwe/druhdOVqluc/Y2TetdSHSbaw8=', base64_encode($password));
}

public function testCalcWithWrongHash()
{
if (!extension_loaded('mhash')) {
$this->markTestSkipped('The mhash extension is not available');
return;
}
$this->setExpectedException('Zend\Crypt\Key\Derivation\Exception\InvalidArgumentException',
'The hash algorihtm wrong is not supported by Zend\Crypt\Key\Derivation\SaltedS2k');
$password = SaltedS2k::calc('wrong', 'test', $this->salt, 32);
}

public function testCalcWithWrongSalt()
{
if (!extension_loaded('mhash')) {
$this->markTestSkipped('The mhash extension is not available');
return;
}
$this->setExpectedException('Zend\Crypt\Key\Derivation\Exception\InvalidArgumentException',
'The salt size must be at least of 8 bytes');
$password = SaltedS2k::calc('sha256', 'test', substr($this->salt,-1), 32);
Expand Down

0 comments on commit b926b75

Please sign in to comment.