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/symmetric_key.h" | 5 #include "crypto/symmetric_key.h" |
6 | 6 |
7 #include <winsock2.h> // For htonl. | |
8 | |
9 #include <vector> | 7 #include <vector> |
10 | 8 |
11 // TODO(wtc): replace scoped_array by std::vector. | 9 // TODO(wtc): replace scoped_array by std::vector. |
12 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/sys_byteorder.h" |
13 | 12 |
14 namespace crypto { | 13 namespace crypto { |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 // The following is a non-public Microsoft header documented in MSDN under | 17 // The following is a non-public Microsoft header documented in MSDN under |
19 // CryptImportKey / CryptExportKey. Following the header is the byte array of | 18 // CryptImportKey / CryptExportKey. Following the header is the byte array of |
20 // the actual plaintext key. | 19 // the actual plaintext key. |
21 struct PlaintextBlobHeader { | 20 struct PlaintextBlobHeader { |
22 BLOBHEADER hdr; | 21 BLOBHEADER hdr; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (!ok) | 255 if (!ok) |
257 return false; | 256 return false; |
258 | 257 |
259 // Iteration U_1: Compute PRF for S. | 258 // Iteration U_1: Compute PRF for S. |
260 ok = CryptHashData(safe_hash, reinterpret_cast<const BYTE*>(salt.data()), | 259 ok = CryptHashData(safe_hash, reinterpret_cast<const BYTE*>(salt.data()), |
261 salt.size(), 0); | 260 salt.size(), 0); |
262 if (!ok) | 261 if (!ok) |
263 return false; | 262 return false; |
264 | 263 |
265 // Iteration U_1: and append (big-endian) INT (i). | 264 // Iteration U_1: and append (big-endian) INT (i). |
266 uint32 big_endian_block_index = htonl(block_index); | 265 uint32 big_endian_block_index = base::HostToNet32(block_index); |
267 ok = CryptHashData(safe_hash, | 266 ok = CryptHashData(safe_hash, |
268 reinterpret_cast<BYTE*>(&big_endian_block_index), | 267 reinterpret_cast<BYTE*>(&big_endian_block_index), |
269 sizeof(big_endian_block_index), 0); | 268 sizeof(big_endian_block_index), 0); |
270 | 269 |
271 std::vector<BYTE> hash_value(hash_size); | 270 std::vector<BYTE> hash_value(hash_size); |
272 | 271 |
273 DWORD size = hash_size; | 272 DWORD size = hash_size; |
274 ok = CryptGetHashParam(safe_hash, HP_HASHVAL, &hash_value[0], &size, 0); | 273 ok = CryptGetHashParam(safe_hash, HP_HASHVAL, &hash_value[0], &size, 0); |
275 if (!ok || size != hash_size) | 274 if (!ok || size != hash_size) |
276 return false; | 275 return false; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 HCRYPTKEY key, | 526 HCRYPTKEY key, |
528 const void* key_data, size_t key_size_in_bytes) | 527 const void* key_data, size_t key_size_in_bytes) |
529 : provider_(provider), key_(key) { | 528 : provider_(provider), key_(key) { |
530 if (key_data) { | 529 if (key_data) { |
531 raw_key_.assign(reinterpret_cast<const char*>(key_data), | 530 raw_key_.assign(reinterpret_cast<const char*>(key_data), |
532 key_size_in_bytes); | 531 key_size_in_bytes); |
533 } | 532 } |
534 } | 533 } |
535 | 534 |
536 } // namespace crypto | 535 } // namespace crypto |
OLD | NEW |