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 #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 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // | 63 // |
64 // If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be | 64 // If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be |
65 // empty. | 65 // empty. |
66 bool Init(SymmetricKey* key, Mode mode, const base::StringPiece& iv); | 66 bool Init(SymmetricKey* key, Mode mode, const base::StringPiece& iv); |
67 | 67 |
68 // Encrypts |plaintext| into |ciphertext|. |plaintext| may only be empty if | 68 // Encrypts |plaintext| into |ciphertext|. |plaintext| may only be empty if |
69 // the mode is CBC. | 69 // the mode is CBC. |
70 bool Encrypt(const base::StringPiece& plaintext, std::string* ciphertext); | 70 bool Encrypt(const base::StringPiece& plaintext, std::string* ciphertext); |
71 | 71 |
72 // Decrypts |ciphertext| into |plaintext|. |ciphertext| must not be empty. | 72 // Decrypts |ciphertext| into |plaintext|. |ciphertext| must not be empty. |
73 // | |
74 // WARNING: In CBC mode, Decrypt() returns false if it detects the padding | |
75 // in the decrypted plaintext is wrong. Padding errors can result from | |
76 // tampered ciphertext or a wrong decryption key. But successful decryption | |
77 // does not imply the authenticity of the data. The caller of Decrypt() | |
78 // must either authenticate the ciphertext before decrypting it, or take | |
79 // care to not report decryption failure. Otherwise it could inadvertently | |
80 // be used as a padding oracle. | |
agl
2012/04/24 22:27:48
...a padding oracle to attack the cryptosystem.
(
| |
73 bool Decrypt(const base::StringPiece& ciphertext, std::string* plaintext); | 81 bool Decrypt(const base::StringPiece& ciphertext, std::string* plaintext); |
74 | 82 |
75 // Sets the counter value when in CTR mode. Currently only 128-bits | 83 // Sets the counter value when in CTR mode. Currently only 128-bits |
76 // counter value is supported. | 84 // counter value is supported. |
77 // | 85 // |
78 // Returns true only if update was successful. | 86 // Returns true only if update was successful. |
79 bool SetCounter(const base::StringPiece& counter); | 87 bool SetCounter(const base::StringPiece& counter); |
80 | 88 |
81 // TODO(albertb): Support streaming encryption. | 89 // TODO(albertb): Support streaming encryption. |
82 | 90 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 std::string iv_; | 138 std::string iv_; |
131 #elif defined(OS_WIN) | 139 #elif defined(OS_WIN) |
132 ScopedHCRYPTKEY capi_key_; | 140 ScopedHCRYPTKEY capi_key_; |
133 DWORD block_size_; | 141 DWORD block_size_; |
134 #endif | 142 #endif |
135 }; | 143 }; |
136 | 144 |
137 } // namespace crypto | 145 } // namespace crypto |
138 | 146 |
139 #endif // CRYPTO_ENCRYPTOR_H_ | 147 #endif // CRYPTO_ENCRYPTOR_H_ |
OLD | NEW |