[+] HashStream SOO

[+] HashSteam extension padding for future use
This commit is contained in:
Reece Wilson 2023-08-26 21:31:34 +01:00
parent a41a27198e
commit 9bd05a0752
3 changed files with 40 additions and 17 deletions

View File

@ -9,6 +9,8 @@
namespace Aurora::Hashing
{
static const auto kSizeHashStream = 512ul;
struct IHashStream
{
/**
@ -58,5 +60,7 @@ namespace Aurora::Hashing
virtual void Reset() = 0;
};
AUKN_SHARED_API(HashStream, IHashStream, EHashType type);
AUKN_SHARED_SOO2(HashStream, IHashStream, kSizeHashStream,
((EHashType,type)),
EHashType type);
}

View File

@ -13,12 +13,17 @@ namespace Aurora::Hashing
{
#define DIGEST_CHECK(n) SysAssert(n == CRYPT_OK)
HashStream::HashStream(EHashType type) : type_(type)
HashStreamImpl::HashStreamImpl(EHashType type) : type_(type)
{
if (!EHashTypeIsValid(type))
{
AU_THROW_CONST_STRING("Invalid Hash Type");
}
Init();
}
void HashStream::Ingest(const Memory::MemoryViewRead &input)
void HashStreamImpl::Ingest(const Memory::MemoryViewRead &input)
{
if (this->bFinished_)
{
@ -72,7 +77,7 @@ namespace Aurora::Hashing
}
}
AuUInt8 const* HashStream::GetBytes(AuUInt32 &length)
AuUInt8 const* HashStreamImpl::GetBytes(AuUInt32 &length)
{
switch (this->type_)
{
@ -201,14 +206,14 @@ namespace Aurora::Hashing
return nullptr;
}
AuMemoryViewRead HashStream::Finalize()
AuMemoryViewRead HashStreamImpl::Finalize()
{
AuUInt32 length;
auto begin = GetBytes(length);
return AuMemoryViewRead(begin, length);
}
Memory::MemoryViewRead HashStream::PeekFinalize()
Memory::MemoryViewRead HashStreamImpl::PeekFinalize()
{
if (this->bFinished_)
{
@ -224,7 +229,7 @@ namespace Aurora::Hashing
return view;
}
AuResult<AuMemoryViewRead> HashStream::Export()
AuResult<AuMemoryViewRead> HashStreamImpl::Export()
{
// Defer to HASH_PROCESS defined in the private libtomcrypt header
@ -289,7 +294,7 @@ namespace Aurora::Hashing
#undef ADD_EXPORT
}
bool HashStream::Import(const Memory::MemoryViewRead &view)
bool HashStreamImpl::Import(const Memory::MemoryViewRead &view)
{
this->bFinished_ = false;
@ -363,12 +368,12 @@ namespace Aurora::Hashing
#undef ADD_IMPORT
}
void HashStream::Reset()
void HashStreamImpl::Reset()
{
Init();
}
void HashStream::Init()
void HashStreamImpl::Init()
{
this->bFinished_ = false;
AuMemset(&this->state_, 0, sizeof(this->state_));
@ -425,11 +430,18 @@ namespace Aurora::Hashing
AUKN_SYM IHashStream *HashStreamNew(EHashType type)
{
return _new HashStream(type);
if (!EHashTypeIsValid(type))
{
return {};
}
AUKN_SYM void HashStreamRelease(IHashStream *stream)
return _new HashStreamImpl(type);
}
AUKN_SYM void HashStreamRelease(IHashStream *pStream)
{
AuSafeDelete<HashStream*>(stream);
AuSafeDelete<HashStreamImpl *>(pStream);
}
AUROXTL_INTERFACE_SOO_SRC(HashStream, HashStreamImpl, (EHashType, type))
}

View File

@ -9,9 +9,11 @@
namespace Aurora::Hashing
{
struct HashStream : IHashStream
#pragma pack(push)
#pragma pack(4)
struct HashStreamImpl : IHashStream
{
HashStream(EHashType type);
HashStreamImpl(EHashType type);
void Ingest(const Memory::MemoryViewRead &input) override;
@ -28,9 +30,14 @@ namespace Aurora::Hashing
void Init();
private:
AuUInt8 buffer_[64] {};
hash_state state_ {};
EHashType type_ {};
bool bFinished_ {};
AuUInt8 buffer_[64] {};
union
{
hash_state state_ {};
char altBuffer_[432];
};
};
#pragma pack(pop)
}