=head1 NAME Deliantra::Util - utility cruft =head1 SYNOPSIS use Deliantra::Util; =head1 DESCRIPTION Various utilities that come in handy when dealing with Deliantra. =over 4 =cut package Deliantra::Util; use Digest::SHA; use Digest::SHA3; =item Deliantra::Util::hash_pw $cleartext Hashes a cleartext password into the binary password used in the protocol. =cut sub hash_pw($) { # we primarily want to protect the password itself, and # secondarily want to protect us against pre-image attacks. # we trust nist, but not a single hash function, so we # use both sha and sha3 my $pw = shift; for (0..20) { $pw = Digest::SHA3::sha3_512 $pw; $pw = "deliantrakdf$pw" x 32; $pw = Digest::SHA::sha512 $pw; } $pw } =item Deliantra::Util::auth_pw $hash, $nonce1, $nonce2 Authenticates a (hashed) password using the given nonce. =cut sub auth_pw($$) { my ($pass, $nonce1, $nonce2) = @_; # simple HMAC application Digest::SHA3::sha3_512 $nonce1 . Digest::SHA3::sha3_512 $nonce2 . $hash } =back =head1 AUTHOR Marc Lehmann http://home.schmorp.de/ =cut 1