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 <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 SecureZeroMemory(key_blob->key_data, key_length); | 149 SecureZeroMemory(key_blob->key_data, key_length); |
150 | 150 |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 HMAC::~HMAC() { | 154 HMAC::~HMAC() { |
155 } | 155 } |
156 | 156 |
157 bool HMAC::Sign(const std::string& data, | 157 bool HMAC::Sign(const std::string& data, |
158 unsigned char* digest, | 158 unsigned char* digest, |
159 int digest_length) { | 159 int digest_length) const { |
160 if (hash_alg_ == SHA256) { | 160 if (hash_alg_ == SHA256) { |
161 if (plat_->raw_key_.empty()) | 161 if (plat_->raw_key_.empty()) |
162 return false; | 162 return false; |
163 ComputeHMACSHA256(&plat_->raw_key_[0], plat_->raw_key_.size(), | 163 ComputeHMACSHA256(&plat_->raw_key_[0], plat_->raw_key_.size(), |
164 reinterpret_cast<const unsigned char*>(data.data()), | 164 reinterpret_cast<const unsigned char*>(data.data()), |
165 data.size(), digest, digest_length); | 165 data.size(), digest, digest_length); |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 if (!plat_->provider_ || !plat_->key_) | 169 if (!plat_->provider_ || !plat_->key_) |
(...skipping 18 matching lines...) Expand all Loading... |
188 | 188 |
189 if (!CryptHashData(hash, reinterpret_cast<const BYTE*>(data.data()), | 189 if (!CryptHashData(hash, reinterpret_cast<const BYTE*>(data.data()), |
190 static_cast<DWORD>(data.size()), 0)) | 190 static_cast<DWORD>(data.size()), 0)) |
191 return false; | 191 return false; |
192 | 192 |
193 DWORD sha1_size = digest_length; | 193 DWORD sha1_size = digest_length; |
194 return !!CryptGetHashParam(hash, HP_HASHVAL, digest, &sha1_size, 0); | 194 return !!CryptGetHashParam(hash, HP_HASHVAL, digest, &sha1_size, 0); |
195 } | 195 } |
196 | 196 |
197 } // namespace crypto | 197 } // namespace crypto |
OLD | NEW |