From 71a071ebdb32b8b8260266de09e7a5d4e1ae262c Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 17 Feb 2019 16:11:30 +0100 Subject: [PATCH] Add -m 8900 unit test --- tools/test_modules/m08900.pm | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tools/test_modules/m08900.pm diff --git a/tools/test_modules/m08900.pm b/tools/test_modules/m08900.pm new file mode 100644 index 000000000..4357a5dc7 --- /dev/null +++ b/tools/test_modules/m08900.pm @@ -0,0 +1,91 @@ +#!/usr/bin/env perl + +## +## Author......: See docs/credits.txt +## License.....: MIT +## + +use strict; +use warnings; + +use Crypt::ScryptKDF qw (scrypt_hash); +use MIME::Base64 qw (decode_base64); + +sub module_constraints { [[0, 255], [1, 15], [-1, -1], [-1, -1], [-1, -1]] } + +sub module_generate_hash +{ + my $word = shift; + my $salt = shift; + my $N = shift // 1024; + my $r = shift // 1; + my $p = shift // 1; + + my $hash_buf = scrypt_hash ($word, $salt, $N, $r, $p, 32); + + my $hash = sprintf ('%s', $hash_buf); + + return $hash; +} + +sub module_verify_hash +{ + my $line = shift; + + # scrypt + next unless (substr ($line, 0, 7) eq 'SCRYPT:'); + + # get hash + my $index1 = index ($line, ":", 7); + + return if $index1 < 1; + + # N + my $N = substr ($line, 7, $index1 - 7); + + my $index2 = index ($line, ":", $index1 + 1); + + return if $index2 < 1; + + # r + my $r = substr ($line, $index1 + 1, $index2 - $index1 - 1); + + $index1 = index ($line, ":", $index2 + 1); + + return if $index1 < 1; + + # p + my $p = substr ($line, $index2 + 1, $index1 - $index2 - 1); + + $index2 = index ($line, ":", $index1 + 1); + + return if $index2 < 1; + + # salt + my $salt = substr ($line, $index1 + 1, $index2 - $index1 - 1); + + $salt = decode_base64 ($salt); + + $index1 = index ($line, ":", $index2 + 1); + + return if $index1 < 1; + + # digest + + my $word = substr ($line, $index1 + 1); + + return unless defined $salt; + return unless defined $word; + return unless defined $N; + return unless defined $r; + return unless defined $p; + + $word = pack_if_HEX_notation ($word); + + my $new_hash = module_generate_hash ($word, $salt, $N, $r, $p); + + return ($new_hash, $word); +} + +1; +