Crypt::Mac::XCBC(3)
π Crypt::Mac::XCBC β the perl manual but make it make sense π
okay so bestie, welcome to the Crypt::Mac::XCBC(3) page β it's giving message authentication code energy, and honestly? iconic. this is XCBC, the MAC algorithm from RFC 3566, and we're gonna walk through it together π«Ά
β¨ NAME β¨
Crypt::Mac::XCBC β Message authentication code XCBC (RFC 3566). literally that's the whole vibe.
πΈ SYNOPSIS πΈ
okay so you can go two ways with this: the functional interface or the OO interface. both slay, pick your fighter π
functional interface π
### Functional interface:
use Crypt::Mac::XCBC qw( xcbc xcbc_hex xcbc_b64 xcbc_b64u );
# calculate MAC from string/buffer
my $xcbc_raw = xcbc($cipher_name, $key, 'data buffer');
my $xcbc_hex = xcbc_hex($cipher_name, $key, 'data buffer');
my $xcbc_b64 = xcbc_b64($cipher_name, $key, 'data buffer');
my $xcbc_b64u = xcbc_b64u($cipher_name, $key, 'data buffer');
OO interface π
### OO interface:
use Crypt::Mac::XCBC;
my $d = Crypt::Mac::XCBC->new($cipher_name, $key);
$d->add('any data');
my $result_hex = $d->hexmac; # finalizes the object
# for another output encoding use a fresh object (or clone before finalizing)
my $result_b64u = Crypt::Mac::XCBC->new($cipher_name, $key)->add('any data')->b64umac;
# or MAC a file instead
my $file_result_raw = Crypt::Mac::XCBC->new($cipher_name, $key)->addfile('filename.dat')->mac;
π¦ DESCRIPTION π¦
so basically this module gives you an interface to the XCBC message authentication code (MAC) algorithm. no cap, that's the whole thing. β¨
π EXPORT π
nothing is exported by default. like, it's not gonna just show up uninvited bestie π
you can export selected functions though:
use Crypt::Mac::XCBC qw( xcbc xcbc_hex xcbc_b64 xcbc_b64u );
or, if you're feeling unhinged, all of them at once:
use Crypt::Mac::XCBC ':all';
π FUNCTIONS π
β xcbc
joins all the arguments into a single string and returns its XCBC message authentication code, encoded as a binary string. honestly? raw. π
π data arguments for the functional helpers get converted to byte strings using Perl's usual scalar stringification. defined scalars β including numbers and string-overloaded objects β are accepted.undefis treated as an empty string and may emit Perl's usual "uninitialized value" warning. same rules apply toxcbc_hex,xcbc_b64, andxcbc_b64u, fr fr.
my $xcbc_raw = xcbc($cipher_name, $key, 'data buffer');
#or
my $xcbc_raw = xcbc($cipher_name, $key, 'any data', 'more data', 'even more data');
π
xcbc_hex
same deal β joins all arguments into one string, returns the XCBC MAC as a hexadecimal string. cute and readable, we love that.
my $xcbc_hex = xcbc_hex($cipher_name, $key, 'data buffer');
#or
my $xcbc_hex = xcbc_hex($cipher_name, $key, 'any data', 'more data', 'even more data');
π xcbc_b64
joins all arguments into a single string, returns the XCBC MAC encoded as a Base64 string. slay β¨
my $xcbc_b64 = xcbc_b64($cipher_name, $key, 'data buffer');
#or
my $xcbc_b64 = xcbc_b64($cipher_name, $key, 'any data', 'more data', 'even more data');
π§ xcbc_b64u
joins all arguments into one string, returns the XCBC MAC as a Base64 URL-safe string (see RFC 4648 section 5, iykyk). the u is for URL-safe, not for "u" as in "you're welcome" π
my $xcbc_b64url = xcbc_b64u($cipher_name, $key, 'data buffer');
#or
my $xcbc_b64url = xcbc_b64u($cipher_name, $key, 'any data', 'more data', 'even more data');
π METHODS π
unless noted otherwise, just assume $d is an existing MAC object created via new, like so:
my $d = Crypt::Mac::XCBC->new($cipher_name, $key);
πΈ new
my $d = Crypt::Mac::XCBC->new($cipher_name, $key);
# $cipher_name .. [string] one of 'AES', 'Camellia', 'Twofish', 'Serpent', etc.
# any <NAME> for which there is a Crypt::Cipher::<NAME> module
# $key .......... [binary string] key of valid length for the chosen cipher (e.g. 16/24/32 bytes for AES)
so $cipher_name is a string β it can be 'AES', 'Camellia', 'Twofish', 'Serpent', etc., or literally any <NAME> that has a Crypt::Cipher::<NAME> module out there in the wild π¦. and $key is a binary string that needs to be a valid length for whichever cipher you picked (like 16/24/32 bytes for AES, bestie, don't forget).
π clone
$d->clone();
makes a copy. periodt. π
π₯ add
appends data to the message. returns the object itself, so you can chain like the main character you are π. croaks if the object has already been finalized by mac, hexmac, b64mac, or b64umac β like, it's done, leave it alone π
each argument gets converted to bytes using Perl's usual scalar stringification. defined scalars β including numbers and string-overloaded objects β are accepted. undef is treated as an empty string and may emit Perl's usual "uninitialized value" warning.
$d->add('any data');
#or
$d->add('any data', 'more data', 'even more data');
π«Ά addfile
reads the file content and appends it to the message. returns the object itself (chaining again π). croaks if the object was already finalized by mac, hexmac, b64mac, or b64umac β same rule as add, no exceptions.
$d->addfile('filename.dat');
#or
my $filehandle = ...; # existing binary-mode filehandle
$d->addfile($filehandle);
β mac
returns the binary MAC (raw bytes) and finalizes the object. once you've called mac, hexmac, b64mac, or b64umac even once, any later add, addfile, or MAC getter call will croak. that's the vibe check β finalized means finalized π«
my $result_raw = $d->mac();
π hexmac
returns the MAC as a lowercase hexadecimal string and finalizes the object. same deal: after the first mac / hexmac / b64mac / b64umac call, later add, addfile, or MAC getter calls croak. no cap.
my $result_hex = $d->hexmac();
π b64mac
returns the MAC as a Base64 string with trailing = padding, and finalizes the object. and yeah β after the first mac, hexmac, b64mac, or b64umac call, later add, addfile, or any MAC getter croaks. π€
my $result_b64 = $d->b64mac();
π§ b64umac
returns the MAC as a Base64 URL-safe string with no trailing =, and finalizes the object. same finalization rules as the others β once you call mac, hexmac, b64mac, or b64umac, every later add, addfile, or MAC getter call croaks. π
my $result_b64url = $d->b64umac();
π SEE ALSO π
CryptXβ the parent vibe π- <https://www.rfc-editor.org/rfc/rfc3566> β the source material, go read it bestie π
okay that's the whole page !! you officially know XCBC now, and honestly? ate. π β¨
πΈ cute little sign-off: this wasperl v5.42.0, dated2026-05-11, and it lives happily atCrypt::Mac::XCBC(3). go forth and MAC responsibly, bestie π«Άπ
π¦ 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