| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Digest::prvhash64; |
|
2
|
2
|
|
|
2
|
|
195798
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
66
|
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
540
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.1.2'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(prvhash64 prvhash64_64m prvhash64_hex prvhash64_64m_hex); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require XSLoader; |
|
11
|
|
|
|
|
|
|
XSLoader::load('Digest::prvhash64', $VERSION); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub prvhash64_hex { |
|
14
|
13
|
|
|
13
|
1
|
141006
|
my ($msg, $hash_len, $seed) = @_; |
|
15
|
13
|
|
50
|
|
|
28
|
$seed //= 0; |
|
16
|
|
|
|
|
|
|
|
|
17
|
13
|
|
|
|
|
43
|
my $bin = prvhash64($msg, $hash_len, $seed); |
|
18
|
13
|
|
|
|
|
36
|
my $ret = unpack('H*', $bin); |
|
19
|
|
|
|
|
|
|
|
|
20
|
13
|
|
|
|
|
36
|
return $ret; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub prvhash64_64m_hex { |
|
24
|
8
|
|
|
8
|
1
|
17
|
my ($msg, $seed) = @_; |
|
25
|
8
|
|
50
|
|
|
15
|
$seed //= 0; |
|
26
|
|
|
|
|
|
|
|
|
27
|
8
|
|
|
|
|
23
|
my $v = prvhash64_64m($msg, $seed); |
|
28
|
8
|
|
|
|
|
22
|
my $ret = sprintf('%016x', $v); |
|
29
|
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
23
|
return $ret; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
################################################################################ |
|
36
|
|
|
|
|
|
|
################################################################################ |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Digest::prvhash64 - Variable length hashing |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Digest::prvhash64; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $raw = prvhash64($str, $hash_bytes); # Raw bytes |
|
49
|
|
|
|
|
|
|
my $hex = prvhash64_hex($str, $hash_bytes); # Hex string |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# 64bit "minimal" variant |
|
52
|
|
|
|
|
|
|
my $num = prvhash64_64m($str); # 64bit unsigned integer |
|
53
|
|
|
|
|
|
|
my $hex2 = prvhash64_64m_hex($str); # 64bit hex string |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Digest::prvhash64 is a I hashing algorithm. It is NOT suitable for |
|
58
|
|
|
|
|
|
|
cryptographic purposes (password storage, signatures, etc.). |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
All functions accept data as a byte string. For deterministic results, callers |
|
63
|
|
|
|
|
|
|
should ensure text is encoded to bytes. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 B |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Compute the hash of C<$str> and return the digest as raw bytes. |
|
68
|
|
|
|
|
|
|
The digest may contain NULs and other non-printable bytes. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 B |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Like C, but returns the digest encoded as a lowercase hexadecimal |
|
73
|
|
|
|
|
|
|
string. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 B |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Compute the "minimal" 64bit hash of C<$str> and return a 64bit unsigned integer. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 B |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Compute the "minimal" 64bit hash of C<$str> and return a lowercase hexadecimal |
|
82
|
|
|
|
|
|
|
string. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 ENCODING AND PORTABILITY |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This hash operates on bytes. If you pass Perl characters (wide/unicode strings) |
|
87
|
|
|
|
|
|
|
the result may vary across platforms and Perl builds. For reproducible results, |
|
88
|
|
|
|
|
|
|
encode strings to a byte representation explicitly, for example: |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
use Encode qw(encode); |
|
91
|
|
|
|
|
|
|
my $hex = prvhash64_hex( encode('UTF-8', $text) ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Digest(3), Encode, Digest::MD5, Digest::SHA |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Scott Baker - https://www.perturb.org/ |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |