1 // Copyright 2012 The Chromium Authors 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 namespace crypto { 11 12 // A wrapper to calculate secure hashes incrementally, allowing to 13 // be used when the full input is not known in advance. 14 class SecureHash { 15 public: 16 enum Algorithm { 17 SHA256, 18 }; 19 20 SecureHash(const SecureHash&) = delete; 21 SecureHash& operator=(const SecureHash&) = delete; 22 ~SecureHash()23 virtual ~SecureHash() {} 24 25 static SecureHash* Create(Algorithm type); 26 27 virtual void Update(const void* input, size_t len) = 0; 28 virtual void Finish(void* output, size_t len) = 0; 29 virtual size_t GetHashLength() const = 0; 30 31 // Create a clone of this SecureHash. The returned clone and this both 32 // represent the same hash state. But from this point on, calling 33 // Update()/Finish() on either doesn't affect the state of the other. 34 virtual SecureHash* Clone() const = 0; 35 36 protected: SecureHash()37 SecureHash() {} 38 }; 39 40 } // namespace crypto 41 42 #endif // CRYPTO_SECURE_HASH_H_ 43