| 1 | package Dancer2::Session::Pg::Cipher::ChaCha20Poly1305; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use Crypt::AuthEnc::ChaCha20Poly1305 (); | ||
| 8 | |||
| 9 | our $VERSION = '0.002'; | ||
| 10 | |||
| 11 | with 'Dancer2::Session::Pg::Cipher'; | ||
| 12 | |||
| 13 | sub cipher_id { return 4 } | ||
| 14 | sub cipher_name { return 'ChaCha20-Poly1305' } | ||
| 15 | sub key_bytes { return 32 } | ||
| 16 | sub iv_bytes { return 12 } | ||
| 17 | sub tag_bytes { return 16 } | ||
| 18 | |||
| 19 | sub seal { | ||
| 20 | my ( $self, $key, $iv, $plaintext, $aad ) = @_; | ||
| 21 | return Crypt::AuthEnc::ChaCha20Poly1305::chacha20poly1305_encrypt_authenticate( $key, $iv, $aad, $plaintext ); | ||
| 22 | } | ||
| 23 | |||
| 24 | sub unseal { ## no critic (Subroutines::ProhibitManyArgs) -- six is the AEAD contract in Dancer2::Session::Pg::Cipher | ||
| 25 | my ( $self, $key, $iv, $ciphertext, $tag, $aad ) = @_; | ||
| 26 | return Crypt::AuthEnc::ChaCha20Poly1305::chacha20poly1305_decrypt_verify( $key, $iv, $aad, $ciphertext, $tag ); | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | __END__ |