Crypt::...oly1305(3)

πŸ’– NAME πŸ’–

Crypt::Mac::Poly1305 β€” Message authentication code Poly1305 (RFC 7539)

okay bestie, this page is from the User Contributed Perl Documentation, and it's all about Crypt::Mac::Poly1305, aka the Poly1305 message authentication code from RFC 7539. iconic crypto behavior, no cap. ✨


✨ SYNOPSIS ✨

here's the whole vibe in code, fr fr:

### Functional interface:
use Crypt::Mac::Poly1305 qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u );

# calculate MAC from string/buffer
my $poly1305_raw  = poly1305($key, 'data buffer');
my $poly1305_hex  = poly1305_hex($key, 'data buffer');
my $poly1305_b64  = poly1305_b64($key, 'data buffer');
my $poly1305_b64u = poly1305_b64u($key, 'data buffer');

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

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

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

🌸 DESCRIPTION 🌸

It gives you an interface to the Poly1305 message authentication code (MAC) algorithm. that's the whole description, and it ate. πŸ’…


πŸŽ€ EXPORT πŸŽ€

Nothing is exported by default. zero exports unless you ask, bestie.

You can export selected functions:

use Crypt::Mac::Poly1305 qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u );

Or all of them at once, because why not:

use Crypt::Mac::Poly1305 ':all';

πŸ¦‹ FUNCTIONS πŸ¦‹

πŸ’… poly1305 πŸ’…

Joins all arguments into a single string and returns its Poly1305 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 poly1305_hex, poly1305_b64, and poly1305_b64u.

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

🌈 poly1305_hex 🌈

Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a hexadecimal string. hex girl summer πŸ’œ

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

🧚 poly1305_b64 🧚

Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a Base64 string. cute little encoded output, slay. πŸŽ€

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

πŸ¦‹ poly1305_b64u πŸ¦‹

Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5). URL-safe means it's ready for the group chat link, iykyk. πŸ”₯

my $poly1305_b64url = poly1305_b64u($key, 'data buffer');
#or
my $poly1305_b64url = poly1305_b64u($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::Poly1305->new($key);

πŸ’– new πŸ’–

my $d = Crypt::Mac::Poly1305->new($key);

# $key .. [binary string] exactly 32 bytes (256 bits); a fresh one-time key per message

so $key is a binary string exactly 32 bytes (256 bits), and it's a fresh one-time key per message. one-time means one time, bestie β€” do not reuse it. πŸ’€

🌸 clone 🌸

$d->clone();

clone it, keep the vibe, copy the object. 🫢

✨ 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 🌈


and that's the whole page, bestie β€” peace out from perl v5.42.0, dated 2026-05-11 πŸ’œπŸ«Άβœ¨

πŸ“¦ where this page comes from