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
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
26 Allocator *allocator,
27 const ByteCursor &secret,
28 const ByteCursor &input,
29 ByteBuf &output,
30 size_t truncateTo = 0) noexcept;
31
39 const ByteCursor &secret,
40 const ByteCursor &input,
41 ByteBuf &output,
42 size_t truncateTo = 0) noexcept;
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
95 size_t DigestSize() const noexcept;
96
107 bool ComputeOneShot(const ByteCursor &input, ByteBuf &output, size_t truncateTo = 0) noexcept;
108
109 private:
110 HMAC(aws_hmac *hmac) noexcept;
111 HMAC() = delete;
112
113 aws_hmac *m_hmac;
114 bool m_good;
115 int m_lastError;
116 };
117
125 {
126 public:
127 virtual ~ByoHMAC() = default;
128
133 aws_hmac *SeatForCInterop(const std::shared_ptr<ByoHMAC> &selfRef);
134
135 protected:
136 ByoHMAC(size_t digestSize, const ByteCursor &secret, Allocator *allocator = ApiAllocator());
137
143 virtual bool UpdateInternal(const ByteCursor &toHash) noexcept = 0;
144
151 virtual bool DigestInternal(ByteBuf &output, size_t truncateTo = 0) noexcept = 0;
152
153 private:
154 static void s_Destroy(struct aws_hmac *hmac);
155 static int s_Update(struct aws_hmac *hmac, const struct aws_byte_cursor *buf);
156 static int s_Finalize(struct aws_hmac *hmac, struct aws_byte_buf *out);
157
158 static aws_hmac_vtable s_Vtable;
159 aws_hmac m_hmacValue;
160 std::shared_ptr<ByoHMAC> m_selfReference;
161 };
162
164 std::function<std::shared_ptr<ByoHMAC>(size_t digestSize, const ByteCursor &secret, Allocator *)>;
165
166 } // namespace Crypto
167 } // namespace Crt
168} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition HMAC.h:125
virtual ~ByoHMAC()=default
virtual bool DigestInternal(ByteBuf &output, size_t truncateTo=0) noexcept=0
virtual bool UpdateInternal(const ByteCursor &toHash) noexcept=0
Definition HMAC.h:49
int LastError() const noexcept
Definition HMAC.h:65
HMAC(const HMAC &)=delete
HMAC & operator=(const HMAC &)=delete
std::function< std::shared_ptr< ByoHMAC >(size_t digestSize, const ByteCursor &secret, Allocator *)> CreateHMACCallback
Definition HMAC.h:164
static const size_t SHA256_HMAC_DIGEST_SIZE
Definition HMAC.h:17
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_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
aws_byte_buf ByteBuf
Definition Types.h:30
Definition Allocator.h:11
Definition StringView.h:862