secure_hash.h 1.3 KB

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