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

File Contents

# User Rev Content
1 root 1.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 root 1.4 use common::sense;
20    
21 root 1.7 use Digest::SHA;
22 root 1.1
23 root 1.8 # 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 root 1.1 =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 root 1.5 # we don't want to overdo it, to keep implementation simple.
40 root 1.1
41     my $pw = shift;
42    
43 root 1.5 for (0..10) {
44     $pw = "deliantrakdf$pw" x 32;
45 root 1.8 $pw = dgst $pw;
46 root 1.1 }
47    
48     $pw
49     }
50    
51 root 1.2 =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2
52    
53     Authenticates a (hashed) password using the given nonce.
54    
55     =cut
56    
57 root 1.6 sub auth_pw($$$) {
58 root 1.4 my ($hash, $nonce1, $nonce2) = @_;
59 root 1.2
60     # simple HMAC application
61 root 1.8 dgst $nonce1 . dgst $nonce2 . $hash
62 root 1.2 }
63    
64 root 1.1 =back
65    
66     =head1 AUTHOR
67    
68     Marc Lehmann <schmorp@schmorp.de>
69     http://home.schmorp.de/
70    
71     =cut
72    
73     1