Crypt::Mac::PMAC(3)
okay so bestie, welcome to Crypt::Mac::PMAC(3) from the User Contributed Perl Documentation π
this page is all about PMAC and itβs lowkey iconic. grab a π and letβs go, no cap.
π NAME π
Crypt::Mac::PMAC β Message authentication code PMAC. Thatβs the name, thatβs the vibe, periodt. β¨
π SYNOPSIS π
hereβs the copy-paste buffet, bestie β keep it exact, fr fr:
### Functional interface:
use Crypt::Mac::PMAC qw( pmac pmac_hex pmac_b64 pmac_b64u );
# calculate MAC from string/buffer
my $pmac_raw = pmac($cipher_name, $key, 'data buffer');
my $pmac_hex = pmac_hex($cipher_name, $key, 'data buffer');
my $pmac_b64 = pmac_b64($cipher_name, $key, 'data buffer');
my $pmac_b64u = pmac_b64u($cipher_name, $key, 'data buffer');
### OO interface:
use Crypt::Mac::PMAC;
my $d = Crypt::Mac::PMAC->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::PMAC->new($cipher_name, $key)->add('any data')->b64umac;
# or MAC a file instead
my $file_result_raw = Crypt::Mac::PMAC->new($cipher_name, $key)->addfile('filename.dat')->mac;
π¦ DESCRIPTION π¦
So the whole description is: it provides an interface to the PMAC message authentication code (MAC) algorithm. Thatβs the tea. π PMAC? A MAC? This module? Your little entry point? Obsessed.
π EXPORT π
By default? Nothing is exported. Zero. Zilch. Nada. π
You can export selected functions like this:
use Crypt::Mac::PMAC qw( pmac pmac_hex pmac_b64 pmac_b64u );
Or all of them at once, main-character style:
use Crypt::Mac::PMAC ':all';
β¨ FUNCTIONS β¨
π
pmac
Joins all arguments into a single string and returns its PMAC message authentication code encoded as a binary string. Raw bytes, bestie. π«Ά
Data arguments for the functional helpers are converted to byte strings 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. The same rules apply to pmac_hex, pmac_b64, and pmac_b64u β periodt.
my $pmac_raw = pmac($cipher_name, $key, 'data buffer');
#or
my $pmac_raw = pmac($cipher_name, $key, 'any data', 'more data', 'even more data');
πΈ pmac_hex
Joins all arguments into a single string and returns its PMAC message authentication code encoded as a hexadecimal string. Same data rules as pmac, bestie. π
my $pmac_hex = pmac_hex($cipher_name, $key, 'data buffer');
#or
my $pmac_hex = pmac_hex($cipher_name, $key, 'any data', 'more data', 'even more data');
π pmac_b64
Joins all arguments into a single string and returns its PMAC message authentication code encoded as a Base64 string. Cute little Base64 moment. β¨
my $pmac_b64 = pmac_b64($cipher_name, $key, 'data buffer');
#or
my $pmac_b64 = pmac_b64($cipher_name, $key, 'any data', 'more data', 'even more data');
π¦ pmac_b64u
Joins all arguments into a single string and returns its PMAC message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5). URL-safe, no cap. π
my $pmac_b64url = pmac_b64u($cipher_name, $key, 'data buffer');
#or
my $pmac_b64url = pmac_b64u($cipher_name, $key, 'any data', 'more data', 'even more data');
π₯ METHODS π₯
Unless noted otherwise, assume $d is an existing MAC object created via new, for example:
my $d = Crypt::Mac::PMAC->new($cipher_name, $key);
π new
This is where you birth your MAC object, bestie. Hereβs the exact signature and the little comment cheat sheet:
my $d = Crypt::Mac::PMAC->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)
πΈ clone
Clone call, thatβs it, thatβs the whole section:
$d->clone();
π«Ά add
Appends data to the message. Returns the object itself (for chaining). Croaks if the object has already been finalized by mac, hexmac, b64mac, or b64umac β so donβt try it, bestie. π
Each argument is 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 (for chaining). Croaks if the object has already been finalized by mac, hexmac, b64mac, or b64umac.
$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. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak. One shot, main character energy. π
my $result_raw = $d->mac();
β¨ hexmac
Returns the MAC encoded as a lowercase hexadecimal string and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.
my $result_hex = $d->hexmac();
π b64mac
Returns the MAC encoded as a Base64 string with trailing = padding and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.
my $result_b64 = $d->b64mac();
π b64umac
Returns the MAC encoded as a Base64 URL-safe string (no trailing =) and finalizes the object. After the first call to mac, hexmac, b64mac, or b64umac, later calls to add, addfile, or any MAC getter croak.
my $result_b64url = $d->b64umac();
π¦ SEE ALSO π¦
Check these out, bestie:
CryptX<https://en.wikipedia.org/wiki/PMAC_%28cryptography%29>β the PMAC wiki page, literal URL, iykyk π§
okay thatβs the page! this one is from perl v5.42.0, dated 2026-05-11, and itβs the Crypt::Mac::PMAC(3) manual page β mwah ππ
π¦ 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