From afd15a241afde83e5f9d8168f1a12af68964ab74 Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 17 Feb 2019 15:10:39 +0100 Subject: [PATCH] Add -m 8000 unit test --- tools/test_modules/m08000.pm | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/test_modules/m08000.pm diff --git a/tools/test_modules/m08000.pm b/tools/test_modules/m08000.pm new file mode 100644 index 000000000..429a653e8 --- /dev/null +++ b/tools/test_modules/m08000.pm @@ -0,0 +1,57 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Digest::SHA qw (sha256_hex); +use Encode; + +sub module_constraints { [[-1, -1], [-1, -1], [0, 27], [16, 16], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $salt_bin = pack ("H*", $salt); + + my $word_utf = encode ("UTF-16BE", $word); + + my $hash_buf = sha256_hex ($word_utf . "\x00" x (510 - (length ($word) * 2)) . $salt_bin); + + my $hash = sprintf ("0xc007%s%s", $salt, $hash_buf); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + # Sybase ASE + my $index = index ($line, ":"); + + return if $index < 1; + + my $hash_in = substr ($line, 0, $index); + + my $word = substr ($line, $index + 1); + + my $salt = substr ($hash_in, 6, 16); + + 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;