2019-06-18 16:41:41 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## Author......: See docs/credits.txt
|
|
|
|
## License.....: MIT
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2022-01-30 09:35:51 +00:00
|
|
|
use Digest::SHA qw (sha256);
|
|
|
|
use MIME::Base64 qw (encode_base64);
|
2019-06-18 16:41:41 +00:00
|
|
|
|
2019-06-19 13:12:25 +00:00
|
|
|
sub module_constraints { [[0, 256], [0, 16], [-1, -1], [-1, -1], [-1, -1]] }
|
2019-06-18 16:41:41 +00:00
|
|
|
|
|
|
|
sub module_generate_hash
|
|
|
|
{
|
|
|
|
my ($word, $salt, $iter) = @_;
|
|
|
|
|
|
|
|
return unless defined $word;
|
|
|
|
return unless defined $salt;
|
|
|
|
|
|
|
|
$iter //= 1000;
|
|
|
|
|
2020-06-13 09:19:00 +00:00
|
|
|
my $digest = sha256 ($salt . $word);
|
2019-06-18 16:41:41 +00:00
|
|
|
|
2020-06-13 09:19:00 +00:00
|
|
|
for (my $i = 1; $i < $iter; $i++)
|
|
|
|
{
|
|
|
|
$digest = sha256 ($digest);
|
2019-06-18 16:41:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 09:19:00 +00:00
|
|
|
chomp ($digest = encode_base64 ($digest));
|
2019-06-18 16:41:41 +00:00
|
|
|
|
|
|
|
my $hash = sprintf ("otm_sha256:%d:%s:%s", $iter, $salt, $digest);
|
|
|
|
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub module_verify_hash
|
|
|
|
{
|
|
|
|
my $line = shift;
|
|
|
|
|
|
|
|
my ($sig, $iter, $salt, $hash, $word) = split (':', $line);
|
|
|
|
|
|
|
|
return unless defined $iter;
|
|
|
|
return unless defined $salt;
|
|
|
|
return unless defined $word;
|
2021-06-21 15:47:22 +00:00
|
|
|
|
2019-06-18 16:41:41 +00:00
|
|
|
my $new_hash = module_generate_hash ($word, $salt, $iter);
|
|
|
|
|
|
|
|
return ($new_hash, $word);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|