add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Cipher / Block / Mode / CBC.php
diff --git a/CryptLib/Cipher/Block/Mode/CBC.php b/CryptLib/Cipher/Block/Mode/CBC.php
new file mode 100644 (file)
index 0000000..a8d3a62
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * The CBC (Cipher Block Chaining) mode implementation
+ *
+ * PHP version 5.3
+ *
+ * @category   PHPCryptLib
+ * @package    Cipher
+ * @subpackage Block
+ * @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\Cipher\Block\Mode;
+
+/**
+ * The CBC (Cipher Block Chaining) mode implementation
+ *
+ * @category   PHPCryptLib
+ * @package    Cipher
+ * @subpackage Block
+ * @author     Anthony Ferrara <ircmaxell@ircmaxell.com>
+ */
+
+class CBC extends \CryptLib\Cipher\Block\AbstractMode {
+
+    /**
+     * Decrypt the data using the supplied key, cipher
+     *
+     * @param string $data The data to decrypt
+     *
+     * @return string The decrypted data
+     */
+    protected function decryptBlock($data) {
+        $stub        = $this->cipher->decryptBlock($data);
+        $result      = $stub ^ $this->state;
+        $this->state = $data;
+        return $result;
+    }
+
+    /**
+     * Encrypt the data using the supplied key, cipher
+     *
+     * @param string $data The data to encrypt
+     *
+     * @return string The encrypted data
+     */
+    protected function encryptBlock($data) {
+        $stub        = $this->cipher->encryptBlock($data ^ $this->state);
+        $this->state = $stub;
+        return $stub;
+    }
+
+}