File Coverage

blib/lib/Crypt/Mac/PMAC.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Crypt::Mac::PMAC;
2              
3             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4              
5 3     3   192185 use strict;
  3         5  
  3         98  
6 3     3   22 use warnings;
  3         5  
  3         224  
7             our $VERSION = '0.089';
8              
9 3     3   17 use base qw(Crypt::Mac Exporter);
  3         23  
  3         1284  
10             our %EXPORT_TAGS = ( all => [qw( pmac pmac_hex pmac_b64 pmac_b64u )] );
11             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
12             our @EXPORT = qw();
13              
14             1;
15              
16             =pod
17              
18             =head1 NAME
19              
20             Crypt::Mac::PMAC - Message authentication code PMAC
21              
22             =head1 SYNOPSIS
23              
24             ### Functional interface:
25             use Crypt::Mac::PMAC qw( pmac pmac_hex pmac_b64 pmac_b64u );
26              
27             # calculate MAC from string/buffer
28             my $pmac_raw = pmac($cipher_name, $key, 'data buffer');
29             my $pmac_hex = pmac_hex($cipher_name, $key, 'data buffer');
30             my $pmac_b64 = pmac_b64($cipher_name, $key, 'data buffer');
31             my $pmac_b64u = pmac_b64u($cipher_name, $key, 'data buffer');
32              
33             ### OO interface:
34             use Crypt::Mac::PMAC;
35              
36             my $d = Crypt::Mac::PMAC->new($cipher_name, $key);
37             $d->add('any data');
38             my $result_hex = $d->hexmac; # finalizes the object
39              
40             # for another output encoding use a fresh object (or clone before finalizing)
41             my $result_b64u = Crypt::Mac::PMAC->new($cipher_name, $key)->add('any data')->b64umac;
42              
43             # or MAC a file instead
44             my $file_result_raw = Crypt::Mac::PMAC->new($cipher_name, $key)->addfile('filename.dat')->mac;
45              
46             =head1 DESCRIPTION
47              
48             Provides an interface to the PMAC message authentication code (MAC) algorithm.
49              
50             =head1 EXPORT
51              
52             Nothing is exported by default.
53              
54             You can export selected functions:
55              
56             use Crypt::Mac::PMAC qw( pmac pmac_hex pmac_b64 pmac_b64u );
57              
58             Or all of them at once:
59              
60             use Crypt::Mac::PMAC ':all';
61              
62             =head1 FUNCTIONS
63              
64             =head2 pmac
65              
66             Joins all arguments into a single string and returns its PMAC message authentication code encoded as a binary string.
67              
68             Data arguments for the functional helpers are converted to byte strings using
69             Perl's usual scalar stringification. Defined scalars, including numbers and
70             string-overloaded objects, are accepted. C is treated as an empty
71             string and may emit Perl's usual "uninitialized value" warning. The same
72             rules apply to C, C, and
73             C.
74              
75             my $pmac_raw = pmac($cipher_name, $key, 'data buffer');
76             #or
77             my $pmac_raw = pmac($cipher_name, $key, 'any data', 'more data', 'even more data');
78              
79             =head2 pmac_hex
80              
81             Joins all arguments into a single string and returns its PMAC message authentication code encoded as a hexadecimal string.
82              
83             my $pmac_hex = pmac_hex($cipher_name, $key, 'data buffer');
84             #or
85             my $pmac_hex = pmac_hex($cipher_name, $key, 'any data', 'more data', 'even more data');
86              
87             =head2 pmac_b64
88              
89             Joins all arguments into a single string and returns its PMAC message authentication code encoded as a Base64 string.
90              
91             my $pmac_b64 = pmac_b64($cipher_name, $key, 'data buffer');
92             #or
93             my $pmac_b64 = pmac_b64($cipher_name, $key, 'any data', 'more data', 'even more data');
94              
95             =head2 pmac_b64u
96              
97             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).
98              
99             my $pmac_b64url = pmac_b64u($cipher_name, $key, 'data buffer');
100             #or
101             my $pmac_b64url = pmac_b64u($cipher_name, $key, 'any data', 'more data', 'even more data');
102              
103             =head1 METHODS
104              
105             Unless noted otherwise, assume C<$d> is an existing MAC object created via
106             C, for example:
107              
108             my $d = Crypt::Mac::PMAC->new($cipher_name, $key);
109              
110             =head2 new
111              
112             my $d = Crypt::Mac::PMAC->new($cipher_name, $key);
113              
114             # $cipher_name .. [string] one of 'AES', 'Camellia', 'Twofish', 'Serpent', etc.
115             # any for which there is a Crypt::Cipher:: module
116             # $key .......... [binary string] key of valid length for the chosen cipher (e.g. 16/24/32 bytes for AES)
117              
118             =head2 clone
119              
120             $d->clone();
121              
122             =head2 add
123              
124             Appends data to the message. Returns the object itself (for chaining).
125             Croaks if the object has already been finalized by C, C,
126             C, or C.
127              
128             Each argument is converted to bytes using Perl's usual scalar stringification.
129             Defined scalars, including numbers and string-overloaded objects, are
130             accepted. C is treated as an empty string and may emit Perl's usual
131             "uninitialized value" warning.
132              
133             $d->add('any data');
134             #or
135             $d->add('any data', 'more data', 'even more data');
136              
137             =head2 addfile
138              
139             Reads the file content and appends it to the message. Returns the object itself
140             (for chaining). Croaks if the object has already been finalized by C,
141             C, C, or C.
142              
143             $d->addfile('filename.dat');
144             #or
145             my $filehandle = ...; # existing binary-mode filehandle
146             $d->addfile($filehandle);
147              
148             =head2 mac
149              
150             Returns the binary MAC (raw bytes) and finalizes the object. After the first
151             call to C, C, C, or C, later calls to C,
152             C, or any MAC getter croak.
153              
154             my $result_raw = $d->mac();
155              
156             =head2 hexmac
157              
158             Returns the MAC encoded as a lowercase hexadecimal string and finalizes the
159             object. After the first call to C, C, C, or C,
160             later calls to C, C, or any MAC getter croak.
161              
162             my $result_hex = $d->hexmac();
163              
164             =head2 b64mac
165              
166             Returns the MAC encoded as a Base64 string with trailing C<=> padding and
167             finalizes the object. After the first call to C, C, C, or
168             C, later calls to C, C, or any MAC getter croak.
169              
170             my $result_b64 = $d->b64mac();
171              
172             =head2 b64umac
173              
174             Returns the MAC encoded as a Base64 URL-safe string (no trailing C<=>) and
175             finalizes the object. After the first call to C, C, C, or
176             C, later calls to C, C, or any MAC getter croak.
177              
178             my $result_b64url = $d->b64umac();
179              
180             =head1 SEE ALSO
181              
182             =over
183              
184             =item * L
185              
186             =item * L
187              
188             =back
189              
190             =cut