add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Random / Mixer / Hash.php
diff --git a/CryptLib/Random/Mixer/Hash.php b/CryptLib/Random/Mixer/Hash.php
new file mode 100644 (file)
index 0000000..086d924
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+/**
+ * The Hash medium strength mixer class
+ *
+ * This class implements a mixer based upon the recommendations in RFC 4086
+ * section 5.2
+ *
+ * PHP version 5.3
+ *
+ * @see        http://tools.ietf.org/html/rfc4086#section-5.2
+ * @category   PHPCryptLib
+ * @package    Random
+ * @subpackage Mixer
+ * @author     Anthony Ferrara <ircmaxell@ircmaxell.com>
+ * @copyright  2011 The Authors
+ * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
+ * @version    Build @@version@@
+ */
+
+namespace CryptLib\Random\Mixer;
+
+use \CryptLib\Core\Strength;
+
+/**
+ * The Hash medium strength mixer class
+ *
+ * This class implements a mixer based upon the recommendations in RFC 4086
+ * section 5.2
+ *
+ * @see        http://tools.ietf.org/html/rfc4086#section-5.2
+ * @category   PHPCryptLib
+ * @package    Random
+ * @subpackage Mixer
+ * @author     Anthony Ferrara <ircmaxell@ircmaxell.com>
+ */
+class Hash extends \CryptLib\Random\AbstractMixer {
+
+    /**
+     * @var string The hash instance to use
+     */
+    protected $hash = null;
+
+    /**
+     * Build the hash mixer
+     *
+     * @param string $hash The hash instance to use (defaults to sha512)
+     *
+     * @return void
+     */
+    public function __construct($hash = 'sha512') {
+        $this->hash = $hash;
+    }
+
+    /**
+     * Return an instance of Strength indicating the strength of the source
+     *
+     * @return Strength An instance of one of the strength classes
+     */
+    public static function getStrength() {
+        return new Strength(Strength::LOW);
+    }
+
+    /**
+     * Test to see if the mixer is available
+     *
+     * @return boolean If the mixer is available on the system
+     */
+    public static function test() {
+        return true;
+    }
+
+    /**
+     * Get the block size (the size of the individual blocks used for the mixing)
+     *
+     * @return int The block size
+     */
+    protected function getPartSize() {
+        return strlen(hash($this->hash, '', true));
+    }
+
+    /**
+     * Mix 2 parts together using one method
+     *
+     * @param string $part1 The first part to mix
+     * @param string $part2 The second part to mix
+     *
+     * @return string The mixed data
+     */
+    protected function mixParts1($part1, $part2) {
+        return hash_hmac($this->hash, $part1, $part2, true);
+    }
+
+    /**
+     * Mix 2 parts together using another different method
+     *
+     * @param string $part1 The first part to mix
+     * @param string $part2 The second part to mix
+     *
+     * @return string The mixed data
+     */
+    protected function mixParts2($part1, $part2) {
+        return hash_hmac($this->hash, $part2, $part1, true);
+    }
+
+}