OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Utility class for calculating the HMAC for a given message. We currently | 5 // Utility class for calculating the HMAC for a given message. We currently |
6 // only support SHA1 for the hash algorithm, but this can be extended easily. | 6 // only support SHA1 for the hash algorithm, but this can be extended easily. |
7 | 7 |
8 #ifndef CRYPTO_HMAC_H_ | 8 #ifndef CRYPTO_HMAC_H_ |
9 #define CRYPTO_HMAC_H_ | 9 #define CRYPTO_HMAC_H_ |
10 | 10 |
11 #include <stddef.h> | 11 #include <stddef.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
| 14 #include <vector> |
14 | 15 |
15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
18 #include "crypto/crypto_export.h" | 19 #include "crypto/crypto_export.h" |
19 | 20 |
20 namespace crypto { | 21 namespace crypto { |
21 | 22 |
22 // Simplify the interface and reduce includes by abstracting out the internals. | 23 // Simplify the interface and reduce includes by abstracting out the internals. |
23 struct HMACPlatformData; | |
24 class SymmetricKey; | 24 class SymmetricKey; |
25 | 25 |
26 class CRYPTO_EXPORT HMAC { | 26 class CRYPTO_EXPORT HMAC { |
27 public: | 27 public: |
28 // The set of supported hash functions. Extend as required. | 28 // The set of supported hash functions. Extend as required. |
29 enum HashAlgorithm { | 29 enum HashAlgorithm { |
30 SHA1, | 30 SHA1, |
31 SHA256, | 31 SHA256, |
32 }; | 32 }; |
33 | 33 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const base::StringPiece& digest) const WARN_UNUSED_RESULT; | 79 const base::StringPiece& digest) const WARN_UNUSED_RESULT; |
80 | 80 |
81 // Verifies a truncated HMAC, behaving identical to Verify(), except | 81 // Verifies a truncated HMAC, behaving identical to Verify(), except |
82 // that |digest| is allowed to be smaller than |DigestLength()|. | 82 // that |digest| is allowed to be smaller than |DigestLength()|. |
83 bool VerifyTruncated( | 83 bool VerifyTruncated( |
84 const base::StringPiece& data, | 84 const base::StringPiece& data, |
85 const base::StringPiece& digest) const WARN_UNUSED_RESULT; | 85 const base::StringPiece& digest) const WARN_UNUSED_RESULT; |
86 | 86 |
87 private: | 87 private: |
88 HashAlgorithm hash_alg_; | 88 HashAlgorithm hash_alg_; |
89 std::unique_ptr<HMACPlatformData> plat_; | 89 bool initialized_; |
| 90 std::vector<unsigned char> key_; |
90 | 91 |
91 DISALLOW_COPY_AND_ASSIGN(HMAC); | 92 DISALLOW_COPY_AND_ASSIGN(HMAC); |
92 }; | 93 }; |
93 | 94 |
94 } // namespace crypto | 95 } // namespace crypto |
95 | 96 |
96 #endif // CRYPTO_HMAC_H_ | 97 #endif // CRYPTO_HMAC_H_ |
OLD | NEW |