1--TEST--
2Test mcrypt_encrypt() function : TripleDES 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_encrypt(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_encrypt() : TripleDES functionality ***\n";
18
19//test CBC, ECB modes
20//test encrypt decrypt
21//test tripledes, aes
22//test different lengths of key, iv
23//test no iv being passed on CBC, ECB
24//test up to 32 bytes with unlimited strength
25
26$cipher = MCRYPT_TRIPLEDES;
27$mode = MCRYPT_MODE_CBC;
28$data = b'This is the secret message which must be encrypted';
29
30// tripledes uses keys up to 192 bits (24 bytes)
31$keys = array(
32   b'12345678',
33   b'12345678901234567890',
34   b'123456789012345678901234',
35   b'12345678901234567890123456'
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
44
45$iv = b'12345678';
46echo "\n--- testing different key lengths\n";
47foreach ($keys as $key) {
48   echo "\nkey length=".strlen($key)."\n";
49   var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
50}
51
52$key = b'123456789012345678901234';
53echo "\n--- testing different iv lengths\n";
54foreach ($ivs as $iv) {
55   echo "\niv length=".strlen($iv)."\n";
56   var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
57}
58
59?>
60===DONE===
61--EXPECTF--
62*** Testing mcrypt_encrypt() : TripleDES functionality ***
63
64--- testing different key lengths
65
66key length=8
67
68Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40
69
70Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
71string(0) ""
72
73key length=20
74
75Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40
76
77Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
78string(0) ""
79
80key length=24
81
82Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40
83string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
84
85key length=26
86
87Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40
88
89Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
90string(0) ""
91
92--- testing different iv lengths
93
94iv length=4
95
96Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47
97
98Warning: mcrypt_encrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d
99string(0) ""
100
101iv length=8
102
103Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47
104string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac"
105
106iv length=9
107
108Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47
109
110Warning: mcrypt_encrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d
111string(0) ""
112===DONE===
113