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

Side by Side Diff: crypto/hmac.cc

Issue 8949056: This adds support for encrypted ONC import (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handling decryption errors better 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
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 #include "crypto/hmac.h" 5 #include "crypto/hmac.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "crypto/secure_util.h" 10 #include "crypto/secure_util.h"
11 #include "crypto/symmetric_key.h"
11 12
12 namespace crypto { 13 namespace crypto {
13 14
15 bool HMAC::Init(const SymmetricKey& key) {
16 std::string raw_key;
17 key.GetRawKey(&raw_key);
Ryan Sleevi 2012/01/04 01:33:43 GetRawKey can fail (eg: non-exportable) bool resu
18 bool result = Init(raw_key);
19 // Zero out key copy.
20 raw_key.assign(raw_key.length(), std::string::value_type());
21 raw_key.clear();
22 raw_key.reserve(0);
Ryan Sleevi 2012/01/04 01:33:43 Unfortunately, it's possible (and in practice, lik
Greg Spencer (Chromium) 2012/01/05 22:18:03 I took this code from the HMAC destructor on mac,
Ryan Sleevi 2012/01/05 22:34:11 std::fill() just gets turned into a memset(), due
23 return result;
24 }
25
14 size_t HMAC::DigestLength() const { 26 size_t HMAC::DigestLength() const {
15 switch (hash_alg_) { 27 switch (hash_alg_) {
16 case SHA1: 28 case SHA1:
17 return 20; 29 return 20;
18 case SHA256: 30 case SHA256:
19 return 32; 31 return 32;
20 default: 32 default:
21 NOTREACHED(); 33 NOTREACHED();
22 return 0; 34 return 0;
23 } 35 }
(...skipping 14 matching lines...) Expand all
38 scoped_array<unsigned char> computed_digest( 50 scoped_array<unsigned char> computed_digest(
39 new unsigned char[digest_length]); 51 new unsigned char[digest_length]);
40 if (!Sign(data, computed_digest.get(), static_cast<int>(digest_length))) 52 if (!Sign(data, computed_digest.get(), static_cast<int>(digest_length)))
41 return false; 53 return false;
42 54
43 return SecureMemEqual(digest.data(), computed_digest.get(), 55 return SecureMemEqual(digest.data(), computed_digest.get(),
44 std::min(digest.size(), digest_length)); 56 std::min(digest.size(), digest_length));
45 } 57 }
46 58
47 } // namespace crypto 59 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698