3 * The Hash medium strength mixer class
5 * This class implements a mixer based upon the recommendations in RFC 4086
10 * @see http://tools.ietf.org/html/rfc4086#section-5.2
11 * @category PHPCryptLib
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@@
20 namespace CryptLib\Random\Mixer
;
22 use \CryptLib\Core\Strength
;
25 * The Hash medium strength mixer class
27 * This class implements a mixer based upon the recommendations in RFC 4086
30 * @see http://tools.ietf.org/html/rfc4086#section-5.2
31 * @category PHPCryptLib
34 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
36 class Hash
extends \CryptLib\Random\AbstractMixer
{
39 * @var string The hash instance to use
41 protected $hash = null;
44 * Build the hash mixer
46 * @param string $hash The hash instance to use (defaults to sha512)
50 public function __construct($hash = 'sha512') {
55 * Return an instance of Strength indicating the strength of the source
57 * @return Strength An instance of one of the strength classes
59 public static function getStrength() {
60 return new Strength(Strength
::LOW
);
64 * Test to see if the mixer is available
66 * @return boolean If the mixer is available on the system
68 public static function test() {
73 * Get the block size (the size of the individual blocks used for the mixing)
75 * @return int The block size
77 protected function getPartSize() {
78 return strlen(hash($this->hash
, '', true));
82 * Mix 2 parts together using one method
84 * @param string $part1 The first part to mix
85 * @param string $part2 The second part to mix
87 * @return string The mixed data
89 protected function mixParts1($part1, $part2) {
90 return hash_hmac($this->hash
, $part1, $part2, true);
94 * Mix 2 parts together using another different method
96 * @param string $part1 The first part to mix
97 * @param string $part2 The second part to mix
99 * @return string The mixed data
101 protected function mixParts2($part1, $part2) {
102 return hash_hmac($this->hash
, $part2, $part1, true);