Crypt::Mac::OMAC(3)
okay bestie, welcome to the manual for Crypt::Mac::OMAC(3) β aka Crypt::Mac::OMAC, the Message authentication code OMAC module, brought to you by the User Contributed Perl Documentation crew. itβs giving crypto-but-make-it-understandable, and weβre getting into every single method, argument, caveat, and example. no cap. π
β¨
β¨ NAME β¨
Crypt::Mac::OMAC β Message authentication code OMAC. literally what it says on the tin, bestie. π«Ά
πΈ SYNOPSIS πΈ
### Functional interface:
use Crypt::Mac::OMAC qw( omac omac_hex omac_b64 omac_b64u );
# calculate MAC from string/buffer
my $omac_raw = omac($cipher_name, $key, 'data buffer');
my $omac_hex = omac_hex($cipher_name, $key, 'data buffer');
my $omac_b64 = omac_b64($cipher_name, $key, 'data buffer');
my $omac_b64u = omac_b64u($cipher_name, $key, 'data buffer');
### OO interface:
use Crypt::Mac::OMAC;
my $d = Crypt::Mac::OMAC->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::OMAC->new($cipher_name, $key)->add('any data')->b64umac;
# or MAC a file instead
my $file_result_raw = Crypt::Mac::OMAC->new($cipher_name, $key)->addfile('filename.dat')->mac;
π¦ DESCRIPTION π¦
Provides an interface to the OMAC message authentication code (MAC) algorithm. thatβs the whole vibe: itβs a MAC, itβs OMAC, and this module is your interface to it. π₯
π EXPORT π
Nothing is exported by default. nothing, bestie β you gotta ask for it.
You can export selected functions:
use Crypt::Mac::OMAC qw( omac omac_hex omac_b64 omac_b64u );
Or all of them at once:
use Crypt::Mac::OMAC ':all';
π FUNCTIONS π
π omac π
Joins all arguments into a single string and returns its OMAC message authentication code encoded as a binary string. yes bestie, raw bytes energy. π§
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 omac_hex, omac_b64, and omac_b64u. no surprise lore, just Perl being Perl. π
my $omac_raw = omac($cipher_name, $key, 'data buffer');
#or
my $omac_raw = omac($cipher_name, $key, 'any data', 'more data', 'even more data');
β omac_hex β
Joins all arguments into a single string and returns its OMAC message authentication code encoded as a hexadecimal string. hex girl summer, but make it authentication. π
my $omac_hex = omac_hex($cipher_name, $key, 'data buffer');
#or
my $omac_hex = omac_hex($cipher_name, $key, 'any data', 'more data', 'even more data');
π omac_b64 π
Joins all arguments into a single string and returns its OMAC message authentication code encoded as a Base64 string. classic Base64, always invited to the group chat. π
my $omac_b64 = omac_b64($cipher_name, $key, 'data buffer');
#or
my $omac_b64 = omac_b64($cipher_name, $key, 'any data', 'more data', 'even more data');
π omac_b64u π
Joins all arguments into a single string and returns its OMAC message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5). URL-safe means it behaves in URLs, iykyk. β¨
my $omac_b64url = omac_b64u($cipher_name, $key, 'data buffer');
#or
my $omac_b64url = omac_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::OMAC->new($cipher_name, $key);
π new π
my $d = Crypt::Mac::OMAC->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 like 'AES', 'Camellia', 'Twofish', 'Serpent', etc. β or literally any <NAME> that has a Crypt::Cipher::<NAME> module. $key is a binary string key of valid length for the cipher you picked (think 16/24/32 bytes for AES). π
π¦ clone π¦
the call looks like this:
$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.
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.
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 π
xoxo, your local Unix bestie π β this page is from perl v5.42.0, dated 2026-05-11, and itβs the Crypt::Mac::OMAC(3) manual. slay, stay secure, and donβt forget to finalize before you try to add more. 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