Add unit tests for multiple modules
11700, 11750, 11760, 11800, 11850, 11860, 12001, 12100, 12200, 12300, 12600 & 12700
2019-02-18 18:49:57 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## Author......: See docs/credits.txt
|
|
|
|
## License.....: MIT
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use MIME::Base64 qw (encode_base64 decode_base64);
|
|
|
|
use Crypt::PBKDF2;
|
|
|
|
|
2019-02-26 20:20:07 +00:00
|
|
|
sub module_constraints { [[0, 256], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
|
Add unit tests for multiple modules
11700, 11750, 11760, 11800, 11850, 11860, 12001, 12100, 12200, 12300, 12600 & 12700
2019-02-18 18:49:57 +00:00
|
|
|
|
|
|
|
sub module_generate_hash
|
|
|
|
{
|
|
|
|
my $word = shift;
|
|
|
|
my $salt = shift;
|
2019-02-19 08:34:58 +00:00
|
|
|
|
Add unit tests for multiple modules
11700, 11750, 11760, 11800, 11850, 11860, 12001, 12100, 12200, 12300, 12600 & 12700
2019-02-18 18:49:57 +00:00
|
|
|
my $pbkdf2 = Crypt::PBKDF2->new
|
|
|
|
(
|
|
|
|
hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1'),
|
|
|
|
iterations => 10000,
|
|
|
|
output_len => 32
|
|
|
|
);
|
|
|
|
|
|
|
|
my $base64 = encode_base64 ($salt . $pbkdf2->PBKDF2 ($salt, $word), "");
|
|
|
|
|
|
|
|
my $hash = sprintf ("{PKCS5S2}%s", $base64);
|
|
|
|
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub module_verify_hash
|
|
|
|
{
|
|
|
|
my $line = shift;
|
|
|
|
|
|
|
|
my ($digest, $word) = split ":", $line;
|
|
|
|
|
|
|
|
return unless defined $digest;
|
|
|
|
return unless defined $word;
|
|
|
|
|
|
|
|
my $signature = substr ($digest, 0, 9);
|
|
|
|
|
|
|
|
return unless ($signature eq '{PKCS5S2}');
|
|
|
|
|
|
|
|
my $hash = substr ($digest, 9);
|
|
|
|
|
|
|
|
# base64 buf
|
|
|
|
|
|
|
|
my $base64_decoded = decode_base64 ($hash);
|
|
|
|
|
|
|
|
return if (length ($base64_decoded) != (16 + 32));
|
|
|
|
|
|
|
|
my $salt = substr ($base64_decoded, 0, 16);
|
|
|
|
|
|
|
|
my $word_packed = pack_if_HEX_notation ($word);
|
|
|
|
|
|
|
|
my $new_hash = module_generate_hash ($word_packed, $salt);
|
|
|
|
|
|
|
|
return ($new_hash, $word);
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|