Skip to content

Commit 15237bd

Browse files
committed
Tests: add testBlowfish
1 parent 3e29bf1 commit 15237bd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/mcrypt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function phpseclib_mcrypt_enc_get_key_size(Base $td)
313313

314314
$backup = clone $td;
315315
$backup->setKeyLength(9999);
316-
return $backup->getKeyLength();
316+
return $backup->getKeyLength() >> 3;
317317
}
318318

319319
/**
@@ -515,7 +515,7 @@ function phpseclib_mcrypt_generic_init(Base $td, $key, $iv)
515515
trigger_error('mcrypt_generic_init(): Key size is 0', E_USER_WARNING);
516516
return -3;
517517
}
518-
$max_key_size = phpseclib_mcrypt_enc_get_key_size($td) >> 3;
518+
$max_key_size = phpseclib_mcrypt_enc_get_key_size($td);
519519
if (strlen($key) > $max_key_size) {
520520
trigger_error('mcrypt_generic_init(): Key size too large; supplied length: ' . strlen($key) . ', max: ' . $max_key_size, E_USER_WARNING);
521521
}

tests/MCryptCompatTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,16 @@ public function testShortKeyIVStream()
278278

279279
$this->assertEquals($mcrypt, $compat);
280280
}
281+
282+
public function testBlowfish()
283+
{
284+
$key = str_repeat('z', phpseclib_mcrypt_module_get_algo_key_size('blowfish'));
285+
$iv = str_repeat('z', phpseclib_mcrypt_module_get_algo_block_size('blowfish'));
286+
287+
$plaintext = str_repeat('a', 100);
288+
289+
$mcrypt = mcrypt_encrypt('blowfish', $key, $plaintext, 'cbc', $iv);
290+
$compat = phpseclib_mcrypt_encrypt('blowfish', $key, $plaintext, 'cbc', $iv);
291+
$this->assertEquals(bin2hex($mcrypt), bin2hex($compat));
292+
}
281293
}

0 commit comments

Comments
 (0)