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

Side by Side Diff: crypto/hmac.cc

Issue 2230873002: crypto: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 | « no previous file | crypto/nss_util.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 <openssl/hmac.h> 7 #include <openssl/hmac.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "crypto/openssl_util.h" 14 #include "crypto/openssl_util.h"
15 #include "crypto/secure_util.h" 15 #include "crypto/secure_util.h"
16 #include "crypto/symmetric_key.h" 16 #include "crypto/symmetric_key.h"
17 17
18 namespace crypto { 18 namespace crypto {
19 19
20 HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg), initialized_(false) { 20 HMAC::HMAC(HashAlgorithm hash_alg) : hash_alg_(hash_alg), initialized_(false) {
21 // Only SHA-1 and SHA-256 hash algorithms are supported now. 21 // Only SHA-1 and SHA-256 hash algorithms are supported now.
22 DCHECK(hash_alg_ == SHA1 || hash_alg_ == SHA256); 22 DCHECK(hash_alg_ == SHA1 || hash_alg_ == SHA256);
23 } 23 }
24 24
25 HMAC::~HMAC() { 25 HMAC::~HMAC() {
26 // Zero out key copy. 26 // Zero out key copy.
27 key_.assign(key_.size(), 0); 27 key_.assign(key_.size(), 0);
28 STLClearObject(&key_); 28 base::STLClearObject(&key_);
29 } 29 }
30 30
31 size_t HMAC::DigestLength() const { 31 size_t HMAC::DigestLength() const {
32 switch (hash_alg_) { 32 switch (hash_alg_) {
33 case SHA1: 33 case SHA1:
34 return 20; 34 return 20;
35 case SHA256: 35 case SHA256:
36 return 32; 36 return 32;
37 default: 37 default:
38 NOTREACHED(); 38 NOTREACHED();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 std::unique_ptr<unsigned char[]> computed_digest( 84 std::unique_ptr<unsigned char[]> computed_digest(
85 new unsigned char[digest_length]); 85 new unsigned char[digest_length]);
86 if (!Sign(data, computed_digest.get(), digest_length)) 86 if (!Sign(data, computed_digest.get(), digest_length))
87 return false; 87 return false;
88 88
89 return SecureMemEqual(digest.data(), computed_digest.get(), 89 return SecureMemEqual(digest.data(), computed_digest.get(),
90 std::min(digest.size(), digest_length)); 90 std::min(digest.size(), digest_length));
91 } 91 }
92 92
93 } // namespace crypto 93 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | crypto/nss_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698