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

Side by Side Diff: crypto/hmac_mac.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed changes to rand_util_unittest Created 9 years, 7 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 | « 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) 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 <CommonCrypto/CommonHMAC.h> 7 #include <CommonCrypto/CommonHMAC.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 HMAC::~HMAC() { 35 HMAC::~HMAC() {
36 // Zero out key copy. 36 // Zero out key copy.
37 plat_->key_.assign(plat_->key_.length(), std::string::value_type()); 37 plat_->key_.assign(plat_->key_.length(), std::string::value_type());
38 plat_->key_.clear(); 38 plat_->key_.clear();
39 plat_->key_.reserve(0); 39 plat_->key_.reserve(0);
40 } 40 }
41 41
42 bool HMAC::Sign(const std::string& data, 42 bool HMAC::Sign(const std::string& data,
43 unsigned char* digest, 43 unsigned char* digest,
44 int digest_length) { 44 int digest_length) const {
45 CCHmacAlgorithm algorithm; 45 CCHmacAlgorithm algorithm;
46 int algorithm_digest_length; 46 int algorithm_digest_length;
47 switch (hash_alg_) { 47 switch (hash_alg_) {
48 case SHA1: 48 case SHA1:
49 algorithm = kCCHmacAlgSHA1; 49 algorithm = kCCHmacAlgSHA1;
50 algorithm_digest_length = CC_SHA1_DIGEST_LENGTH; 50 algorithm_digest_length = CC_SHA1_DIGEST_LENGTH;
51 break; 51 break;
52 case SHA256: 52 case SHA256:
53 algorithm = kCCHmacAlgSHA256; 53 algorithm = kCCHmacAlgSHA256;
54 algorithm_digest_length = CC_SHA256_DIGEST_LENGTH; 54 algorithm_digest_length = CC_SHA256_DIGEST_LENGTH;
55 break; 55 break;
56 default: 56 default:
57 NOTREACHED(); 57 NOTREACHED();
58 return false; 58 return false;
59 } 59 }
60 60
61 if (digest_length < algorithm_digest_length) { 61 if (digest_length < algorithm_digest_length) {
62 NOTREACHED(); 62 NOTREACHED();
63 return false; 63 return false;
64 } 64 }
65 65
66 CCHmac(algorithm, 66 CCHmac(algorithm,
67 plat_->key_.data(), plat_->key_.length(), data.data(), data.length(), 67 plat_->key_.data(), plat_->key_.length(), data.data(), data.length(),
68 digest); 68 digest);
69 69
70 return true; 70 return true;
71 } 71 }
72 72
73 } // namespace crypto 73 } // 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