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

Side by Side Diff: crypto/hmac.cc

Issue 2934893003: Deleted redundant SymmetricKey::GetRawKey(). (Closed)
Patch Set: Rebased to fix conflict with ToT. Created 3 years, 6 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
« no previous file with comments | « components/sync/base/nigori_unittest.cc ('k') | crypto/symmetric_key.h » ('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) 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 #include "crypto/hmac.h" 5 #include "crypto/hmac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 bool HMAC::Init(const unsigned char* key, size_t key_length) { 44 bool HMAC::Init(const unsigned char* key, size_t key_length) {
45 // Init must not be called more than once on the same HMAC object. 45 // Init must not be called more than once on the same HMAC object.
46 DCHECK(!initialized_); 46 DCHECK(!initialized_);
47 initialized_ = true; 47 initialized_ = true;
48 key_.assign(key, key + key_length); 48 key_.assign(key, key + key_length);
49 return true; 49 return true;
50 } 50 }
51 51
52 bool HMAC::Init(const SymmetricKey* key) { 52 bool HMAC::Init(const SymmetricKey* key) {
53 std::string raw_key; 53 return Init(key->key());
54 bool result = key->GetRawKey(&raw_key) && Init(raw_key);
55 // Zero out key copy. This might get optimized away, but one can hope.
56 // Using std::string to store key info at all is a larger problem.
57 std::fill(raw_key.begin(), raw_key.end(), 0);
58 return result;
59 } 54 }
60 55
61 bool HMAC::Sign(const base::StringPiece& data, 56 bool HMAC::Sign(const base::StringPiece& data,
62 unsigned char* digest, 57 unsigned char* digest,
63 size_t digest_length) const { 58 size_t digest_length) const {
64 DCHECK(initialized_); 59 DCHECK(initialized_);
65 60
66 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length); 61 ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> result(digest, digest_length);
67 return !!::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), key_.data(), 62 return !!::HMAC(hash_alg_ == SHA1 ? EVP_sha1() : EVP_sha256(), key_.data(),
68 key_.size(), 63 key_.size(),
(...skipping 16 matching lines...) Expand all
85 std::unique_ptr<unsigned char[]> computed_digest( 80 std::unique_ptr<unsigned char[]> computed_digest(
86 new unsigned char[digest_length]); 81 new unsigned char[digest_length]);
87 if (!Sign(data, computed_digest.get(), digest_length)) 82 if (!Sign(data, computed_digest.get(), digest_length))
88 return false; 83 return false;
89 84
90 return SecureMemEqual(digest.data(), computed_digest.get(), 85 return SecureMemEqual(digest.data(), computed_digest.get(),
91 std::min(digest.size(), digest_length)); 86 std::min(digest.size(), digest_length));
92 } 87 }
93 88
94 } // namespace crypto 89 } // namespace crypto
OLDNEW
« no previous file with comments | « components/sync/base/nigori_unittest.cc ('k') | crypto/symmetric_key.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698