Add some more modules converted

This commit is contained in:
jsteube
2019-02-08 13:00:40 +01:00
parent a59d1c17eb
commit c9e796fcf0
51 changed files with 14225 additions and 5241 deletions
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Convert::EBCDIC qw (ascii2ebcdic);
use Crypt::DES;
sub module_constraints { [[1, 8], [1, 8], [1, 8], [1, 8], [-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 racf_hash
{
my ($username, $password) = @_;
$username = substr ($username . " " x 8, 0, 8);
$password = substr ($password . " " x 8, 0, 8);
my $username_ebc = ascii2ebcdic ($username);
my $password_ebc = ascii2ebcdic ($password);
my @pw = split ("", $password_ebc);
for (my $i = 0; $i < 8; $i++)
{
$pw[$i] = unpack ("C", $pw[$i]);
$pw[$i] ^= 0x55;
$pw[$i] <<= 1;
$pw[$i] = pack ("C", $pw[$i] & 0xff);
}
my $key = join ("", @pw);
my $cipher = new Crypt::DES $key;
my $ciphertext = $cipher->encrypt ($username_ebc);
my $ct = unpack ("H16", $ciphertext);
return $ct;
}
1;
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::UnixCrypt_XS qw (crypt_rounds fold_password base64_to_int24 block_to_base64 int24_to_base64);
sub module_constraints { [[1, 31], [4, 4], [1, 31], [4, 4], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iter = shift // random_number (1, 5000);
my $key_value = fold_password ($word);
my $data = "\x00\x00\x00\x00\x00\x00\x00\x00";
my $salt_value = base64_to_int24 ($salt);
my $hash_buf = crypt_rounds ($key_value, $iter, $salt_value, $data);
my $tmp_hash = sprintf ("_%s%s%s", int24_to_base64 ($iter), $salt, block_to_base64 ($hash_buf));
return $tmp_hash;
}
sub module_verify_hash
{
my $line = shift;
return unless (substr ($line, 0, 1) eq '_');
my $index1 = index ($line, ':', 20);
return if ($index1 != 20);
# iter
my $iter = substr ($line, 1, 4);
$iter = base64_to_int24 ($iter);
# salt
my $salt = substr ($line, 5, 4);
# word / hash
my $word = substr ($line, $index1 + 1);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $iter);
return ($new_hash, $word);
}
1;