cryptal
latest
Cryptography Abstraction Layer
Main Page
Classes
Files
File List
CBC.php
1
<?php
2
3
namespace
fpoirotte\Cryptal\Modes
;
4
5
use
fpoirotte\Cryptal\Implementers\CryptoInterface
;
6
use
fpoirotte\Cryptal\AsymmetricModeInterface
;
7
11
class
CBC
implements
AsymmetricModeInterface
12
{
14
protected
$cipher
;
15
17
protected
$iv
;
18
19
public
function
__construct
(
CryptoInterface
$cipher
,
$iv
, $tagLength)
20
{
21
$ivSize = strlen(
$iv
);
22
$blockSize = $cipher->
getBlockSize
();
23
if
($ivSize !== $blockSize) {
24
throw
new \Exception(
"Invalid IV size (got $ivSize bytes; should be $blockSize)"
);
25
}
26
27
$this->cipher =
$cipher
;
28
$this->iv =
$iv
;
29
}
30
31
public
function
encrypt
($data, $context)
32
{
33
$data ^=
$this->iv
;
34
$res = $this->cipher->encrypt(
''
, $data);
35
$this->iv = $res;
36
return
$res;
37
}
38
39
public
function
decrypt
($data, $context)
40
{
41
$res = $this->cipher->decrypt(
''
, $data) ^
$this->iv
;
42
$this->iv = $data;
43
return
$res;
44
}
45
}
CryptoInterface
fpoirotte\Cryptal\Implementers\CryptoInterface\getBlockSize
getBlockSize()
fpoirotte\Cryptal\Implementers\CryptoInterface
Definition:
CryptoInterface.php:13
fpoirotte\Cryptal\Modes\CBC\encrypt
encrypt($data, $context)
Definition:
CBC.php:31
fpoirotte\Cryptal\Modes\CBC\$cipher
$cipher
Cipher.
Definition:
CBC.php:14
fpoirotte\Cryptal\Modes\CBC\decrypt
decrypt($data, $context)
Definition:
CBC.php:39
fpoirotte\Cryptal\Modes
Definition:
CBC.php:3
AsymmetricModeInterface
fpoirotte\Cryptal\AsymmetricModeInterface
Definition:
AsymmetricModeInterface.php:11
fpoirotte\Cryptal\Modes\CBC
Definition:
CBC.php:11
fpoirotte\Cryptal\Modes\CBC\__construct
__construct(CryptoInterface $cipher, $iv, $tagLength)
Definition:
CBC.php:19
fpoirotte\Cryptal\Modes\CBC\$iv
$iv
Initialization Vector.
Definition:
CBC.php:17
src
Cryptal
Modes
CBC.php
Generated on Sat Sep 29 2018 22:22:05 for cryptal by
1.8.11