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> |
| 9 #include <stdint.h> |
| 10 |
8 #include <string> | 11 #include <string> |
9 | 12 |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "crypto/crypto_export.h" | 16 #include "crypto/crypto_export.h" |
15 | 17 |
16 #if !defined(USE_OPENSSL) | 18 #if !defined(USE_OPENSSL) |
17 #include "crypto/scoped_nss_types.h" | 19 #include "crypto/scoped_nss_types.h" |
18 #endif | 20 #endif |
19 | 21 |
20 namespace crypto { | 22 namespace crypto { |
(...skipping 19 matching lines...) Expand all Loading... |
40 | 42 |
41 // Write the content of the counter to |buf|. |buf| should have enough | 43 // Write the content of the counter to |buf|. |buf| should have enough |
42 // space for |GetLengthInBytes()|. | 44 // space for |GetLengthInBytes()|. |
43 void Write(void* buf); | 45 void Write(void* buf); |
44 | 46 |
45 // Return the length of this counter. | 47 // Return the length of this counter. |
46 size_t GetLengthInBytes() const; | 48 size_t GetLengthInBytes() const; |
47 | 49 |
48 private: | 50 private: |
49 union { | 51 union { |
50 uint32 components32[4]; | 52 uint32_t components32[4]; |
51 uint64 components64[2]; | 53 uint64_t components64[2]; |
52 } counter_; | 54 } counter_; |
53 }; | 55 }; |
54 | 56 |
55 Encryptor(); | 57 Encryptor(); |
56 virtual ~Encryptor(); | 58 virtual ~Encryptor(); |
57 | 59 |
58 // Initializes the encryptor using |key| and |iv|. Returns false if either the | 60 // Initializes the encryptor using |key| and |iv|. Returns false if either the |
59 // key or the initialization vector cannot be used. | 61 // key or the initialization vector cannot be used. |
60 // | 62 // |
61 // If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be | 63 // If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be |
(...skipping 30 matching lines...) Expand all Loading... |
92 // Make sure there's enough space in mask when calling this method. | 94 // Make sure there's enough space in mask when calling this method. |
93 // Reserve at least |plaintext_len| + 16 bytes for |mask|. | 95 // Reserve at least |plaintext_len| + 16 bytes for |mask|. |
94 // | 96 // |
95 // The generated mask will always have at least |plaintext_len| bytes and | 97 // The generated mask will always have at least |plaintext_len| bytes and |
96 // will be a multiple of the counter length. | 98 // will be a multiple of the counter length. |
97 // | 99 // |
98 // This method is used only in CTR mode. | 100 // This method is used only in CTR mode. |
99 // | 101 // |
100 // Returns false if this call failed. | 102 // Returns false if this call failed. |
101 bool GenerateCounterMask(size_t plaintext_len, | 103 bool GenerateCounterMask(size_t plaintext_len, |
102 uint8* mask, | 104 uint8_t* mask, |
103 size_t* mask_len); | 105 size_t* mask_len); |
104 | 106 |
105 // Mask the |plaintext| message using |mask|. The output will be written to | 107 // Mask the |plaintext| message using |mask|. The output will be written to |
106 // |ciphertext|. |ciphertext| must have at least |plaintext_len| bytes. | 108 // |ciphertext|. |ciphertext| must have at least |plaintext_len| bytes. |
107 void MaskMessage(const void* plaintext, | 109 void MaskMessage(const void* plaintext, |
108 size_t plaintext_len, | 110 size_t plaintext_len, |
109 const void* mask, | 111 const void* mask, |
110 void* ciphertext) const; | 112 void* ciphertext) const; |
111 | 113 |
112 SymmetricKey* key_; | 114 SymmetricKey* key_; |
(...skipping 15 matching lines...) Expand all Loading... |
128 bool CryptCTR(PK11Context* context, | 130 bool CryptCTR(PK11Context* context, |
129 const base::StringPiece& input, | 131 const base::StringPiece& input, |
130 std::string* output); | 132 std::string* output); |
131 ScopedSECItem param_; | 133 ScopedSECItem param_; |
132 #endif | 134 #endif |
133 }; | 135 }; |
134 | 136 |
135 } // namespace crypto | 137 } // namespace crypto |
136 | 138 |
137 #endif // CRYPTO_ENCRYPTOR_H_ | 139 #endif // CRYPTO_ENCRYPTOR_H_ |
OLD | NEW |