File Coverage

blib/lib/Web3/Tiny/Keccak256.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1             package Web3::Tiny::Keccak256;
2              
3 6     6   153980 use strict;
  6         10  
  6         209  
4 6     6   32 use warnings;
  6         10  
  6         353  
5 6     6   30 use Exporter 'import';
  6         8  
  6         158  
6 6     6   2435 use Crypt::Digest::Keccak256 ();
  6         15054  
  6         649  
7              
8             our $VERSION = '0.01';
9             our @EXPORT_OK = qw(keccak256 keccak256_hex);
10              
11             # keccak256($bytes) -> 32 raw bytes
12             #
13             # Crypt::Digest::Keccak256 (part of CryptX) implements the original Keccak
14             # padding/domain separation (0x01), which is what Ethereum uses for function
15             # selectors, address derivation, and hashing in general -- NOT NIST SHA3-256
16             # (which uses a 0x06 domain separator and would give different digests).
17             sub keccak256 {
18 52     52 0 12833 my ($msg) = @_;
19 52 100       130 $msg = '' unless defined $msg;
20 52         142 return Crypt::Digest::Keccak256::keccak256($msg);
21             }
22              
23             sub keccak256_hex {
24 20     20 0 266605 my ($msg) = @_;
25 20         35 return unpack('H*', keccak256($msg));
26             }
27              
28             1;
29              
30             __END__