add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Random / Source / MTRand.php
1 <?php
2 /**
3 * The MTRand Random Number Source
4 *
5 * This source generates low strength random numbers by using the internal
6 * mt_rand() function. By itself it is quite weak. However when combined with
7 * other sources it does provide significant benefit.
8 *
9 * PHP version 5.3
10 *
11 * @category PHPCryptLib
12 * @package Random
13 * @subpackage Source
14 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
15 * @copyright 2011 The Authors
16 * @license http://www.opensource.org/licenses/mit-license.html MIT License
17 * @version Build @@version@@
18 */
19
20 namespace CryptLib\Random\Source;
21
22 use CryptLib\Core\Strength;
23
24 /**
25 * The MTRand Random Number Source
26 *
27 * This source generates low strength random numbers by using the internal
28 * mt_rand() function. By itself it is quite weak. However when combined with
29 * other sources it does provide significant benefit.
30 *
31 * @category PHPCryptLib
32 * @package Random
33 * @subpackage Source
34 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
35 * @codeCoverageIgnore
36 */
37 class MTRand implements \CryptLib\Random\Source {
38
39 /**
40 * Return an instance of Strength indicating the strength of the source
41 *
42 * @return Strength An instance of one of the strength classes
43 */
44 public static function getStrength() {
45 // Detect if Suhosin Hardened PHP patch is applied
46 if (defined('S_ALL')) {
47 return new Strength(Strength::MEDIUM);
48 } else {
49 return new Strength(Strength::LOW);
50 }
51 }
52
53 /**
54 * Generate a random string of the specified size
55 *
56 * @param int $size The size of the requested random string
57 *
58 * @return string A string of the requested size
59 */
60 public function generate($size) {
61 $result = '';
62 for ($i = 0; $i < $size; $i++) {
63 $result .= chr((mt_rand() ^ mt_rand()) % 256);
64 }
65 return $result;
66 }
67
68 }