2019-01-23 14:05:22 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## Author......: See docs/credits.txt
|
|
|
|
## License.....: MIT
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2019-02-26 20:20:07 +00:00
|
|
|
sub module_constraints { [[0, 256], [0, 16], [0, 15], [0, 16], [-1, -1]] }
|
2019-01-23 14:05:22 +00:00
|
|
|
|
|
|
|
sub module_generate_hash
|
|
|
|
{
|
|
|
|
my $word = shift;
|
|
|
|
my $salt = shift;
|
|
|
|
my $iter = shift;
|
|
|
|
|
2019-02-17 08:37:50 +00:00
|
|
|
my $hash_buf;
|
2019-01-23 14:05:22 +00:00
|
|
|
|
2019-02-17 08:37:50 +00:00
|
|
|
if (defined $iter)
|
2019-01-23 14:05:22 +00:00
|
|
|
{
|
2019-02-17 08:37:50 +00:00
|
|
|
$hash_buf = crypt ($word, "\$6\$rounds=$iter\$$salt\$");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$hash_buf = crypt ($word, "\$6\$$salt\$");
|
2019-01-23 14:05:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 08:37:50 +00:00
|
|
|
my $hash = sprintf ("%s", $hash_buf);
|
2019-01-23 14:05:22 +00:00
|
|
|
|
2019-02-17 08:37:50 +00:00
|
|
|
return $hash;
|
2019-01-23 14:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub module_verify_hash
|
|
|
|
{
|
|
|
|
my $line = shift;
|
|
|
|
|
|
|
|
my ($hash, $word) = split (':', $line);
|
|
|
|
|
|
|
|
return unless defined $hash;
|
|
|
|
return unless defined $word;
|
|
|
|
|
|
|
|
my $index1 = index ($hash, ',', 1);
|
|
|
|
my $index2 = index ($hash, '$', 1);
|
|
|
|
|
|
|
|
if ($index1 != -1)
|
|
|
|
{
|
|
|
|
if ($index1 < $index2)
|
|
|
|
{
|
|
|
|
$index2 = $index1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$index2++;
|
|
|
|
|
|
|
|
# rounds= if available
|
|
|
|
my $iter = 0;
|
|
|
|
|
|
|
|
if (substr ($hash, $index2, 7) eq "rounds=")
|
|
|
|
{
|
|
|
|
my $old_index = $index2;
|
|
|
|
|
|
|
|
$index2 = index ($hash, '$', $index2 + 1);
|
|
|
|
|
2019-02-19 11:50:57 +00:00
|
|
|
return if $index2 < 1;
|
2019-01-23 14:05:22 +00:00
|
|
|
|
|
|
|
$iter = substr ($hash, $old_index + 7, $index2 - $old_index - 7);
|
|
|
|
|
|
|
|
$index2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
# get salt
|
|
|
|
my $index3 = rindex ($hash, '$');
|
|
|
|
|
2019-02-19 11:50:57 +00:00
|
|
|
return if $index3 < 1;
|
2019-01-23 14:05:22 +00:00
|
|
|
|
|
|
|
my $salt = substr ($hash, $index2, $index3 - $index2);
|
|
|
|
|
|
|
|
my $word_packed = pack_if_HEX_notation ($word);
|
|
|
|
|
|
|
|
my $new_hash = module_generate_hash ($word_packed, $salt, $iter);
|
|
|
|
|
|
|
|
return ($new_hash, $word);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|