ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/Deliantra/Util.pm
Revision: 1.4
Committed: Thu Nov 15 09:48:51 2012 UTC (11 years, 6 months ago) by root
Branch: MAIN
Changes since 1.3: +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.1 use Digest::SHA;
22     use Digest::SHA3;
23    
24     =item Deliantra::Util::hash_pw $cleartext
25    
26     Hashes a cleartext password into the binary password used in the protocol.
27    
28     =cut
29    
30     sub hash_pw($) {
31     # we primarily want to protect the password itself, and
32     # secondarily want to protect us against pre-image attacks.
33 root 1.2 # we trust nist, but not a single hash function, so we
34 root 1.1 # use both sha and sha3
35    
36     my $pw = shift;
37    
38     for (0..20) {
39     $pw = Digest::SHA3::sha3_512 $pw;
40 root 1.3 $pw = "deliantrakdf$pw" x 32;
41 root 1.1 $pw = Digest::SHA::sha512 $pw;
42     }
43    
44     $pw
45     }
46    
47 root 1.2 =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2
48    
49     Authenticates a (hashed) password using the given nonce.
50    
51     =cut
52    
53     sub auth_pw($$) {
54 root 1.4 my ($hash, $nonce1, $nonce2) = @_;
55 root 1.2
56     # simple HMAC application
57     Digest::SHA3::sha3_512 $nonce1 . Digest::SHA3::sha3_512 $nonce2 . $hash
58     }
59    
60 root 1.1 =back
61    
62     =head1 AUTHOR
63    
64     Marc Lehmann <schmorp@schmorp.de>
65     http://home.schmorp.de/
66    
67     =cut
68    
69     1