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 (sha1_hex sha256_hex);
12
13sub module_constraints { [[0, 256], [64, 64], [0, 55], [64, 64], [-1, -1]] }
14
15sub module_generate_hash
16{
17  my $word = shift;
18  my $salt = shift;
19
20  my $digest = sha1_hex ($word);
21
22  $digest = sha256_hex ($salt . uc $digest);
23
24  my $hash = sprintf ("%s:%s", $digest, $salt);
25
26  return $hash;
27}
28
29sub module_verify_hash
30{
31  my $line = shift;
32
33  my ($hash, $salt, $word) = split (':', $line);
34
35  return unless defined $hash;
36  return unless defined $salt;
37  return unless defined $word;
38
39  my $word_packed = pack_if_HEX_notation ($word);
40
41  my $new_hash = module_generate_hash ($word_packed, $salt);
42
43  return ($new_hash, $word);
44}
45
461;
47