1--TEST--
2Test mcrypt_decrypt() function : basic functionality
3--SKIPIF--
4<?php
5if (!extension_loaded("mcrypt")) {
6	print "skip - mcrypt extension not loaded";
7}
8?>
9--FILE--
10<?php
11/* Prototype  : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
12 * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
13 * Source code: ext/mcrypt/mcrypt.c
14 * Alias to functions:
15 */
16
17echo "*** Testing mcrypt_decrypt() : basic functionality ***\n";
18
19
20// Initialise all required variables
21$cipher = MCRYPT_3DES;
22$mode = MCRYPT_MODE_ECB;
23
24// tripledes uses keys with exactly 192 bits (24 bytes)
25$keys = array(
26   b'12345678',
27   b'12345678901234567890',
28   b'123456789012345678901234',
29   b'12345678901234567890123456'
30);
31$data1 = array(
32   '0D4ArM3ejyhic9rnCcIW9A==',
33   'q0wt1YeOjLpnKm5WsrzKEw==',
34   'zwKEFeqHkhlj+7HZTRA/yA==',
35   'zwKEFeqHkhlj+7HZTRA/yA=='
36);
37// tripledes is a block cipher of 64 bits (8 bytes)
38$ivs = array(
39   b'1234',
40   b'12345678',
41   b'123456789'
42);
43$data2 = array(
44   '+G7nGcWIxigQcJD+2P14HA==',
45   '+G7nGcWIxigQcJD+2P14HA==',
46   '+G7nGcWIxigQcJD+2P14HA=='
47);
48
49echo "\n--- testing different key lengths\n";
50for ($i = 0; $i < sizeof($keys); $i++) {
51   echo "\nkey length=".strlen($keys[$i])."\n";
52   special_var_dump(mcrypt_decrypt($cipher, $keys[$i], base64_decode($data1[$i]), $mode));
53}
54
55$key = b'123456789012345678901234';
56echo "\n--- testing different iv lengths\n";
57for ($i = 0; $i < sizeof($ivs); $i++) {
58   echo "\niv length=".strlen($ivs[$i])."\n";
59   special_var_dump(mcrypt_decrypt($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
60}
61
62function special_var_dump($str) {
63   var_dump(bin2hex($str));
64}
65?>
66===DONE===
67--EXPECTF--
68*** Testing mcrypt_decrypt() : basic functionality ***
69
70--- testing different key lengths
71
72key length=8
73
74Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43
75
76Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
77string(0) ""
78
79key length=20
80
81Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43
82
83Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
84string(0) ""
85
86key length=24
87
88Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43
89string(32) "736563726574206d6573736167650000"
90
91key length=26
92
93Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43
94
95Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
96string(0) ""
97
98--- testing different iv lengths
99
100iv length=4
101
102Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50
103string(32) "a9298896ed1b7335f8f10f7ff6d7a239"
104
105iv length=8
106
107Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50
108string(32) "a9298896ed1b7335f8f10f7ff6d7a239"
109
110iv length=9
111
112Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50
113string(32) "a9298896ed1b7335f8f10f7ff6d7a239"
114===DONE===
115