Crypt::...Enc::EAX(3)
π NAME π
okay so this is the Crypt::...Enc::EAX(3) page from User Contributed Perl Documentation, and the main character is Crypt::AuthEnc::EAX β Authenticated encryption in EAX mode. π
β¨ SYNOPSIS β¨
bestie, there are two whole flavors here: the OO interface and the functional interface. Both are iconic:
### OO interface
use Crypt::AuthEnc::EAX;
my $key = '...';
my $nonce = '...';
my $expected_tag = '...';
# encrypt and authenticate
my $ae_enc = Crypt::AuthEnc::EAX->new("AES", $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');
$ct .= $ae_enc->encrypt_add('data3');
my $tag = $ae_enc->encrypt_done();
# decrypt and verify
my $ae_dec = Crypt::AuthEnc::EAX->new("AES", $key, $nonce);
$ae_dec->adata_add('additional_authenticated_data1');
$ae_dec->adata_add('additional_authenticated_data2');
my $pt = $ae_dec->decrypt_add('ciphertext1');
$pt .= $ae_dec->decrypt_add('ciphertext2');
$pt .= $ae_dec->decrypt_add('ciphertext3');
my $computed_tag = $ae_dec->decrypt_done();
die "decrypt failed" unless $computed_tag eq $expected_tag;
#or
my $result = $ae_dec->decrypt_done($expected_tag); # 0 or 1
### functional interface
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
my $key = '...';
my $nonce = '...';
my $adata = '...';
my $plaintext = '...';
my ($ciphertext, $tag) = eax_encrypt_authenticate('AES', $key, $nonce, $adata, $plaintext);
my $decrypted = eax_decrypt_verify('AES', $key, $nonce, $adata, $ciphertext, $tag);
πΈ DESCRIPTION πΈ
EAX is that mode that needs a cipher plus CTR and OMAC support, and it gives you encryption and authentication together. It gets initialized with a random IV that can be shared publicly, additional authenticated data that can be fixed and public, and a random secret symmetric key. π
This is a stateful API, bestie. You build one message by calling, in order: new, optional extra adata_add, zero or more encrypt_add or decrypt_add calls, then encrypt_done or decrypt_done. β¨
Use a fresh object per message. The optional $adata argument to new is equivalent to adding initial AAD before processing any payload. 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 adata_add, encrypt_add, decrypt_add, encrypt_done, and decrypt_done calls croak. π
π EXPORT π
Nothing is exported by default. π«Ά
You can export selected functions:
use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
π§ FUNCTIONS π§
β eax_encrypt_authenticate
this one hands you back both the ciphertext and the tag:
my ($ciphertext, $tag) = eax_encrypt_authenticate($cipher, $key, $nonce, $adata, $plaintext);
# $cipher .. [string] 'AES' or name of any other cipher with 16-byte block len
# $key ..... [binary string] AES key of proper length (128/192/256 bits)
# $nonce ... [binary string] unique nonce (no need to keep it secret)
# $adata ... [binary string] additional authenticated data
π¦ eax_decrypt_verify
and this one gives you the plaintext back:
my $plaintext = eax_decrypt_verify($cipher, $key, $nonce, $adata, $ciphertext, $tag);
# on error returns undef
π METHODS π
Unless noted otherwise, assume $ae is an existing AEAD object created via new, for example:
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $nonce);
π new
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $nonce);
#or
my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $nonce, $adata);
# $cipher .. [string] 'AES' or name of any other cipher with 16-byte block len
# $key ..... [binary string] AES key of proper length (128/192/256 bits)
# $nonce ... [binary string] unique nonce (no need to keep it secret)
# $adata ... [binary string] additional authenticated data (optional)
π adata_add
Can be called only before the first encrypt_add or decrypt_add. Returns the object itself (for chaining). π
$ae->adata_add($adata); # 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)
π clone
Returns a copy of the AEAD object in its current state. twin energy, lowkey.
my $ae_new = $ae->clone;
π«Ά SEE ALSO π«Ά
CryptX,Crypt::AuthEnc::CCM,Crypt::AuthEnc::GCM,Crypt::AuthEnc::OCBβ the whole squad.- the wiki vibe:
<https://en.wikipedia.org/wiki/EAX_mode> - the paper:
<https://web.cs.ucdavis.edu/~rogaway/papers/eax.pdf>
okay bye bestie, that's the whole page β source/version says perl v5.42.0, date says 2026-05-11, and it's all for Crypt::...Enc::EAX(3). π
β¨
π¦ 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