HashResult Sha256HMACCommonCryptoImpl::Calculate(const ByteBuffer& toSign, const ByteBuffer& secret) { unsigned int length = CC_SHA256_DIGEST_LENGTH; ByteBuffer digest(length); std::memset(digest.GetUnderlyingData(), 0, length); CCHmac(kCCHmacAlgSHA256, secret.GetUnderlyingData(), secret.GetLength(), toSign.GetUnderlyingData(), toSign.GetLength(), digest.GetUnderlyingData()); return HashResult(std::move(digest)); }
TEST(UUIDTest, TestUUIDToStringConversion) { ByteBuffer rawUuuid = HashingUtils::HexDecode("f81d4fae7dec11d0a76500a0c91e6bf6"); const char* expectedStr = "F81D4FAE-7DEC-11D0-A765-00A0C91E6BF6"; UUID uuid(rawUuuid.GetUnderlyingData()); Aws::String convertedStr = uuid; ASSERT_STREQ(expectedStr, convertedStr.c_str()); }
HashResult BCryptHashImpl::Calculate(const ByteBuffer& toHash, const ByteBuffer& secret) { if (!IsValid()) { return HashResult(); } std::lock_guard<std::mutex> locker(m_algorithmMutex); BCryptHashContext context(m_algorithmHandle, m_hashObject, m_hashObjectLength, secret); if (!context.IsValid()) { AWS_LOG_ERROR(logTag, "Error creating hash handle."); return HashResult(); } return HashData(context, static_cast<PBYTE>(toHash.GetUnderlyingData()), static_cast<ULONG>(toHash.GetLength())); }
BCryptHashContext(void* algorithmHandle, PBYTE hashObject, DWORD hashObjectLength, const ByteBuffer& secret) : m_hashHandle(nullptr), m_isValid(false) { NTSTATUS status = BCryptCreateHash(algorithmHandle, &m_hashHandle, hashObject, hashObjectLength, secret.GetUnderlyingData(), (ULONG)secret.GetLength(), 0); m_isValid = NT_SUCCESS(status); }