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 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 // Sets the counter value when in CTR mode. Currently only 128-bits | 78 // Sets the counter value when in CTR mode. Currently only 128-bits |
79 // counter value is supported. | 79 // counter value is supported. |
80 // | 80 // |
81 // Returns true only if update was successful. | 81 // Returns true only if update was successful. |
82 bool SetCounter(const base::StringPiece& counter); | 82 bool SetCounter(const base::StringPiece& counter); |
83 | 83 |
84 // TODO(albertb): Support streaming encryption. | 84 // TODO(albertb): Support streaming encryption. |
85 | 85 |
86 private: | 86 private: |
87 // Generates a mask using |counter_| to be used for encryption in CTR mode. | |
88 // Resulting mask will be written to |mask| with |mask_len| bytes. | |
89 // | |
90 // Make sure there's enough space in mask when calling this method. | |
91 // Reserve at least |plaintext_len| + 16 bytes for |mask|. | |
92 // | |
93 // The generated mask will always have at least |plaintext_len| bytes and | |
94 // will be a multiple of the counter length. | |
95 // | |
96 // This method is used only in CTR mode. | |
97 // | |
98 // Returns false if this call failed. | |
99 bool GenerateCounterMask(size_t plaintext_len, | |
100 uint8_t* mask, | |
101 size_t* mask_len); | |
102 | |
103 // Mask the |plaintext| message using |mask|. The output will be written to | |
104 // |ciphertext|. |ciphertext| must have at least |plaintext_len| bytes. | |
105 void MaskMessage(const void* plaintext, | |
106 size_t plaintext_len, | |
107 const void* mask, | |
108 void* ciphertext) const; | |
109 | |
110 SymmetricKey* key_; | 87 SymmetricKey* key_; |
111 Mode mode_; | 88 Mode mode_; |
112 std::unique_ptr<Counter> counter_; | 89 std::unique_ptr<Counter> counter_; |
113 | 90 |
114 bool Crypt(bool do_encrypt, // Pass true to encrypt, false to decrypt. | 91 bool Crypt(bool do_encrypt, // Pass true to encrypt, false to decrypt. |
115 const base::StringPiece& input, | 92 const base::StringPiece& input, |
116 std::string* output); | 93 std::string* output); |
117 bool CryptCTR(bool do_encrypt, | 94 bool CryptCTR(bool do_encrypt, |
118 const base::StringPiece& input, | 95 const base::StringPiece& input, |
119 std::string* output); | 96 std::string* output); |
120 std::string iv_; | 97 std::string iv_; |
121 }; | 98 }; |
122 | 99 |
123 } // namespace crypto | 100 } // namespace crypto |
124 | 101 |
125 #endif // CRYPTO_ENCRYPTOR_H_ | 102 #endif // CRYPTO_ENCRYPTOR_H_ |
OLD | NEW |