Skip to content

Commit 5f7baba

Browse files
committed
Merge branch '1.0' into 2.0
2 parents 8a9f9f0 + 077eccc commit 5f7baba

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/mcrypt.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ function phpseclib_mcrypt_module_open($algorithm, $algorithm_directory, $mode, $
338338

339339
$cipher->disablePadding();
340340

341+
$cipher->key = null;
342+
341343
return $cipher;
342344
}
343345

@@ -677,7 +679,6 @@ function phpseclib_mcrypt_generic_init(Base $td, $key, $iv)
677679
phpseclib_set_iv($td, $iv);
678680

679681
$td->enableContinuousBuffer();
680-
$td->mcrypt_polyfill_init = true;
681682

682683
return 0;
683684
}
@@ -699,7 +700,7 @@ function phpseclib_mcrypt_generic_helper(Base $td, &$data, $op)
699700
// Warning: mcrypt_generic(): supplied resource is not a valid MCrypt resource
700701
// that error doesn't really make a lot of sense in this context since $td is not a resource nor should it be one.
701702
// in light of that we'll just display the same error that you get when you don't call mcrypt_generic_init() at all
702-
if (!isset($td->mcrypt_polyfill_init)) {
703+
if (!isset($td->key)) {
703704
trigger_error('m' . $op . '_generic(): Operation disallowed prior to mcrypt_generic_init().', E_USER_WARNING);
704705
return false;
705706
}
@@ -775,13 +776,13 @@ function phpseclib_mdecrypt_generic(Base $td, $data)
775776
*/
776777
function phpseclib_mcrypt_generic_deinit(Base $td)
777778
{
778-
if (!isset($td->mcrypt_polyfill_init)) {
779+
if (!isset($td->key)) {
779780
trigger_error('mcrypt_generic_deinit(): Could not terminate encryption specifier', E_USER_WARNING);
780781
return false;
781782
}
782783

783784
$td->disableContinuousBuffer();
784-
unset($td->mcrypt_polyfill_init);
785+
$td->key = null;
785786
return true;
786787
}
787788

@@ -796,7 +797,7 @@ function phpseclib_mcrypt_generic_deinit(Base $td)
796797
*/
797798
function phpseclib_mcrypt_module_close(Base $td)
798799
{
799-
//unset($td->mcrypt_polyfill_init);
800+
$td->key = null;
800801
return true;
801802
}
802803

tests/MCryptCompatTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,14 @@ public function testOFB()
10211021
}
10221022
}
10231023

1024+
public function testModuleOpenWithoutInit()
1025+
{
1026+
$this->setExpectedException('PHPUnit_Framework_Error_Warning');
1027+
1028+
$td = phpseclib_mcrypt_module_open('rijndael-128', '', 'cbc', '');
1029+
$result = phpseclib_mcrypt_generic($td, 'zzz');
1030+
}
1031+
10241032
public function mcryptModuleNameProvider()
10251033
{
10261034
return array(

0 commit comments

Comments
 (0)