AU: Sign delta payloads

- Change .proto to have explicit offset/length of signature. I was
  hoping the length could be kept out of the proto, but it needs to go
  in. The way we cheat and keep the signature in the file is to have a
  dummer install operation at the end that will cause old clients to
  write the signature data to nowhere.

- Change delta generator to take an optional private key, which if
  present will cause the payload to be signed

- Cleanup Omaha hash calculator, which should be renamed to SHA1 hash
  calculator, and allow export of the non-base64 encoded SHA1 result.

- Note: signatures are not yet checked. That will come in a future CL.

BUG=5662
TEST=unittests

Review URL: http://codereview.chromium.org/3132033
diff --git a/omaha_hash_calculator.h b/omaha_hash_calculator.h
index 900da80..5a666b6 100644
--- a/omaha_hash_calculator.h
+++ b/omaha_hash_calculator.h
@@ -9,6 +9,7 @@
 #include <vector>
 #include <openssl/sha.h>
 #include "base/basictypes.h"
+#include "base/logging.h"
 
 // Omaha uses base64 encoded SHA-1 as the hash. This class provides a simple
 // wrapper around OpenSSL providing such a formatted hash of data passed in.
@@ -20,23 +21,28 @@
 
 class OmahaHashCalculator {
  public:
-   OmahaHashCalculator();
+  OmahaHashCalculator();
 
   // Update is called with all of the data that should be hashed in order.
-  // Update will read |length| bytes of |data|
-   void Update(const char* data, size_t length);
+  // Update will read |length| bytes of |data|.
+  // Returns true on success.
+  bool Update(const char* data, size_t length);
 
   // Call Finalize() when all data has been passed in. This method tells
   // OpenSSl that no more data will come in and base64 encodes the resulting
   // hash.
-   void Finalize();
+  // Returns true on success.
+  bool Finalize();
 
   // Gets the hash. Finalize() must have been called.
   const std::string& hash() const {
-    CHECK(!hash_.empty()) << "Call Finalize() first";
+    DCHECK(!hash_.empty()) << "Call Finalize() first";
     return hash_;
   }
 
+  static bool RawHashOfData(const std::vector<char>& data,
+                            std::vector<char>* out_hash);
+
   // Used by tests
   static std::string OmahaHashOfBytes(const void* data, size_t length);
   static std::string OmahaHashOfString(const std::string& str);
@@ -47,6 +53,9 @@
   // non-empty when Finalize is called.
   std::string hash_;
 
+  // Init success
+  bool valid_;
+
   // The hash state used by OpenSSL
   SHA_CTX ctx_;
   DISALLOW_COPY_AND_ASSIGN(OmahaHashCalculator);
@@ -54,4 +63,4 @@
 
 }  // namespace chromeos_update_engine
 
-#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__
\ No newline at end of file
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_OMAHA_HASH_CALCULATOR_H__