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_CBC;
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   'IleMhoxiOthmHua4tFBHOw==',
33   'EeF1s6C+w1IiHj1gdDn81g==',
34   'EEuXpjZPueyYoG0LGQ199Q==',
35   'EEuXpjZPueyYoG0LGQ199Q=='
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   '+G7nGcWIxij3TZjpI9lJdQ==',
45   '3bJiFMeyScxOLQcE6mZtLg==',
46   '+G7nGcWIxij3TZjpI9lJdQ=='
47);
48
49$iv = b'12345678';
50echo "\n--- testing different key lengths\n";
51for ($i = 0; $i < sizeof($keys); $i++) {
52   echo "\nkey length=".strlen($keys[$i])."\n";
53   special_var_dump(mcrypt_decrypt($cipher, $keys[$i], base64_decode($data1[$i]), $mode, $iv));
54}
55
56$key = b'123456789012345678901234';
57echo "\n--- testing different iv lengths\n";
58for ($i = 0; $i < sizeof($ivs); $i++) {
59   echo "\niv length=".strlen($ivs[$i])."\n";
60   special_var_dump(mcrypt_decrypt($cipher, $key, base64_decode($data2[$i]), $mode, $ivs[$i]));
61}
62
63function special_var_dump($str) {
64   var_dump(bin2hex($str));
65}
66?>
67===DONE===
68--EXPECTF--
69*** Testing mcrypt_decrypt() : basic functionality ***
70
71--- testing different key lengths
72
73key length=8
74
75Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44
76
77Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
78string(0) ""
79
80key length=20
81
82Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44
83
84Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
85string(0) ""
86
87key length=24
88
89Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44
90string(32) "736563726574206d6573736167650000"
91
92key length=26
93
94Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44
95
96Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
97string(0) ""
98
99--- testing different iv lengths
100
101iv length=4
102
103Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51
104
105Warning: mcrypt_decrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
106string(0) ""
107
108iv length=8
109
110Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51
111string(32) "659ec947f4dc3a3b9c50de744598d3c8"
112
113iv length=9
114
115Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51
116
117Warning: mcrypt_decrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
118string(0) ""
119===DONE===
120