AWS SDK for C++
AWS SDK for C++
Loading...
Searching...
No Matches
CryptoImpl.h
Go to the documentation of this file.
1
6#pragma once
7
12#include <CommonCrypto/CommonDigest.h>
13
14#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED)
15#if defined(__MAC_10_13) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_13)
16#define MAC_13_AVAILABLE 1
17#elif defined(__MAC_10_14_4) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_14_4)
18#define MAC_14_4_AVAILABLE 1
19#endif
20#endif
21
22struct _CCCryptor;
23
24namespace Aws
25{
26 namespace Utils
27 {
28 namespace Crypto
29 {
36 {
37 public:
49 void GetBytes(unsigned char* buffer, size_t bufferSize) override;
50
51 private:
52 FILE* fp;
53 };
54
55
57 {
58 public:
59
62
63 virtual HashResult Calculate(const Aws::String& str) override;
64
65 virtual HashResult Calculate(Aws::IStream& stream) override;
66
67 virtual void Update(unsigned char* buffer, size_t bufferSize) override;
68
69 virtual HashResult GetHash() override;
70
71 private:
72// AWS_SUPPRESS_DEPRECATION(
73 CC_MD5_CTX m_ctx;
74 // )
75 };
76
78 {
79 public:
80
83
84 virtual HashResult Calculate(const Aws::String& str) override;
85
86 virtual HashResult Calculate(Aws::IStream& stream) override;
87
88 virtual void Update(unsigned char* buffer, size_t bufferSize) override;
89
90 virtual HashResult GetHash() override;
91
92 private:
93 CC_SHA1_CTX m_ctx;
94 };
95
97 {
98 public:
99
102
103 virtual HashResult Calculate(const Aws::String& str) override;
104
105 virtual HashResult Calculate(Aws::IStream& stream) override;
106
107 virtual void Update(unsigned char* buffer, size_t bufferSize) override;
108
109 virtual HashResult GetHash() override;
110
111 private:
112 CC_SHA256_CTX m_ctx;
113 };
114
116 {
117 public:
118
121
122 virtual HashResult Calculate(const ByteBuffer& toSign, const ByteBuffer& secret) override;
123 };
124
129 {
130 public:
134 CommonCryptoCipher(const CryptoBuffer& key, size_t ivSize, bool ctrMode = false);
135
140 CommonCryptoCipher(CryptoBuffer&& key, CryptoBuffer&& initializationVector,
141 CryptoBuffer&& tag = CryptoBuffer(0));
142
147 CommonCryptoCipher(const CryptoBuffer& key, const CryptoBuffer& initializationVector,
148 const CryptoBuffer& tag = CryptoBuffer(0));
149
151
153
160
167
168
170
176 CryptoBuffer EncryptBuffer(const CryptoBuffer& unEncryptedData) override;
177
182
188 CryptoBuffer DecryptBuffer(const CryptoBuffer& encryptedData) override;
189
194
195 void Reset() override;
196
197 protected:
198 virtual size_t GetBlockSizeBytes() const = 0;
199
200 virtual size_t GetKeyLengthBits() const = 0;
201
202 bool CheckKeyAndIVLength(size_t expectedKeyLength, size_t expectedIVLength);
203
204 _CCCryptor* m_encryptorHandle;
205 _CCCryptor* m_decryptorHandle;
206
207 private:
208 void Init();
209 };
210
215 {
216 public:
221
226
230 AES_CBC_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
231
233
235
237
238 void Reset() override;
239
240 protected:
241 size_t GetBlockSizeBytes() const override;
242
243 size_t GetKeyLengthBits() const override;
244
245 private:
246 void InitCipher();
247
248 static size_t BlockSizeBytes;
249 static size_t KeyLengthBits;
250 };
251
256 {
257 public:
263
268
272 AES_CTR_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector);
273
275
277
279
280 void Reset() override;
281
282 protected:
283 size_t GetBlockSizeBytes() const override;
284
285 size_t GetKeyLengthBits() const override;
286
287 private:
288 void InitCipher();
289
290 static size_t BlockSizeBytes;
291 static size_t KeyLengthBits;
292 };
293
298 {
299 public:
304
309
315 CryptoBuffer&& tag = CryptoBuffer(0), CryptoBuffer&& aad = CryptoBuffer(0));
316
321 AES_GCM_Cipher_CommonCrypto(const CryptoBuffer& key, const CryptoBuffer& initializationVector,
322 const CryptoBuffer& tag = CryptoBuffer(), const CryptoBuffer& aad = CryptoBuffer());
323
325
327
329
332
333 void Reset() override;
334
335 protected:
336 size_t GetBlockSizeBytes() const override;
337
338 size_t GetKeyLengthBits() const override;
339
340 private:
341 void InitCipher();
342
343 CryptoBuffer m_aad;
344 static size_t BlockSizeBytes;
345 static size_t KeyLengthBits;
346 static size_t TagLengthBytes;
347 static size_t IVLengthBytes;
348 };
349
355 {
356 public:
361
363
365
367
368 CryptoBuffer EncryptBuffer(const CryptoBuffer& unEncryptedData) override;
369
371
372 CryptoBuffer DecryptBuffer(const CryptoBuffer& encryptedData) override;
373
375
376 void Reset() override;
377
378 protected:
379 inline size_t GetBlockSizeBytes() const override { return BlockSizeBytes; }
380
381 inline size_t GetKeyLengthBits() const override { return KeyLengthBits; }
382
383 private:
384 static size_t BlockSizeBytes;
385 static size_t KeyLengthBits;
386
387 CryptoBuffer m_workingKeyBuffer;
388 };
389
390 } // namespace Crypto
391 } // namespace Utils
392} // namespace Aws
char * buffer
Definition: cJSON.h:174
AES_CBC_Cipher_CommonCrypto & operator=(const AES_CBC_Cipher_CommonCrypto &other)=delete
AES_CBC_Cipher_CommonCrypto(const CryptoBuffer &key)
AES_CBC_Cipher_CommonCrypto(const AES_CBC_Cipher_CommonCrypto &other)=delete
AES_CBC_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector)
AES_CBC_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector)
AES_CBC_Cipher_CommonCrypto(AES_CBC_Cipher_CommonCrypto &&toMove)=default
AES_CTR_Cipher_CommonCrypto(AES_CTR_Cipher_CommonCrypto &&toMove)=default
AES_CTR_Cipher_CommonCrypto(const CryptoBuffer &key)
AES_CTR_Cipher_CommonCrypto(const AES_CTR_Cipher_CommonCrypto &other)=delete
AES_CTR_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector)
AES_CTR_Cipher_CommonCrypto & operator=(const AES_CTR_Cipher_CommonCrypto &other)=delete
AES_CTR_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector)
AES_GCM_Cipher_CommonCrypto(const AES_GCM_Cipher_CommonCrypto &other)=delete
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key)
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer &initializationVector, const CryptoBuffer &tag=CryptoBuffer(), const CryptoBuffer &aad=CryptoBuffer())
AES_GCM_Cipher_CommonCrypto(CryptoBuffer &&key, CryptoBuffer &&initializationVector, CryptoBuffer &&tag=CryptoBuffer(0), CryptoBuffer &&aad=CryptoBuffer(0))
AES_GCM_Cipher_CommonCrypto(const CryptoBuffer &key, const CryptoBuffer *aad)
AES_GCM_Cipher_CommonCrypto(AES_GCM_Cipher_CommonCrypto &&toMove)=default
AES_GCM_Cipher_CommonCrypto & operator=(const AES_GCM_Cipher_CommonCrypto &other)=delete
AES_KeyWrap_Cipher_CommonCrypto(AES_KeyWrap_Cipher_CommonCrypto &&)=default
AES_KeyWrap_Cipher_CommonCrypto & operator=(const AES_KeyWrap_Cipher_CommonCrypto &)=delete
CryptoBuffer EncryptBuffer(const CryptoBuffer &unEncryptedData) override
AES_KeyWrap_Cipher_CommonCrypto(const AES_KeyWrap_Cipher_CommonCrypto &)=delete
CryptoBuffer DecryptBuffer(const CryptoBuffer &encryptedData) override
AES_KeyWrap_Cipher_CommonCrypto(const CryptoBuffer &key)
CommonCryptoCipher(CryptoBuffer &&key, CryptoBuffer &&initializationVector, CryptoBuffer &&tag=CryptoBuffer(0))
CryptoBuffer DecryptBuffer(const CryptoBuffer &encryptedData) override
CryptoBuffer FinalizeDecryption() override
CommonCryptoCipher & operator=(const CommonCryptoCipher &other)=delete
CommonCryptoCipher(const CryptoBuffer &key, const CryptoBuffer &initializationVector, const CryptoBuffer &tag=CryptoBuffer(0))
CommonCryptoCipher(CommonCryptoCipher &&toMove)
virtual size_t GetBlockSizeBytes() const =0
CommonCryptoCipher(const CommonCryptoCipher &other)=delete
virtual size_t GetKeyLengthBits() const =0
CommonCryptoCipher(const CryptoBuffer &key, size_t ivSize, bool ctrMode=false)
CryptoBuffer FinalizeEncryption() override
CommonCryptoCipher & operator=(CommonCryptoCipher &&toMove)=default
CryptoBuffer EncryptBuffer(const CryptoBuffer &unEncryptedData) override
bool CheckKeyAndIVLength(size_t expectedKeyLength, size_t expectedIVLength)
virtual HashResult Calculate(const Aws::String &str) override
virtual void Update(unsigned char *buffer, size_t bufferSize) override
virtual HashResult GetHash() override
virtual HashResult Calculate(Aws::IStream &stream) override
void GetBytes(unsigned char *buffer, size_t bufferSize) override
virtual void Update(unsigned char *buffer, size_t bufferSize) override
virtual HashResult GetHash() override
virtual HashResult Calculate(const Aws::String &str) override
virtual HashResult Calculate(Aws::IStream &stream) override
virtual HashResult Calculate(const Aws::String &str) override
virtual HashResult GetHash() override
virtual HashResult Calculate(Aws::IStream &stream) override
virtual void Update(unsigned char *buffer, size_t bufferSize) override
virtual HashResult Calculate(const ByteBuffer &toSign, const ByteBuffer &secret) override
std::basic_istream< char, std::char_traits< char > > IStream
Definition: AWSStreamFwd.h:20
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97