OLD | NEW |
1 // Copyright (c) 2010 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 "base/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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/crypto/scoped_capi_types.h" | |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/third_party/nss/blapi.h" | 14 #include "crypto/scoped_capi_types.h" |
16 #include "base/third_party/nss/sha256.h" | 15 #include "crypto/third_party/nss/blapi.h" |
| 16 #include "crypto/third_party/nss/sha256.h" |
17 | 17 |
18 namespace base { | 18 namespace crypto { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Implementation of HMAC-SHA-256: | 22 // Implementation of HMAC-SHA-256: |
23 // | 23 // |
24 // SHA-256 is supported in Windows XP SP3 or later. We still need to support | 24 // SHA-256 is supported in Windows XP SP3 or later. We still need to support |
25 // Windows XP SP2, so unfortunately we have to implement HMAC-SHA-256 here. | 25 // Windows XP SP2, so unfortunately we have to implement HMAC-SHA-256 here. |
26 | 26 |
27 enum { | 27 enum { |
28 SHA256_BLOCK_SIZE = 64 // Block size (in bytes) of the input to SHA-256. | 28 SHA256_BLOCK_SIZE = 64 // Block size (in bytes) of the input to SHA-256. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 return false; | 187 return false; |
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 base | 197 } // namespace crypto |
OLD | NEW |