add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Random / Mixer / Hash.php
1 <?php
2 /**
3 * The Hash medium strength mixer class
4 *
5 * This class implements a mixer based upon the recommendations in RFC 4086
6 * section 5.2
7 *
8 * PHP version 5.3
9 *
10 * @see http://tools.ietf.org/html/rfc4086#section-5.2
11 * @category PHPCryptLib
12 * @package Random
13 * @subpackage Mixer
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\Mixer;
21
22 use \CryptLib\Core\Strength;
23
24 /**
25 * The Hash medium strength mixer class
26 *
27 * This class implements a mixer based upon the recommendations in RFC 4086
28 * section 5.2
29 *
30 * @see http://tools.ietf.org/html/rfc4086#section-5.2
31 * @category PHPCryptLib
32 * @package Random
33 * @subpackage Mixer
34 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
35 */
36 class Hash extends \CryptLib\Random\AbstractMixer {
37
38 /**
39 * @var string The hash instance to use
40 */
41 protected $hash = null;
42
43 /**
44 * Build the hash mixer
45 *
46 * @param string $hash The hash instance to use (defaults to sha512)
47 *
48 * @return void
49 */
50 public function __construct($hash = 'sha512') {
51 $this->hash = $hash;
52 }
53
54 /**
55 * Return an instance of Strength indicating the strength of the source
56 *
57 * @return Strength An instance of one of the strength classes
58 */
59 public static function getStrength() {
60 return new Strength(Strength::LOW);
61 }
62
63 /**
64 * Test to see if the mixer is available
65 *
66 * @return boolean If the mixer is available on the system
67 */
68 public static function test() {
69 return true;
70 }
71
72 /**
73 * Get the block size (the size of the individual blocks used for the mixing)
74 *
75 * @return int The block size
76 */
77 protected function getPartSize() {
78 return strlen(hash($this->hash, '', true));
79 }
80
81 /**
82 * Mix 2 parts together using one method
83 *
84 * @param string $part1 The first part to mix
85 * @param string $part2 The second part to mix
86 *
87 * @return string The mixed data
88 */
89 protected function mixParts1($part1, $part2) {
90 return hash_hmac($this->hash, $part1, $part2, true);
91 }
92
93 /**
94 * Mix 2 parts together using another different method
95 *
96 * @param string $part1 The first part to mix
97 * @param string $part2 The second part to mix
98 *
99 * @return string The mixed data
100 */
101 protected function mixParts2($part1, $part2) {
102 return hash_hmac($this->hash, $part2, $part1, true);
103 }
104
105 }