Crypt::Mac::F9(3)

✨ NAME ✨

Okay bestie, this is the Crypt::Mac::F9(3) page πŸ’… β€” all about Crypt::Mac::F9, aka message authentication code F9. Iconic little MAC module, no cap. πŸŽ€


πŸ›  SYNOPSIS πŸ› 

Here’s the whole vibe in code, bestie β€” functional interface first, then OO:

### Functional interface:
use Crypt::Mac::F9 qw( f9 f9_hex f9_b64 f9_b64u );

# calculate MAC from string/buffer
my $f9_raw  = f9($cipher_name, $key, 'data buffer');
my $f9_hex  = f9_hex($cipher_name, $key, 'data buffer');
my $f9_b64  = f9_b64($cipher_name, $key, 'data buffer');
my $f9_b64u = f9_b64u($cipher_name, $key, 'data buffer');

### OO interface:
use Crypt::Mac::F9;

my $d = Crypt::Mac::F9->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::F9->new($cipher_name, $key)->add('any data')->b64umac;

# or MAC a file instead
my $file_result_raw = Crypt::Mac::F9->new($cipher_name, $key)->addfile('filename.dat')->mac;

🌸 DESCRIPTION 🌸

This module provides an interface to the F9 message authentication code (MAC) algorithm β€” yes, the whole point is MAC-ing your data, and it’s giving exactly that. ✨


🎁 EXPORT 🎁

Nothing is exported by default. Literally zero, bestie. 🫢

You can export selected functions, like this:

use Crypt::Mac::F9 qw( f9 f9_hex f9_b64 f9_b64u );

Or go all in and grab all of them at once:

use Crypt::Mac::F9 ':all';

🌈 FUNCTIONS 🌈

🌟 f9 🌟

Joins all arguments into a single string and returns its F9 message authentication code encoded as a binary string. Raw bytes, main character 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 f9_hex, f9_b64, and f9_b64u.

my $f9_raw = f9($cipher_name, $key, 'data buffer');
#or
my $f9_raw = f9($cipher_name, $key, 'any data', 'more data', 'even more data');

🌟 f9_hex 🌟

Joins all arguments into a single string and returns its F9 message authentication code encoded as a hexadecimal string. Hex girlies rise. 🧚

my $f9_hex = f9_hex($cipher_name, $key, 'data buffer');
#or
my $f9_hex = f9_hex($cipher_name, $key, 'any data', 'more data', 'even more data');

🌟 f9_b64 🌟

Joins all arguments into a single string and returns its F9 message authentication code encoded as a Base64 string. Cute, compact, done. πŸŽ€

my $f9_b64 = f9_b64($cipher_name, $key, 'data buffer');
#or
my $f9_b64 = f9_b64($cipher_name, $key, 'any data', 'more data', 'even more data');

🌟 f9_b64u 🌟

Joins all arguments into a single string and returns its F9 message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5). URL-safe and unbothered. πŸ¦‹

my $f9_b64url = f9_b64u($cipher_name, $key, 'data buffer');
#or
my $f9_b64url = f9_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::F9->new($cipher_name, $key);

πŸ‘‘ new πŸ‘‘

my $d = Crypt::Mac::F9->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, one of 'AES', 'Camellia', 'Twofish', 'Serpent', etc., or any <NAME> for which there’s a Crypt::Cipher::<NAME> module. $key is a binary string key of valid length for the chosen cipher (like 16/24/32 bytes for AES). Slay. πŸ”₯

πŸ‘‘ clone πŸ‘‘

$d->clone();

Clone it, bestie. That’s the method. 🫢

πŸ‘‘ 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. So like… don’t push it, bestie. 😭

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 πŸ¦‹

  • CryptX β€” that’s the one, bestie. πŸ‘‘

That’s the whole page! Source/version: perl v5.42.0, date: 2026-05-11. Byeee πŸ’–πŸ‘‘βœ¨

πŸ“¦ where this page comes from