| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 257   if (!ok) | 256   if (!ok) | 
| 258     return false; | 257     return false; | 
| 259 | 258 | 
| 260   // Iteration U_1: Compute PRF for S. | 259   // Iteration U_1: Compute PRF for S. | 
| 261   ok = CryptHashData(safe_hash, reinterpret_cast<const BYTE*>(salt.data()), | 260   ok = CryptHashData(safe_hash, reinterpret_cast<const BYTE*>(salt.data()), | 
| 262                      static_cast<DWORD>(salt.size()), 0); | 261                      static_cast<DWORD>(salt.size()), 0); | 
| 263   if (!ok) | 262   if (!ok) | 
| 264     return false; | 263     return false; | 
| 265 | 264 | 
| 266   // Iteration U_1: and append (big-endian) INT (i). | 265   // Iteration U_1: and append (big-endian) INT (i). | 
| 267   uint32 big_endian_block_index = htonl(block_index); | 266   uint32 big_endian_block_index = base::HostToNet32(block_index); | 
| 268   ok = CryptHashData(safe_hash, | 267   ok = CryptHashData(safe_hash, | 
| 269                      reinterpret_cast<BYTE*>(&big_endian_block_index), | 268                      reinterpret_cast<BYTE*>(&big_endian_block_index), | 
| 270                      sizeof(big_endian_block_index), 0); | 269                      sizeof(big_endian_block_index), 0); | 
| 271 | 270 | 
| 272   std::vector<BYTE> hash_value(hash_size); | 271   std::vector<BYTE> hash_value(hash_size); | 
| 273 | 272 | 
| 274   DWORD size = hash_size; | 273   DWORD size = hash_size; | 
| 275   ok = CryptGetHashParam(safe_hash, HP_HASHVAL, &hash_value[0], &size, 0); | 274   ok = CryptGetHashParam(safe_hash, HP_HASHVAL, &hash_value[0], &size, 0); | 
| 276   if (!ok  || size != hash_size) | 275   if (!ok  || size != hash_size) | 
| 277     return false; | 276     return false; | 
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 528                            HCRYPTKEY key, | 527                            HCRYPTKEY key, | 
| 529                            const void* key_data, size_t key_size_in_bytes) | 528                            const void* key_data, size_t key_size_in_bytes) | 
| 530     : provider_(provider), key_(key) { | 529     : provider_(provider), key_(key) { | 
| 531   if (key_data) { | 530   if (key_data) { | 
| 532     raw_key_.assign(reinterpret_cast<const char*>(key_data), | 531     raw_key_.assign(reinterpret_cast<const char*>(key_data), | 
| 533                     key_size_in_bytes); | 532                     key_size_in_bytes); | 
| 534   } | 533   } | 
| 535 } | 534 } | 
| 536 | 535 | 
| 537 }  // namespace crypto | 536 }  // namespace crypto | 
| OLD | NEW | 
|---|