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::SHA; |
22 |
|
23 |
# helepr function to wrok around bugs in Digest::SHA |
24 |
sub dgst { |
25 |
my $s = shift; |
26 |
utf8::downgrade $s; |
27 |
Digest::SHA::sha512 $s |
28 |
} |
29 |
|
30 |
=item Deliantra::Util::hash_pw $cleartext |
31 |
|
32 |
Hashes a cleartext password into the binary password used in the protocol. |
33 |
|
34 |
=cut |
35 |
|
36 |
sub hash_pw($) { |
37 |
# we primarily want to protect the password itself, and |
38 |
# secondarily want to protect us against pre-image attacks. |
39 |
# we don't want to overdo it, to keep implementation simple. |
40 |
|
41 |
my $pass = shift; |
42 |
utf8::encode $pass; |
43 |
$pass = substr $pass, 0, 512 / 8; |
44 |
|
45 |
my $hash; # first iteration is just dgst $pass |
46 |
|
47 |
$hash = dgst $hash ^ $pass |
48 |
for 0..499; |
49 |
|
50 |
$hash |
51 |
} |
52 |
|
53 |
=item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2 |
54 |
|
55 |
Authenticates a (hashed) password using the given nonce. |
56 |
|
57 |
=cut |
58 |
|
59 |
sub auth_pw($$$) { |
60 |
my ($hash, $nonce1, $nonce2) = @_; |
61 |
|
62 |
# simple HMAC application |
63 |
dgst $nonce1 . dgst $nonce2 . $hash |
64 |
} |
65 |
|
66 |
=back |
67 |
|
68 |
=head1 AUTHOR |
69 |
|
70 |
Marc Lehmann <schmorp@schmorp.de> |
71 |
http://home.schmorp.de/ |
72 |
|
73 |
=cut |
74 |
|
75 |
1 |