]> granicus.if.org Git - php/commitdiff
Tests from Munich PHP Testfest 2008
authorDavid Soria Parra <dsp@php.net>
Sat, 17 May 2008 23:27:42 +0000 (23:27 +0000)
committerDavid Soria Parra <dsp@php.net>
Sat, 17 May 2008 23:27:42 +0000 (23:27 +0000)
30 files changed:
ext/mcrypt/tests/mcrypt_cbc.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_cbf.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_create_iv.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_decrypt.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_ecb.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_algorithms_name.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_block_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_iv_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_key_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_mode_name.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_get_supported_key_sizes.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_is_block_algorithm.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_is_block_algorithm_mode.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_is_block_mode.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_enc_self_test.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_get_block_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_get_cipher_name.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_get_iv_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_get_key_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_list_algorithms.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_list_modes.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_get_algo_block_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_get_algo_key_size.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_get_supported_key_sizes.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_is_block_algorithm.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_is_block_algorithm_mode.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_is_block_mode.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_open.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_module_self_test.phpt [new file with mode: 0644]
ext/mcrypt/tests/mcrypt_ofb.phpt [new file with mode: 0644]

diff --git a/ext/mcrypt/tests/mcrypt_cbc.phpt b/ext/mcrypt/tests/mcrypt_cbc.phpt
new file mode 100644 (file)
index 0000000..43b50ab
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+mcrypt_cbc
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+$key      = "FooBar";
+$secret   = "PHP Testfest 2008";
+$cipher   = MCRYPT_RIJNDAEL_128;
+
+$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
+$enc_data = mcrypt_cbc($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
+
+// we have to trim as AES rounds the blocks and decrypt doesnt detect that
+echo trim(mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
+
+// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
+mcrypt_cbc($cipher, $key, $enc_data, MCRYPT_DECRYPT);
+
+--EXPECTF--
+PHP Testfest 2008
+
+Warning: mcrypt_cbc(): Attempt to use an empty IV, which is NOT recommended in %s on line %d
diff --git a/ext/mcrypt/tests/mcrypt_cbf.phpt b/ext/mcrypt/tests/mcrypt_cbf.phpt
new file mode 100644 (file)
index 0000000..ebc2834
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+mcrypt_cbf
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+$key      = "FooBar";
+$secret   = "PHP Testfest 2008";
+$cipher   = MCRYPT_RIJNDAEL_128;
+
+$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
+$enc_data = mcrypt_cfb($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
+
+// we have to trim as AES rounds the blocks and decrypt doesnt detect that
+echo trim(mcrypt_cfb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
+
+// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
+mcrypt_cfb($cipher, $key, $enc_data, MCRYPT_DECRYPT);
+
+--EXPECTF--
+PHP Testfest 2008
+
+Warning: mcrypt_cfb(): Attempt to use an empty IV, which is NOT recommended in %s on line %d
diff --git a/ext/mcrypt/tests/mcrypt_create_iv.phpt b/ext/mcrypt/tests/mcrypt_create_iv.phpt
new file mode 100644 (file)
index 0000000..cf6456f
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+mcrypt_create_iv
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$iv1 = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND);
+$iv2 = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_192, MCRYPT_MODE_ECB), MCRYPT_DEV_URANDOM);
+$iv3 = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_DEV_RANDOM);
+
+echo strlen($iv1) . "\n";
+echo strlen($iv2) . "\n";
+echo strlen($iv3) . "\n";
+--EXPECT--
+16
+24
+32
diff --git a/ext/mcrypt/tests/mcrypt_decrypt.phpt b/ext/mcrypt/tests/mcrypt_decrypt.phpt
new file mode 100644 (file)
index 0000000..498762b
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+mcrypt_decrypt
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+$key      = "FooBar";
+$secret   = "PHP Testfest 2008";
+$mode     = MCRYPT_MODE_CBC;
+$cipher   = MCRYPT_RIJNDAEL_128;
+
+$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, $mode), MCRYPT_RAND);
+$enc_data = mcrypt_encrypt($cipher, $key, $secret, $mode, $iv);
+
+// we have to trim as AES rounds the blocks and decrypt doesnt detect that
+echo trim(mcrypt_decrypt($cipher, $key, $enc_data, $mode, $iv)) . "\n";
+
+// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
+mcrypt_decrypt($cipher, $key, $enc_data, MCRYPT_MODE_CBC);
+
+var_dump(strpos(mcrypt_decrypt(MCRYPT_BLOWFISH, "FooBar", $enc_data, MCRYPT_MODE_CBC, $iv), "Testfest") !== false);
+--EXPECTF--
+PHP Testfest 2008
+
+Warning: mcrypt_decrypt(): Attempt to use an empty IV, which is NOT recommended in %s on line %d
+
+Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
+bool(false)
diff --git a/ext/mcrypt/tests/mcrypt_ecb.phpt b/ext/mcrypt/tests/mcrypt_ecb.phpt
new file mode 100644 (file)
index 0000000..fc54516
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+mcrypt_ecb
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+$key      = "FooBar";
+$secret   = "PHP Testfest 2008";
+$cipher   = MCRYPT_RIJNDAEL_128;
+
+$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
+$enc_data = mcrypt_ecb($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
+
+// we have to trim as AES rounds the blocks and decrypt doesnt detect that
+echo trim(mcrypt_ecb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
+
+// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
+mcrypt_ecb($cipher, $key, $enc_data, MCRYPT_DECRYPT);
+
+--EXPECTF--
+PHP Testfest 2008
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_algorithms_name.phpt b/ext/mcrypt/tests/mcrypt_enc_get_algorithms_name.phpt
new file mode 100644 (file)
index 0000000..5b0bb01
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+mcrypt_enc_get_algorithms_name
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td  = mcrypt_module_open('rijndael-128', '', MCRYPT_MODE_ECB, '');
+echo mcrypt_enc_get_algorithms_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
+echo mcrypt_enc_get_algorithms_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_RC2, '', MCRYPT_MODE_CBC, '');
+echo mcrypt_enc_get_algorithms_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
+echo mcrypt_enc_get_algorithms_name($td) . "\n";
+$td  = mcrypt_module_open('des', '', 'ecb', '');
+echo mcrypt_enc_get_algorithms_name($td) . "\n";
+--EXPECT--
+Rijndael-128
+Rijndael-128
+RC2
+Blowfish
+DES
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_block_size.phpt b/ext/mcrypt/tests/mcrypt_enc_get_block_size.phpt
new file mode 100644 (file)
index 0000000..06f5add
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_enc_get_block_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_block_size($td));
+$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_block_size($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_get_block_size($td));
+--EXPECT--
+int(32)
+int(8)
+int(1)
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_iv_size.phpt b/ext/mcrypt/tests/mcrypt_enc_get_iv_size.phpt
new file mode 100644 (file)
index 0000000..b4f9d6e
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_enc_get_iv_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_iv_size($td));
+$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_iv_size($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_get_iv_size($td));
+--EXPECT--
+int(32)
+int(8)
+int(0)
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_key_size.phpt b/ext/mcrypt/tests/mcrypt_enc_get_key_size.phpt
new file mode 100644 (file)
index 0000000..22328e1
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_enc_get_key_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_key_size($td));
+$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_get_key_size($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_get_key_size($td));
+--EXPECT--
+int(32)
+int(24)
+int(32)
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_mode_name.phpt b/ext/mcrypt/tests/mcrypt_enc_get_mode_name.phpt
new file mode 100644 (file)
index 0000000..21c41f9
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+mcrypt_enc_get_modes_name
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td  = mcrypt_module_open('rijndael-128', '', MCRYPT_MODE_ECB, '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+$td  = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_OFB, '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+$td  = mcrypt_module_open('des', '', 'ecb', '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+$td  = mcrypt_module_open('des', '', 'cbc', '');
+echo mcrypt_enc_get_modes_name($td) . "\n";
+--EXPECT--
+ECB
+CBC
+STREAM
+OFB
+ECB
+CBC
diff --git a/ext/mcrypt/tests/mcrypt_enc_get_supported_key_sizes.phpt b/ext/mcrypt/tests/mcrypt_enc_get_supported_key_sizes.phpt
new file mode 100644 (file)
index 0000000..0ce1f15
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+mcrypt_enc_get_supported_key_sizes
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td  = mcrypt_module_open('rijndael-256', '', 'ecb', '');
+$var = mcrypt_enc_get_supported_key_sizes($td);
+var_dump($var);
+--EXPECT--
+array(3) {
+  [0]=>
+  int(16)
+  [1]=>
+  int(24)
+  [2]=>
+  int(32)
+}
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_enc_is_block_algorithm.phpt b/ext/mcrypt/tests/mcrypt_enc_is_block_algorithm.phpt
new file mode 100644 (file)
index 0000000..21a0ed2
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_enc_is_block_algorithm
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_is_block_algorithm($td));
+$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_is_block_algorithm($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_is_block_algorithm($td));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
diff --git a/ext/mcrypt/tests/mcrypt_enc_is_block_algorithm_mode.phpt b/ext/mcrypt/tests/mcrypt_enc_is_block_algorithm_mode.phpt
new file mode 100644 (file)
index 0000000..69c9654
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_enc_is_block_algorithm_mode
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_ECB, '');
+var_dump(mcrypt_enc_is_block_algorithm_mode($td));
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_is_block_algorithm_mode($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '',  MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_is_block_algorithm_mode($td));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
diff --git a/ext/mcrypt/tests/mcrypt_enc_is_block_mode.phpt b/ext/mcrypt/tests/mcrypt_enc_is_block_mode.phpt
new file mode 100644 (file)
index 0000000..551f7a6
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+mcrypt_enc_is_block_mode
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_is_block_mode($td));
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_ECB, '');
+var_dump(mcrypt_enc_is_block_mode($td));
+$td = mcrypt_module_open(MCRYPT_ARCFOUR, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_is_block_mode($td));
+$td = mcrypt_module_open(MCRYPT_WAKE, '', MCRYPT_MODE_STREAM, '');
+var_dump(mcrypt_enc_is_block_mode($td));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(false)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_enc_self_test.phpt b/ext/mcrypt/tests/mcrypt_enc_self_test.phpt
new file mode 100644 (file)
index 0000000..a161e0e
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+mcrypt_enc_self_test
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+$td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
+var_dump(mcrypt_enc_self_test($td));
+--EXPECT--
+int(0)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_get_block_size.phpt b/ext/mcrypt/tests/mcrypt_get_block_size.phpt
new file mode 100644 (file)
index 0000000..bf1f24d
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+mcrypt_get_block_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_get_block_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_block_size(MCRYPT_WAKE, MCRYPT_MODE_STREAM));
+--EXPECT--
+int(32)
+int(8)
+int(1)
diff --git a/ext/mcrypt/tests/mcrypt_get_cipher_name.phpt b/ext/mcrypt/tests/mcrypt_get_cipher_name.phpt
new file mode 100644 (file)
index 0000000..9d4961a
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+mcrypt_get_cipher_name
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+echo mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_256) . "\n";
+echo mcrypt_get_cipher_name(MCRYPT_RC2) . "\n";
+echo mcrypt_get_cipher_name(MCRYPT_ARCFOUR) . "\n";
+echo mcrypt_get_cipher_name(MCRYPT_WAKE) . "\n";
+--EXPECT--
+Rijndael-256
+RC2
+RC4
+WAKE
diff --git a/ext/mcrypt/tests/mcrypt_get_iv_size.phpt b/ext/mcrypt/tests/mcrypt_get_iv_size.phpt
new file mode 100644 (file)
index 0000000..ad35997
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+mcrypt_enc_get_iv_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_iv_size(MCRYPT_WAKE, MCRYPT_MODE_STREAM));
+var_dump(mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_STREAM));
+--EXPECTF--
+int(32)
+int(8)
+int(0)
+
+Warning: mcrypt_get_iv_size(): Module initialization failed in %s on line %d
+bool(false)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_get_key_size.phpt b/ext/mcrypt/tests/mcrypt_get_key_size.phpt
new file mode 100644 (file)
index 0000000..930cf4d
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+mcrypt_get_key_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_key_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
+var_dump(mcrypt_get_key_size(MCRYPT_WAKE, MCRYPT_MODE_STREAM));
+--EXPECT--
+int(32)
+int(24)
+int(32)
diff --git a/ext/mcrypt/tests/mcrypt_list_algorithms.phpt b/ext/mcrypt/tests/mcrypt_list_algorithms.phpt
new file mode 100644 (file)
index 0000000..9baf9a6
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+mcrypt_list_algorithms
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+foreach (mcrypt_list_algorithms() as $algo) {
+       if (in_array($algo, array('rijndael-256', 'des', 'blowfish', 'twofish'))) {
+          echo "FOUND\n";
+       }
+}
+--EXPECT--
+FOUND
+FOUND
+FOUND
+FOUND
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_list_modes.phpt b/ext/mcrypt/tests/mcrypt_list_modes.phpt
new file mode 100644 (file)
index 0000000..4b9fa79
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+mcrypt_list_modes
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_list_modes());
+--EXPECT--
+array(8) {
+  [0]=>
+  string(3) "cbc"
+  [1]=>
+  string(3) "cfb"
+  [2]=>
+  string(3) "ctr"
+  [3]=>
+  string(3) "ecb"
+  [4]=>
+  string(4) "ncfb"
+  [5]=>
+  string(4) "nofb"
+  [6]=>
+  string(3) "ofb"
+  [7]=>
+  string(6) "stream"
+}
diff --git a/ext/mcrypt/tests/mcrypt_module_get_algo_block_size.phpt b/ext/mcrypt/tests/mcrypt_module_get_algo_block_size.phpt
new file mode 100644 (file)
index 0000000..c89a44a
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+mcrypt_module_get_algo_block_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RIJNDAEL_256));
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RIJNDAEL_192));
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_RC2));
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_XTEA));
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_CAST_128));
+var_dump(mcrypt_module_get_algo_block_size(MCRYPT_BLOWFISH));
+--EXPECT--
+int(32)
+int(24)
+int(8)
+int(8)
+int(8)
+int(8)
diff --git a/ext/mcrypt/tests/mcrypt_module_get_algo_key_size.phpt b/ext/mcrypt/tests/mcrypt_module_get_algo_key_size.phpt
new file mode 100644 (file)
index 0000000..7d3841f
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+mcrypt_module_get_algo_key_size
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_256));
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RIJNDAEL_192));
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_RC2));
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_XTEA));
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_CAST_128));
+var_dump(mcrypt_module_get_algo_key_size(MCRYPT_BLOWFISH));
+--EXPECT--
+int(32)
+int(32)
+int(128)
+int(16)
+int(16)
+int(56)
diff --git a/ext/mcrypt/tests/mcrypt_module_get_supported_key_sizes.phpt b/ext/mcrypt/tests/mcrypt_module_get_supported_key_sizes.phpt
new file mode 100644 (file)
index 0000000..bf45bb4
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+mcrypt_module_get_supported_key_sizes
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_get_supported_key_sizes(MCRYPT_RIJNDAEL_256));
+var_dump(mcrypt_module_get_supported_key_sizes(MCRYPT_RC2));
+--EXPECT--
+array(3) {
+  [0]=>
+  int(16)
+  [1]=>
+  int(24)
+  [2]=>
+  int(32)
+}
+array(0) {
+}
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_module_is_block_algorithm.phpt b/ext/mcrypt/tests/mcrypt_module_is_block_algorithm.phpt
new file mode 100644 (file)
index 0000000..2cfc87d
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+mcrypt_module_is_block_algorithm
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_is_block_algorithm(MCRYPT_RIJNDAEL_128));
+var_dump(mcrypt_module_is_block_algorithm(MCRYPT_DES));
+var_dump(mcrypt_module_is_block_algorithm(MCRYPT_WAKE));
+var_dump(mcrypt_module_is_block_algorithm(MCRYPT_XTEA));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(true)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_module_is_block_algorithm_mode.phpt b/ext/mcrypt/tests/mcrypt_module_is_block_algorithm_mode.phpt
new file mode 100644 (file)
index 0000000..2924551
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+mcrypt_module_is_block_algorithm_mode
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_is_block_algorithm_mode(MCRYPT_MODE_CBC));
+var_dump(mcrypt_module_is_block_algorithm_mode(MCRYPT_MODE_ECB));
+var_dump(mcrypt_module_is_block_algorithm_mode(MCRYPT_MODE_STREAM));
+var_dump(mcrypt_module_is_block_algorithm_mode(MCRYPT_MODE_OFB));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(true)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_module_is_block_mode.phpt b/ext/mcrypt/tests/mcrypt_module_is_block_mode.phpt
new file mode 100644 (file)
index 0000000..662279f
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+mcrypt_module_is_block_mode
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_is_block_mode(MCRYPT_MODE_CBC));
+var_dump(mcrypt_module_is_block_mode(MCRYPT_MODE_ECB));
+var_dump(mcrypt_module_is_block_mode(MCRYPT_MODE_STREAM));
+var_dump(mcrypt_module_is_block_mode(MCRYPT_MODE_NOFB));
+var_dump(mcrypt_module_is_block_mode(MCRYPT_MODE_OFB));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(false)
+bool(false)
\ No newline at end of file
diff --git a/ext/mcrypt/tests/mcrypt_module_open.phpt b/ext/mcrypt/tests/mcrypt_module_open.phpt
new file mode 100644 (file)
index 0000000..92f0d55
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+mcrypt_module_open
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, ''));
+mcrypt_module_open('', '', '', '');
+
+--EXPECTF--
+resource(%d) of type (mcrypt)
+
+Warning: mcrypt_module_open(): Could not open encryption module in %s on line %d
+
diff --git a/ext/mcrypt/tests/mcrypt_module_self_test.phpt b/ext/mcrypt/tests/mcrypt_module_self_test.phpt
new file mode 100644 (file)
index 0000000..cf07bfe
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+mcrypt_module_self_test
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
+--FILE--
+<?php
+var_dump(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128));
+var_dump(mcrypt_module_self_test(MCRYPT_RC2));
+var_dump(mcrypt_module_self_test(''));
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
diff --git a/ext/mcrypt/tests/mcrypt_ofb.phpt b/ext/mcrypt/tests/mcrypt_ofb.phpt
new file mode 100644 (file)
index 0000000..0ed1e19
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+mcrypt_ofb
+--SKIPIF--
+<?php if (!extension_loaded("mcrypt") || unicode_semantics()) print "skip"; ?>
+--FILE--
+<?php
+$key      = "FooBar";
+$secret   = "PHP Testfest 2008";
+$cipher   = MCRYPT_RIJNDAEL_128;
+
+$iv       = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
+$enc_data = mcrypt_ofb($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
+
+// we have to trim as AES rounds the blocks and decrypt doesnt detect that
+echo trim(mcrypt_ofb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
+
+// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
+mcrypt_ofb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv);
+
+--EXPECT--
+PHP Testfest 2008