Commit | Line | Data |
---|---|---|
14d4f286 S |
1 | <?php |
2 | /** | |
3 | * The CBC (Cipher Block Chaining) mode implementation | |
4 | * | |
5 | * PHP version 5.3 | |
6 | * | |
7 | * @category PHPCryptLib | |
8 | * @package Cipher | |
9 | * @subpackage Block | |
10 | * @author Anthony Ferrara <ircmaxell@ircmaxell.com> | |
11 | * @copyright 2011 The Authors | |
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License | |
13 | * @version Build @@version@@ | |
14 | */ | |
15 | ||
16 | namespace CryptLib\Cipher\Block\Mode; | |
17 | ||
18 | /** | |
19 | * The CBC (Cipher Block Chaining) mode implementation | |
20 | * | |
21 | * @category PHPCryptLib | |
22 | * @package Cipher | |
23 | * @subpackage Block | |
24 | * @author Anthony Ferrara <ircmaxell@ircmaxell.com> | |
25 | */ | |
26 | ||
27 | class CBC extends \CryptLib\Cipher\Block\AbstractMode { | |
28 | ||
29 | /** | |
30 | * Decrypt the data using the supplied key, cipher | |
31 | * | |
32 | * @param string $data The data to decrypt | |
33 | * | |
34 | * @return string The decrypted data | |
35 | */ | |
36 | protected function decryptBlock($data) { | |
37 | $stub = $this->cipher->decryptBlock($data); | |
38 | $result = $stub ^ $this->state; | |
39 | $this->state = $data; | |
40 | return $result; | |
41 | } | |
42 | ||
43 | /** | |
44 | * Encrypt the data using the supplied key, cipher | |
45 | * | |
46 | * @param string $data The data to encrypt | |
47 | * | |
48 | * @return string The encrypted data | |
49 | */ | |
50 | protected function encryptBlock($data) { | |
51 | $stub = $this->cipher->encryptBlock($data ^ $this->state); | |
52 | $this->state = $stub; | |
53 | return $stub; | |
54 | } | |
55 | ||
56 | } |