cosmetic: minor code style fixes

This commit is contained in:
philsmd
2020-06-13 11:19:00 +02:00
parent 323e7463b8
commit e59f61e8cf
120 changed files with 895 additions and 888 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ sub module_generate_hash
my $word = shift;
my $salt = shift;
my $salt_bin = pack("H*", $salt);
my $salt_bin = pack ("H*", $salt);
my $digest = sha1_hex ($word . $salt_bin);
+2 -2
View File
@@ -33,9 +33,9 @@ sub module_verify_hash
my ($digest, $word) = split (':', $line);
my ($prefix, $hash) = split('-', $digest);
my ($prefix, $hash) = split ('-', $digest);
my $salt = substr($prefix, 6, 8);
my $salt = substr ($prefix, 6, 8);
return unless defined $hash;
return unless defined $salt;
-1
View File
@@ -49,4 +49,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -80,4 +80,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -114,4 +114,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -105,4 +105,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -69,4 +69,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -61,4 +61,3 @@ sub module_verify_hash
}
1;
+2 -2
View File
@@ -47,11 +47,11 @@ sub module_verify_hash
my $word = substr ($line, $index1 + 1);
my $index2 = index ($hash_in, ".", 19);
my $index2 = index ($hash_in, ".", 19);
return if $index2 < 1;
my $index3 = index ($hash_in, ".", $index2 + 1);
my $index3 = index ($hash_in, ".", $index2 + 1);
my $salt = substr ($hash_in, $index2 + 1, $index3 - $index2 - 1);
-1
View File
@@ -178,4 +178,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -178,4 +178,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -104,4 +104,3 @@ sub module_verify_hash
}
1;
+1 -2
View File
@@ -61,7 +61,7 @@ sub module_generate_hash
my $hash_buf = sha1_hex ($word . substr ($theMagicArray_s, $offsetMagicArray, $lengthMagicArray) . $salt);
my $hash = sprintf("%s\$%.20s%020X", $salt, uc $hash_buf, 0);
my $hash = sprintf ("%s\$%.20s%020X", $salt, uc $hash_buf, 0);
return $hash;
}
@@ -104,4 +104,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -89,4 +89,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -88,4 +88,3 @@ sub module_verify_hash
}
1;
-1
View File
@@ -84,4 +84,3 @@ sub module_verify_hash
}
1;
+1 -1
View File
@@ -47,7 +47,7 @@ sub module_verify_hash
my @data = split (':', $digest);
return unless scalar(@data) == 4;
return unless scalar (@data) == 4;
my $signature = shift @data;
+7 -8
View File
@@ -23,20 +23,20 @@ sub module_generate_hash
$salt = random_bytes (16);
}
my $pbkdf2 = Crypt::PBKDF2->new(
my $pbkdf2 = Crypt::PBKDF2->new (
hash_class => 'HMACSHA2',
iterations => $iter,
output_len => 256,
salt_len => 64,
);
my $p = $pbkdf2->generate($word, $salt);
my $p = $pbkdf2->generate ($word, $salt);
my $decoded_hash = $pbkdf2->decode_string($p);
my $decoded_hash = $pbkdf2->decode_string ($p);
my $diter = $decoded_hash->{"iterations"};
my $iterbytes = pack('I', unpack('N*', pack('L*', $diter)));
my $iterbytes = pack ('I', unpack ('N*', pack ('L*', $diter)));
my $dsalt = $decoded_hash->{"salt"};
@@ -44,7 +44,7 @@ sub module_generate_hash
my $tmp = $iterbytes . $dsalt . $dhash;
my $hash = "{PBKDF2_SHA256}" . encode_base64($tmp, '');
my $hash = "{PBKDF2_SHA256}" . encode_base64 ($tmp, '');
return $hash;
}
@@ -57,11 +57,11 @@ sub module_verify_hash
return unless (substr ($hash, 0, 15) eq '{PBKDF2_SHA256}');
my $hashbytes = decode_base64(substr ($hash, 15, length $hash));
my $hashbytes = decode_base64 (substr ($hash, 15, length $hash));
my $iterbytes = substr $hashbytes, 0, 4;
my $iter = unpack('N*', pack('L*', unpack("I",$iterbytes)));
my $iter = unpack ('N*', pack ('L*', unpack ('I', $iterbytes)));
my $salt = substr $hashbytes, 4, 64;
@@ -75,4 +75,3 @@ sub module_verify_hash
}
1;
+2 -2
View File
@@ -22,8 +22,8 @@ sub module_generate_hash
import binascii
import sys
from pygost import gost34112012256
digest = gost34112012256.new(b"$word").digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = gost34112012256.new (b"$word").digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+2 -2
View File
@@ -22,8 +22,8 @@ import sys
from pygost import gost34112012256
key = b"$word"
msg = b"$salt"
digest = hmac.new(key, msg, gost34112012256).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = hmac.new (key, msg, gost34112012256).digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+2 -2
View File
@@ -22,8 +22,8 @@ import sys
from pygost import gost34112012256
key = b"$salt"
msg = b"$word"
digest = hmac.new(key, msg, gost34112012256).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = hmac.new (key, msg, gost34112012256).digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+2 -2
View File
@@ -19,8 +19,8 @@ sub module_generate_hash
import binascii
import sys
from pygost import gost34112012512
digest = gost34112012512.new(b"$word").digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = gost34112012512.new (b"$word").digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+2 -2
View File
@@ -23,8 +23,8 @@ import sys
from pygost import gost34112012512
key = b"$word"
msg = b"$salt"
digest = hmac.new(key, msg, gost34112012512).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = hmac.new (key, msg, gost34112012512).digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+2 -2
View File
@@ -23,8 +23,8 @@ import sys
from pygost import gost34112012512
key = b"$salt"
msg = b"$word"
digest = hmac.new(key, msg, gost34112012512).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
digest = hmac.new (key, msg, gost34112012512).digest ()
sys.stdout.write (binascii.hexlify (digest[::-1]))
END_CODE
+1 -1
View File
@@ -125,7 +125,7 @@ sub module_verify_hash
my @data = split (':', $digest);
return unless scalar(@data) == 4;
return unless scalar (@data) == 4;
my $signature = shift @data;
+2 -2
View File
@@ -66,7 +66,7 @@ sub module_verify_hash
my $default_salt = 1;
my ($param, $hash) = split('\$', $digest);
my ($param, $hash) = split ('\$', $digest);
$default_salt = 0 if ($param eq '1');
@@ -74,7 +74,7 @@ sub module_verify_hash
if ($default_salt == 0)
{
($salt, $hash) = split('\$', $hash);
($salt, $hash) = split ('\$', $hash);
}
my $word_packed = pack_if_HEX_notation ($word);
+21 -15
View File
@@ -73,27 +73,33 @@ sub get_random_dpapimk_salt
return $salt_buf;
}
#Thanks to Jochen Hoenicke <hoenicke@gmail.com>
# Thanks to Jochen Hoenicke <hoenicke@gmail.com>
# (one of the authors of Palm Keyring)
# for these next two subs.
sub dpapi_pbkdf2
{
my ($password, $salt, $iter, $keylen, $prf) = @_;
my ($k, $t, $u, $ui, $i);
$t = "";
for ($k = 1; length ($t) < $keylen; $k++)
my ($password, $salt, $iter, $keylen, $prf) = @_;
my ($k, $t, $u, $ui, $i);
$t = "";
for ($k = 1; length ($t) < $keylen; $k++)
{
$u = $ui = &$prf ($salt . pack ('N', $k), $password);
for ($i = 1; $i < $iter; $i++)
{
$u = $ui = &$prf ($salt.pack ('N', $k), $password);
for ($i = 1; $i < $iter; $i++)
{
# modification to fit Microsoft
# weird pbkdf2 implementation...
$ui = &$prf ($u, $password);
$u ^= $ui;
}
$t .= $u;
# modification to fit Microsoft
# weird pbkdf2 implementation...
$ui = &$prf ($u, $password);
$u ^= $ui;
}
return substr ($t, 0, $keylen);
$t .= $u;
}
return substr ($t, 0, $keylen);
}
sub module_generate_hash
+22 -15
View File
@@ -74,27 +74,34 @@ sub get_random_dpapimk_salt
return $salt_buf;
}
#Thanks to Jochen Hoenicke <hoenicke@gmail.com>
# Thanks to Jochen Hoenicke <hoenicke@gmail.com>
# (one of the authors of Palm Keyring)
# for these next two subs.
sub dpapi_pbkdf2
{
my ($password, $salt, $iter, $keylen, $prf) = @_;
my ($k, $t, $u, $ui, $i);
$t = "";
for ($k = 1; length ($t) < $keylen; $k++)
my ($password, $salt, $iter, $keylen, $prf) = @_;
my ($k, $t, $u, $ui, $i);
$t = "";
for ($k = 1; length ($t) < $keylen; $k++)
{
$u = $ui = &$prf ($salt . pack ('N', $k), $password);
for ($i = 1; $i < $iter; $i++)
{
$u = $ui = &$prf ($salt.pack ('N', $k), $password);
for ($i = 1; $i < $iter; $i++)
{
# modification to fit Microsoft
# weird pbkdf2 implementation...
$ui = &$prf ($u, $password);
$u ^= $ui;
}
$t .= $u;
# modification to fit Microsoft
# weird pbkdf2 implementation...
$ui = &$prf ($u, $password);
$u ^= $ui;
}
return substr ($t, 0, $keylen);
$t .= $u;
}
return substr ($t, 0, $keylen);
}
sub module_generate_hash
+1 -1
View File
@@ -21,7 +21,7 @@ sub module_generate_hash
$md5->{_data} = $word ^ ("\x5c" x $length);
$md5->{_data} .= "\x5c" x (64 - $length);
$md5->add();
$md5->add ();
my $digest = unpack ("H*", pack ('V4', @{$md5->{_state}}));
+1 -1
View File
@@ -120,4 +120,4 @@ sub get_random_jwt_salt
return $header_base64 . "." . $payload_base64;
}
1;
1;
+1 -1
View File
@@ -137,4 +137,4 @@ sub get_random_jwt_salt
return $header_base64 . "." . $payload_base64;
}
1;
1;
+1 -1
View File
@@ -169,4 +169,4 @@ sub module_verify_hash
return ($new_hash, $word);
}
1;
1;
-1
View File
@@ -74,4 +74,3 @@ sub module_verify_hash
}
1;
+1 -1
View File
@@ -39,4 +39,4 @@ sub module_verify_hash
return ($new_hash, $word);
}
1;
1;
+1 -1
View File
@@ -39,4 +39,4 @@ sub module_verify_hash
return ($new_hash, $word);
}
1;
1;
-1
View File
@@ -240,4 +240,3 @@ sub module_verify_hash
}
1;
+1 -1
View File
@@ -40,7 +40,7 @@ sub module_generate_hash
my $cipher = unpack ('H*', $b_cipher);
my $checksum = sha256_hex ($b_plain);
my $hash = '$odf$'."*1*1*$iter*32*$checksum*16*$iv*16*$salt*0*$cipher";
my $hash = '$odf$' . "*1*1*$iter*32*$checksum*16*$iv*16*$salt*0*$cipher";
return $hash;
}
+2 -2
View File
@@ -54,7 +54,7 @@ sub module_generate_hash
my $cipher = unpack ('H*', $b_cipher);
my $checksum = sha1_hex ($b_plain);
my $hash = '$odf$'."*0*0*$iter*16*$checksum*8*$iv*16*$salt*0*$cipher";
my $hash = '$odf$' . "*0*0*$iter*16*$checksum*8*$iv*16*$salt*0*$cipher";
return $hash;
}
@@ -113,7 +113,7 @@ sub module_verify_hash
my $pass_hash = sha1 ($word);
my $key = $kdf->PBKDF2 ($b_salt, $pass_hash);
my $cfb = Crypt::GCrypt->new(
my $cfb = Crypt::GCrypt->new (
type => 'cipher',
algorithm => 'blowfish',
mode => 'cfb'
+17 -17
View File
@@ -60,9 +60,9 @@ sub module_generate_hash
my $b_seed = $pbkdf2->PBKDF2 ($mysalt, $word);
# we can precompute this
my $b_kerberos_nfolded = hex2byte('6b65726265726f737b9b5b2b93132b93');
my $b_kerberos_nfolded = hex2byte ('6b65726265726f737b9b5b2b93132b93');
my $b_iv = hex2byte('0' x 32);
my $b_iv = hex2byte ('0' x 32);
# 'key_bytes' will be the AES key used to generate 'ki' (for final hmac-sha1)
# and 'ke' (AES key to decrypt/encrypt the ticket)
@@ -70,8 +70,8 @@ sub module_generate_hash
my $b_key_bytes = $cbc->encrypt ($b_kerberos_nfolded, $b_seed, $b_iv);
# precomputed stuff
my $b_nfolded1 = hex2byte('62dc6e371a63a80958ac562b15404ac5');
my $b_nfolded2 = hex2byte('b5b0582c14b6500aad56ab55aa80556a');
my $b_nfolded1 = hex2byte ('62dc6e371a63a80958ac562b15404ac5');
my $b_nfolded2 = hex2byte ('b5b0582c14b6500aad56ab55aa80556a');
my $b_ki = $cbc->encrypt ($b_nfolded1, $b_key_bytes, $b_iv);
my $b_ke = $cbc->encrypt ($b_nfolded2, $b_key_bytes, $b_iv);
@@ -85,7 +85,7 @@ sub module_generate_hash
if (defined $edata2)
{
my $len_last_block = length($edata2) % 32;
my $len_last_block = length ($edata2) % 32;
my $tmp = $len_last_block + 32;
@@ -93,11 +93,11 @@ sub module_generate_hash
my $b_last_block = hex2byte (substr $edata2, -$len_last_block);
my $b_n_1_block = hex2byte (substr(substr($edata2, -$tmp), 0, 32));
my $b_n_1_block = hex2byte (substr (substr ($edata2, -$tmp), 0, 32));
my $b_truncated_ticket_decrypted = $cbc->decrypt ($b_truncated_enc_ticket, $b_ke, $b_iv);
my $truncated_ticket_decrypted = byte2hex($b_truncated_ticket_decrypted);
my $truncated_ticket_decrypted = byte2hex ($b_truncated_ticket_decrypted);
my $check_correct = ((substr ($truncated_ticket_decrypted, 32, 4) eq "6381" && substr ($truncated_ticket_decrypted, 38, 2) eq "30") ||
(substr ($truncated_ticket_decrypted, 32, 4) eq "6382")) &&
@@ -110,11 +110,11 @@ sub module_generate_hash
my $b_n_1_decrypted = $cbc->decrypt ($b_n_1_block, $b_ke, $b_iv);
my $b_last_plain = substr $b_n_1_decrypted, 0, $len_last_block/2;
my $b_last_plain = substr $b_n_1_decrypted, 0, $len_last_block / 2;
$b_last_plain = $b_last_plain ^ $b_last_block;
my $omitted = substr $b_n_1_decrypted, -(16 - $len_last_block/2);
my $omitted = substr $b_n_1_decrypted, -(16 - $len_last_block / 2);
my $b_n_1 = $b_last_block . $omitted;
@@ -124,7 +124,7 @@ sub module_generate_hash
my $b_cleartext_ticket = $b_truncated_ticket_decrypted . $b_n_1 . $b_last_plain;
$cleartext_ticket = byte2hex($b_cleartext_ticket);
$cleartext_ticket = byte2hex ($b_cleartext_ticket);
}
else # validation failed
{
@@ -147,26 +147,26 @@ sub module_generate_hash
$cleartext_ticket = $nonce . $cleartext_ticket;
}
# we have what is required to compute checksum
$checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
$checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$checksum = substr $checksum, 0, 12;
}
my $len_cleartext_last_block = length($cleartext_ticket) % 32;
my $len_cleartext_last_block = length ($cleartext_ticket) % 32;
my $cleartext_last_block = substr $cleartext_ticket, -$len_cleartext_last_block;
my $padding = pad(length($cleartext_ticket), 32);
my $padding = pad (length ($cleartext_ticket), 32);
my $b_cleartext_last_block_padded = hex2byte($cleartext_last_block . '0' x $padding);
my $b_cleartext_last_block_padded = hex2byte ($cleartext_last_block . '0' x $padding);
# we will encrypt until n-1 block (included)
my $truncated_cleartext_ticket = substr $cleartext_ticket, 0, -$len_cleartext_last_block;
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte ($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_enc_ticket_n_1_block= substr $b_truncated_enc_ticket, -16;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block/2;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block / 2;
# we now craft the new n-1 block
my $tmp = $b_enc_ticket_n_1_block ^ $b_cleartext_last_block_padded;
@@ -216,4 +216,4 @@ sub module_verify_hash
return ($new_hash, $word);
}
1;
1;
+17 -17
View File
@@ -60,9 +60,9 @@ sub module_generate_hash
my $b_seed = $pbkdf2->PBKDF2 ($mysalt, $word);
# we can precompute this
my $b_kerberos_nfolded = hex2byte('6b65726265726f737b9b5b2b93132b93');
my $b_kerberos_nfolded = hex2byte ('6b65726265726f737b9b5b2b93132b93');
my $b_iv = hex2byte('0' x 32);
my $b_iv = hex2byte ('0' x 32);
# 'key_bytes' will be the AES key used to generate 'ki' (for final hmac-sha1)
# and 'ke' (AES key to decrypt/encrypt the ticket)
@@ -72,8 +72,8 @@ sub module_generate_hash
$b_key_bytes = $b_key_bytes . $cbc->encrypt ($b_key_bytes, $b_seed, $b_iv);
# precomputed stuff
my $b_nfolded1 = hex2byte('62dc6e371a63a80958ac562b15404ac5');
my $b_nfolded2 = hex2byte('b5b0582c14b6500aad56ab55aa80556a');
my $b_nfolded1 = hex2byte ('62dc6e371a63a80958ac562b15404ac5');
my $b_nfolded2 = hex2byte ('b5b0582c14b6500aad56ab55aa80556a');
my $b_ki = $cbc->encrypt ($b_nfolded1, $b_key_bytes, $b_iv);
@@ -92,7 +92,7 @@ sub module_generate_hash
if (defined $edata2)
{
my $len_last_block = length($edata2) % 32;
my $len_last_block = length ($edata2) % 32;
my $tmp = $len_last_block + 32;
@@ -100,11 +100,11 @@ sub module_generate_hash
my $b_last_block = hex2byte (substr $edata2, -$len_last_block);
my $b_n_1_block = hex2byte (substr(substr($edata2, -$tmp), 0, 32));
my $b_n_1_block = hex2byte (substr (substr ($edata2, -$tmp), 0, 32));
my $b_truncated_ticket_decrypted = $cbc->decrypt ($b_truncated_enc_ticket, $b_ke, $b_iv);
my $truncated_ticket_decrypted = byte2hex($b_truncated_ticket_decrypted);
my $truncated_ticket_decrypted = byte2hex ($b_truncated_ticket_decrypted);
my $check_correct = ((substr ($truncated_ticket_decrypted, 32, 4) eq "6381" && substr ($truncated_ticket_decrypted, 38, 2) eq "30") ||
(substr ($truncated_ticket_decrypted, 32, 4) eq "6382")) &&
@@ -117,11 +117,11 @@ sub module_generate_hash
my $b_n_1_decrypted = $cbc->decrypt ($b_n_1_block, $b_ke, $b_iv);
my $b_last_plain = substr $b_n_1_decrypted, 0, $len_last_block/2;
my $b_last_plain = substr $b_n_1_decrypted, 0, $len_last_block / 2;
$b_last_plain = $b_last_plain ^ $b_last_block;
my $omitted = substr $b_n_1_decrypted, -(16 - $len_last_block/2);
my $omitted = substr $b_n_1_decrypted, -(16 - $len_last_block / 2);
my $b_n_1 = $b_last_block . $omitted;
@@ -131,7 +131,7 @@ sub module_generate_hash
my $b_cleartext_ticket = $b_truncated_ticket_decrypted . $b_n_1 . $b_last_plain;
$cleartext_ticket = byte2hex($b_cleartext_ticket);
$cleartext_ticket = byte2hex ($b_cleartext_ticket);
}
else # validation failed
{
@@ -154,26 +154,26 @@ sub module_generate_hash
$cleartext_ticket = $nonce . $cleartext_ticket;
}
# we have what is required to compute checksum
$checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
$checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$checksum = substr $checksum, 0, 12;
}
my $len_cleartext_last_block = length($cleartext_ticket)%32;
my $len_cleartext_last_block = length ($cleartext_ticket) % 32;
my $cleartext_last_block = substr $cleartext_ticket, -$len_cleartext_last_block;
my $padding = pad(length($cleartext_ticket), 32);
my $padding = pad (length ($cleartext_ticket), 32);
my $b_cleartext_last_block_padded = hex2byte($cleartext_last_block . '0' x $padding);
my $b_cleartext_last_block_padded = hex2byte ($cleartext_last_block . '0' x $padding);
# we will encrypt until n-1 block (included)
my $truncated_cleartext_ticket = substr $cleartext_ticket, 0, -$len_cleartext_last_block;
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte ($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_enc_ticket_n_1_block= substr $b_truncated_enc_ticket, -16;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block/2;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block / 2;
# we now craft the new n-1 block
my $tmp = $b_enc_ticket_n_1_block ^ $b_cleartext_last_block_padded;
@@ -223,4 +223,4 @@ sub module_verify_hash
return ($new_hash, $word);
}
1;
1;
+20 -20
View File
@@ -60,9 +60,9 @@ sub module_generate_hash
my $b_seed = $pbkdf2->PBKDF2 ($mysalt, $word);
# we can precompute this
my $b_kerberos_nfolded = hex2byte('6b65726265726f737b9b5b2b93132b93');
my $b_kerberos_nfolded = hex2byte ('6b65726265726f737b9b5b2b93132b93');
my $b_iv = hex2byte('0' x 32);
my $b_iv = hex2byte ('0' x 32);
# 'key_bytes' will be the AES key used to generate 'ki' (for final hmac-sha1)
# and 'ke' (AES key to decrypt/encrypt the ticket)
@@ -71,10 +71,10 @@ sub module_generate_hash
# precomputed stuff
# nfold 0x0000000155 to 16 bytes
my $b_nfolded1 = hex2byte('5b582c160a5aa80556ab55aad5402ab5');
my $b_nfolded1 = hex2byte ('5b582c160a5aa80556ab55aad5402ab5');
# nfold 0x00000001aa to 16 bytes
my $b_nfolded2 = hex2byte('ae2c160b04ad5006ab55aad56a80355a');
my $b_nfolded2 = hex2byte ('ae2c160b04ad5006ab55aad56a80355a');
my $b_ki = $cbc->encrypt ($b_nfolded1, $b_key_bytes, $b_iv);
@@ -88,36 +88,36 @@ sub module_generate_hash
{
# Do CTS Decryption https://en.wikipedia.org/wiki/Ciphertext_stealing
# Decrypt n-1 block
my $len_last_block = length($enc_timestamp) % 32;
my $len_last_block = length ($enc_timestamp) % 32;
my $len_last_2_blocks = $len_last_block + 32;
my $b_n_1_block = hex2byte (substr($enc_timestamp, -$len_last_2_blocks, 32));
my $b_n_1_block = hex2byte (substr ($enc_timestamp, -$len_last_2_blocks, 32));
my $b_n_1_decrypted = $cbc->decrypt ($b_n_1_block, $b_ke, $b_iv);
# Pad the last block with last bytes from the decrypted n-1
my $b_padded_enc_ticket = hex2byte($enc_timestamp).(substr $b_n_1_decrypted, -(16 - $len_last_block/2));
my $b_padded_enc_ticket = hex2byte ($enc_timestamp) . (substr $b_n_1_decrypted, -(16 - $len_last_block / 2));
# Swap the last two blocks
my $b_cbc_enc_ticket = (substr $b_padded_enc_ticket, 0, -32).(substr $b_padded_enc_ticket, -16, 16).
my $b_cbc_enc_ticket = (substr $b_padded_enc_ticket, 0, -32) . (substr $b_padded_enc_ticket, -16, 16).
(substr $b_padded_enc_ticket, -32, 16);
# Decrypt and truncate
my $b_dec_ticket_padded = $cbc->decrypt ($b_cbc_enc_ticket, $b_ke, $b_iv);
my $b_cleartext_ticket = substr $b_dec_ticket_padded, 0, length($enc_timestamp)/2;
my $b_cleartext_ticket = substr $b_dec_ticket_padded, 0, length ($enc_timestamp) / 2;
$cleartext_ticket = byte2hex($b_cleartext_ticket);
$cleartext_ticket = byte2hex ($b_cleartext_ticket);
my $check_correct = ((substr ($b_cleartext_ticket, 22, 2) eq "20") &&
(substr ($b_cleartext_ticket, 36, 1) eq "Z"));
(substr ($b_cleartext_ticket, 36, 1) eq "Z"));
if ($check_correct == 1 && defined $checksum)
{
my $b_checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
my $b_checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$check_correct = ($checksum eq byte2hex(substr $b_checksum, 0, 12));
$check_correct = ($checksum eq byte2hex (substr $b_checksum, 0, 12));
}
}
@@ -129,27 +129,27 @@ sub module_generate_hash
'32313131363134323835355aa10502030c28a2';
# we have what is required to compute checksum
$checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
$checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$checksum = byte2hex(substr $checksum, 0, 12);
$checksum = byte2hex (substr $checksum, 0, 12);
}
# CTS Encrypt our new block
my $len_cleartext_last_block = length($cleartext_ticket)%32;
my $len_cleartext_last_block = length ($cleartext_ticket) % 32;
my $cleartext_last_block = substr $cleartext_ticket, -$len_cleartext_last_block;
my $padding = pad(length($cleartext_ticket), 32);
my $padding = pad (length ($cleartext_ticket), 32);
my $b_cleartext_last_block_padded = hex2byte($cleartext_last_block . '0' x $padding);
my $b_cleartext_last_block_padded = hex2byte ($cleartext_last_block . '0' x $padding);
# we will encrypt until n-1 block (included)
my $truncated_cleartext_ticket = substr $cleartext_ticket, 0, -$len_cleartext_last_block;
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte ($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_enc_ticket_n_1_block= substr $b_truncated_enc_ticket, -16;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block/2;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block / 2;
# we now craft the new n-1 block
my $tmp = $b_enc_ticket_n_1_block ^ $b_cleartext_last_block_padded;
+20 -20
View File
@@ -60,9 +60,9 @@ sub module_generate_hash
my $b_seed = $pbkdf2->PBKDF2 ($mysalt, $word);
# we can precompute this
my $b_kerberos_nfolded = hex2byte('6b65726265726f737b9b5b2b93132b93');
my $b_kerberos_nfolded = hex2byte ('6b65726265726f737b9b5b2b93132b93');
my $b_iv = hex2byte('0' x 32);
my $b_iv = hex2byte ('0' x 32);
# 'key_bytes' will be the AES key used to generate 'ki' (for final hmac-sha1)
# and 'ke' (AES key to decrypt/encrypt the ticket)
@@ -73,10 +73,10 @@ sub module_generate_hash
# precomputed stuff
# nfold 0x0000000155 to 16 bytes
my $b_nfolded1 = hex2byte('5b582c160a5aa80556ab55aad5402ab5');
my $b_nfolded1 = hex2byte ('5b582c160a5aa80556ab55aad5402ab5');
# nfold 0x00000001aa to 16 bytes
my $b_nfolded2 = hex2byte('ae2c160b04ad5006ab55aad56a80355a');
my $b_nfolded2 = hex2byte ('ae2c160b04ad5006ab55aad56a80355a');
my $b_ki = $cbc->encrypt ($b_nfolded1, $b_key_bytes, $b_iv);
@@ -93,36 +93,36 @@ sub module_generate_hash
{
# Do CTS Decryption https://en.wikipedia.org/wiki/Ciphertext_stealing
# Decrypt n-1 block
my $len_last_block = length($enc_timestamp) % 32;
my $len_last_block = length ($enc_timestamp) % 32;
my $len_last_2_blocks = $len_last_block + 32;
my $b_n_1_block = hex2byte (substr($enc_timestamp, -$len_last_2_blocks, 32));
my $b_n_1_block = hex2byte (substr ($enc_timestamp, -$len_last_2_blocks, 32));
my $b_n_1_decrypted = $cbc->decrypt ($b_n_1_block, $b_ke, $b_iv);
# Pad the last block with last bytes from the decrypted n-1
my $b_padded_enc_ticket = hex2byte($enc_timestamp).(substr $b_n_1_decrypted, -(16 - $len_last_block/2));
my $b_padded_enc_ticket = hex2byte ($enc_timestamp) . (substr $b_n_1_decrypted, -(16 - $len_last_block / 2));
# Swap the last two blocks
my $b_cbc_enc_ticket = (substr $b_padded_enc_ticket, 0, -32).(substr $b_padded_enc_ticket, -16, 16).
my $b_cbc_enc_ticket = (substr $b_padded_enc_ticket, 0, -32) . (substr $b_padded_enc_ticket, -16, 16).
(substr $b_padded_enc_ticket, -32, 16);
# Decrypt and truncate
my $b_dec_ticket_padded = $cbc->decrypt ($b_cbc_enc_ticket, $b_ke, $b_iv);
my $b_cleartext_ticket = substr $b_dec_ticket_padded, 0, length($enc_timestamp)/2;
my $b_cleartext_ticket = substr $b_dec_ticket_padded, 0, length ($enc_timestamp) / 2;
$cleartext_ticket = byte2hex($b_cleartext_ticket);
$cleartext_ticket = byte2hex ($b_cleartext_ticket);
my $check_correct = ((substr ($b_cleartext_ticket, 22, 2) eq "20") &&
(substr ($b_cleartext_ticket, 36, 1) eq "Z"));
(substr ($b_cleartext_ticket, 36, 1) eq "Z"));
if ($check_correct == 1 && defined $checksum)
{
my $b_checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
my $b_checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$check_correct = ($checksum eq byte2hex(substr $b_checksum, 0, 12));
$check_correct = ($checksum eq byte2hex (substr $b_checksum, 0, 12));
}
}
@@ -134,27 +134,27 @@ sub module_generate_hash
'32313131363134323835355aa10502030c28a2';
# we have what is required to compute checksum
$checksum = hmac_sha1 (hex2byte($cleartext_ticket), $b_ki);
$checksum = hmac_sha1 (hex2byte ($cleartext_ticket), $b_ki);
$checksum = byte2hex(substr $checksum, 0, 12);
$checksum = byte2hex (substr $checksum, 0, 12);
}
# CTS Encrypt our new block
my $len_cleartext_last_block = length($cleartext_ticket)%32;
my $len_cleartext_last_block = length ($cleartext_ticket) % 32;
my $cleartext_last_block = substr $cleartext_ticket, -$len_cleartext_last_block;
my $padding = pad(length($cleartext_ticket), 32);
my $padding = pad (length ($cleartext_ticket), 32);
my $b_cleartext_last_block_padded = hex2byte($cleartext_last_block . '0' x $padding);
my $b_cleartext_last_block_padded = hex2byte ($cleartext_last_block . '0' x $padding);
# we will encrypt until n-1 block (included)
my $truncated_cleartext_ticket = substr $cleartext_ticket, 0, -$len_cleartext_last_block;
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_truncated_enc_ticket = $cbc->encrypt (hex2byte ($truncated_cleartext_ticket), $b_ke, $b_iv);
my $b_enc_ticket_n_1_block= substr $b_truncated_enc_ticket, -16;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block/2;
my $b_enc_last_block = substr $b_enc_ticket_n_1_block, 0, $len_cleartext_last_block / 2;
# we now craft the new n-1 block
my $tmp = $b_enc_ticket_n_1_block ^ $b_cleartext_last_block_padded;
+1 -1
View File
@@ -80,7 +80,7 @@ sub module_verify_hash
$salt =~ s/\./\+/g;
$salt .= '==';
my $new_hash = module_generate_hash ($word, decode_base64($salt), $iter);
my $new_hash = module_generate_hash ($word, decode_base64 ($salt), $iter);
return ($new_hash, $word);
}
+1 -1
View File
@@ -80,7 +80,7 @@ sub module_verify_hash
$salt =~ s/\./\+/g;
$salt .= '==';
my $new_hash = module_generate_hash ($word, decode_base64($salt), $iter);
my $new_hash = module_generate_hash ($word, decode_base64 ($salt), $iter);
return ($new_hash, $word);
}
+1 -1
View File
@@ -80,7 +80,7 @@ sub module_verify_hash
$salt =~ s/\./\+/g;
$salt .= '==';
my $new_hash = module_generate_hash ($word, decode_base64($salt), $iter);
my $new_hash = module_generate_hash ($word, decode_base64 ($salt), $iter);
return ($new_hash, $word);
}
+5 -4
View File
@@ -22,13 +22,14 @@ sub module_generate_hash
$iter //= 1000;
my $digest = sha256($salt.$word);
my $digest = sha256 ($salt . $word);
for (my $i = 1; $i < $iter; $i++) {
$digest = sha256($digest);
for (my $i = 1; $i < $iter; $i++)
{
$digest = sha256 ($digest);
}
chomp($digest = encode_base64($digest));
chomp ($digest = encode_base64 ($digest));
my $hash = sprintf ("otm_sha256:%d:%s:%s", $iter, $salt, $digest);