25 public function __construct($key)
27 $this->main = new \fpoirotte\Pssht\Algorithms\ChaCha20(substr($key, 0, 32));
28 $this->header = new \fpoirotte\Pssht\Algorithms\ChaCha20(substr($key, 32));
31 public function ae($IV, $P, $A)
33 $polyKey = $this->main->encrypt(str_repeat(
"\x00", 32), $IV, 0);
34 $poly = new \fpoirotte\Pssht\Algorithms\Poly1305($polyKey);
35 $aad = $this->header->encrypt($A, $IV, 0);
36 $res = $this->main->encrypt($P, $IV, 1);
37 return $aad . $res . $poly->mac($aad . $res);
40 public function ad($IV, $C, $A, $T)
42 $len = $this->header->decrypt($A, $IV, 0);
43 if ($C === null && $T === null) {
47 $polyKey = $this->main->encrypt(str_repeat(
"\x00", 32), $IV, 0);
48 $poly = new \fpoirotte\Pssht\Algorithms\Poly1305($polyKey);
49 if ($poly->mac($A . $C) !== $T) {
52 return $this->main->decrypt($C, $IV, 1);
$header
Instance of ChaCha20 used to encrypt/decrypt additional data.
$main
Instance of ChaCha20 used to encrypt/decrypt plaintext/cipher data.