AWS IoT Device SDK C++ v2 1.44.1
AWS IoT Device SDK C++ v2
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
41 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
42 const Optional<ByteCursor> &iv = Optional<ByteCursor>(),
43 Allocator *allocator = ApiAllocator()) noexcept;
44
50 const Optional<ByteCursor> &key = Optional<ByteCursor>(),
51 const Optional<ByteCursor> &iv = Optional<ByteCursor>(),
52 Allocator *allocator = ApiAllocator()) noexcept;
53
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
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
Definition SymmetricCipher.h:29
SymmetricCipher(const SymmetricCipher &)=delete
static SymmetricCipher CreateAES_256_KeyWrap_Cipher(const Optional< ByteCursor > &key=Optional< ByteCursor >(), Allocator *allocator=ApiAllocator()) noexcept
Definition SymmetricCipher.cpp:175
int LastError() const noexcept
Definition SymmetricCipher.h:88
static SymmetricCipher CreateAES_256_GCM_Cipher(const Optional< ByteCursor > &key=Optional< ByteCursor >(), const Optional< ByteCursor > &iv=Optional< ByteCursor >(), const Optional< ByteCursor > &aad=Optional< ByteCursor >(), Allocator *allocator=ApiAllocator()) noexcept
Definition SymmetricCipher.cpp:162
SymmetricCipher & operator=(const SymmetricCipher &)=delete
SymmetricCipherState GetState() const noexcept
Definition SymmetricCipher.cpp:28
static SymmetricCipher CreateAES_256_CTR_Cipher(const Optional< ByteCursor > &key=Optional< ByteCursor >(), const Optional< ByteCursor > &iv=Optional< ByteCursor >(), Allocator *allocator=ApiAllocator()) noexcept
Definition SymmetricCipher.cpp:153
static SymmetricCipher CreateAES_256_CBC_Cipher(const Optional< ByteCursor > &key=Optional< ByteCursor >(), const Optional< ByteCursor > &iv=Optional< ByteCursor >(), Allocator *allocator=ApiAllocator()) noexcept
Definition SymmetricCipher.cpp:144
SymmetricCipher(SymmetricCipher &&) noexcept=default
Definition Optional.h:19
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition Hash.h:17
static const size_t AES_256_CIPHER_BLOCK_SIZE
Definition SymmetricCipher.h:18
SymmetricCipherState
Definition SymmetricCipher.h:22
@ Finalized
Definition SymmetricCipher.h:24
@ Error
Definition SymmetricCipher.h:25
@ Ready
Definition SymmetricCipher.h:23
static const size_t AES_256_KEY_SIZE_BYTES
Definition SymmetricCipher.h:19
Definition Allocator.h:13
std::unique_ptr< T, std::function< void(T *)> > ScopedResource
Definition Types.h:163
aws_byte_cursor ByteCursor
Definition Types.h:31
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
aws_allocator Allocator
Definition Allocator.h:14
aws_byte_buf ByteBuf
Definition Types.h:30
Definition Allocator.h:11