File Coverage

blib/lib/Digest/HMAC_MD6.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Digest::HMAC_MD6;
2              
3 2     2   51220 use warnings;
  2         4  
  2         62  
4 2     2   9 use strict;
  2         3  
  2         72  
5              
6 2     2   2295 use Digest::MD6 qw( md6 md6_hex md6_base64 );
  0            
  0            
7              
8             use base qw( Digest::HMAC Exporter );
9              
10             our @EXPORT_OK = qw( hmac_md6 hmac_md6_hex hmac_md6_base64 );
11              
12             =head1 NAME
13              
14             Digest::HMAC_MD6 - MD6 Keyed-Hashing for Message Authentication
15              
16             =head1 VERSION
17              
18             This document describes Digest::HMAC_MD6 version 0.01
19              
20             =cut
21              
22             our $VERSION = '0.01';
23              
24             =head1 SYNOPSIS
25              
26             use Digest::HMAC_MD6 qw(hmac_md6 hmac_md6_hex);
27             $digest = hmac_md6($data, $key);
28             print hmac_md6_hex($data, $key);
29              
30             # OO style
31             use Digest::HMAC_MD6;
32             $hmac = Digest::HMAC_MD6->new($key);
33              
34             $hmac->add($data);
35             $hmac->addfile(*FILE);
36              
37             $digest = $hmac->digest;
38             $digest = $hmac->hexdigest;
39             $digest = $hmac->b64digest;
40            
41             =head1 DESCRIPTION
42              
43             This module provides HMAC-MD6 hashing.
44              
45             =head1 INTERFACE
46              
47             =head2 C<< new >>
48              
49             Create a new C. The arguments are
50              
51             =over
52              
53             =item C<$key>
54              
55             The key to hash with.
56              
57             =item C<$block_size>
58              
59             The block size to use.
60              
61             =item C<$hash_bits>
62              
63             The number of bits of hash to compute.
64              
65             =back
66              
67             The C<$block_size> and C<$hash_bits> arguments may be omitted in which
68             case they default to 64 and 256 respectively.
69              
70             =cut
71              
72             sub new {
73             my ( $class, $key, $block_size, $hash_bits ) = @_;
74              
75             $block_size ||= 64;
76              
77             $key = Digest::MD6->new( $hash_bits )->add( $key )->digest
78             if length( $key ) > $block_size;
79              
80             my $self = bless {}, $class;
81             $self->{k_ipad} = $key ^ ( chr( 0x36 ) x $block_size );
82             $self->{k_opad} = $key ^ ( chr( 0x5c ) x $block_size );
83             $self->{hasher}
84             = Digest::MD6->new( $hash_bits )->add( $self->{k_ipad} );
85             return $self;
86             }
87              
88             ### Functional interface
89              
90             =head2 C
91              
92             Compute a MD6 HMAC hash and return its binary representation. The arguments are
93              
94             =over
95              
96             =item C<$data>
97              
98             The data to hash.
99              
100             =item C<$key>
101              
102             The key to hash with.
103              
104             =item C<$block_size>
105              
106             The block size to use.
107              
108             =item C<$hash_bits>
109              
110             The number of bits of hash to compute.
111              
112             =back
113              
114             The C<$block_size> and C<$hash_bits> arguments may be omitted in which
115             case they default to 64 and 256 respectively.
116              
117             =cut
118              
119             sub hmac_md6 {
120             my $data = shift;
121             __PACKAGE__->new( @_ )->add( $data )->digest;
122             }
123              
124             =head2 C
125              
126             Like L but return the hex representation of the key.
127              
128             =cut
129              
130             sub hmac_md6_hex {
131             my $data = shift;
132             __PACKAGE__->new( @_ )->add( $data )->hexdigest;
133             }
134              
135             =head2 C
136              
137             Like L but return the base 64 representation of the key.
138              
139             =cut
140              
141             sub hmac_md6_base64 {
142             my $data = shift;
143             __PACKAGE__->new( @_ )->add( $data )->b64digest;
144             }
145              
146             1;
147             __END__