AWS SDK for C++  1.9.132
AWS SDK for C++
CryptoImpl.h
Go to the documentation of this file.
1 
6 #pragma once
7 
12 
13 #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
14 #if defined(__MAC_10_13) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_13)
15 #define MAC_13_AVAILABLE 1
16 #elif defined(__MAC_10_14_4) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_14_4)
17 #define MAC_14_4_AVAILABLE 1
18 #endif
19 #endif
20 
21 struct _CCCryptor;
22 
23 namespace Aws
24 {
25  namespace Utils
26  {
27  namespace Crypto
28  {
35  {
36  public:
48  void GetBytes(unsigned char* buffer, size_t bufferSize) override;
49 
50  private:
51  FILE* fp;
52  };
53 
54 
55  class MD5CommonCryptoImpl : public Hash
56  {
57  public:
58 
60  virtual ~MD5CommonCryptoImpl() {}
61 
62  virtual HashResult Calculate(const Aws::String& str) override;
63 
64  virtual HashResult Calculate(Aws::IStream& stream) override;
65 
66  };
67 
68  class Sha1CommonCryptoImpl : public Hash
69  {
70  public:
71 
73  virtual ~Sha1CommonCryptoImpl() {}
74 
75  virtual HashResult Calculate(const Aws::String& str) override;
76 
77  virtual HashResult Calculate(Aws::IStream& stream) override;
78  };
79 
81  {
82  public:
83 
86 
87  virtual HashResult Calculate(const Aws::String& str) override;
88 
89  virtual HashResult Calculate(Aws::IStream& stream) override;
90  };
91 
93  {
94  public:
95 
98 
99  virtual HashResult Calculate(const ByteBuffer& toSign, const ByteBuffer& secret) override;
100  };
101 
106  {
107  public:
111  CommonCryptoCipher(const CryptoBuffer& key, size_t ivSize, bool ctrMode = false);
112 
117  CommonCryptoCipher(CryptoBuffer&& key, CryptoBuffer&& initializationVector,
118  CryptoBuffer&& tag = CryptoBuffer(0));
119 
124  CommonCryptoCipher(const CryptoBuffer& key, const CryptoBuffer& initializationVector,
125  const CryptoBuffer& tag = CryptoBuffer(0));
126 
127  CommonCryptoCipher(const CommonCryptoCipher& other) = delete;
128 
130 
137 
144 
145 
147 
153  CryptoBuffer EncryptBuffer(const CryptoBuffer& unEncryptedData) override;
154 
159 
165  CryptoBuffer DecryptBuffer(const CryptoBuffer& encryptedData) override;
166 
171 
172  void Reset() override;
173 
174  protected:
175  virtual size_t GetBlockSizeBytes() const = 0;
176 
177  virtual size_t GetKeyLengthBits() const = 0;
178 
179  bool CheckKeyAndIVLength(size_t expectedKeyLength, size_t expectedIVLength);
180 
181  _CCCryptor* m_encryptorHandle;
182  _CCCryptor* m_decryptorHandle;
183 
184  private:
185  void Init();
186  };
187 
192  {
193  public:
198 
202  AES_CBC_Cipher_CommonCrypto(CryptoBuffer&& key, CryptoBuffer&& initializationVector);
203 
207  AES_CBC_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
208 
210 
212 
214 
215  void Reset() override;
216 
217  protected:
218  size_t GetBlockSizeBytes() const override;
219 
220  size_t GetKeyLengthBits() const override;
221 
222  private:
223  void InitCipher();
224 
225  static size_t BlockSizeBytes;
226  static size_t KeyLengthBits;
227  };
228 
233  {
234  public:
240 
244  AES_CTR_Cipher_CommonCrypto(CryptoBuffer&& key, CryptoBuffer&& initializationVector);
245 
249  AES_CTR_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
250 
252 
254 
256 
257  void Reset() override;
258 
259  protected:
260  size_t GetBlockSizeBytes() const override;
261 
262  size_t GetKeyLengthBits() const override;
263 
264  private:
265  void InitCipher();
266 
267  static size_t BlockSizeBytes;
268  static size_t KeyLengthBits;
269  };
270 
275  {
276  public:
281 
286 
292  CryptoBuffer&& tag = CryptoBuffer(0), CryptoBuffer&& aad = CryptoBuffer(0));
293 
298  AES_GCM_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector,
299  const CryptoBuffer& tag = CryptoBuffer(), const CryptoBuffer& aad = CryptoBuffer());
300 
302 
304 
306 
309 
310  void Reset() override;
311 
312  protected:
313  size_t GetBlockSizeBytes() const override;
314 
315  size_t GetKeyLengthBits() const override;
316 
317  private:
318  void InitCipher();
319 
320  CryptoBuffer m_aad;
321  static size_t BlockSizeBytes;
322  static size_t KeyLengthBits;
323  static size_t TagLengthBytes;
324  static size_t IVLengthBytes;
325  };
326 
332  {
333  public:
338 
340 
342 
344 
345  CryptoBuffer EncryptBuffer(const CryptoBuffer& unEncryptedData) override;
346 
348 
349  CryptoBuffer DecryptBuffer(const CryptoBuffer& encryptedData) override;
350 
352 
353  void Reset() override;
354 
355  protected:
356  inline size_t GetBlockSizeBytes() const override { return BlockSizeBytes; }
357 
358  inline size_t GetKeyLengthBits() const override { return KeyLengthBits; }
359 
360  private:
361  static size_t BlockSizeBytes;
362  static size_t KeyLengthBits;
363 
364  CryptoBuffer m_workingKeyBuffer;
365  };
366 
367  } // namespace Crypto
368  } // namespace Utils
369 } // namespace Aws
Aws::Utils::Crypto::SecureRandomBytes
Definition: SecureRandom.h:21
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::Reset
void Reset() override
Cipher.h
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::GetKeyLengthBits
size_t GetKeyLengthBits() const override
Definition: CryptoImpl.h:358
Aws::Utils::Crypto::CommonCryptoCipher::operator=
CommonCryptoCipher & operator=(CommonCryptoCipher &&toMove)=default
Aws::Utils::Crypto::MD5CommonCryptoImpl::Calculate
virtual HashResult Calculate(Aws::IStream &stream) override
Aws::Utils::Crypto::SecureRandomBytes_CommonCrypto
Definition: CryptoImpl.h:35
buffer
char * buffer
Definition: cJSON.h:174
Aws::Utils::Crypto::Sha256CommonCryptoImpl
Definition: CryptoImpl.h:81
Aws::Utils::Crypto::Sha1CommonCryptoImpl::Calculate
virtual HashResult Calculate(const Aws::String &str) override
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::GetKeyLengthBits
size_t GetKeyLengthBits() const override
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::AES_CBC_Cipher_CommonCrypto
AES_CBC_Cipher_CommonCrypto(const CryptoBuffer &key)
Aws::Utils::Crypto::CommonCryptoCipher::DecryptBuffer
CryptoBuffer DecryptBuffer(const CryptoBuffer &encryptedData) override
Aws::Utils::Crypto::CommonCryptoCipher::CommonCryptoCipher
CommonCryptoCipher(const CryptoBuffer &key, size_t ivSize, bool ctrMode=false)
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::FinalizeDecryption
CryptoBuffer FinalizeDecryption() override
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::operator=
AES_GCM_Cipher_CommonCrypto & operator=(const AES_GCM_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::SecureRandomBytes_CommonCrypto::~SecureRandomBytes_CommonCrypto
~SecureRandomBytes_CommonCrypto()
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector, CryptoBuffer &&tag=CryptoBuffer(0), CryptoBuffer &&aad=CryptoBuffer(0))
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::AES_CBC_Cipher_CommonCrypto
AES_CBC_Cipher_CommonCrypto(const AES_CBC_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::Sha1CommonCryptoImpl::Calculate
virtual HashResult Calculate(Aws::IStream &stream) override
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer *aad)
Aws::Utils::Crypto::CommonCryptoCipher::CommonCryptoCipher
CommonCryptoCipher(const CryptoBuffer &key, const CryptoBuffer &initializationVector, const CryptoBuffer &tag=CryptoBuffer(0))
Aws::Utils::Crypto::Hash
Definition: Hash.h:23
HMAC.h
Aws::Utils::Crypto::CommonCryptoCipher::Reset
void Reset() override
Aws::Utils::Crypto::MD5CommonCryptoImpl::MD5CommonCryptoImpl
MD5CommonCryptoImpl()
Definition: CryptoImpl.h:59
Aws::Utils::Crypto::Sha256HMACCommonCryptoImpl
Definition: CryptoImpl.h:93
Aws::Utils::Crypto::Sha1CommonCryptoImpl
Definition: CryptoImpl.h:69
Aws::Utils::Crypto::SecureRandomBytes_CommonCrypto::GetBytes
void GetBytes(unsigned char *buffer, size_t bufferSize) override
Aws::IStream
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:20
Aws::Utils::Crypto::Sha256HMACCommonCryptoImpl::Calculate
virtual HashResult Calculate(const ByteBuffer &toSign, const ByteBuffer &secret) override
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::AES_KeyWrap_Cipher_CommonCrypto
AES_KeyWrap_Cipher_CommonCrypto(const CryptoBuffer &key)
Aws::Utils::Crypto::CommonCryptoCipher::GetKeyLengthBits
virtual size_t GetKeyLengthBits() const =0
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::AES_KeyWrap_Cipher_CommonCrypto
AES_KeyWrap_Cipher_CommonCrypto(AES_KeyWrap_Cipher_CommonCrypto &&)=default
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::FinalizeEncryption
CryptoBuffer FinalizeEncryption() override
Aws::Utils::Crypto::HMAC
Definition: HMAC.h:26
Aws::Utils::Crypto::Sha256CommonCryptoImpl::Calculate
virtual HashResult Calculate(const Aws::String &str) override
Aws::Utils::Crypto::SymmetricCipher
Definition: Cipher.h:28
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::GetKeyLengthBits
size_t GetKeyLengthBits() const override
SecureRandom.h
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto
Definition: CryptoImpl.h:233
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::AES_CBC_Cipher_CommonCrypto
AES_CBC_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector)
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::AES_CTR_Cipher_CommonCrypto
AES_CTR_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector)
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(const AES_GCM_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::AES_KeyWrap_Cipher_CommonCrypto
AES_KeyWrap_Cipher_CommonCrypto(const AES_KeyWrap_Cipher_CommonCrypto &)=delete
Aws::Utils::Crypto::CommonCryptoCipher::m_decryptorHandle
_CCCryptor * m_decryptorHandle
Definition: CryptoImpl.h:182
Aws::Utils::Crypto::CommonCryptoCipher::EncryptBuffer
CryptoBuffer EncryptBuffer(const CryptoBuffer &unEncryptedData) override
Aws::Utils::Crypto::CommonCryptoCipher::CheckKeyAndIVLength
bool CheckKeyAndIVLength(size_t expectedKeyLength, size_t expectedIVLength)
Aws::Utils::Crypto::CommonCryptoCipher::m_encryptorHandle
_CCCryptor * m_encryptorHandle
Definition: CryptoImpl.h:181
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector, const CryptoBuffer &tag=CryptoBuffer(), const CryptoBuffer &aad=CryptoBuffer())
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::AES_CBC_Cipher_CommonCrypto
AES_CBC_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector)
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key)
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::GetBlockSizeBytes
size_t GetBlockSizeBytes() const override
Aws::Utils::Crypto::CommonCryptoCipher::operator=
CommonCryptoCipher & operator=(const CommonCryptoCipher &other)=delete
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::GetBlockSizeBytes
size_t GetBlockSizeBytes() const override
Definition: CryptoImpl.h:356
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::DecryptBuffer
CryptoBuffer DecryptBuffer(const CryptoBuffer &encryptedData) override
Aws::Utils::Crypto::CommonCryptoCipher::~CommonCryptoCipher
virtual ~CommonCryptoCipher()
Aws::Utils::Crypto::MD5CommonCryptoImpl::Calculate
virtual HashResult Calculate(const Aws::String &str) override
Aws::Utils::Array< unsigned char >
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::Reset
void Reset() override
Aws::Utils::Crypto::SecureRandomBytes_CommonCrypto::SecureRandomBytes_CommonCrypto
SecureRandomBytes_CommonCrypto()
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::operator=
AES_CTR_Cipher_CommonCrypto & operator=(const AES_CTR_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto
Definition: CryptoImpl.h:192
Aws::Utils::Crypto::CommonCryptoCipher::FinalizeDecryption
CryptoBuffer FinalizeDecryption() override
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::EncryptBuffer
CryptoBuffer EncryptBuffer(const CryptoBuffer &unEncryptedData) override
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::FinalizeEncryption
CryptoBuffer FinalizeEncryption() override
Aws::Utils::Crypto::Sha1CommonCryptoImpl::Sha1CommonCryptoImpl
Sha1CommonCryptoImpl()
Definition: CryptoImpl.h:72
Aws::Utils::Crypto::CommonCryptoCipher::CommonCryptoCipher
CommonCryptoCipher(CryptoBuffer &&key, CryptoBuffer &&initializationVector, CryptoBuffer &&tag=CryptoBuffer(0))
Aws::Utils::Crypto::CommonCryptoCipher
Definition: CryptoImpl.h:106
Aws::Utils::Crypto::CommonCryptoCipher::CommonCryptoCipher
CommonCryptoCipher(const CommonCryptoCipher &other)=delete
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::operator=
AES_CBC_Cipher_CommonCrypto & operator=(const AES_CBC_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::AES_GCM_Cipher_CommonCrypto
AES_GCM_Cipher_CommonCrypto(AES_GCM_Cipher_CommonCrypto &&toMove)=default
Aws::Utils::Crypto::Sha1CommonCryptoImpl::~Sha1CommonCryptoImpl
virtual ~Sha1CommonCryptoImpl()
Definition: CryptoImpl.h:73
Aws::Utils::Crypto::Sha256CommonCryptoImpl::Sha256CommonCryptoImpl
Sha256CommonCryptoImpl()
Definition: CryptoImpl.h:84
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::GetKeyLengthBits
size_t GetKeyLengthBits() const override
Aws::Utils::Crypto::Sha256CommonCryptoImpl::~Sha256CommonCryptoImpl
virtual ~Sha256CommonCryptoImpl()
Definition: CryptoImpl.h:85
Aws::Utils::CryptoBuffer
Definition: Array.h:229
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto
Definition: CryptoImpl.h:275
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::FinalizeDecryption
CryptoBuffer FinalizeDecryption() override
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::Reset
void Reset() override
Aws
Definition: AccessManagementClient.h:15
Aws::Utils::Crypto::MD5CommonCryptoImpl::~MD5CommonCryptoImpl
virtual ~MD5CommonCryptoImpl()
Definition: CryptoImpl.h:60
Aws::Utils::Outcome
Definition: Outcome.h:26
Aws::Utils::Crypto::AES_GCM_Cipher_CommonCrypto::GetBlockSizeBytes
size_t GetBlockSizeBytes() const override
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto::operator=
AES_KeyWrap_Cipher_CommonCrypto & operator=(const AES_KeyWrap_Cipher_CommonCrypto &)=delete
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::AES_CTR_Cipher_CommonCrypto
AES_CTR_Cipher_CommonCrypto(const CryptoBuffer &key)
Aws::Utils::Crypto::CommonCryptoCipher::CommonCryptoCipher
CommonCryptoCipher(CommonCryptoCipher &&toMove)
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::AES_CTR_Cipher_CommonCrypto
AES_CTR_Cipher_CommonCrypto(AES_CTR_Cipher_CommonCrypto &&toMove)=default
Aws::Utils::Crypto::CommonCryptoCipher::GetBlockSizeBytes
virtual size_t GetBlockSizeBytes() const =0
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::AES_CTR_Cipher_CommonCrypto
AES_CTR_Cipher_CommonCrypto(const AES_CTR_Cipher_CommonCrypto &other)=delete
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::AES_CTR_Cipher_CommonCrypto
AES_CTR_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector)
Aws::Utils::Crypto::Sha256HMACCommonCryptoImpl::Sha256HMACCommonCryptoImpl
Sha256HMACCommonCryptoImpl()
Definition: CryptoImpl.h:96
Aws::Utils::Crypto::AES_KeyWrap_Cipher_CommonCrypto
Definition: CryptoImpl.h:332
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::AES_CBC_Cipher_CommonCrypto
AES_CBC_Cipher_CommonCrypto(AES_CBC_Cipher_CommonCrypto &&toMove)=default
Aws::Utils::Crypto::Sha256CommonCryptoImpl::Calculate
virtual HashResult Calculate(Aws::IStream &stream) override
Hash.h
Aws::Utils::Crypto::MD5CommonCryptoImpl
Definition: CryptoImpl.h:56
Aws::Utils::Crypto::AES_CTR_Cipher_CommonCrypto::Reset
void Reset() override
Aws::Utils::Crypto::Sha256HMACCommonCryptoImpl::~Sha256HMACCommonCryptoImpl
virtual ~Sha256HMACCommonCryptoImpl()
Definition: CryptoImpl.h:97
Aws::Utils::Crypto::AES_CBC_Cipher_CommonCrypto::GetBlockSizeBytes
size_t GetBlockSizeBytes() const override
Aws::Utils::Crypto::CommonCryptoCipher::FinalizeEncryption
CryptoBuffer FinalizeEncryption() override