1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CRYPTO_SECURE_HASH_H_ 6 #define CRYPTO_SECURE_HASH_H_ 7 8 #include <stddef.h> 9 10 #include "base/macros.h" 11 #include "crypto/crypto_export.h" 12 13 namespace base { 14 class Pickle; 15 class PickleIterator; 16 } 17 18 namespace crypto { 19 20 // A wrapper to calculate secure hashes incrementally, allowing to 21 // be used when the full input is not known in advance. 22 class CRYPTO_EXPORT SecureHash { 23 public: 24 enum Algorithm { 25 SHA256, 26 }; ~SecureHash()27 virtual ~SecureHash() {} 28 29 static SecureHash* Create(Algorithm type); 30 31 virtual void Update(const void* input, size_t len) = 0; 32 virtual void Finish(void* output, size_t len) = 0; 33 34 // Serialize the context, so it can be restored at a later time. 35 // |pickle| will contain the serialized data. 36 // Returns whether or not |pickle| was filled. 37 virtual bool Serialize(base::Pickle* pickle) = 0; 38 39 // Restore the context that was saved earlier. 40 // |data_iterator| allows this to be used as part of a larger pickle. 41 // |pickle| holds the saved data. 42 // Returns success or failure. 43 virtual bool Deserialize(base::PickleIterator* data_iterator) = 0; 44 45 protected: SecureHash()46 SecureHash() {} 47 48 private: 49 DISALLOW_COPY_AND_ASSIGN(SecureHash); 50 }; 51 52 } // namespace crypto 53 54 #endif // CRYPTO_SECURE_HASH_H_ 55