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$cipher = MCRYPT_TRIPLEDES;
20$mode = MCRYPT_MODE_ECB;
21$data = b'This is the secret message which must be encrypted';
22
23// tripledes uses keys up to 192 bits (24 bytes)
24$keys = array(
25   b'12345678',
26   b'12345678901234567890',
27   b'123456789012345678901234',
28   b'12345678901234567890123456'
29);
30
31echo "\n--- testing different key lengths\n";
32foreach ($keys as $key) {
33   echo "\nkey length=".strlen($key)."\n";
34   var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode)));
35}
36
37$key = b'123456789012345678901234';
38$ivs = array(
39   b'1234',
40   b'12345678',
41   b'123456789'
42);
43
44// ivs should be ignored in ecb mode
45echo "\n--- testing different iv lengths\n";
46foreach ($ivs as $iv) {
47   echo "\niv length=".strlen($iv)."\n";
48   var_dump(bin2hex(mcrypt_encrypt($cipher, $key, $data, $mode, $iv)));
49}
50
51?>
52===DONE===
53--EXPECTF--
54*** Testing mcrypt_encrypt() : TripleDES functionality ***
55
56--- testing different key lengths
57
58key length=8
59
60Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25
61
62Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
63string(0) ""
64
65key length=20
66
67Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25
68
69Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
70string(0) ""
71
72key length=24
73
74Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25
75string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
76
77key length=26
78
79Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25
80
81Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d
82string(0) ""
83
84--- testing different iv lengths
85
86iv length=4
87
88Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39
89string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
90
91iv length=8
92
93Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39
94string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
95
96iv length=9
97
98Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39
99string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27"
100===DONE===
101