From f16f04ac17c97e1726d4371be9ff1a14c16f3d4a Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 8 Jan 2019 23:46:44 +0100 Subject: [PATCH] Added test modules for mode 150 and 160 --- tools/test_modules/m00150.pm | 45 ++++++++++++++++++++++++++++++++++++ tools/test_modules/m00160.pm | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tools/test_modules/m00150.pm create mode 100644 tools/test_modules/m00160.pm diff --git a/tools/test_modules/m00150.pm b/tools/test_modules/m00150.pm new file mode 100644 index 000000000..22c721382 --- /dev/null +++ b/tools/test_modules/m00150.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::SHA1 qw (sha1); +use Digest::HMAC qw (hmac hmac_hex); + +sub module_constraints { [[0, 255], [0, 255], [0, 55], [0, 55], [0, 55]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = hmac_hex ($salt, $word, \&sha1, 64); + + my $hash = sprintf ("%s:%s", $digest, $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; diff --git a/tools/test_modules/m00160.pm b/tools/test_modules/m00160.pm new file mode 100644 index 000000000..f73639eab --- /dev/null +++ b/tools/test_modules/m00160.pm @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::SHA1 qw (sha1); +use Digest::HMAC qw (hmac hmac_hex); + +sub module_constraints { [[0, 255], [0, 255], [0, 55], [0, 55], [0, 55]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $digest = hmac_hex ($word, $salt, \&sha1, 64); + + my $hash = sprintf ("%s:%s", $digest, $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;