Annotation of embedaddon/php/ext/mcrypt/tests/mcrypt_rijndael128_128BitKey.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test mcrypt_encrypt() function : TripleDES functionality
3: --SKIPIF--
4: <?php
5: if (!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: /* Prototype : string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv)
17: * Description: OFB crypt/decrypt data using key key with cipher cipher starting with iv
18: * Source code: ext/mcrypt/mcrypt.c
19: * Alias to functions:
20: */
21: /* Prototype : string mcrypt_cbc(int cipher, string key, string data, int mode, string iv)
22: * Description: CBC crypt/decrypt data using key key with cipher cipher starting with iv
23: * Source code: ext/mcrypt/mcrypt.c
24: * Alias to functions:
25: */
26:
27: echo "*** Testing mcrypt : Rijndael128 functionality ***\n";
28:
29: $cipher = MCRYPT_RIJNDAEL_128;
30: $mode = MCRYPT_MODE_CBC;
31: $data = b'This is the secret message which must be encrypted';
32:
33: // keys upto 128 bits (16 bytes)
34: $keys = array(
35: null,
36: '',
37: b'12345678',
38: b'1234567890123456'
39: );
40: // rijndael128 is a block cipher of 128 bits (16 bytes)
41: $ivs = array(
42: null,
43: '',
44: b'12345678',
45: b'1234567890123456',
46: b'12345678901234567'
47: );
48:
49:
50: $iv = b'1234567890123456';
51: echo "\n--- testing different key lengths\n";
52: foreach ($keys as $key) {
53: echo "\nkey length=".strlen($key)."\n";
54: $res = mcrypt_encrypt($cipher, $key, $data, MCRYPT_MODE_CBC, $iv);
55: var_dump(bin2hex($res));
56: $res = mcrypt_cbc($cipher, $key, $res, MCRYPT_DECRYPT, $iv);
57: var_dump(bin2hex($res));
58: }
59:
60: $key = b'1234567890123456';
61: echo "\n--- testing different iv lengths\n";
62: foreach ($ivs as $iv) {
63: echo "\niv length=".strlen($iv)."\n";
64: $res = mcrypt_cbc($cipher, $key, $data, $mode, $iv);
65: var_dump(bin2hex($res));
66: $res = mcrypt_decrypt($cipher, $key, $res, MCRYPT_MODE_CBC, $iv);
67: var_dump(bin2hex($res));
68: }
69:
70: ?>
71: ===DONE===
72: --EXPECTF--
73: *** Testing mcrypt : Rijndael128 functionality ***
74:
75: --- testing different key lengths
76:
77: key length=0
78: string(128) "4fbf24aaa789f5194260ade1acd9499402c1845cc517e8fe43cfb5b90a0df294db33ecd1a836c47d6bf6d8600512ba415e17008a1e1991f81056258d82099397"
79: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
80:
81: key length=0
82: string(128) "4fbf24aaa789f5194260ade1acd9499402c1845cc517e8fe43cfb5b90a0df294db33ecd1a836c47d6bf6d8600512ba415e17008a1e1991f81056258d82099397"
83: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
84:
85: key length=8
86: string(128) "d6a3042b278fa5816dc6f46152acbe5fd7d1813c3808c27cd969d8e10a64d0238724edfda0322f4512308f22d142df0e92bed861c2b732f7650e234df59183dc"
87: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
88:
89: key length=16
90: string(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101"
91: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
92:
93: --- testing different iv lengths
94:
95: iv length=0
96:
97: Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
98: string(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
99:
100: Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
101: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
102:
103: iv length=0
104:
105: Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
106: string(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
107:
108: Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
109: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
110:
111: iv length=8
112:
113: Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
114: string(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
115:
116: Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
117: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
118:
119: iv length=16
120: string(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101"
121: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
122:
123: iv length=17
124:
125: Warning: mcrypt_cbc(): The IV parameter must be as long as the blocksize in %s on line %d
126: string(128) "c082b3fabaae4c8c410eb8dba64bae10e48d79b5241fb8f24462cad43bd0b35ad2746b00817e9dcbc636b44df0ec60b46a57e7a310a308a0947724e3817a13b4"
127:
128: Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in %s on line %d
129: string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000"
130: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>