Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: crypto/encryptor.h

Issue 10216004: Add a warning about Decrypt() being used as a padding oracle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698