Package: libdigest-hmac-perl Version: 1.03+dfsg-1 Tags: patch It isn't currently possible to use the Digest::HMAC module's OO interface along with the Digest subclasses whose constructors require an argument, such as the Digest::SHA class (as provided by the libdigest-sha-perl package) or Digest->new () itself.
The patch MIME'd provides a way for the caller to pass a prepared Digest instance, which is then clone ()'d and reset () to produce a “clean” Digest object. Examples: require Digest::HMAC; require Digest::SHA; my $hmac = Digest::HMAC->new ($key, Digest::SHA->new (256)); ## check, e. g., [1] my $hmac = Digest::HMAC->new ($key, Digest::SHA->new (384), 128); my $hmac = Digest::HMAC->new ($key, Digest::SHA->new (512), 128); FWIW, I've tested HMAC-SHA512 by making DNS updates to BIND9-hosted zones with Net::DNS. [1] https://bugzilla.mozilla.org/show_bug.cgi?id=313196 -- FSF associate member #7257
--- HMAC.pm 2011-07-25 16:51:15.000000000 +0000 +++ HMAC.pm 2013-02-15 08:55:09.000000000 +0000 @@ -9,12 +9,16 @@ { my($class, $key, $hasher, $block_size) = @_; $block_size ||= 64; - $key = $hasher->new->add($key)->digest if length($key) > $block_size; + my $d + = (ref($hasher) eq "" + ? $hasher->new() + : $hasher->clone()->reset()); + $key = $d->add($key)->digest if length($key) > $block_size; my $self = bless {}, $class; $self->{k_ipad} = $key ^ (chr(0x36) x $block_size); $self->{k_opad} = $key ^ (chr(0x5c) x $block_size); - $self->{hasher} = $hasher->new->add($self->{k_ipad}); + $self->{hasher} = $d->add($self->{k_ipad}); $self; } @@ -79,6 +83,7 @@ # OO style use Digest::HMAC; $hmac = Digest::HMAC->new($key, "Digest::MyHash"); + $hmac = Digest::HMAC->new($key, Digest::MyHash->new()); $hmac->add($data); $hmac->addfile(*FILE);