msix-packaging/MsixCore/msixmgr/CryptoProvider.hpp

49 строки
1.2 KiB
C++

#pragma once
#include <vector>
#define APPXCOMMON_NEW_TAG (std::nothrow)
namespace MsixCoreLib
{
struct COMMON_BYTES
{
ULONG length;
__field_ecount(length) BYTE* bytes;
};
// CryptoProvider objects are not thread-safe, hence should not be called from multiple threads simultaneously.
// Usage:
// (StartDigest DigestData* GetDigest* Reset)*
class CryptoProvider
{
private:
BCRYPT_ALG_HANDLE providerHandle;
BCRYPT_HASH_HANDLE hashHandle;
std::vector<BYTE> hashObjectBuffer;
std::vector<BYTE> digestBuffer;
BYTE quickHashObjectBuffer[700]; // Tests shows that HMAC with 256-bit or 512-bit keys requires 600+ bytes of hash object space.
BYTE quickDigestBuffer[64]; // accommodates up to 64-byte hashes
COMMON_BYTES digest;
HRESULT OpenProvider();
CryptoProvider();
public:
~CryptoProvider();
void Reset();
HRESULT StartDigest();
HRESULT DigestData(
_In_ const COMMON_BYTES* data);
HRESULT GetDigest(
_Out_ COMMON_BYTES* digest);
static HRESULT Create(
_Outptr_ CryptoProvider** provider);
};
}