From 179194a576d00236979dcf6de1e8a559c3c6144f Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 15 Feb 2019 21:13:54 +0100 Subject: [PATCH] Add -m 7300 unit test --- tools/test_modules/m07300.pm | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tools/test_modules/m07300.pm diff --git a/tools/test_modules/m07300.pm b/tools/test_modules/m07300.pm new file mode 100644 index 000000000..03e9b18f8 --- /dev/null +++ b/tools/test_modules/m07300.pm @@ -0,0 +1,58 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::HMAC qw (hmac_hex); +use Digest::SHA qw (sha1); + +sub module_constraints { [[0, 255], [32, 255], [0, 55], [32, 32], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $hash_buf = hmac_hex ($salt, $word, \&sha1); + + my $hash = sprintf ("%s:%s", unpack ("H*", $salt), $hash_buf); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my $index1 = index ($line, ":"); + + return if $index1 < 1; + + my $salt = substr ($line, 0, $index1); + + $salt = pack ("H*", $salt); + + my $rest = substr ($line, $index1 + 1); + + my $index2 = index ($rest, ":"); + + return if $index2 < 1; + + my $word = substr ($rest, $index2 + 1); + + return unless defined $salt; + return unless defined $word; + + $word = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word, $salt); + + return ($new_hash, $word); +} + +1;