1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | if (!defined('PHP_VERSION_ID')) { |
33: | |
34: | $RandomCompatversion = array_map('intval', explode('.', PHP_VERSION)); |
35: | define( |
36: | 'PHP_VERSION_ID', |
37: | $RandomCompatversion[0] * 10000 |
38: | + $RandomCompatversion[1] * 100 |
39: | + $RandomCompatversion[2] |
40: | ); |
41: | $RandomCompatversion = null; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | if (PHP_VERSION_ID >= 70000) { |
48: | return; |
49: | } |
50: | |
51: | if (!defined('RANDOM_COMPAT_READ_BUFFER')) { |
52: | define('RANDOM_COMPAT_READ_BUFFER', 8); |
53: | } |
54: | |
55: | $RandomCompatDIR = dirname(__FILE__); |
56: | |
57: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'byte_safe_strings.php'; |
58: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'cast_to_int.php'; |
59: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'error_polyfill.php'; |
60: | |
61: | if (!is_callable('random_bytes')) { |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | if (extension_loaded('libsodium')) { |
77: | |
78: | if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) { |
79: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium.php'; |
80: | } elseif (method_exists('Sodium', 'randombytes_buf')) { |
81: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_libsodium_legacy.php'; |
82: | } |
83: | } |
84: | |
85: | |
86: | |
87: | |
88: | if (DIRECTORY_SEPARATOR === '/') { |
89: | |
90: | |
91: | $RandomCompatUrandom = true; |
92: | $RandomCompat_basedir = ini_get('open_basedir'); |
93: | |
94: | if (!empty($RandomCompat_basedir)) { |
95: | $RandomCompat_open_basedir = explode( |
96: | PATH_SEPARATOR, |
97: | strtolower($RandomCompat_basedir) |
98: | ); |
99: | $RandomCompatUrandom = (array() !== array_intersect( |
100: | array('/dev', '/dev/', '/dev/urandom'), |
101: | $RandomCompat_open_basedir |
102: | )); |
103: | $RandomCompat_open_basedir = null; |
104: | } |
105: | |
106: | if ( |
107: | !is_callable('random_bytes') |
108: | && |
109: | $RandomCompatUrandom |
110: | && |
111: | @is_readable('/dev/urandom') |
112: | ) { |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_dev_urandom.php'; |
121: | } |
122: | |
123: | $RandomCompat_basedir = null; |
124: | } else { |
125: | $RandomCompatUrandom = false; |
126: | } |
127: | |
128: | |
129: | |
130: | |
131: | |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | |
138: | |
139: | |
140: | |
141: | |
142: | |
143: | |
144: | |
145: | |
146: | if ( |
147: | !is_callable('random_bytes') |
148: | && |
149: | |
150: | (DIRECTORY_SEPARATOR === '/' || PHP_VERSION_ID >= 50307) |
151: | && |
152: | |
153: | |
154: | ( |
155: | DIRECTORY_SEPARATOR !== '/' || |
156: | (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613) |
157: | ) |
158: | && |
159: | extension_loaded('mcrypt') |
160: | ) { |
161: | |
162: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_mcrypt.php'; |
163: | } |
164: | $RandomCompatUrandom = null; |
165: | |
166: | |
167: | |
168: | |
169: | |
170: | if ( |
171: | !is_callable('random_bytes') |
172: | && |
173: | extension_loaded('com_dotnet') |
174: | && |
175: | class_exists('COM') |
176: | ) { |
177: | $RandomCompat_disabled_classes = preg_split( |
178: | '#\s*,\s*#', |
179: | strtolower(ini_get('disable_classes')) |
180: | ); |
181: | |
182: | if (!in_array('com', $RandomCompat_disabled_classes)) { |
183: | try { |
184: | $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); |
185: | |
186: | if (is_callable(array($RandomCompatCOMtest, 'GetRandom'))) { |
187: | |
188: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_com_dotnet.php'; |
189: | } |
190: | } catch (com_exception $e) { |
191: | |
192: | } |
193: | } |
194: | $RandomCompat_disabled_classes = null; |
195: | $RandomCompatCOMtest = null; |
196: | } |
197: | |
198: | |
199: | |
200: | |
201: | if (!is_callable('random_bytes')) { |
202: | |
203: | |
204: | |
205: | |
206: | |
207: | |
208: | |
209: | |
210: | |
211: | function random_bytes($length) |
212: | { |
213: | unset($length); |
214: | throw new Exception( |
215: | 'There is no suitable CSPRNG installed on your system' |
216: | ); |
217: | return ''; |
218: | } |
219: | } |
220: | } |
221: | |
222: | if (!is_callable('random_int')) { |
223: | require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_int.php'; |
224: | } |
225: | |
226: | $RandomCompatDIR = null; |
227: | |