cryptal  latest
Cryptography Abstraction Layer
OFB.php
1 <?php
2 
4 
7 
11 class OFB implements SymmetricModeInterface
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  $res = $this->cipher->encrypt('', $this->iv);
34  $this->iv = $res;
35  return $res ^ $data;
36  }
37 }
$iv
Initialization Vector.
Definition: OFB.php:17
encrypt($data, $context)
Definition: OFB.php:31
__construct(CryptoInterface $cipher, $iv, $tagLength)
Definition: OFB.php:19