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 #ifndef CRYPTO_ENCRYPTOR_H_ | 5 #ifndef CRYPTO_ENCRYPTOR_H_ |
6 #define CRYPTO_ENCRYPTOR_H_ | 6 #define CRYPTO_ENCRYPTOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "crypto/crypto_export.h" | 15 #include "crypto/crypto_export.h" |
16 | 16 |
17 #if defined(USE_NSS) | 17 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
18 #include "crypto/scoped_nss_types.h" | 18 #include "crypto/scoped_nss_types.h" |
19 #elif defined(OS_WIN) | |
20 #include "crypto/scoped_capi_types.h" | |
21 #endif | 19 #endif |
22 | 20 |
23 namespace crypto { | 21 namespace crypto { |
24 | 22 |
25 class SymmetricKey; | 23 class SymmetricKey; |
26 | 24 |
27 class CRYPTO_EXPORT Encryptor { | 25 class CRYPTO_EXPORT Encryptor { |
28 public: | 26 public: |
29 enum Mode { | 27 enum Mode { |
30 CBC, | 28 CBC, |
31 CTR, | 29 CTR, |
32 }; | 30 }; |
33 | 31 |
34 // This class implements a 128-bits counter to be used in AES-CTR encryption. | 32 // This class implements a 128-bits counter to be used in AES-CTR encryption. |
35 // Only 128-bits counter is supported in this class. | 33 // Only 128-bits counter is supported in this class. |
36 class Counter { | 34 class CRYPTO_EXPORT Counter { |
37 public: | 35 public: |
38 explicit Counter(const base::StringPiece& counter); | 36 explicit Counter(const base::StringPiece& counter); |
39 ~Counter(); | 37 ~Counter(); |
40 | 38 |
41 // Increment the counter value. | 39 // Increment the counter value. |
42 bool Increment(); | 40 bool Increment(); |
43 | 41 |
44 // Write the content of the counter to |buf|. |buf| should have enough | 42 // Write the content of the counter to |buf|. |buf| should have enough |
45 // space for |GetLengthInBytes()|. | 43 // space for |GetLengthInBytes()|. |
46 void Write(void* buf); | 44 void Write(void* buf); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 112 |
115 SymmetricKey* key_; | 113 SymmetricKey* key_; |
116 Mode mode_; | 114 Mode mode_; |
117 scoped_ptr<Counter> counter_; | 115 scoped_ptr<Counter> counter_; |
118 | 116 |
119 #if defined(USE_OPENSSL) | 117 #if defined(USE_OPENSSL) |
120 bool Crypt(bool encrypt, // Pass true to encrypt, false to decrypt. | 118 bool Crypt(bool encrypt, // Pass true to encrypt, false to decrypt. |
121 const base::StringPiece& input, | 119 const base::StringPiece& input, |
122 std::string* output); | 120 std::string* output); |
123 std::string iv_; | 121 std::string iv_; |
124 #elif defined(USE_NSS) | 122 #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
125 bool Crypt(PK11Context* context, | 123 bool Crypt(PK11Context* context, |
126 const base::StringPiece& input, | 124 const base::StringPiece& input, |
127 std::string* output); | 125 std::string* output); |
128 bool CryptCTR(PK11Context* context, | 126 bool CryptCTR(PK11Context* context, |
129 const base::StringPiece& input, | 127 const base::StringPiece& input, |
130 std::string* output); | 128 std::string* output); |
131 ScopedPK11Slot slot_; | 129 ScopedPK11Slot slot_; |
132 ScopedSECItem param_; | 130 ScopedSECItem param_; |
133 #elif defined(OS_MACOSX) | |
134 bool Crypt(int /*CCOperation*/ op, | |
135 const base::StringPiece& input, | |
136 std::string* output); | |
137 | |
138 std::string iv_; | |
139 #elif defined(OS_WIN) | |
140 ScopedHCRYPTKEY capi_key_; | |
141 DWORD block_size_; | |
142 #endif | 131 #endif |
143 }; | 132 }; |
144 | 133 |
145 } // namespace crypto | 134 } // namespace crypto |
146 | 135 |
147 #endif // CRYPTO_ENCRYPTOR_H_ | 136 #endif // CRYPTO_ENCRYPTOR_H_ |
OLD | NEW |