Use key_from_input as originally intended

This commit is contained in:
Stephen Paul Weber 2013-02-24 18:10:46 -05:00
parent 778c83dbc3
commit 1ecb990a02
2 changed files with 6 additions and 24 deletions

View File

@ -1486,11 +1486,10 @@ class OpenPGP_SecretKeyPacket extends OpenPGP_PublicKeyPacket {
$this->symmetric_algorithm = $this->s2k_useage; $this->symmetric_algorithm = $this->s2k_useage;
} }
if($this->s2k_useage > 0) { if($this->s2k_useage > 0) {
// TODO: IV of the same length as cipher's block size
$this->encrypted_data = $this->input; // Rest of input is MPIs and checksum (encrypted) $this->encrypted_data = $this->input; // Rest of input is MPIs and checksum (encrypted)
} else { } else {
$this->data = $this->input; // Rest of input is MPIs and checksum $this->key_from_input();
$this->key_from_data(); $this->private_hash = $this->read_bytes(2); // TODO: Validate checksum?
} }
} }
@ -1502,22 +1501,10 @@ class OpenPGP_SecretKeyPacket extends OpenPGP_PublicKeyPacket {
17 => array('x'), // DSA 17 => array('x'), // DSA
); );
function key_from_data() { function key_from_input() {
if(!$this->data) return NULL; // Not decrypted yet
$this->input = $this->data;
foreach(self::$secret_key_fields[$this->algorithm] as $field) { foreach(self::$secret_key_fields[$this->algorithm] as $field) {
$this->key[$field] = $this->read_mpi(); $this->key[$field] = $this->read_mpi();
} }
// TODO: Validate checksum?
if($this->s2k_useage == 254) { // 20 octet sha1 hash
$this->private_hash = $this->read_bytes(20);
} else { // two-octet checksum
$this->private_hash = $this->read_bytes(2);
}
unset($this->input);
} }
function body() { function body() {

View File

@ -93,14 +93,9 @@ class OpenPGP_Crypt_AES_TripleDES {
$packet->s2k_useage = 0; $packet->s2k_useage = 0;
$packet->symmetric_algorithm = 0; $packet->symmetric_algorithm = 0;
$packet->encrypted_data = NULL; $packet->encrypted_data = NULL;
$packet->input = $material;
foreach($packet::$secret_key_fields[$packet->algorithm] as $f) { $packet->key_from_input();
$length = unpack('n', substr($material, 0, 2)); // in bits unset($packet->input);
$length = (int)floor((reset($length) + 7) / 8); // in bytes
$packet->key[$f] = substr($material, 2, $length);
$material = substr($material, 2 + $length);
}
return $packet; return $packet;
} }