Whitespace and proper padAmount
This commit is contained in:
parent
04b89decd1
commit
3afd401688
@ -104,33 +104,33 @@ class OpenPGP_Crypt_AES_TripleDES {
|
|||||||
if(!$cipher) return NULL;
|
if(!$cipher) return NULL;
|
||||||
$cipher->setKey($key);
|
$cipher->setKey($key);
|
||||||
|
|
||||||
$padAmount = $key_block_bytes - (strlen($epacket->data) % $key_block_bytes);
|
|
||||||
|
|
||||||
if($epacket instanceof OpenPGP_IntegrityProtectedDataPacket) {
|
if($epacket instanceof OpenPGP_IntegrityProtectedDataPacket) {
|
||||||
$data = substr($cipher->decrypt($epacket->data . str_repeat("\0", $padAmount)), 0, strlen($epacket->data));
|
$padAmount = $key_block_bytes - (strlen($epacket->data) % $key_block_bytes);
|
||||||
$prefix = substr($data, 0, $key_block_bytes + 2);
|
$data = substr($cipher->decrypt($epacket->data . str_repeat("\0", $padAmount)), 0, strlen($epacket->data));
|
||||||
$mdc = substr(substr($data, -22, 22), 2);
|
$prefix = substr($data, 0, $key_block_bytes + 2);
|
||||||
$data = substr($data, $key_block_bytes + 2, -22);
|
$mdc = substr(substr($data, -22, 22), 2);
|
||||||
|
$data = substr($data, $key_block_bytes + 2, -22);
|
||||||
|
|
||||||
$mkMDC = hash("sha1", $prefix . $data . "\xD3\x14", true);
|
$mkMDC = hash("sha1", $prefix . $data . "\xD3\x14", true);
|
||||||
if($mkMDC !== $mdc) return false;
|
if($mkMDC !== $mdc) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$msg = OpenPGP_Message::parse($data);
|
$msg = OpenPGP_Message::parse($data);
|
||||||
} catch (Exception $ex) { $msg = NULL; }
|
} catch (Exception $ex) { $msg = NULL; }
|
||||||
if($msg) return $msg; /* Otherwise keep trying */
|
if($msg) return $msg; /* Otherwise keep trying */
|
||||||
} else {
|
} else {
|
||||||
// No MDC mean decrypt with resync
|
// No MDC mean decrypt with resync
|
||||||
$iv = substr($epacket->data, 2, $key_block_bytes);
|
$iv = substr($epacket->data, 2, $key_block_bytes);
|
||||||
$edata = substr($epacket->data, $key_block_bytes + 2);
|
$edata = substr($epacket->data, $key_block_bytes + 2);
|
||||||
|
$padAmount = $key_block_bytes - (strlen($edata) % $key_block_bytes);
|
||||||
|
|
||||||
$cipher->setIV($iv);
|
$cipher->setIV($iv);
|
||||||
$data = substr($cipher->decrypt($edata . str_repeat("\0", $padAmount)), 0, strlen($edata));
|
$data = substr($cipher->decrypt($edata . str_repeat("\0", $padAmount)), 0, strlen($edata));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$msg = OpenPGP_Message::parse($data);
|
$msg = OpenPGP_Message::parse($data);
|
||||||
} catch (Exception $ex) { $msg = NULL; }
|
} catch (Exception $ex) { $msg = NULL; }
|
||||||
if($msg) return $msg; /* Otherwise keep trying */
|
if($msg) return $msg; /* Otherwise keep trying */
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL; /* Failed */
|
return NULL; /* Failed */
|
||||||
|
Loading…
Reference in New Issue
Block a user