AU: Verify source rootfs/kernel hashes before applying delta.

New style full updates will not send the old rootfs hash so no check takes
place.

BUG=7562
TEST=unit tests, gmerged on device and tested with good/bad source partition

Change-Id: I65b28bf57110e4d87472d4aea59121878cde24b0

Review URL: http://codereview.chromium.org/3712003
diff --git a/delta_performer.h b/delta_performer.h
index 7394f94..0e3cb93 100644
--- a/delta_performer.h
+++ b/delta_performer.h
@@ -34,7 +34,9 @@
         next_operation_num_(0),
         buffer_offset_(0),
         last_updated_buffer_offset_(kuint64max),
-        block_size_(0) {}
+        block_size_(0),
+        current_kernel_hash_(NULL),
+        current_rootfs_hash_(NULL) {}
 
   // Opens the kernel. Should be called before or after Open(), but before
   // Write(). The kernel file will be close()d when Close() is called.
@@ -94,6 +96,14 @@
   // success, false otherwise.
   static bool ResetUpdateProgress(PrefsInterface* prefs, bool quick);
 
+  void set_current_kernel_hash(const std::vector<char>* hash) {
+    current_kernel_hash_ = hash;
+  }
+
+  void set_current_rootfs_hash(const std::vector<char>* hash) {
+    current_rootfs_hash_ = hash;
+  }
+
  private:
   friend class DeltaPerformerTest;
   FRIEND_TEST(DeltaPerformerTest, IsIdempotentOperationTest);
@@ -101,6 +111,12 @@
   static bool IsIdempotentOperation(
       const DeltaArchiveManifest_InstallOperation& op);
 
+  // Verifies that the expected source partition hashes (if present) match the
+  // hashes for the current partitions. Returns true if there're no expected
+  // hashes in the payload (e.g., if it's a new-style full update) or if the
+  // hashes match; returns false otherwise.
+  bool VerifySourcePartitions();
+
   // Returns true if enough of the delta file has been passed via Write()
   // to be able to perform a given install operation.
   bool CanPerformInstallOperation(
@@ -181,6 +197,11 @@
   // Signatures message blob extracted directly from the payload.
   std::vector<char> signatures_message_data_;
 
+  // Hashes for the current partitions to be used for source partition
+  // verification.
+  const std::vector<char>* current_kernel_hash_;
+  const std::vector<char>* current_rootfs_hash_;
+
   DISALLOW_COPY_AND_ASSIGN(DeltaPerformer);
 };