line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Mac::HMAC; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
176446
|
use strict; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
100
|
|
6
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
181
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.080'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
21
|
use base qw(Crypt::Mac Exporter); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1254
|
|
10
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [qw( hmac hmac_hex hmac_b64 hmac_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::HMAC - Message authentication code HMAC |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
### Functional interface: |
25
|
|
|
|
|
|
|
use Crypt::Mac::HMAC qw( hmac hmac_hex ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# calculate MAC from string/buffer |
28
|
|
|
|
|
|
|
$hmac_raw = hmac('SHA256', $key, 'data buffer'); |
29
|
|
|
|
|
|
|
$hmac_hex = hmac_hex('SHA256', $key, 'data buffer'); |
30
|
|
|
|
|
|
|
$hmac_b64 = hmac_b64('SHA256', $key, 'data buffer'); |
31
|
|
|
|
|
|
|
$hmac_b64u = hmac_b64u('SHA256', $key, 'data buffer'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
### OO interface: |
34
|
|
|
|
|
|
|
use Crypt::Mac::HMAC; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$d = Crypt::Mac::HMAC->new('SHA256', $key); |
37
|
|
|
|
|
|
|
$d->add('any data'); |
38
|
|
|
|
|
|
|
$d->addfile('filename.dat'); |
39
|
|
|
|
|
|
|
$d->addfile(*FILEHANDLE); |
40
|
|
|
|
|
|
|
$result_raw = $d->mac; # raw bytes |
41
|
|
|
|
|
|
|
$result_hex = $d->hexmac; # hexadecimal form |
42
|
|
|
|
|
|
|
$result_b64 = $d->b64mac; # Base64 form |
43
|
|
|
|
|
|
|
$result_b64u = $d->b64umac; # Base64 URL Safe form |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Provides an interface to the HMAC message authentication code (MAC) algorithm. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 EXPORT |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Nothing is exported by default. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
You can export selected functions: |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Crypt::Mac::HMAC qw(hmac hmac_hex ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Or all of them at once: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use Crypt::Mac::HMAC ':all'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 FUNCTIONS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 hmac |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a binary string. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$hmac_raw = hmac($hash_name, $key, 'data buffer'); |
68
|
|
|
|
|
|
|
#or |
69
|
|
|
|
|
|
|
$hmac_raw = hmac($hash_name, $key, 'any data', 'more data', 'even more data'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# $hash_name ... any for which there exists Crypt::Digest:: |
72
|
|
|
|
|
|
|
# $key ......... the key (octets/bytes) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 hmac_hex |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a hexadecimal string. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$hmac_hex = hmac_hex($hash_name, $key, 'data buffer'); |
79
|
|
|
|
|
|
|
#or |
80
|
|
|
|
|
|
|
$hmac_hex = hmac_hex($hash_name, $key, 'any data', 'more data', 'even more data'); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# $hash_name ... any for which there exists Crypt::Digest:: |
83
|
|
|
|
|
|
|
# $key ......... the key (octets/bytes, not hex!) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 hmac_b64 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a Base64 string. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$hmac_b64 = hmac_b64($hash_name, $key, 'data buffer'); |
90
|
|
|
|
|
|
|
#or |
91
|
|
|
|
|
|
|
$hmac_b64 = hmac_b64($hash_name, $key, 'any data', 'more data', 'even more data'); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# $hash_name ... any for which there exists Crypt::Digest:: |
94
|
|
|
|
|
|
|
# $key ......... the key (octets/bytes, not Base64!) |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 hmac_b64u |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a Base64 URL Safe string (see RFC 4648 section 5). |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$hmac_b64url = hmac_b64u($hash_name, $key, 'data buffer'); |
101
|
|
|
|
|
|
|
#or |
102
|
|
|
|
|
|
|
$hmac_b64url = hmac_b64u($hash_name, $key, 'any data', 'more data', 'even more data'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# $hash_name ... any for which there exists Crypt::Digest:: |
105
|
|
|
|
|
|
|
# $key ......... the key (octets/bytes, not Base64url!) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 METHODS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 new |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$d = Crypt::Mac::HMAC->new($hash_name, $key); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# $hash_name ... any for which there exists Crypt::Digest:: |
114
|
|
|
|
|
|
|
# $key ......... the key (octets/bytes) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 clone |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$d->clone(); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 reset |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$d->reset(); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 add |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$d->add('any data'); |
127
|
|
|
|
|
|
|
#or |
128
|
|
|
|
|
|
|
$d->add('any data', 'more data', 'even more data'); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 addfile |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$d->addfile('filename.dat'); |
133
|
|
|
|
|
|
|
#or |
134
|
|
|
|
|
|
|
$d->addfile(*FILEHANDLE); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 mac |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$result_raw = $d->mac(); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 hexmac |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$result_hex = $d->hexmac(); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 b64mac |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
$result_b64 = $d->b64mac(); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 b64umac |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$result_b64url = $d->b64umac(); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=over |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * L |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |