Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: crypto/hmac.h

Issue 8949056: This adds support for encrypted ONC import (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed merge Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_chromeos.cc ('k') | crypto/hmac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 10 #pragma once
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/string_piece.h" 15 #include "base/string_piece.h"
16 #include "crypto/crypto_export.h" 16 #include "crypto/crypto_export.h"
17 17
18 namespace crypto { 18 namespace crypto {
19 19
20 // Simplify the interface and reduce includes by abstracting out the internals. 20 // Simplify the interface and reduce includes by abstracting out the internals.
21 struct HMACPlatformData; 21 struct HMACPlatformData;
22 class SymmetricKey;
22 23
23 class CRYPTO_EXPORT HMAC { 24 class CRYPTO_EXPORT HMAC {
24 public: 25 public:
25 // The set of supported hash functions. Extend as required. 26 // The set of supported hash functions. Extend as required.
26 enum HashAlgorithm { 27 enum HashAlgorithm {
27 SHA1, 28 SHA1,
28 SHA256, 29 SHA256,
29 }; 30 };
30 31
31 explicit HMAC(HashAlgorithm hash_alg); 32 explicit HMAC(HashAlgorithm hash_alg);
32 ~HMAC(); 33 ~HMAC();
33 34
34 // Returns the length of digest that this HMAC will create. 35 // Returns the length of digest that this HMAC will create.
35 size_t DigestLength() const; 36 size_t DigestLength() const;
36 37
37 // TODO(abarth): Add a PreferredKeyLength() member function. 38 // TODO(abarth): Add a PreferredKeyLength() member function.
38 39
39 // Initializes this instance using |key| of the length |key_length|. Call Init 40 // Initializes this instance using |key| of the length |key_length|. Call Init
40 // only once. It returns false on the second or later calls. 41 // only once. It returns false on the second or later calls.
41 // TODO(abarth): key_length should be a size_t. 42 // TODO(abarth): key_length should be a size_t.
42 bool Init(const unsigned char* key, int key_length) WARN_UNUSED_RESULT; 43 bool Init(const unsigned char* key, int key_length) WARN_UNUSED_RESULT;
43 44
45 // Initializes this instance using |key|. Call Init
46 // only once. It returns false on the second or later calls.
47 bool Init(SymmetricKey* key) WARN_UNUSED_RESULT;
48
44 // Initializes this instance using |key|. Call Init only once. It returns 49 // Initializes this instance using |key|. Call Init only once. It returns
45 // false on the second or later calls. 50 // false on the second or later calls.
46 bool Init(const base::StringPiece& key) WARN_UNUSED_RESULT { 51 bool Init(const base::StringPiece& key) WARN_UNUSED_RESULT {
47 return Init(reinterpret_cast<const unsigned char*>(key.data()), 52 return Init(reinterpret_cast<const unsigned char*>(key.data()),
48 static_cast<int>(key.size())); 53 static_cast<int>(key.size()));
49 } 54 }
50 55
51 // Calculates the HMAC for the message in |data| using the algorithm supplied 56 // Calculates the HMAC for the message in |data| using the algorithm supplied
52 // to the constructor and the key supplied to the Init method. The HMAC is 57 // to the constructor and the key supplied to the Init method. The HMAC is
53 // returned in |digest|, which has |digest_length| bytes of storage available. 58 // returned in |digest|, which has |digest_length| bytes of storage available.
(...skipping 20 matching lines...) Expand all
74 private: 79 private:
75 HashAlgorithm hash_alg_; 80 HashAlgorithm hash_alg_;
76 scoped_ptr<HMACPlatformData> plat_; 81 scoped_ptr<HMACPlatformData> plat_;
77 82
78 DISALLOW_COPY_AND_ASSIGN(HMAC); 83 DISALLOW_COPY_AND_ASSIGN(HMAC);
79 }; 84 };
80 85
81 } // namespace crypto 86 } // namespace crypto
82 87
83 #endif // CRYPTO_HMAC_H_ 88 #endif // CRYPTO_HMAC_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_chromeos.cc ('k') | crypto/hmac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698