1#!/usr/bin/env perl
2
3##
4## Author......: See docs/credits.txt
5## License.....: MIT
6##
7
8use strict;
9use warnings;
10
11use Crypt::DES;
12
13sub module_constraints { [[24, 24], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
14
15sub module_generate_hash
16{
17  my $word = shift;
18  my $salt = shift;
19
20  my $word1 = substr ($word,  0, 8);
21  my $word2 = substr ($word,  8, 8);
22  my $word3 = substr ($word, 16, 8);
23
24  my $cipher1 = new Crypt::DES ($word1);
25  my $cipher2 = new Crypt::DES ($word2);
26  my $cipher3 = new Crypt::DES ($word3);
27
28  my $pt1_bin = pack ("H*", $salt);
29
30  my $ct1_bin = $cipher1->encrypt ($pt1_bin);
31  my $ct2_bin = $cipher2->decrypt ($ct1_bin);
32  my $ct3_bin = $cipher3->encrypt ($ct2_bin);
33
34  my $hash = sprintf ("%s:%s", unpack ("H*", $ct3_bin), $salt);
35
36  return $hash;
37}
38
39sub module_verify_hash
40{
41  my $line = shift;
42
43  my ($hash, $salt, $word) = split (':', $line);
44
45  return unless defined $hash;
46  return unless defined $salt;
47  return unless defined $word;
48
49  my $word_packed = pack_if_HEX_notation ($word);
50
51  my $new_hash = module_generate_hash ($word_packed, $salt);
52
53  return ($new_hash, $word);
54}
55
561;
57