ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Util.pm
Revision: 1.6
Committed: Fri Nov 16 07:01:32 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.5: +1 -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.1 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 root 1.5 # we don't want to overdo it, to keep implementation simple.
33 root 1.1
34     my $pw = shift;
35    
36 root 1.5 for (0..10) {
37     $pw = "deliantrakdf$pw" x 32;
38 root 1.1 $pw = Digest::SHA3::sha3_512 $pw;
39     }
40    
41     $pw
42     }
43    
44 root 1.2 =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2
45    
46     Authenticates a (hashed) password using the given nonce.
47    
48     =cut
49    
50 root 1.6 sub auth_pw($$$) {
51 root 1.4 my ($hash, $nonce1, $nonce2) = @_;
52 root 1.2
53     # simple HMAC application
54     Digest::SHA3::sha3_512 $nonce1 . Digest::SHA3::sha3_512 $nonce2 . $hash
55     }
56    
57 root 1.1 =back
58    
59     =head1 AUTHOR
60    
61     Marc Lehmann <schmorp@schmorp.de>
62     http://home.schmorp.de/
63    
64     =cut
65    
66     1