Skip Menu |

This queue is for tickets about the Digest-HMAC CPAN distribution.

Report information
The Basics
Id: 84467
Status: open
Priority: 0/
Queue: Digest-HMAC

People
Owner: Nobody in particular
Requestors: oneingray [...] gmail.com
Cc: CARNIL [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



CC: Ivan Shmakov <oneingray [...] gmail.com>
Subject: Digest::HMAC->new () is "incompatible" with Digest::SHA (512), etc.
Date: Sat, 06 Apr 2013 11:57:37 +0000
To: bug-Digest-HMAC [...] rt.cpan.org
From: Ivan Shmakov <oneingray [...] gmail.com>
[Forwarding Debian Bug#700617.] 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, 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); [1] https://bugzilla.mozilla.org/show_bug.cgi?id=313196 -- FSF associate member #7257 http://hfday.org/
--- 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);
From: rwfranks [...] acm.org
On Sat Apr 06 07:57:59 2013, oneingray@gmail.com wrote: Show quoted text
> [Forwarding Debian Bug#700617.] > > 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, or > Digest->new () itself. >
The documentation would appear to suggest so, and probably is correct for the general case. In the particular case of interest here, Digest::SHA, $instance->new() is indistinguishable from $instance->reset() which is effectively a NO-OP as invoked in Digest::HMAC. This is documented behaviour. Note that when (ab)used in this way, sha->new() does *NOT* create a new object when invoked inside Digest::HMAC. $sha512 = new Digest::SHA(512); $hmac_sha512 = new Digest::HMAC($key, $sha512, 128); Show quoted text