MCrypt tests: checked on PHP 5.2.6, 5.3 and 6.0 (Windows and Linux but not Linux 64 bit or 5.3).

This commit is contained in:
Ant Phillips 2008-12-11 10:41:50 +00:00
parent 08796b0bb9
commit 8496060286
34 changed files with 5575 additions and 0 deletions

View File

@ -0,0 +1,104 @@
--TEST--
Test mcrypt_cbc() function : basic functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : basic functionality ***\n";
$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_DECRYPT;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
$data1 = array(
'IleMhoxiOthmHua4tFBHOw==',
'EeF1s6C+w1IiHj1gdDn81g==',
'EEuXpjZPueyYoG0LGQ199Q==',
'EEuXpjZPueyYoG0LGQ199Q=='
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
// data represented in base64 (ascii)
$data2 = array(
'+G7nGcWIxij3TZjpI9lJdQ==',
'3bJiFMeyScxOLQcE6mZtLg==',
'+G7nGcWIxij3TZjpI9lJdQ=='
);
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
for ($i = 0; $i < sizeof($keys); $i++) {
echo "\nkey length=".strlen($keys[$i])."\n";
special_var_dump(mcrypt_cbc($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
for ($i = 0; $i < sizeof($ivs); $i++) {
echo "\niv length=".strlen($ivs[$i])."\n";
special_var_dump(mcrypt_cbc($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
}
function special_var_dump($str) {
var_dump(bin2hex($str));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : basic functionality ***
--- testing different key lengths
key length=8
unicode(32) "736563726574206d6573736167650000"
key length=20
unicode(32) "736563726574206d6573736167650000"
key length=24
unicode(32) "736563726574206d6573736167650000"
key length=26
Warning: mcrypt_cbc(): Size of key is too large for this algorithm in %s on line %d
unicode(32) "736563726574206d6573736167650000"
--- testing different iv lengths
iv length=4
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(32) "736563726574206d6573736167650000"
iv length=8
unicode(32) "736563726574206d6573736167650000"
iv length=9
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(32) "736563726574206d6573736167650000"
===DONE===

View File

@ -0,0 +1,87 @@
--TEST--
Test mcrypt_cbc() function : basic functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : basic functionality ***\n";
$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_ENCRYPT;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456');
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789');
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $iv)));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : basic functionality ***
--- testing different key lengths
key length=8
unicode(112) "082b437d039d09418e20dc9de1dafa7ed6da5c6335b78950968441da1faf40c1f886e04da8ca177b80b376811e138c1bf51cb48dae2e7939"
key length=20
unicode(112) "0627351e0f8a082bf7981ae2c700a43fd3d44b270ac67b00fded1c5796eea935be0fef2a23da0b3f5e243929e62ac957bf0bf463aa90fc4f"
key length=24
unicode(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
key length=26
Warning: mcrypt_cbc(): Size of key is too large for this algorithm in %s on line %d
unicode(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
--- testing different iv lengths
iv length=4
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"
iv length=8
unicode(112) "bac347506bf092c5557c4363c301745d78f047028e2953e84fd66b30aeb6005812dadbe8baa871b83278341599b0c448ddaaa52b5a378ce5"
iv length=9
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"
===DONE===

View File

@ -0,0 +1,52 @@
--TEST--
Test mcrypt_cbc() function : error conditions
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : error conditions ***\n";
//Test mcrypt_cbc with one more than the expected number of arguments
echo "\n-- Testing mcrypt_cbc() function with more than expected no. of arguments --\n";
$cipher = 10;
$key = 'string_val';
$data = 'string_val';
$mode = 10;
$iv = 'string_val';
$extra_arg = 10;
var_dump( mcrypt_cbc($cipher, $key, $data, $mode, $iv, $extra_arg) );
// Testing mcrypt_cbc with one less than the expected number of arguments
echo "\n-- Testing mcrypt_cbc() function with less than expected no. of arguments --\n";
$cipher = 10;
$key = 'string_val';
$data = 'string_val';
var_dump( mcrypt_cbc($cipher, $key, $data) );
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : error conditions ***
-- Testing mcrypt_cbc() function with more than expected no. of arguments --
Warning: mcrypt_cbc() expects at most 5 parameters, 6 given in %s on line %d
NULL
-- Testing mcrypt_cbc() function with less than expected no. of arguments --
Warning: mcrypt_cbc() expects at least 4 parameters, 3 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_cbc() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'string_val';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for cipher
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_cbc($value, $key, $data, $mode, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : usage variation ***
--int 0--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_cbc(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_cbc() expects parameter 1 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_cbc() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for key
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $value, $data, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : usage variation ***
--int 0--
unicode(32) "bc27b3a4e33b531d5983fc7df693cd09"
--int 1--
unicode(32) "bc27b3a4e33b531d5983fc7df693cd09"
--int 12345--
unicode(32) "d109b7973383127002474ae731c4b3a8"
--int -12345--
unicode(32) "3e82a931cedb03a38b91a637ff8c9f9e"
--float 10.5--
unicode(32) "de71833586c1d7132a289960ebeeca7a"
--float -10.5--
unicode(32) "7d0489dd2e99ae910ecc015573f3dd16"
--float 12.3456789000e10--
unicode(32) "978055b42c0506a8947e3c3c8d994baf"
--float -12.3456789000e10--
unicode(32) "4aa84ba400c2b8ef467d4d98372b4f4e"
--float .5--
unicode(32) "e731dc5059b84e0c8774ac490f77d6e6"
--empty array--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--lowercase null--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--lowercase true--
unicode(32) "bc27b3a4e33b531d5983fc7df693cd09"
--lowercase false--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--uppercase TRUE--
unicode(32) "bc27b3a4e33b531d5983fc7df693cd09"
--uppercase FALSE--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--empty string DQ--
Error: 2 - mcrypt_cbc() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_cbc() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "19420fa26f561ee82ed84abbcd2d284b"
--instance of classWithoutToString--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--unset var--
unicode(32) "be722a5ffc361d721fbcab1eacc6acf5"
--resource--
Error: 2 - mcrypt_cbc() expects parameter 2 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_cbc() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for data
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $value, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : usage variation ***
--int 0--
unicode(16) "ce5fcfe737859795"
--int 1--
unicode(16) "84df495f6cd82dd9"
--int 12345--
unicode(16) "905ab1ae27ee9991"
--int -12345--
unicode(16) "5835174e9c67c3e7"
--float 10.5--
unicode(16) "28ff0601ad9e47fa"
--float -10.5--
unicode(16) "ce9f2b6e2fc3d9f7"
--float 12.3456789000e10--
unicode(32) "24eb882ce9763e4018fba9b7f01b0c3e"
--float -12.3456789000e10--
unicode(32) "5eed30e428f32de1d7a7064d0ed4d3eb"
--float .5--
unicode(16) "bebf2a13676e1e30"
--empty array--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(16) "206f6d3617a5ab32"
--lowercase null--
unicode(16) "206f6d3617a5ab32"
--lowercase true--
unicode(16) "84df495f6cd82dd9"
--lowercase false--
unicode(16) "206f6d3617a5ab32"
--uppercase TRUE--
unicode(16) "84df495f6cd82dd9"
--uppercase FALSE--
unicode(16) "206f6d3617a5ab32"
--empty string DQ--
Error: 2 - mcrypt_cbc() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_cbc() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "7c91cdf8f8c51485034a9ee528eb016b"
--instance of classWithoutToString--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(16) "206f6d3617a5ab32"
--unset var--
unicode(16) "206f6d3617a5ab32"
--resource--
Error: 2 - mcrypt_cbc() expects parameter 3 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,207 @@
--TEST--
Test mcrypt_cbc() function : usage variation
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for mode
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_cbc($cipher, $key, $data, $value, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : usage variation ***
--float 10.5--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--float -10.5--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--float 12.3456789000e10--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--float -12.3456789000e10--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--float .5--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--empty array--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--int indexed array--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--associative array--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--nested arrays--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--uppercase NULL--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--lowercase null--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--lowercase true--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--lowercase false--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--uppercase TRUE--
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--uppercase FALSE--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--empty string DQ--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--empty string SQ--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--string DQ--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--string SQ--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--mixed case string--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--heredoc--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--instance of classWithToString--
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--instance of classWithoutToString--
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
unicode(32) "983d5edc5f77fe42e2372a0339dc22b0"
--undefined var--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--unset var--
unicode(32) "5f781523f696d596e4b809d72197a0cc"
--resource--
unicode(%d) %s
===DONE===

View File

@ -0,0 +1,232 @@
--TEST--
Test mcrypt_cbc() function : usage variation
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_cbc(string cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_cbc() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for iv
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( bin2hex(mcrypt_cbc($cipher, $key, $data, $mode, $value)) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_cbc() : usage variation ***
--int 0--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int 1--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int 12345--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int -12345--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float 10.5--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float -10.5--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float 12.3456789000e10--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float -12.3456789000e10--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float .5--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty array--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase null--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase true--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase false--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--uppercase TRUE--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--uppercase FALSE--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty string DQ--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty string SQ--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--instance of classWithToString--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--instance of classWithoutToString--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--unset var--
Error: 2 - mcrypt_cbc(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--resource--
Error: 2 - mcrypt_cbc() expects parameter 5 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,103 @@
--TEST--
Test mcrypt_decrypt() function : basic functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : basic functionality ***\n";
// Initialise all required variables
$cipher = MCRYPT_3DES;
$mode = MCRYPT_MODE_CBC;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
$data1 = array(
'IleMhoxiOthmHua4tFBHOw==',
'EeF1s6C+w1IiHj1gdDn81g==',
'EEuXpjZPueyYoG0LGQ199Q==',
'EEuXpjZPueyYoG0LGQ199Q=='
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
$data2 = array(
'+G7nGcWIxij3TZjpI9lJdQ==',
'3bJiFMeyScxOLQcE6mZtLg==',
'+G7nGcWIxij3TZjpI9lJdQ=='
);
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
for ($i = 0; $i < sizeof($keys); $i++) {
echo "\nkey length=".strlen($keys[$i])."\n";
special_var_dump(mcrypt_decrypt($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
for ($i = 0; $i < sizeof($ivs); $i++) {
echo "\niv length=".strlen($ivs[$i])."\n";
special_var_dump(mcrypt_decrypt($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
}
function special_var_dump($str) {
var_dump(bin2hex($str));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : basic functionality ***
--- testing different key lengths
key length=8
unicode(32) "736563726574206d6573736167650000"
key length=20
unicode(32) "736563726574206d6573736167650000"
key length=24
unicode(32) "736563726574206d6573736167650000"
key length=26
Warning: mcrypt_decrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(32) "736563726574206d6573736167650000"
--- testing different iv lengths
iv length=4
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(32) "736563726574206d6573736167650000"
iv length=8
unicode(32) "736563726574206d6573736167650000"
iv length=9
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(32) "736563726574206d6573736167650000"
===DONE===

View File

@ -0,0 +1,96 @@
--TEST--
Test mcrypt_decrypt() function : basic functionality
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : basic functionality ***\n";
// Initialise all required variables
$cipher = MCRYPT_3DES;
$mode = MCRYPT_MODE_ECB;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
$data1 = array(
'0D4ArM3ejyhic9rnCcIW9A==',
'q0wt1YeOjLpnKm5WsrzKEw==',
'zwKEFeqHkhlj+7HZTRA/yA==',
'zwKEFeqHkhlj+7HZTRA/yA=='
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
$data2 = array(
'+G7nGcWIxigQcJD+2P14HA==',
'+G7nGcWIxigQcJD+2P14HA==',
'+G7nGcWIxigQcJD+2P14HA=='
);
echo "\n--- testing different key lengths\n";
for ($i = 0; $i < sizeof($keys); $i++) {
echo "\nkey length=".strlen($keys[$i])."\n";
special_var_dump(mcrypt_decrypt($cipher, $keys[$i], base64_decode($data1[$i]), $mode));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
for ($i = 0; $i < sizeof($ivs); $i++) {
echo "\niv length=".strlen($ivs[$i])."\n";
special_var_dump(mcrypt_decrypt($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
}
function special_var_dump($str) {
var_dump(bin2hex($str));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : basic functionality ***
--- testing different key lengths
key length=8
unicode(32) "736563726574206d6573736167650000"
key length=20
unicode(32) "736563726574206d6573736167650000"
key length=24
unicode(32) "736563726574206d6573736167650000"
key length=26
Warning: mcrypt_decrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(32) "736563726574206d6573736167650000"
--- testing different iv lengths
iv length=4
unicode(32) "736563726574206d6573736167650000"
iv length=8
unicode(32) "736563726574206d6573736167650000"
iv length=9
unicode(32) "736563726574206d6573736167650000"
===DONE===

View File

@ -0,0 +1,52 @@
--TEST--
Test mcrypt_decrypt() function : error conditions
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : error conditions ***\n";
//Test mcrypt_decrypt with one more than the expected number of arguments
echo "\n-- Testing mcrypt_decrypt() function with more than expected no. of arguments --\n";
$cipher = 'string_val';
$key = 'string_val';
$data = 'string_val';
$mode = 'string_val';
$iv = 'string_val';
$extra_arg = 10;
var_dump( mcrypt_decrypt($cipher, $key, $data, $mode, $iv, $extra_arg) );
// Testing mcrypt_decrypt with one less than the expected number of arguments
echo "\n-- Testing mcrypt_decrypt() function with less than expected no. of arguments --\n";
$cipher = 'string_val';
$key = 'string_val';
$data = 'string_val';
var_dump( mcrypt_decrypt($cipher, $key, $data) );
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : error conditions ***
-- Testing mcrypt_decrypt() function with more than expected no. of arguments --
Warning: mcrypt_decrypt() expects at most 5 parameters, 6 given in %s on line %d
NULL
-- Testing mcrypt_decrypt() function with less than expected no. of arguments --
Warning: mcrypt_decrypt() expects at least 4 parameters, 3 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_decrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'string_val';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for cipher
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_decrypt($value, $key, $data, $mode, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_decrypt() expects parameter 1 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_decrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$data = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for key
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( bin2hex(mcrypt_decrypt($cipher, $value, $data, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : usage variation ***
--int 0--
unicode(32) "43a1ae011df36064589d06bc922ecd97"
--int 1--
unicode(32) "43a1ae011df36064589d06bc922ecd97"
--int 12345--
unicode(32) "e5885552e16c44d4eb6164f477b40200"
--int -12345--
unicode(32) "adf7873831a9035cda9f9dc3b7dc626b"
--float 10.5--
unicode(32) "08b0b9fac9c227437b7b5d0147e6153b"
--float -10.5--
unicode(32) "f470cc74d83471b42a3e28d4ec57799a"
--float 12.3456789000e10--
unicode(32) "36c618c00523fadc372b871eaa9c7b16"
--float -12.3456789000e10--
unicode(32) "a554a5bdb7a5ceb6ae6f20566ef02e49"
--float .5--
unicode(32) "bcb840ff76d3788a7911ed36f088a910"
--empty array--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase null--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase true--
unicode(32) "43a1ae011df36064589d06bc922ecd97"
--lowercase false--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--uppercase TRUE--
unicode(32) "43a1ae011df36064589d06bc922ecd97"
--uppercase FALSE--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--empty string DQ--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "478f9d080563835cc3136610802f1433"
--instance of classWithoutToString--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--unset var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--resource--
Error: 2 - mcrypt_decrypt() expects parameter 2 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_decrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for data
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_decrypt($cipher, $key, $value, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : usage variation ***
--int 0--
unicode(16) "52833a00168e547f"
--int 1--
unicode(16) "82011a0a93098a13"
--int 12345--
unicode(16) "e8b71c21b6acc162"
--int -12345--
unicode(16) "db3c458e975563a8"
--float 10.5--
unicode(16) "6ee8764562f25913"
--float -10.5--
unicode(16) "d63b39fd5f65678e"
--float 12.3456789000e10--
unicode(32) "7712cc4828221be40672239d9c32e742"
--float -12.3456789000e10--
unicode(32) "caa892cb5d28b53c2b75b1e0799427c3"
--float .5--
unicode(16) "99880c86884385d9"
--empty array--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(16) "d27689f6fd9700f4"
--lowercase null--
unicode(16) "d27689f6fd9700f4"
--lowercase true--
unicode(16) "82011a0a93098a13"
--lowercase false--
unicode(16) "d27689f6fd9700f4"
--uppercase TRUE--
unicode(16) "82011a0a93098a13"
--uppercase FALSE--
unicode(16) "d27689f6fd9700f4"
--empty string DQ--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "46677e368bc07ef375bd580e0c4b2594"
--instance of classWithoutToString--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(16) "d27689f6fd9700f4"
--unset var--
unicode(16) "d27689f6fd9700f4"
--resource--
Error: 2 - mcrypt_decrypt() expects parameter 3 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_decrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for mode
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_decrypt($cipher, $key, $data, $value, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_decrypt(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_decrypt() expects parameter 4 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,232 @@
--TEST--
Test mcrypt_decrypt() function : usage variation
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_decrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_MODE_CBC;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for iv
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_decrypt($cipher, $key, $data, $mode, $value)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_decrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--int 1--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--int 12345--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--int -12345--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--float 10.5--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--float -10.5--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--float 12.3456789000e10--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--float -12.3456789000e10--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--float .5--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--empty array--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--lowercase null--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--lowercase true--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--lowercase false--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--uppercase TRUE--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--uppercase FALSE--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--empty string DQ--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--empty string SQ--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--instance of classWithToString--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--instance of classWithoutToString--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--unset var--
Error: 2 - mcrypt_decrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "a80c6cef6b42c875e2372a0339dc22b0"
--resource--
Error: 2 - mcrypt_decrypt() expects parameter 5 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,97 @@
--TEST--
Test mcrypt_cbc() function : basic functionality
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : basic functionality ***\n";
$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_DECRYPT;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
$data1 = array(
'0D4ArM3ejyhic9rnCcIW9A==',
'q0wt1YeOjLpnKm5WsrzKEw==',
'zwKEFeqHkhlj+7HZTRA/yA==',
'zwKEFeqHkhlj+7HZTRA/yA=='
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
$data2 = array(
'+G7nGcWIxigQcJD+2P14HA==',
'+G7nGcWIxigQcJD+2P14HA==',
'+G7nGcWIxigQcJD+2P14HA=='
);
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
for ($i = 0; $i < sizeof($keys); $i++) {
echo "\nkey length=".strlen($keys[$i])."\n";
special_var_dump(mcrypt_ecb($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
for ($i = 0; $i < sizeof($ivs); $i++) {
echo "\niv length=".strlen($ivs[$i])."\n";
special_var_dump(mcrypt_ecb($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
}
function special_var_dump($str) {
var_dump(bin2hex($str));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : basic functionality ***
--- testing different key lengths
key length=8
unicode(32) "736563726574206d6573736167650000"
key length=20
unicode(32) "736563726574206d6573736167650000"
key length=24
unicode(32) "736563726574206d6573736167650000"
key length=26
Warning: mcrypt_ecb(): Size of key is too large for this algorithm in %s on line %d
unicode(32) "736563726574206d6573736167650000"
--- testing different iv lengths
iv length=4
unicode(32) "736563726574206d6573736167650000"
iv length=8
unicode(32) "736563726574206d6573736167650000"
iv length=9
unicode(32) "736563726574206d6573736167650000"
===DONE===

View File

@ -0,0 +1,82 @@
--TEST--
Test mcrypt_ecb() function : basic functionality
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : basic functionality ***\n";
$cipher = MCRYPT_TRIPLEDES;
$data = b"This is the secret message which must be encrypted";
$mode = MCRYPT_ENCRYPT;
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $mode, $iv)));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $mode, $iv)));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : basic functionality ***
--- testing different key lengths
key length=8
unicode(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
key length=20
unicode(112) "0fc7045c4fb4dbcf44baf9ed15ab40331a42ff0632318a16b12ed5873f02e7945e4f63f408d6849534cbb7419c22c8854aaa85e0e05a28e6"
key length=24
unicode(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
key length=26
Warning: mcrypt_ecb(): Size of key is too large for this algorithm in %s on line %d
unicode(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
--- testing different iv lengths
iv length=4
unicode(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
iv length=8
unicode(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
iv length=9
unicode(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165"
===DONE===

View File

@ -0,0 +1,52 @@
--TEST--
Test mcrypt_ecb() function : error conditions
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : error conditions ***\n";
//Test mcrypt_ecb with one more than the expected number of arguments
echo "\n-- Testing mcrypt_ecb() function with more than expected no. of arguments --\n";
$cipher = 10;
$key = 'string_val';
$data = 'string_val';
$mode = 10;
$iv = 'string_val';
$extra_arg = 10;
var_dump( mcrypt_ecb($cipher, $key, $data, $mode, $iv, $extra_arg) );
// Testing mcrypt_ecb with one less than the expected number of arguments
echo "\n-- Testing mcrypt_ecb() function with less than expected no. of arguments --\n";
$cipher = 10;
$key = 'string_val';
$data = 'string_val';
var_dump( mcrypt_ecb($cipher, $key, $data) );
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : error conditions ***
-- Testing mcrypt_ecb() function with more than expected no. of arguments --
Warning: mcrypt_ecb() expects at most 5 parameters, 6 given in %s on line %d
NULL
-- Testing mcrypt_ecb() function with less than expected no. of arguments --
Warning: mcrypt_ecb() expects at least 4 parameters, 3 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_ecb() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'string_val';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for cipher
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_ecb($value, $key, $data, $mode, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : usage variation ***
--int 0--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_ecb(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_ecb() expects parameter 1 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_ecb() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for key
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_ecb($cipher, $value, $data, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : usage variation ***
--int 0--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--int 1--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--int 12345--
unicode(32) "d74e5f51d1199bcfa61f80168e913007"
--int -12345--
unicode(32) "17fe485ed735abb34c1dd4455af7b79c"
--float 10.5--
unicode(32) "cd735509aa4013a130e011686d66ae01"
--float -10.5--
unicode(32) "a57d99d6d5813039abf50fc50d631e47"
--float 12.3456789000e10--
unicode(32) "f17ede0bfdaa4408f545f7f4c8b040d2"
--float -12.3456789000e10--
unicode(32) "326f64e3b9bd5a6beb0a9b52a09a5a48"
--float .5--
unicode(32) "2aedf7661cd4d8c7593f44c58718e2b8"
--empty array--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase null--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase true--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--lowercase false--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--uppercase TRUE--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--uppercase FALSE--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--empty string DQ--
Error: 2 - mcrypt_ecb() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_ecb() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "1fd3514d8ced44d04d9dc7511fce33ef"
--instance of classWithoutToString--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--unset var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--resource--
Error: 2 - mcrypt_ecb() expects parameter 2 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_ecb() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$mode = MCRYPT_ENCRYPT;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for data
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_ecb($cipher, $key, $value, $mode, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : usage variation ***
--int 0--
unicode(16) "51dc9cd9179b718b"
--int 1--
unicode(16) "619c335f8c4f9cbf"
--int 12345--
unicode(16) "b1258d67ab73de00"
--int -12345--
unicode(16) "8eecf134443bd6b9"
--float 10.5--
unicode(16) "34b5750a793baff5"
--float -10.5--
unicode(16) "7a605f2aacc8a11d"
--float 12.3456789000e10--
unicode(32) "74a0d7026ae586f476d4b17808851e86"
--float -12.3456789000e10--
unicode(32) "bfb155997017986c01090afebd62c7ca"
--float .5--
unicode(16) "cc60ac201164b6c7"
--empty array--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(16) "6ece228c41457539"
--lowercase null--
unicode(16) "6ece228c41457539"
--lowercase true--
unicode(16) "619c335f8c4f9cbf"
--lowercase false--
unicode(16) "6ece228c41457539"
--uppercase TRUE--
unicode(16) "619c335f8c4f9cbf"
--uppercase FALSE--
unicode(16) "6ece228c41457539"
--empty string DQ--
Error: 2 - mcrypt_ecb() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_ecb() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "749c3b4d16731d98370128754b7c930f"
--instance of classWithoutToString--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(16) "6ece228c41457539"
--unset var--
unicode(16) "6ece228c41457539"
--resource--
Error: 2 - mcrypt_ecb() expects parameter 3 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,207 @@
--TEST--
Test mcrypt_ecb() function : usage variation
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// string data
'string DQ' => "string",
'string SQ' => 'string',
'mixed case string' => "sTrInG",
'heredoc' => $heredoc,
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for mode
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex(mcrypt_ecb($cipher, $key, $data, $value, $iv)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : usage variation ***
--float 10.5--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--float -10.5--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--float 12.3456789000e10--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--float -12.3456789000e10--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--float .5--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--empty array--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--int indexed array--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--associative array--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--nested arrays--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--uppercase NULL--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--lowercase null--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--lowercase true--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--lowercase false--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--uppercase TRUE--
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--uppercase FALSE--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--empty string DQ--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--empty string SQ--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--string DQ--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--string SQ--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--mixed case string--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--heredoc--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--instance of classWithToString--
Error: 8 - Object of class classWithToString could not be converted to int, %s(%d)
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--instance of classWithoutToString--
Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d)
unicode(32) "a80c6cef6b42c8759143586a57bb7dc6"
--undefined var--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--unset var--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--resource--
unicode(%d) %s
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_ecb() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_ecb(string cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_ecb() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_ENCRYPT;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for iv
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump(bin2hex( mcrypt_ecb($cipher, $key, $data, $mode, $value)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_ecb() : usage variation ***
--int 0--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--int 1--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--int 12345--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--int -12345--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--float 10.5--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--float -10.5--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--float 12.3456789000e10--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--float -12.3456789000e10--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--float .5--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--empty array--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--lowercase null--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--lowercase true--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--lowercase false--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--uppercase TRUE--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--uppercase FALSE--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--empty string DQ--
Error: 2 - mcrypt_ecb() expects parameter 5 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_ecb() expects parameter 5 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--instance of classWithoutToString--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--unset var--
unicode(32) "6438db90653c4d300909aa02fd6163c2"
--resource--
Error: 2 - mcrypt_ecb() expects parameter 5 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,96 @@
--TEST--
Test mcrypt_encrypt() function : TripleDES functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : TripleDES functionality ***\n";
//test CBC, ECB modes
//test encrypt decrypt
//test tripledes, aes
//test different lengths of key, iv
//test no iv being passed on CBC, ECB
//test upto 32 bytes with unlimited strength
$cipher = MCRYPT_TRIPLEDES;
$mode = MCRYPT_MODE_CBC;
$data = b'This is the secret message which must be encrypted';
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
// tripledes is a block cipher of 64 bits (8 bytes)
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
$iv = b'12345678';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : TripleDES functionality ***
--- testing different key lengths
key length=8
unicode(112) "082b437d039d09418e20dc9de1dafa7ed6da5c6335b78950968441da1faf40c1f886e04da8ca177b80b376811e138c1bf51cb48dae2e7939"
key length=20
unicode(112) "0627351e0f8a082bf7981ae2c700a43fd3d44b270ac67b00fded1c5796eea935be0fef2a23da0b3f5e243929e62ac957bf0bf463aa90fc4f"
key length=24
unicode(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
key length=26
Warning: mcrypt_encrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
--- testing different iv lengths
iv length=4
Warning: mcrypt_encrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"
iv length=8
unicode(112) "bac347506bf092c5557c4363c301745d78f047028e2953e84fd66b30aeb6005812dadbe8baa871b83278341599b0c448ddaaa52b5a378ce5"
iv length=9
Warning: mcrypt_encrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(112) "440a6f54601969b127aad3c217ce7583c7f7b29989693130645569301db0020b29a34a3dcd104b2d0e3ba19d6cbd8a33d352b9c27cc34ef1"
===DONE===

View File

@ -0,0 +1,82 @@
--TEST--
Test mcrypt_encrypt() function : TripleDES functionality
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : TripleDES functionality ***\n";
$cipher = MCRYPT_TRIPLEDES;
$mode = MCRYPT_MODE_ECB;
$data = b'This is the secret message which must be encrypted';
// tripledes uses keys upto 192 bits (24 bytes)
$keys = array(
b'12345678',
b'12345678901234567890',
b'123456789012345678901234',
b'12345678901234567890123456'
);
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode)));
}
$key = b'12345678';
$ivs = array(
b'1234',
b'12345678',
b'123456789'
);
// ivs should be ignored in ecb mode
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : TripleDES functionality ***
--- testing different key lengths
key length=8
unicode(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
key length=20
unicode(112) "0fc7045c4fb4dbcf44baf9ed15ab40331a42ff0632318a16b12ed5873f02e7945e4f63f408d6849534cbb7419c22c8854aaa85e0e05a28e6"
key length=24
unicode(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
key length=26
Warning: mcrypt_encrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
--- testing different iv lengths
iv length=4
unicode(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
iv length=8
unicode(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
iv length=9
unicode(112) "05c9c4cafb9937d950bdae60ee3abcb8d9f3e1f1fac8acaaa5b11d70b7ca02f3b76d447ab3dd85a4b5df5dedb4b4654595ccdf6da97fa93f"
===DONE===

View File

@ -0,0 +1,52 @@
--TEST--
Test mcrypt_encrypt() function : error conditions
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : error conditions ***\n";
//Test mcrypt_encrypt with one more than the expected number of arguments
echo "\n-- Testing mcrypt_encrypt() function with more than expected no. of arguments --\n";
$cipher = 'string_val';
$key = 'string_val';
$data = 'string_val';
$mode = 'string_val';
$iv = 'string_val';
$extra_arg = 10;
var_dump( mcrypt_encrypt($cipher, $key, $data, $mode, $iv, $extra_arg) );
// Testing mcrypt_encrypt with one less than the expected number of arguments
echo "\n-- Testing mcrypt_encrypt() function with less than expected no. of arguments --\n";
$cipher = 'string_val';
$key = 'string_val';
$data = 'string_val';
var_dump( mcrypt_encrypt($cipher, $key, $data) );
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : error conditions ***
-- Testing mcrypt_encrypt() function with more than expected no. of arguments --
Warning: mcrypt_encrypt() expects at most 5 parameters, 6 given in %s on line %d
NULL
-- Testing mcrypt_encrypt() function with less than expected no. of arguments --
Warning: mcrypt_encrypt() expects at least 4 parameters, 3 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_encrypt() function : usage variation - different types for cipher
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$key = b'string_val';
$data = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'string_val';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for cipher
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_encrypt($value, $key, $data, $mode, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_encrypt() expects parameter 1 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_encrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$data = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for key
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( bin2hex(mcrypt_encrypt($cipher, $value, $data, $mode, $iv) ));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : usage variation ***
--int 0--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--int 1--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--int 12345--
unicode(32) "d74e5f51d1199bcfa61f80168e913007"
--int -12345--
unicode(32) "17fe485ed735abb34c1dd4455af7b79c"
--float 10.5--
unicode(32) "cd735509aa4013a130e011686d66ae01"
--float -10.5--
unicode(32) "a57d99d6d5813039abf50fc50d631e47"
--float 12.3456789000e10--
unicode(32) "f17ede0bfdaa4408f545f7f4c8b040d2"
--float -12.3456789000e10--
unicode(32) "326f64e3b9bd5a6beb0a9b52a09a5a48"
--float .5--
unicode(32) "2aedf7661cd4d8c7593f44c58718e2b8"
--empty array--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase null--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--lowercase true--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--lowercase false--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--uppercase TRUE--
unicode(32) "e469e6b066f9600e1eefd8f53365f96c"
--uppercase FALSE--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--empty string DQ--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "1fd3514d8ced44d04d9dc7511fce33ef"
--instance of classWithoutToString--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--unset var--
unicode(32) "bfa2cb7240c8d2f6abeb34960c04f6d3"
--resource--
Error: 2 - mcrypt_encrypt() expects parameter 2 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test mcrypt_encrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$mode = MCRYPT_MODE_ECB;
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for data
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $value, $mode, $iv) ));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : usage variation ***
--int 0--
unicode(16) "51dc9cd9179b718b"
--int 1--
unicode(16) "619c335f8c4f9cbf"
--int 12345--
unicode(16) "b1258d67ab73de00"
--int -12345--
unicode(16) "8eecf134443bd6b9"
--float 10.5--
unicode(16) "34b5750a793baff5"
--float -10.5--
unicode(16) "7a605f2aacc8a11d"
--float 12.3456789000e10--
unicode(32) "74a0d7026ae586f476d4b17808851e86"
--float -12.3456789000e10--
unicode(32) "bfb155997017986c01090afebd62c7ca"
--float .5--
unicode(16) "cc60ac201164b6c7"
--empty array--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
unicode(16) "6ece228c41457539"
--lowercase null--
unicode(16) "6ece228c41457539"
--lowercase true--
unicode(16) "619c335f8c4f9cbf"
--lowercase false--
unicode(16) "6ece228c41457539"
--uppercase TRUE--
unicode(16) "619c335f8c4f9cbf"
--uppercase FALSE--
unicode(16) "6ece228c41457539"
--empty string DQ--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--empty string SQ--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be strictly a binary string, Unicode string given, %s(%d)
unicode(0) ""
--instance of classWithToString--
unicode(32) "749c3b4d16731d98370128754b7c930f"
--instance of classWithoutToString--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
unicode(16) "6ece228c41457539"
--unset var--
unicode(16) "6ece228c41457539"
--resource--
Error: 2 - mcrypt_encrypt() expects parameter 3 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,230 @@
--TEST--
Test mcrypt_encrypt() function : usage variation
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
$iv = b'01234567';
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = <<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for mode
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( mcrypt_encrypt($cipher, $key, $data, $value, $iv) );
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int 1--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int 12345--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--int -12345--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float 10.5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float -10.5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float 12.3456789000e10--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float -12.3456789000e10--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--float .5--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty array--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--int indexed array--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--associative array--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--nested arrays--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, array given, %s(%d)
NULL
--uppercase NULL--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase null--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase true--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--lowercase false--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase TRUE--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--uppercase FALSE--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string DQ--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--empty string SQ--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithToString--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--instance of classWithoutToString--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, object given, %s(%d)
NULL
--undefined var--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--unset var--
Error: 2 - mcrypt_encrypt(): Module initialization failed, %s(%d)
bool(false)
--resource--
Error: 2 - mcrypt_encrypt() expects parameter 4 to be binary string, resource given, %s(%d)
NULL
===DONE===

View File

@ -0,0 +1,233 @@
--TEST--
Test mcrypt_encrypt() function : usage variation
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt_encrypt() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
}
set_error_handler('test_error_handler');
// Initialise function arguments not being substituted (if any)
$cipher = MCRYPT_TRIPLEDES;
$key = b'string_val';
$data = b'string_val';
//in php, it incorrectly reports problems with iv in ECB mode.
$mode = MCRYPT_MODE_CBC;
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// define some classes
class classWithToString
{
public function __toString() {
return "Class A object";
}
}
class classWithoutToString
{
}
// heredoc string
$heredoc = b<<<EOT
hello world
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// add arrays
$index_array = array (1, 2, 3);
$assoc_array = array ('one' => 1, 'two' => 2);
//array of values to iterate over
$inputs = array(
// int data
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -2345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float 12.3456789000e10' => 12.3456789000e10,
'float -12.3456789000e10' => -12.3456789000e10,
'float .5' => .5,
// array data
'empty array' => array(),
'int indexed array' => $index_array,
'associative array' => $assoc_array,
'nested arrays' => array('foo', $index_array, $assoc_array),
// null data
'uppercase NULL' => NULL,
'lowercase null' => null,
// boolean data
'lowercase true' => true,
'lowercase false' =>false,
'uppercase TRUE' =>TRUE,
'uppercase FALSE' =>FALSE,
// empty data
'empty string DQ' => "",
'empty string SQ' => '',
// object data
'instance of classWithToString' => new classWithToString(),
'instance of classWithoutToString' => new classWithoutToString(),
// undefined data
'undefined var' => @$undefined_var,
// unset data
'unset var' => @$unset_var,
// resource variable
'resource' => $fp
);
// loop through each element of the array for iv
foreach($inputs as $valueType =>$value) {
echo "\n--$valueType--\n";
var_dump( bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $value)));
};
fclose($fp);
?>
===DONE===
--EXPECTF--
*** Testing mcrypt_encrypt() : usage variation ***
--int 0--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int 1--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int 12345--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--int -12345--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float 10.5--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float -10.5--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float 12.3456789000e10--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float -12.3456789000e10--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--float .5--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty array--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--int indexed array--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--associative array--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--nested arrays--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, array given, %s(%d)
unicode(0) ""
--uppercase NULL--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase null--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase true--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--lowercase false--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--uppercase TRUE--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--uppercase FALSE--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty string DQ--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--empty string SQ--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--instance of classWithToString--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--instance of classWithoutToString--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, object given, %s(%d)
unicode(0) ""
--undefined var--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--unset var--
Error: 2 - mcrypt_encrypt(): The IV parameter must be as long as the blocksize, %s(%d)
unicode(32) "6438db90653c4d3080c3ceab43618c05"
--resource--
Error: 2 - mcrypt_encrypt() expects parameter 5 to be binary string, resource given, %s(%d)
unicode(0) ""
===DONE===

View File

@ -0,0 +1,132 @@
--TEST--
Test mcrypt_encrypt() function : TripleDES functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
/* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt : Rijndael128 functionality ***\n";
$cipher = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$data = b'This is the secret message which must be encrypted';
// keys upto 128 bits (16 bytes)
$keys = array(
null,
'',
b'12345678',
b'1234567890123456'
);
// rijndael128 is a block cipher of 128 bits (16 bytes)
$ivs = array(
null,
'',
b'12345678',
b'1234567890123456',
b'12345678901234567'
);
$iv = b'1234567890123456';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
$res = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv);
var_dump(bin2hex($res));
$res = mcrypt_cbc($cipher, $key, $res, MCRYPT_DECRYPT, $iv);
var_dump(bin2hex($res));
}
$key = b'1234567890123456';
echo "\n--- testing different iv lengths\n";
foreach ($ivs as $iv) {
echo "\niv length=".strlen($iv)."\n";
$res = mcrypt_cbc($cipher, $key, $data, $mode, $iv);
var_dump(bin2hex($res));
$res = mcrypt_decrypt($cipher, $key, $res, MCRYPT_MODE_CBC, $iv);
var_dump(bin2hex($res));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt : Rijndael128 functionality ***
--- testing different key lengths
key length=0
unicode(128) "4fbf24aaa789f5194260ade1acd9499402c1845cc517e8fe43cfb5b90a0df294db33ecd1a836c47d6bf6d8600512ba415e17008a1e1991f81056258d82099397"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=0
unicode(128) "4fbf24aaa789f5194260ade1acd9499402c1845cc517e8fe43cfb5b90a0df294db33ecd1a836c47d6bf6d8600512ba415e17008a1e1991f81056258d82099397"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=8
unicode(128) "d6a3042b278fa5816dc6f46152acbe5fd7d1813c3808c27cd969d8e10a64d0238724edfda0322f4512308f22d142df0e92bed861c2b732f7650e234df59183dc"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=16
unicode(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
--- testing different iv lengths
iv length=0
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
iv length=0
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
iv length=8
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
iv length=16
unicode(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
iv length=17
Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
===DONE===

View File

@ -0,0 +1,89 @@
--TEST--
Test mcrypt_encrypt() function : TripleDES functionality
--XFAIL--
Bug #46834
--SKIPIF--
<?php
if (!extension_loaded("mcrypt")) {
print "skip - mcrypt extension not loaded";
}
?>
--FILE--
<?php
/* Prototype : string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
/* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
* Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
/* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
* Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
/* Prototype : string mcrypt_ecb(int cipher, string key, string data, int mode, string iv)
* Description: ECB crypt/decrypt data using key key with cipher cipher starting with iv
* Source code: ext/mcrypt/mcrypt.c
* Alias to functions:
*/
echo "*** Testing mcrypt : Rijndael128 functionality ***\n";
$cipher = MCRYPT_RIJNDAEL_128;
$mode = MCRYPT_MODE_CBC;
$data = b'This is the secret message which must be encrypted';
// keys : 20 bytes, 24 bytes, 30 Bytes, 32 Bytes, 40 Bytes
$keys = array(
b'12345678901234567890',
b'123456789012345678901234',
b'123456789012345678901234567890',
b'12345678901234567890123456789012',
b'1234567890123456789012345678901234567890'
);
// rijndael128 is a block cipher of 128 bits (16 bytes)
$iv = b'1234567890123456';
echo "\n--- testing different key lengths\n";
foreach ($keys as $key) {
echo "\nkey length=".strlen($key)."\n";
$res = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv);
var_dump(bin2hex($res));
$res = mcrypt_decrypt($cipher, $key, $res, MCRYPT_MODE_CBC, $iv);
var_dump(bin2hex($res));
}
?>
===DONE===
--EXPECTF--
*** Testing mcrypt : Rijndael128 functionality ***
--- testing different key lengths
key length=20
unicode(128) "6369830bfc89a39c9981c9a40e349e3bbc8599c28d7ffbd7a330a67690dac6dfb76a55814e95c83cced68eb1544cdd8406d272c249bd0a60fa5b605d4aefbaa0"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=24
unicode(128) "8ecdf1ed5742aff16ef34c819c8d22c707c54f4d9ffc18e5f6ab79fe68c25705351e2c001a0b9f29e5def67570ca9da644efb69a8bb97940cb4bec094dae8bb5"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=30
unicode(128) "f7731f0c0ab22270b2f516c7837256ed731ba6658ca8f78cda2ab1588e204f990843719ae88474f6572711674fcda9f40d99155e4cc4f5a31aa461ad36a7871d"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=32
unicode(128) "f23bc103bfd0859a8318acee6d96e5f43dff68f3cdeae817a1e77c33492e32bdb82c5f660fcd1a2bfda70d9de4d5d8028ce179a9e2f7f9ee7dd61c7b4b409e95"
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
key length=40
Warning: mcrypt_encrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(128) "f23bc103bfd0859a8318acee6d96e5f43dff68f3cdeae817a1e77c33492e32bdb82c5f660fcd1a2bfda70d9de4d5d8028ce179a9e2f7f9ee7dd61c7b4b409e95"
Warning: mcrypt_decrypt(): Size of key is too large for this algorithm in %s on line %d
unicode(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
===DONE===