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 "base/crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/crypto/symmetric_key.h" | 9 #include "crypto/symmetric_key.h" |
10 | 10 |
11 namespace base { | 11 namespace crypto { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // On success, returns the block size (in bytes) for the algorithm that |key| | 15 // On success, returns the block size (in bytes) for the algorithm that |key| |
16 // is for. On failure, returns 0. | 16 // is for. On failure, returns 0. |
17 DWORD GetCipherBlockSize(HCRYPTKEY key) { | 17 DWORD GetCipherBlockSize(HCRYPTKEY key) { |
18 DWORD block_size_in_bits = 0; | 18 DWORD block_size_in_bits = 0; |
19 DWORD param_size = sizeof(block_size_in_bits); | 19 DWORD param_size = sizeof(block_size_in_bits); |
20 BOOL ok = CryptGetKeyParam(key, KP_BLOCKLEN, | 20 BOOL ok = CryptGetKeyParam(key, KP_BLOCKLEN, |
21 reinterpret_cast<BYTE*>(&block_size_in_bits), | 21 reinterpret_cast<BYTE*>(&block_size_in_bits), |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len); | 105 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len); |
106 if (!ok) | 106 if (!ok) |
107 return false; | 107 return false; |
108 | 108 |
109 DCHECK_GT(tmp.size(), data_len); | 109 DCHECK_GT(tmp.size(), data_len); |
110 | 110 |
111 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); | 111 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 } // namespace base | 115 } // namespace crypto |
OLD | NEW |