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

# 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 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 # we trust nist, but not a single hash function, so we
34 # use both sha and sha3
35
36 my $pw = shift;
37
38 for (0..20) {
39 $pw = Digest::SHA3::sha3_512 $pw;
40 $pw = "deliantrakdf$pw" x 32;
41 $pw = Digest::SHA::sha512 $pw;
42 }
43
44 $pw
45 }
46
47 =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 my ($hash, $nonce1, $nonce2) = @_;
55
56 # simple HMAC application
57 Digest::SHA3::sha3_512 $nonce1 . Digest::SHA3::sha3_512 $nonce2 . $hash
58 }
59
60 =back
61
62 =head1 AUTHOR
63
64 Marc Lehmann <schmorp@schmorp.de>
65 http://home.schmorp.de/
66
67 =cut
68
69 1