OLD | NEW |
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 21 matching lines...) Expand all Loading... |
32 return true; | 32 return true; |
33 } | 33 } |
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 base::StringPiece& data, |
43 unsigned char* digest, | 43 unsigned char* digest, |
44 int digest_length) const { | 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: |
(...skipping 11 matching lines...) Expand all Loading... |
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 |
OLD | NEW |