1#!/usr/bin/env perl
2
3##
4## Author......: See docs/credits.txt
5## License.....: MIT
6##
7
8use strict;
9use warnings;
10
11use Digest::SHA  qw (sha512);
12use Digest::HMAC qw (hmac_hex);
13
14sub module_constraints { [[0, 256], [0, 256], [0, 55], [0, 55], [-1, -1]] }
15
16sub module_generate_hash
17{
18  my $word = shift;
19  my $salt = shift;
20
21  my $digest = hmac_hex ($word, $salt, \&sha512, 128);
22
23  my $hash = sprintf ("%s:%s", $digest, $salt);
24
25  return $hash;
26}
27
28sub module_verify_hash
29{
30  my $line = shift;
31
32  my ($hash, $salt, $word) = split (':', $line);
33
34  return unless defined $hash;
35  return unless defined $salt;
36  return unless defined $word;
37
38  my $word_packed = pack_if_HEX_notation ($word);
39
40  my $new_hash = module_generate_hash ($word_packed, $salt);
41
42  return ($new_hash, $word);
43}
44
451;
46