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::MD5 qw (md5_hex);
12
13sub module_constraints { [[0, 256], [0, 221], [0, 55], [0, 22], [-1, -1]] }
14
15sub module_generate_hash
16{
17  my $word = shift;
18  my $salt = shift;
19
20  my $digest = md5_hex ($salt . "-" . md5_hex ($word));
21
22  my $hash = sprintf ("\$B\$%s\$%s", $salt, $digest);
23
24  return $hash;
25}
26
27sub module_verify_hash
28{
29  my $line = shift;
30
31  my ($hash, $word) = split (':', $line);
32
33  return unless defined $hash;
34  return unless defined $word;
35
36  my @data = split ('\$', $hash);
37
38  return unless scalar @data == 4;
39
40  shift @data;
41
42  my $signature = shift @data;
43  my $salt      = shift @data;
44  my $digest    = shift @data;
45
46  return unless defined $signature;
47  return unless defined $salt;
48  return unless defined $digest;
49
50  my $word_packed = pack_if_HEX_notation ($word);
51
52  my $new_hash = module_generate_hash ($word_packed, $salt);
53
54  return ($new_hash, $word);
55}
56
571;
58