ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Util.pm
Revision: 1.14
Committed: Thu Nov 22 14:40:57 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-2_01, rel-2_0, HEAD
Changes since 1.13: +3 -1 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 root 1.14 my $pass = shift;
42     utf8::encode $pass;
43     $pass = substr $pass, 0, 512 / 8;
44 root 1.1
45 root 1.11 my $hash; # first iteration is just dgst $pass
46 root 1.1
47 root 1.11 $hash = dgst $hash ^ $pass
48 root 1.13 for 0..499;
49 root 1.11
50     $hash
51 root 1.1 }
52    
53 root 1.2 =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2
54    
55     Authenticates a (hashed) password using the given nonce.
56    
57     =cut
58    
59 root 1.6 sub auth_pw($$$) {
60 root 1.4 my ($hash, $nonce1, $nonce2) = @_;
61 root 1.2
62     # simple HMAC application
63 root 1.8 dgst $nonce1 . dgst $nonce2 . $hash
64 root 1.2 }
65    
66 root 1.1 =back
67    
68     =head1 AUTHOR
69    
70     Marc Lehmann <schmorp@schmorp.de>
71     http://home.schmorp.de/
72    
73     =cut
74    
75     1