xref: /PHP-7.1/ext/mcrypt/tests/blowfish.phpt (revision 7af945e2)
1--TEST--
2Test for blowfish compatibility
3--SKIPIF--
4<?php if (!extension_loaded("mcrypt")) print "skip"; ?>
5--FILE--
6<?php
7if(!function_exists("hex2bin")) {
8    function hex2bin($data) {
9       $len = strlen($data);
10       return pack("H" . $len, $data);
11    }
12}
13
14print "key               plain             crypt             guess             stat\n";
15$null = "\0\0\0\0\0\0\0\0";
16$vectors = file(dirname(__FILE__) . "/vectors.txt");
17
18$td = mcrypt_module_open ("blowfish", "", MCRYPT_MODE_ECB, "");
19
20foreach($vectors as $data) {
21    $data = trim($data);
22    if ($data) {
23        list($key,$plain,$crypt) = preg_split("/[[:space:]]+/",$data);
24        printf("%s  %s  ",
25            $key,
26            $plain
27        );
28        $key = hex2bin(trim($key));
29        $plain = hex2bin(($plain));
30        $crypt = strtolower(trim($crypt));
31
32        mcrypt_generic_init ($td, $key, $null);
33        $guess = mcrypt_generic ($td, $plain);
34        $guess = bin2hex($guess);
35        printf("%s  %s  %s\n",
36            $crypt,
37            $guess,
38            ($crypt==$guess ? "OK" : "BAD")
39        );
40    }
41}
42
43// Longer test case from http://www.schneier.com/code/vectors.txt
44$td = mcrypt_module_open ("blowfish", "", MCRYPT_MODE_CBC, "");
45
46$key = hex2bin( "0123456789ABCDEFF0E1D2C3B4A59687" );
47$iv = hex2bin( "FEDCBA9876543210" );
48$plain = hex2bin( "37363534333231204E6F77206973207468652074696D6520666F722000" );
49
50mcrypt_generic_init( $td, $key, $iv );
51$guess = bin2hex( mcrypt_generic( $td, $plain ) );
52
53echo "\n", $guess, "\n";
54?>
55--EXPECTF--
56key               plain             crypt             guess             stat
57
58Deprecated: Function mcrypt_module_open() is deprecated in %s%eblowfish.php on line %d
590000000000000000  0000000000000000
60Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
61
62Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
634ef997456198dd78  4ef997456198dd78  OK
64FFFFFFFFFFFFFFFF  FFFFFFFFFFFFFFFF
65Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
66
67Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
6851866fd5b85ecb8a  51866fd5b85ecb8a  OK
693000000000000000  1000000000000001
70Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
71
72Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
737d856f9a613063f2  7d856f9a613063f2  OK
741111111111111111  1111111111111111
75Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
76
77Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
782466dd878b963c9d  2466dd878b963c9d  OK
790123456789ABCDEF  1111111111111111
80Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
81
82Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
8361f9c3802281b096  61f9c3802281b096  OK
841111111111111111  0123456789ABCDEF
85Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
86
87Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
887d0cc630afda1ec7  7d0cc630afda1ec7  OK
89FEDCBA9876543210  0123456789ABCDEF
90Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
91
92Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
930aceab0fc6a0a28d  0aceab0fc6a0a28d  OK
947CA110454A1A6E57  01A1D6D039776742
95Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
96
97Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
9859c68245eb05282b  59c68245eb05282b  OK
990131D9619DC1376E  5CD54CA83DEF57DA
100Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
101
102Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
103b1b8cc0b250f09a0  b1b8cc0b250f09a0  OK
10407A1133E4A0B2686  0248D43806F67172
105Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
106
107Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1081730e5778bea1da4  1730e5778bea1da4  OK
1093849674C2602319E  51454B582DDF440A
110Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
111
112Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
113a25e7856cf2651eb  a25e7856cf2651eb  OK
11404B915BA43FEB5B6  42FD443059577FA2
115Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
116
117Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
118353882b109ce8f1a  353882b109ce8f1a  OK
1190113B970FD34F2CE  059B5E0851CF143A
120Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
121
122Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
12348f4d0884c379918  48f4d0884c379918  OK
1240170F175468FB5E6  0756D8E0774761D2
125Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
126
127Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
128432193b78951fc98  432193b78951fc98  OK
12943297FAD38E373FE  762514B829BF486A
130Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
131
132Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
13313f04154d69d1ae5  13f04154d69d1ae5  OK
13407A7137045DA2A16  3BDD119049372802
135Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
136
137Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1382eedda93ffd39c79  2eedda93ffd39c79  OK
13904689104C2FD3B2F  26955F6835AF609A
140Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
141
142Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
143d887e0393c2da6e3  d887e0393c2da6e3  OK
14437D06BB516CB7546  164D5E404F275232
145Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
146
147Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1485f99d04f5b163969  5f99d04f5b163969  OK
1491F08260D1AC2465E  6B056E18759F5CCA
150Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
151
152Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1534a057a3b24d3977b  4a057a3b24d3977b  OK
154584023641ABA6176  004BD6EF09176062
155Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
156
157Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
158452031c1e4fada8e  452031c1e4fada8e  OK
159025816164629B007  480D39006EE762F2
160Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
161
162Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1637555ae39f59b87bd  7555ae39f59b87bd  OK
16449793EBC79B3258F  437540C8698F3CFA
165Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
166
167Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
16853c55f9cb49fc019  53c55f9cb49fc019  OK
1694FB05E1515AB73A7  072D43A077075292
170Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
171
172Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
1737a8e7bfa937e89a3  7a8e7bfa937e89a3  OK
17449E95D6D4CA229BF  02FE55778117F12A
175Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
176
177Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
178cf9c5d7a4986adb5  cf9c5d7a4986adb5  OK
179018310DC409B26D6  1D9D5C5018F728C2
180Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
181
182Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
183d1abb290658bc778  d1abb290658bc778  OK
1841C587F1C13924FEF  305532286D6F295A
185Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
186
187Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
18855cb3774d13ef201  55cb3774d13ef201  OK
1890101010101010101  0123456789ABCDEF
190Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
191
192Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
193fa34ec4847b268b2  fa34ec4847b268b2  OK
1941F1F1F1F0E0E0E0E  0123456789ABCDEF
195Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
196
197Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
198a790795108ea3cae  a790795108ea3cae  OK
199E0FEE0FEF1FEF1FE  0123456789ABCDEF
200Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
201
202Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
203c39e072d9fac631d  c39e072d9fac631d  OK
2040000000000000000  FFFFFFFFFFFFFFFF
205Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
206
207Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
208014933e0cdaff6e4  014933e0cdaff6e4  OK
209FFFFFFFFFFFFFFFF  0000000000000000
210Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
211
212Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
213f21e9a77b71c49bc  f21e9a77b71c49bc  OK
2140123456789ABCDEF  0000000000000000
215Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
216
217Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
218245946885754369a  245946885754369a  OK
219FEDCBA9876543210  FFFFFFFFFFFFFFFF
220Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
221
222Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
2236b5c5a9c5d9e0a5a  6b5c5a9c5d9e0a5a  OK
224
225Deprecated: Function mcrypt_module_open() is deprecated in %s%eblowfish.php on line %d
226
227Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d
228
229Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d
230
2316b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc
232