AWS SDK for C++  0.12.9
AWS SDK for C++
CryptoImpl.h
Go to the documentation of this file.
1 /*
2 * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15 
16 #pragma once
17 
22 
23 struct _CCCryptor;
24 
25 namespace Aws
26 {
27  namespace Utils
28  {
29  namespace Crypto
30  {
37  {
38  public:
50  void GetBytes(unsigned char* buffer, size_t bufferSize) override;
51 
52  private:
53  FILE* fp;
54  };
55 
56 
57  class MD5CommonCryptoImpl : public Hash
58  {
59  public:
60 
62  virtual ~MD5CommonCryptoImpl() {}
63 
64  virtual HashResult Calculate(const Aws::String& str) override;
65 
66  virtual HashResult Calculate(Aws::IStream& stream) override;
67 
68  };
69 
71  {
72  public:
73 
76 
77  virtual HashResult Calculate(const Aws::String& str) override;
78 
79  virtual HashResult Calculate(Aws::IStream& stream) override;
80  };
81 
83  {
84  public:
85 
88 
89  virtual HashResult Calculate(const ByteBuffer& toSign, const ByteBuffer& secret) override;
90 
91 
92  };
93 
98  {
99  public:
103  CommonCryptoCipher(const CryptoBuffer& key, size_t ivSize, bool ctrMode = false);
104 
109  CommonCryptoCipher(CryptoBuffer&& key, CryptoBuffer&& initializationVector,
110  CryptoBuffer&& tag = CryptoBuffer(0));
111 
116  CommonCryptoCipher(const CryptoBuffer& key, const CryptoBuffer& initializationVector,
117  const CryptoBuffer& tag = CryptoBuffer(0));
118 
119  CommonCryptoCipher(const CommonCryptoCipher& other) = delete;
120 
121  CommonCryptoCipher& operator=(const CommonCryptoCipher& other) = delete;
122 
129 
135  CommonCryptoCipher& operator=(CommonCryptoCipher&& toMove) = default;
136 
137 
138  virtual ~CommonCryptoCipher();
139 
145  CryptoBuffer EncryptBuffer(const CryptoBuffer& unEncryptedData) override;
146 
150  CryptoBuffer FinalizeEncryption() override;
151 
157  CryptoBuffer DecryptBuffer(const CryptoBuffer& encryptedData) override;
158 
162  CryptoBuffer FinalizeDecryption() override;
163 
164  void Reset() override;
165 
166  protected:
170  virtual void InitEncryptor_Internal() = 0;
171 
175  virtual void InitDecryptor_Internal() = 0;
176 
177  virtual size_t GetBlockSizeBytes() const = 0;
178 
179  virtual size_t GetKeyLengthBits() const = 0;
180 
181  _CCCryptor* m_cryptoHandle;
182 
183  private:
184  void Init();
185 
186  void CheckInitEncryptor();
187 
188  void CheckInitDecryptor();
189 
190  bool m_encDecInitialized;
191  bool m_encryptionMode;
192  bool m_decryptionMode;
193  };
194 
199  {
200  public:
205 
209  AES_CBC_Cipher_CommonCrypto(CryptoBuffer&& key, CryptoBuffer&& initializationVector);
210 
214  AES_CBC_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
215 
217 
218  AES_CBC_Cipher_CommonCrypto& operator=(const AES_CBC_Cipher_CommonCrypto& other) = delete;
219 
221 
222  protected:
223  void InitEncryptor_Internal() override;
224 
225  void InitDecryptor_Internal() override;
226 
227  size_t GetBlockSizeBytes() const override;
228 
229  size_t GetKeyLengthBits() const override;
230 
231  private:
232  static size_t BlockSizeBytes;
233  static size_t KeyLengthBits;
234  };
235 
240  {
241  public:
247 
251  AES_CTR_Cipher_CommonCrypto(CryptoBuffer&& key, CryptoBuffer&& initializationVector);
252 
256  AES_CTR_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
257 
259 
260  AES_CTR_Cipher_CommonCrypto& operator=(const AES_CTR_Cipher_CommonCrypto& other) = delete;
261 
263 
264  protected:
265  void InitEncryptor_Internal() override;
266 
267  void InitDecryptor_Internal() override;
268 
269  size_t GetBlockSizeBytes() const override;
270 
271  size_t GetKeyLengthBits() const override;
272 
273  private:
274  static size_t BlockSizeBytes;
275  static size_t KeyLengthBits;
276  };
277 
278  } // namespace Crypto
279  } // namespace Utils
280 } // namespace Aws
void GetBytes(unsigned char *buffer, size_t bufferSize) override
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:30
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
JSON (JavaScript Object Notation).