AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/crypto/HMAC.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

HMAC.h
Go to the documentation of this file.
1#pragma once
6#include <aws/cal/hmac.h>
7#include <aws/crt/Exports.h>
8#include <aws/crt/Types.h>
9
10struct aws_hmac;
11namespace Aws
12{
13 namespace Crt
14 {
15 namespace Crypto
16 {
17 static const size_t SHA256_HMAC_DIGEST_SIZE = 32;
18
25 bool AWS_CRT_CPP_API ComputeSHA256HMAC(
26 Allocator *allocator,
27 const ByteCursor &secret,
28 const ByteCursor &input,
29 ByteBuf &output,
30 size_t truncateTo = 0) noexcept;
31
38 bool AWS_CRT_CPP_API ComputeSHA256HMAC(
39 const ByteCursor &secret,
40 const ByteCursor &input,
41 ByteBuf &output,
42 size_t truncateTo = 0) noexcept;
48 class AWS_CRT_CPP_API HMAC final
49 {
50 public:
51 ~HMAC();
52 HMAC(const HMAC &) = delete;
53 HMAC &operator=(const HMAC &) = delete;
54 HMAC(HMAC &&toMove);
55 HMAC &operator=(HMAC &&toMove);
56
60 inline operator bool() const noexcept { return m_good; }
61
65 inline int LastError() const noexcept { return m_lastError; }
66
70 static HMAC CreateSHA256HMAC(Allocator *allocator, const ByteCursor &secret) noexcept;
71
75 static HMAC CreateSHA256HMAC(const ByteCursor &secret) noexcept;
76
81 bool Update(const ByteCursor &toHMAC) noexcept;
82
89 bool Digest(ByteBuf &output, size_t truncateTo = 0) noexcept;
90
91 private:
92 HMAC(aws_hmac *hmac) noexcept;
93 HMAC() = delete;
94
95 aws_hmac *m_hmac;
96 bool m_good;
97 int m_lastError;
98 };
99
106 class AWS_CRT_CPP_API ByoHMAC
107 {
108 public:
109 virtual ~ByoHMAC() = default;
110
115 aws_hmac *SeatForCInterop(const std::shared_ptr<ByoHMAC> &selfRef);
116
117 protected:
118 ByoHMAC(size_t digestSize, const ByteCursor &secret, Allocator *allocator = g_allocator);
119
125 virtual bool UpdateInternal(const ByteCursor &toHash) noexcept = 0;
126
133 virtual bool DigestInternal(ByteBuf &output, size_t truncateTo = 0) noexcept = 0;
134
135 private:
136 static void s_Destroy(struct aws_hmac *hmac);
137 static int s_Update(struct aws_hmac *hmac, const struct aws_byte_cursor *buf);
138 static int s_Finalize(struct aws_hmac *hmac, struct aws_byte_buf *out);
139
140 static aws_hmac_vtable s_Vtable;
141 aws_hmac m_hmacValue;
142 std::shared_ptr<ByoHMAC> m_selfReference;
143 };
144
145 using CreateHMACCallback =
146 std::function<std::shared_ptr<ByoHMAC>(size_t digestSize, const ByteCursor &secret, Allocator *)>;
147
148 } // namespace Crypto
149 } // namespace Crt
150} // namespace Aws
Types.h
Aws::Crt::Crypto::ByoHMAC
Definition: HMAC.h:107
Aws::Crt::Crypto::ByoHMAC::~ByoHMAC
virtual ~ByoHMAC()=default
Aws::Crt::Crypto::ByoHMAC::DigestInternal
virtual bool DigestInternal(ByteBuf &output, size_t truncateTo=0) noexcept=0
Aws::Crt::Crypto::ByoHMAC::UpdateInternal
virtual bool UpdateInternal(const ByteCursor &toHash) noexcept=0
Aws::Crt::Crypto::HMAC
Definition: HMAC.h:49
Aws::Crt::Crypto::HMAC::LastError
int LastError() const noexcept
Definition: HMAC.h:65
Aws::Crt::Crypto::HMAC::HMAC
HMAC(const HMAC &)=delete
Aws::Crt::Crypto::HMAC::operator=
HMAC & operator=(const HMAC &)=delete
Exports.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Crypto::CreateHMACCallback
std::function< std::shared_ptr< ByoHMAC >(size_t digestSize, const ByteCursor &secret, Allocator *)> CreateHMACCallback
Definition: HMAC.h:146
Aws::Crt::Crypto::SHA256_HMAC_DIGEST_SIZE
static const size_t SHA256_HMAC_DIGEST_SIZE
Definition: HMAC.h:17
Aws::Crt::Crypto::ComputeSHA256HMAC
bool AWS_CRT_CPP_API ComputeSHA256HMAC(Allocator *allocator, const ByteCursor &secret, const ByteCursor &input, ByteBuf &output, size_t truncateTo=0) noexcept
Definition: HMAC.cpp:15
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:33
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::g_allocator
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:32
Aws
Definition: Api.h:17
std
Definition: StringView.h:851