28 $this->taglen = $tagLength;
34 $options = stream_context_get_options($context);
35 $H = isset($options[
'cryptal'][
'data']) ? (string) $options[
'cryptal'][
'data'] :
'';
36 $blockSize = $this->cipher->getBlockSize();
37 $pad = str_repeat(
"\x00", $blockSize - 1);
39 $omac = clone $this->omac;
40 $tN = $omac->update($pad .
"\x00" . $this->nonce)->finalize(
true);
41 $omac = clone $this->omac;
42 $tH = $omac->update($pad .
"\x01" . $H)->finalize(
true);
44 $ctr =
new CTR($this->cipher, $tN, $this->taglen);
46 foreach (str_split($data, $blockSize) as $block) {
47 $C .= $ctr->encrypt($block, null);
50 $omac = clone $this->omac;
51 $tC = $omac->update($pad .
"\x02" . $C)->finalize(
true);
52 stream_context_set_option($context,
'cryptal',
'tag', (
string) substr($tN ^ $tH ^ $tC, 0, $this->taglen));
58 $options = stream_context_get_options($context);
59 $H = isset($options[
'cryptal'][
'data']) ? (string) $options[
'cryptal'][
'data'] :
'';
60 $T = isset($options[
'cryptal'][
'tag']) ? (string) $options[
'cryptal'][
'tag'] :
'';
61 $blockSize = $this->cipher->getBlockSize();
62 $pad = str_repeat(
"\x00", $blockSize - 1);
64 $omac = clone $this->omac;
65 $tN = $omac->update($pad .
"\x00" . $this->nonce)->finalize(
true);
66 $omac = clone $this->omac;
67 $tH = $omac->update($pad .
"\x01" . $H)->finalize(
true);
68 $omac = clone $this->omac;
69 $tC = $omac->update($pad .
"\x02" . $data)->finalize(
true);
70 $T2 = (string) substr($tN ^ $tH ^ $tC, 0, $this->taglen);
73 throw new \InvalidArgumentException(
'Tag does not match expected value');
76 $ctr =
new CTR($this->cipher, $tN, $this->taglen);
78 foreach (str_split($data, $blockSize) as $block) {
79 $P .= $ctr->encrypt($block, null);
$taglen
Output tag length.
__construct(CryptoInterface $cipher, $iv, $tagLength)