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 <memory> 11 12 #include "base/macros.h" 13 #include "crypto/crypto_export.h" 14 15 namespace crypto { 16 17 // A wrapper to calculate secure hashes incrementally, allowing to 18 // be used when the full input is not known in advance. The end result will the 19 // same as if we have the full input in advance. 20 class CRYPTO_EXPORT SecureHash { 21 public: 22 enum Algorithm { 23 SHA256, 24 }; ~SecureHash()25 virtual ~SecureHash() {} 26 27 static std::unique_ptr<SecureHash> Create(Algorithm type); 28 29 virtual void Update(const void* input, size_t len) = 0; 30 virtual void Finish(void* output, size_t len) = 0; 31 virtual size_t GetHashLength() const = 0; 32 33 // Create a clone of this SecureHash. The returned clone and this both 34 // represent the same hash state. But from this point on, calling 35 // Update()/Finish() on either doesn't affect the state of the other. 36 virtual std::unique_ptr<SecureHash> Clone() const = 0; 37 38 protected: SecureHash()39 SecureHash() {} 40 41 private: 42 DISALLOW_COPY_AND_ASSIGN(SecureHash); 43 }; 44 45 } // namespace crypto 46 47 #endif // CRYPTO_SECURE_HASH_H_ 48