• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
19 class CRYPTO_EXPORT SecureHash {
20  public:
21   enum Algorithm {
22     SHA256,
23   };
~SecureHash()24   virtual ~SecureHash() {}
25 
26   static std::unique_ptr<SecureHash> Create(Algorithm type);
27 
28   virtual void Update(const void* input, size_t len) = 0;
29   virtual void Finish(void* output, size_t len) = 0;
30   virtual size_t GetHashLength() const = 0;
31 
32   // Create a clone of this SecureHash. The returned clone and this both
33   // represent the same hash state. But from this point on, calling
34   // Update()/Finish() on either doesn't affect the state of the other.
35   virtual std::unique_ptr<SecureHash> Clone() const = 0;
36 
37  protected:
SecureHash()38   SecureHash() {}
39 
40  private:
41   DISALLOW_COPY_AND_ASSIGN(SecureHash);
42 };
43 
44 }  // namespace crypto
45 
46 #endif  // CRYPTO_SECURE_HASH_H_
47