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