ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Util.pm
Revision: 1.10
Committed: Fri Nov 16 12:14:59 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.9: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 $pw = shift;
42
43 for (0..9) {
44 $pw = "deliantrakdf$_$pw" x 32;
45 $pw = dgst $pw;
46 }
47
48 $pw
49 }
50
51 =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2
52
53 Authenticates a (hashed) password using the given nonce.
54
55 =cut
56
57 sub auth_pw($$$) {
58 my ($hash, $nonce1, $nonce2) = @_;
59
60 # simple HMAC application
61 dgst $nonce1 . dgst $nonce2 . $hash
62 }
63
64 =back
65
66 =head1 AUTHOR
67
68 Marc Lehmann <schmorp@schmorp.de>
69 http://home.schmorp.de/
70
71 =cut
72
73 1