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

Side by Side Diff: crypto/hmac.cc

Issue 1870233002: Convert crypto to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 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 | « crypto/hmac.h ('k') | crypto/hmac_nss.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) 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 <memory>
10 11
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "crypto/secure_util.h" 13 #include "crypto/secure_util.h"
13 #include "crypto/symmetric_key.h" 14 #include "crypto/symmetric_key.h"
14 15
15 namespace crypto { 16 namespace crypto {
16 17
17 bool HMAC::Init(SymmetricKey* key) { 18 bool HMAC::Init(SymmetricKey* key) {
18 std::string raw_key; 19 std::string raw_key;
19 bool result = key->GetRawKey(&raw_key) && Init(raw_key); 20 bool result = key->GetRawKey(&raw_key) && Init(raw_key);
(...skipping 20 matching lines...) Expand all
40 if (digest.size() != DigestLength()) 41 if (digest.size() != DigestLength())
41 return false; 42 return false;
42 return VerifyTruncated(data, digest); 43 return VerifyTruncated(data, digest);
43 } 44 }
44 45
45 bool HMAC::VerifyTruncated(const base::StringPiece& data, 46 bool HMAC::VerifyTruncated(const base::StringPiece& data,
46 const base::StringPiece& digest) const { 47 const base::StringPiece& digest) const {
47 if (digest.empty()) 48 if (digest.empty())
48 return false; 49 return false;
49 size_t digest_length = DigestLength(); 50 size_t digest_length = DigestLength();
50 scoped_ptr<unsigned char[]> computed_digest( 51 std::unique_ptr<unsigned char[]> computed_digest(
51 new unsigned char[digest_length]); 52 new unsigned char[digest_length]);
52 if (!Sign(data, computed_digest.get(), digest_length)) 53 if (!Sign(data, computed_digest.get(), digest_length))
53 return false; 54 return false;
54 55
55 return SecureMemEqual(digest.data(), computed_digest.get(), 56 return SecureMemEqual(digest.data(), computed_digest.get(),
56 std::min(digest.size(), digest_length)); 57 std::min(digest.size(), digest_length));
57 } 58 }
58 59
59 } // namespace crypto 60 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/hmac.h ('k') | crypto/hmac_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698