mirror of
https://github.com/hashcat/hashcat
synced 2024-12-23 14:13:43 +01:00
Merge pull request #1893 from 0xbsec/m18100_unit_test
Add unit test for -m 18100
This commit is contained in:
commit
7df7476430
57
tools/test_modules/m18100.pm
Normal file
57
tools/test_modules/m18100.pm
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Digest::SHA qw (sha1);
|
||||
use Digest::HMAC qw (hmac_hex);
|
||||
|
||||
sub module_constraints { [[0, 255], [0, 55], [0, 255], [0, 55], [-1, -1]] }
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
|
||||
my $padded_time = sprintf ("%016x", int (int ($salt) / 30));
|
||||
my $data = pack ('H*', $padded_time);
|
||||
my $key = $word;
|
||||
|
||||
my $digest = hmac_hex ($data, $key, \&sha1, 64);
|
||||
|
||||
my $offset = hex (substr ($digest, -8)) & 0xf;
|
||||
$offset *= 2;
|
||||
|
||||
my $token = hex (substr ($digest, $offset, 8));
|
||||
$token &= 0x7fffffff;
|
||||
$token %= 1000000;
|
||||
|
||||
# token must be leading zero padded, and salt leading zero stripped
|
||||
my $hash = sprintf ("%06d:%d", $token, int ($salt));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my ($hash, $salt, $word) = split (':', $line);
|
||||
|
||||
return unless defined $hash;
|
||||
return unless defined $salt;
|
||||
return unless defined $word;
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user