1 |
=head1 NAME |
2 |
|
3 |
Deliantra::Util - utility cruft |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
use Deliantra::Util; |
8 |
|
9 |
=head1 DESCRIPTION |
10 |
|
11 |
Various utilities that come in handy when dealing with Deliantra. |
12 |
|
13 |
=over 4 |
14 |
|
15 |
=cut |
16 |
|
17 |
package Deliantra::Util; |
18 |
|
19 |
use common::sense; |
20 |
|
21 |
use Digest::SHA3; |
22 |
|
23 |
=item Deliantra::Util::hash_pw $cleartext |
24 |
|
25 |
Hashes a cleartext password into the binary password used in the protocol. |
26 |
|
27 |
=cut |
28 |
|
29 |
sub hash_pw($) { |
30 |
# we primarily want to protect the password itself, and |
31 |
# secondarily want to protect us against pre-image attacks. |
32 |
# we don't want to overdo it, to keep implementation simple. |
33 |
|
34 |
my $pw = shift; |
35 |
|
36 |
for (0..10) { |
37 |
$pw = "deliantrakdf$pw" x 32; |
38 |
$pw = Digest::SHA3::sha3_512 $pw; |
39 |
} |
40 |
|
41 |
$pw |
42 |
} |
43 |
|
44 |
=item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2 |
45 |
|
46 |
Authenticates a (hashed) password using the given nonce. |
47 |
|
48 |
=cut |
49 |
|
50 |
sub auth_pw($$$) { |
51 |
my ($hash, $nonce1, $nonce2) = @_; |
52 |
|
53 |
# simple HMAC application |
54 |
Digest::SHA3::sha3_512 $nonce1 . Digest::SHA3::sha3_512 $nonce2 . $hash |
55 |
} |
56 |
|
57 |
=back |
58 |
|
59 |
=head1 AUTHOR |
60 |
|
61 |
Marc Lehmann <schmorp@schmorp.de> |
62 |
http://home.schmorp.de/ |
63 |
|
64 |
=cut |
65 |
|
66 |
1 |