manpagez: man pages & more
man Crypt::Mac::Poly1305(3)
Home | html | info | man
Crypt::Mac::Poly1305(3)                    User Contributed Perl Documentation



NAME

       Crypt::Mac::Poly1305 - Message authentication code Poly1305 (RFC 7539)


SYNOPSIS

          ### 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

       Provides an interface to the Poly1305 message authentication code (MAC)
       algorithm.


EXPORT

       Nothing is exported by default.

       You can export selected functions:

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

       Or all of them at once:

         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.

       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.

        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.

        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).

        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

   clone
        $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

       o   CryptX(3)

       o   <https://www.rfc-editor.org/rfc/rfc7539>

perl v5.34.3                      2026-05-11           Crypt::Mac::Poly1305(3)

cryptx 0.89.0 - Generated Tue May 12 07:16:53 CDT 2026
© manpagez.com 2000-2026
Individual documents may contain additional copyright information.