Crypt::...Poly1305(3)
okay so bestie, welcome to the manual page for Crypt::AuthEnc::XChaCha20Poly1305 in the User Contributed Perl Documentation section (3) π the header labels it Crypt::...Poly1305(3) β yes itβs that truncated-looking name, iykyk π
πΈ NAME πΈ
Crypt::AuthEnc::XChaCha20Poly1305 β Authenticated encryption in XChaCha20-Poly1305 mode β¨
β¨ SYNOPSIS β¨
okay bestie, hereβs the whole thing in both flavors β OO interface and functional interface, copy-paste energy, no cap:
### OO interface
use Crypt::AuthEnc::XChaCha20Poly1305;
my $key = '...';
my $nonce = '...';
my $expected_tag = '...';
# encrypt and authenticate
my $ae_enc = Crypt::AuthEnc::XChaCha20Poly1305->new($key, $nonce);
$ae_enc->adata_add('additional_authenticated_data1');
$ae_enc->adata_add('additional_authenticated_data2');
my $ct = $ae_enc->encrypt_add('data1');
$ct .= $ae_enc->encrypt_add('data2');
my $tag = $ae_enc->encrypt_done();
# decrypt and verify
my $ae_dec = Crypt::AuthEnc::XChaCha20Poly1305->new($key, $nonce);
$ae_dec->adata_add('additional_authenticated_data1');
my $pt = $ae_dec->decrypt_add($ct);
die "decrypt failed" unless $ae_dec->decrypt_done($tag);
### functional interface
use Crypt::AuthEnc::XChaCha20Poly1305 qw(
xchacha20poly1305_encrypt_authenticate
xchacha20poly1305_decrypt_verify
);
my $key = '...';
my $nonce = '...';
my $adata = '...';
my $plaintext = '...';
my ($ciphertext, $tag) = xchacha20poly1305_encrypt_authenticate($key, $nonce, $adata, $plaintext);
my $decrypted = xchacha20poly1305_decrypt_verify($key, $nonce, $adata, $ciphertext, $tag);
π DESCRIPTION π
so this module has been around since CryptX-0.089 π¦ It provides encryption and authentication based on XChaCha20 + Poly1305, using the extended 192-bit (24-byte) nonce variant of ChaCha20-Poly1305. slay.
This is a stateful API. You build one message by calling, in order:
neworset_iv- optional
adata_add - zero or more
encrypt_addordecrypt_addcalls - then
encrypt_doneordecrypt_done
Use a fresh object per message β literally, one message per object, no recycling vibes. If you construct with new($key) you must call set_iv($nonce) before adding AAD or processing plaintext/ciphertext.
When verifying, decrypt_done($expected_tag) is the safer one-step form; decrypt_done() without arguments only returns the calculated tag. The first encrypt_done / decrypt_done call finalizes the object. After that, further set_iv, adata_add, encrypt_add, decrypt_add, encrypt_done, and decrypt_done calls croak. π«
β οΈ warning bestie: once itβs finalized, itβs finalized β those later calls croak, periodt.
π¦ EXPORT π¦
Nothing is exported by default.
You can export selected functions:
use Crypt::AuthEnc::XChaCha20Poly1305 qw(
xchacha20poly1305_encrypt_authenticate
xchacha20poly1305_decrypt_verify
);
π FUNCTIONS π
β¨ xchacha20poly1305_encrypt_authenticate β¨
my ($ciphertext, $tag) = xchacha20poly1305_encrypt_authenticate($key, $nonce, $adata, $plaintext);
# $key ..... [binary string] encryption key (256 bits / 32 bytes)
# $nonce ... [binary string] extended nonce (192 bits / 24 bytes)
# $adata ... [binary string] additional authenticated data (optional)
Invalid key or nonce lengths croak. String-overloaded objects are accepted for $key and $nonce. π«Ά
π xchacha20poly1305_decrypt_verify π
my $plaintext = xchacha20poly1305_decrypt_verify($key, $nonce, $adata, $ciphertext, $tag);
# on error returns undef
Invalid key or nonce lengths croak. String-overloaded objects are accepted for $key and $nonce.
π METHODS π
Unless noted otherwise, assume $ae is an existing AEAD object created via new, for example:
my $ae = Crypt::AuthEnc::XChaCha20Poly1305->new($key, $nonce);
π§ new π§
two ways to make one, bestie:
my $ae = Crypt::AuthEnc::XChaCha20Poly1305->new($key, $nonce);
my $ae = Crypt::AuthEnc::XChaCha20Poly1305->new($key);
# $key ..... [binary string] encryption key (256 bits / 32 bytes)
# $nonce ... [binary string] extended nonce (192 bits / 24 bytes)
πΈ adata_add πΈ
Add additional authenticated data. Can be called only before the first encrypt_add or decrypt_add. Returns the object itself (for chaining). β¨ chaining is main character energy.
$ae->adata_add($aad_data); # can be called multiple times
π encrypt_add π
Returns a binary string of ciphertext (raw bytes).
my $ciphertext = $ae->encrypt_add($data); # can be called multiple times
π₯ encrypt_done π₯
Returns the authentication tag as a binary string (raw bytes). This call finalizes the current message.
my $tag = $ae->encrypt_done(); # returns $tag value
π decrypt_add π
Returns a binary string of plaintext (raw bytes).
my $plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
π decrypt_done π
Without argument returns the computed tag as a binary string. With $tag argument returns 1 (success) or 0 (failure). This call finalizes the current message.
my $tag = $ae->decrypt_done; # returns $tag value
#or
my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
π set_iv π
my $ae = Crypt::AuthEnc::XChaCha20Poly1305->new($key)->set_iv($nonce);
# $nonce ... [binary string] extended nonce (192 bits / 24 bytes)
Call set_iv before the first adata_add, encrypt_add, or decrypt_add for a message.
π¦ clone π¦
Returns a copy of the AEAD object in its current state.
my $ae_new = $ae->clone;
π SEE ALSO π
Crypt::AuthEnc::ChaCha20Poly1305,Crypt::AuthEnc::GCM,Crypt::AuthEnc::CCM- the draft:
https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchachaπ¦
okay bye bestie π this page is from perl v5.42.0, dated 2026-05-11, and the footer labels it Crypt::...Poly1305(3). periodt. π
π¦ where this page comes from
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms