From ac5bcd89faae74da3c98142f6f1ecec290a0b94d Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 17 Feb 2019 15:49:57 +0100 Subject: [PATCH] Add -m 8500 unit test --- tools/test_modules/m08500.pm | 85 ++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/tools/test_modules/m08500.pm b/tools/test_modules/m08500.pm index d245c6b97..6b018ee4a 100644 --- a/tools/test_modules/m08500.pm +++ b/tools/test_modules/m08500.pm @@ -11,48 +11,7 @@ use warnings; use Convert::EBCDIC qw (ascii2ebcdic); use Crypt::DES; -sub module_constraints { [[1, 8], [1, 8], [-1, -1], [-1, -1], [-1, -1]] } - -sub module_generate_hash -{ - my $word = shift; - my $salt = shift; - - my $hash_buf = racf_hash (uc $salt, $word); - - my $tmp_hash = sprintf ('$racf$*%s*%s', uc $salt, uc $hash_buf); - - return $tmp_hash; -} - -sub module_verify_hash -{ - my $line = shift; - - my @line_elements = split (":", $line); - - return if scalar @line_elements < 2; - - # get hash and word - - my $hash_in = shift @line_elements; - - my $word = join (":", @line_elements); - - # get signature - - my @hash_elements = split ('\*', $hash_in); - - return unless ($hash_elements[0] eq '$racf$'); - - my $salt = $hash_elements[1]; - - my $word_packed = pack_if_HEX_notation ($word); - - my $new_hash = module_generate_hash ($word_packed, $salt); - - return ($new_hash, $word); -} +sub module_constraints { [[0, 8], [1, 8], [-1, -1], [-1, -1], [-1, -1]] } sub racf_hash { @@ -85,4 +44,46 @@ sub racf_hash return $ct; } +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + + my $hash_buf = racf_hash (uc $salt, $word); + + my $hash = sprintf ('$racf$*%s*%s', uc $salt, uc $hash_buf); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + my @line_elements = split (":", $line); + + return if scalar @line_elements < 2; + + my $hash_in = shift @line_elements; + + my $word = join (":", @line_elements); + + # check signature + + my @hash_elements = split ('\*', $hash_in); + + return unless ($hash_elements[0] eq '$racf$'); + + my $salt = $hash_elements[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;