File Coverage

blib/lib/Digest/OMAC2.pm
Criterion Covered Total %
statement 24 26 92.3
branch 3 6 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 34 39 87.1


line stmt bran cond sub pod time code
1             package Digest::OMAC2;
2              
3 15     15   13812 use base qw(Digest::OMAC::Base);
  15         27  
  15         1181  
4              
5 15     15   162 use strict;
  15         30  
  15         669  
6             #use warnings;
7 15     15   77 use Carp;
  15         26  
  15         971  
8 15     15   163 use MIME::Base64;
  15         29  
  15         5060  
9              
10             # we still call it Lu2 even though it's actually no longer squared ;-)
11              
12             sub _lu2 {
13 14     14   654 my ( $self, $blocksize, $L ) = @_;
14 14         73 $self->_shift_lu2( $L, $self->_lu2_constant($blocksize) );
15             }
16              
17             sub _shift_lu2 {
18 14     14   33 my ( $self, $L, $constant ) = @_;
19              
20             # used to do Bit::Vector's shift_left but that's broken
21 14         49 my $unpacked = unpack("B*",$L);
22 14         48 my $lsb = chop $unpacked;
23 14         64 my $Lt = pack("B*", "0" . $unpacked);
24              
25 14 100       58 if ( $lsb ) {
26 9         52 return $Lt ^ $constant;
27             } else {
28 5         22 return $Lt;
29             }
30             }
31              
32             sub _lu2_constant {
33 14     14   28 my ( $self, $blocksize ) = @_;
34              
35 14 50       56 if ( $blocksize == 16 ) { # 128
    0          
36 14         72 return ("\x80" . ("\x00" x 14) . "\x43");
37             } elsif ( $blocksize == 8 ) { # 64
38 0           return ("\x80" . ("\x00" x 6) . "\x0d");
39             } else {
40 0           die "Blocksize $blocksize is not supported by OMAC";
41             }
42             }
43              
44             1;
45             __END__
46              
47             =pod
48              
49             =head1 NAME
50              
51             Digest::OMAC2 - OMAC 2 implementation
52              
53             =head1 SYNOPSIS
54              
55             use Digest::OMAC2;
56              
57             my $d = Digest::OMAC2->new( $key, $cipher );
58              
59             =head1 DESCRIPTION
60              
61             OMAC 2 is a variant of the CMAC/OMAC 1 algorithm. The initialization routines
62             are slightly different. OMAC2 actually precedes OMAC1, so
63             L<Digest::CMAC>/L<Digest::OMAC1> is the reccomended version. Supposedly OMAC1
64             was more rigorously analyzed.