m25400.pm should no longer recalculate $u

pull/2877/head
Your Name 3 years ago
parent 4934e92cda
commit c91b61e237

@ -171,32 +171,41 @@ sub module_generate_hash
################ USER PASSWORD #################
my $res = pdf_compute_encryption_key_user($word, $padding, $id, $u, $o, $P, $V, $R, $enc);
my $digest = md5 ($padding . pack ("H*", $id));
# do not change $u if it exists, keep this the same, as we don't know the user password,
# we cannot calculate this part of the hash again
if("".$u eq "0000000000000000000000000000000000000000000000000000000000000000")
{
my $res = pdf_compute_encryption_key_user($word, $padding, $id, $u, $o, $P, $V, $R, $enc);
my $m = Crypt::RC4->new ($res);
$u = $m->RC4 ($digest);
my $digest = md5 ($padding . pack ("H*", $id));
my @ress = split "", $res;
my $m = Crypt::RC4->new ($res);
$u = $m->RC4 ($digest);
#do xor of rc4 19 times
for (my $x = 1; $x <= 19; $x++)
{
my @xor;
my @ress = split "", $res;
for (my $i = 0; $i < 16; $i++)
#do xor of rc4 19 times
for (my $x = 1; $x <= 19; $x++)
{
$xor[$i] = chr (ord ($ress[$i]) ^ $x);
}
my @xor;
for (my $i = 0; $i < 16; $i++)
{
$xor[$i] = chr (ord ($ress[$i]) ^ $x);
}
my $s = join ("", @xor);
my $s = join ("", @xor);
my $m2 = Crypt::RC4->new ($s);
my $m2 = Crypt::RC4->new ($s);
$u = $m2->RC4 ($u);
$u = $m2->RC4 ($u);
}
$u .= substr (pack ("H*", $u_save), 16, 16);
}
else
{
$u = pack("H*", $u)
}
################ OWNER PASSWORD #################
my $o_key = pdf_compute_encryption_key_owner($word, $padding, $id, $u, $o, $P, $V, $R, $enc);
@ -228,14 +237,11 @@ sub module_generate_hash
}
#printf("\$u = %s\n", unpack ("H*", $u));
$u .= substr (pack ("H*", $u_save), 16, 16);
#printf("\$o = %s\n", unpack ("H*", $o));
#printf("\$u = %s\n", unpack ("H*", $u));
my $hash = sprintf ('$pdf$%d*%d*128*%d*%d*16*%s*32*%s*32*%s', $V, $R, $P, $enc, $id, unpack ("H*", $u), unpack ("H*", $o));
print("hash\n".$hash."\n");
return $hash;
}

Loading…
Cancel
Save