aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
SymmetricCipher.h
Go to the documentation of this file.
1#pragma once
6#include <aws/cal/symmetric_cipher.h>
7#include <aws/crt/Exports.h>
8#include <aws/crt/Types.h>
9
10struct aws_symmetric_cipher;
11
12namespace Aws
13{
14 namespace Crt
15 {
16 namespace Crypto
17 {
18 static const size_t AES_256_CIPHER_BLOCK_SIZE = 16u;
19 static const size_t AES_256_KEY_SIZE_BYTES = 32u;
20
22 {
23 Ready = AWS_SYMMETRIC_CIPHER_READY,
24 Finalized = AWS_SYMMETRIC_CIPHER_FINALIZED,
25 Error = AWS_SYMMETRIC_CIPHER_ERROR,
26 };
27
29 {
30 public:
33 SymmetricCipher(SymmetricCipher &&) noexcept = default;
34 SymmetricCipher &operator=(SymmetricCipher &&) noexcept = default;
35
40 static SymmetricCipher CreateAES_256_CBC_Cipher(
41 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
42 const Optional<ByteCursor> &iv = Optional<ByteCursor>(),
43 Allocator *allocator = ApiAllocator()) noexcept;
44
49 static SymmetricCipher CreateAES_256_CTR_Cipher(
50 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
51 const Optional<ByteCursor> &iv = Optional<ByteCursor>(),
52 Allocator *allocator = ApiAllocator()) noexcept;
53
60 static SymmetricCipher CreateAES_256_GCM_Cipher(
61 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
62 const Optional<ByteCursor> &iv = Optional<ByteCursor>(),
63 const Optional<ByteCursor> &aad = Optional<ByteCursor>(),
64 Allocator *allocator = ApiAllocator()) noexcept;
65
70 static SymmetricCipher CreateAES_256_KeyWrap_Cipher(
71 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
72 Allocator *allocator = ApiAllocator()) noexcept;
73
77 operator bool() const noexcept;
78
83 SymmetricCipherState GetState() const noexcept;
84
88 inline int LastError() const noexcept { return m_lastError; }
89
98 bool Encrypt(const ByteCursor &toEncrypt, ByteBuf &out) noexcept;
99
108 bool FinalizeEncryption(ByteBuf &out) noexcept;
109
116 bool Decrypt(const ByteCursor &toDecrypt, ByteBuf &out) noexcept;
117
126 bool FinalizeDecryption(ByteBuf &out) noexcept;
127
131 bool Reset() noexcept;
132
137 ByteCursor GetKey() const noexcept;
138
144 ByteCursor GetIV() const noexcept;
145
151 ByteCursor GetTag() const noexcept;
152
157 void SetTag(ByteCursor tag) const noexcept;
158
159 private:
160 SymmetricCipher(aws_symmetric_cipher *cipher) noexcept;
161 ScopedResource<struct aws_symmetric_cipher> m_cipher;
162 int m_lastError;
163 };
164 } // namespace Crypto
165 } // namespace Crt
166} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition SymmetricCipher.h:29
SymmetricCipher(const SymmetricCipher &)=delete
SymmetricCipher & operator=(const SymmetricCipher &)=delete
SymmetricCipher(SymmetricCipher &&) noexcept=default
Definition Optional.h:19
static const size_t AES_256_CIPHER_BLOCK_SIZE
Definition SymmetricCipher.h:18
SymmetricCipherState
Definition SymmetricCipher.h:22
static const size_t AES_256_KEY_SIZE_BYTES
Definition SymmetricCipher.h:19
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
aws_byte_buf ByteBuf
Definition Types.h:30
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition Types.h:163
Definition Allocator.h:11