From 1ecb990a02739e618c46334004cb766d78112e11 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 24 Feb 2013 18:10:46 -0500 Subject: [PATCH] Use key_from_input as originally intended --- lib/openpgp.php | 19 +++---------------- lib/openpgp_crypt_aes_tripledes.php | 11 +++-------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/lib/openpgp.php b/lib/openpgp.php index 5c090f4..38667a7 100644 --- a/lib/openpgp.php +++ b/lib/openpgp.php @@ -1486,11 +1486,10 @@ class OpenPGP_SecretKeyPacket extends OpenPGP_PublicKeyPacket { $this->symmetric_algorithm = $this->s2k_useage; } 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) } else { - $this->data = $this->input; // Rest of input is MPIs and checksum - $this->key_from_data(); + $this->key_from_input(); + $this->private_hash = $this->read_bytes(2); // TODO: Validate checksum? } } @@ -1502,22 +1501,10 @@ class OpenPGP_SecretKeyPacket extends OpenPGP_PublicKeyPacket { 17 => array('x'), // DSA ); - function key_from_data() { - if(!$this->data) return NULL; // Not decrypted yet - $this->input = $this->data; - + function key_from_input() { foreach(self::$secret_key_fields[$this->algorithm] as $field) { $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() { diff --git a/lib/openpgp_crypt_aes_tripledes.php b/lib/openpgp_crypt_aes_tripledes.php index c889d7e..6f9eb54 100644 --- a/lib/openpgp_crypt_aes_tripledes.php +++ b/lib/openpgp_crypt_aes_tripledes.php @@ -93,14 +93,9 @@ class OpenPGP_Crypt_AES_TripleDES { $packet->s2k_useage = 0; $packet->symmetric_algorithm = 0; $packet->encrypted_data = NULL; - - foreach($packet::$secret_key_fields[$packet->algorithm] as $f) { - $length = unpack('n', substr($material, 0, 2)); // in bits - $length = (int)floor((reset($length) + 7) / 8); // in bytes - $packet->key[$f] = substr($material, 2, $length); - $material = substr($material, 2 + $length); - } - + $packet->input = $material; + $packet->key_from_input(); + unset($packet->input); return $packet; }