Skip Menu |

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

Report information
The Basics
Id: 52551
Status: resolved
Priority: 0/
Queue: Digest-Skein

People
Owner: RADEK [...] cpan.org
Requestors: bugfood-c [...] fatooh.org
Cc:
AdminCc:

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



Subject: $ctx->digest doesn't reset the digest state
Date: Mon, 07 Dec 2009 22:43:32 -0800
To: bug-Digest-Skein [...] rt.cpan.org
From: Corey Hickey <bugfood-c [...] fatooh.org>
Hello, Thanks for providing Digest::Skein. It seems to work nicely, except for a bug I think I found. When I call the digest() method, I would expect the digest state to be reset as written in the Digest documentation: ------------------------------------------------------------------------ Note that the "digest" operation is effectively a destructive, read-once operation. Once it has been performed, the $ctx object is automatically reset" and can be used to calculate another digest value. Call $ctx->clone->digest if you want to calculate the digest without resetting the digest state. ------------------------------------------------------------------------ Digest::SHA1 and Digest::MD5 work that way, at least. With Digest::Skein, however, I get a different value the second time if I try to hash the same data twice without manually calling the reset() method. I've attached a small test script that illustrates the problem; it emits the following text: ------------------------------------------------------------------------ Show quoted text
--------- testing Skein 256 --------- initial hash of data with new context: 8a62e0aa350e48167888bce63cbe19dbe6f7050a741b9aea9a71fcadae3135bd second hash of same data: 015b19fef178954ccb1b0475010b5b0faf48a4353d57ec6d8e4aeced698af631 hash of data after reset: 8a62e0aa350e48167888bce63cbe19dbe6f7050a741b9aea9a71fcadae3135bd
--------- testing SHA1 --------- initial hash of data with new context: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 second hash of same data: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 hash of data after reset: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 ------------------------------------------------------------------------ Notice how the second Skein hash is different from the other two, but all three SHA1 hashes are the same. Is this a bug or am I doing something dumb? In case they're relevant, here are a few system details: Debian Sid Linux 2.6.31.4 Perl 5.10.1 GCC 4.3.4 all 64-bit Thanks again, Corey
#!/usr/bin/perl use strict; use warnings; use bytes; use Digest::Skein; use Digest::SHA1; my $data = 'foo'; print "--------- testing Skein 256 ---------\n"; my $ctx = Digest::Skein->new(256); test_hash($ctx, $data); print "\n--------- testing SHA1 ---------\n"; $ctx = Digest::SHA1->new(); test_hash($ctx, $data); sub test_hash { my $ctx = shift; my $data = shift; print " initial hash of data with new context:\n"; print_hash($ctx, $data); print " second hash of same data:\n"; print_hash($ctx, $data); print " hash of data after reset:\n"; $ctx->reset; print_hash($ctx, $data); } sub print_hash { my $ctx = shift; my $data = shift; $ctx->add($data); print $ctx->hexdigest, "\n"; }
Thanks for the report, fixed in v0.05.