[+] AuHashing::Whirlpool

[+] AuHashing::Blake2S_32
[+] AuHashing::Blake2S_28
[+] AuHashing::Blake2S_20
[+] AuHashing::Blake2S_16
[+] AuHashing::Blake2B_64
[+] AuHashing::Blake2B_48
[+] AuHashing::Blake2B_32
[+] AuHashing::Blake2B_20
[+] AuHashing::GetHashLength
[+] AuHashing::GetHashBits
[+] AuHashing::IHashStream::GetHashType
This commit is contained in:
Reece Wilson 2024-02-18 17:53:37 +00:00
parent ce33642b1e
commit 3732352b4e
6 changed files with 382 additions and 8 deletions

View File

@ -9,6 +9,9 @@
namespace Aurora::Hashing
{
AUKN_SYM AuUInt8 GetHashLength(EHashType eType);
AUKN_SYM AuUInt8 GetHashBits(EHashType eType);
AUKN_SYM void MD4(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 16> &md4);
AUKN_SYM void MD5(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 16> &md5);
@ -50,4 +53,22 @@ namespace Aurora::Hashing
* @brief RipeMD-320
*/
AUKN_SYM void RMD320(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 40> &rmd320);
AUKN_SYM void Whirlpool(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 64> &whirlpool);
AUKN_SYM void Blake2S_32(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 32> &blake2S);
AUKN_SYM void Blake2S_28(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 28> &blake2S);
AUKN_SYM void Blake2S_20(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 20> &blake2S);
AUKN_SYM void Blake2S_16(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 16> &blake2S);
AUKN_SYM void Blake2B_64(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 64> &blake2B);
AUKN_SYM void Blake2B_48(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 48> &blake2B);
AUKN_SYM void Blake2B_32(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 32> &blake2B);
AUKN_SYM void Blake2B_20(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 20> &blake2B);
}

View File

@ -25,6 +25,15 @@ namespace Aurora::Hashing
eRMD128,
eRMD160,
eRMD256,
eRMD320
eRMD320,
eWhirlpool,
eBlake2S_32,
eBlake2S_28,
eBlake2S_20,
eBlake2S_16,
eBlake2B_64,
eBlake2B_48,
eBlake2B_32,
eBlake2B_20
));
}

View File

@ -43,6 +43,7 @@ namespace Aurora::Hashing
/**
* @brief Exports the state of an aligned stream
* @warning This method assumes you're dealing with block aligned streams
* @return
*/
virtual AuResult<Memory::MemoryViewRead> Export() = 0;
@ -58,6 +59,8 @@ namespace Aurora::Hashing
* @brief Reuse the IHashStream of the EHashType variant by resetting the stream state to its' default configuration
*/
virtual void Reset() = 0;
virtual EHashType GetHashType() = 0;
};
AUKN_SHARED_SOO2(HashStream, IHashStream, kSizeHashStream,

View File

@ -132,4 +132,162 @@ namespace Aurora::Hashing
DIGEST_CHECK(rmd320_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
DIGEST_CHECK(rmd320_done(&hs, rmd320.data()));
}
AUKN_SYM void Whirlpool(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 64> &whirlpool)
{
hash_state hs;
DIGEST_CHECK(whirlpool_init(&hs));
DIGEST_CHECK(whirlpool_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(whirlpool_done(&hs, whirlpool.data()));
}
AUKN_SYM void Blake2S_32(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 32> &blake2S)
{
hash_state hs;
DIGEST_CHECK(blake2s_256_init(&hs));
DIGEST_CHECK(blake2s_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2s_done(&hs, blake2S.data()));
}
AUKN_SYM void Blake2S_28(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 28> &blake2S)
{
hash_state hs;
DIGEST_CHECK(blake2s_224_init(&hs));
DIGEST_CHECK(blake2s_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2s_done(&hs, blake2S.data()));
}
AUKN_SYM void Blake2S_20(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 20> &blake2S)
{
hash_state hs;
DIGEST_CHECK(blake2s_160_init(&hs));
DIGEST_CHECK(blake2s_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2s_done(&hs, blake2S.data()));
}
AUKN_SYM void Blake2S_16(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 16> &blake2S)
{
hash_state hs;
DIGEST_CHECK(blake2s_128_init(&hs));
DIGEST_CHECK(blake2s_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2s_done(&hs, blake2S.data()));
}
AUKN_SYM void Blake2B_64(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 64> &blake2B)
{
hash_state hs;
DIGEST_CHECK(blake2b_512_init(&hs));
DIGEST_CHECK(blake2b_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2b_done(&hs, blake2B.data()));
}
AUKN_SYM void Blake2B_48(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 48> &blake2B)
{
hash_state hs;
DIGEST_CHECK(blake2b_384_init(&hs));
DIGEST_CHECK(blake2b_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2b_done(&hs, blake2B.data()));
}
AUKN_SYM void Blake2B_32(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 32> &blake2B)
{
hash_state hs;
DIGEST_CHECK(blake2b_256_init(&hs));
DIGEST_CHECK(blake2b_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2b_done(&hs, blake2B.data()));
}
AUKN_SYM void Blake2B_20(const Memory::MemoryViewRead &toHash, AuArray<AuUInt8, 20> &blake2B)
{
hash_state hs;
DIGEST_CHECK(blake2b_160_init(&hs));
DIGEST_CHECK(blake2b_process(&hs, reinterpret_cast<const unsigned char *>(toHash.ptr), toHash.length));
DIGEST_CHECK(blake2b_done(&hs, blake2B.data()));
}
AUKN_SYM AuUInt8 GetHashLength(EHashType eType)
{
switch (eType)
{
case EHashType::eMD4:
return 16;
case EHashType::eMD5:
return 16;
case EHashType::eSHA1:
return 20;
case EHashType::eSHA2_48:
return 48;
case EHashType::eSHA2_32:
return 32;
case EHashType::eSHA2_64:
return 64;
case EHashType::eSHA3_28:
return 28;
case EHashType::eSHA3_48:
return 48;
case EHashType::eSHA3_32:
return 32;
case EHashType::eSHA3_64:
return 64;
case EHashType::eTiger:
return 24;
case EHashType::eRMD128:
return 16;
case EHashType::eRMD160:
return 20;
case EHashType::eRMD256:
return 32;
case EHashType::eRMD320:
return 40;
case EHashType::eWhirlpool:
return 64;
case EHashType::eBlake2S_32:
return 32;
case EHashType::eBlake2S_28:
return 28;
case EHashType::eBlake2S_20:
return 20;
case EHashType::eBlake2S_16:
return 16;
case EHashType::eBlake2B_64:
return 64;
case EHashType::eBlake2B_48:
return 48;
case EHashType::eBlake2B_32:
return 32;
case EHashType::eBlake2B_20:
return 20;
}
SysPushErrorArg("Invalid hash type");
return 0;
}
AUKN_SYM AuUInt8 GetHashBits(EHashType eType)
{
return GetHashLength(eType) * 8;
}
}

View File

@ -80,6 +80,21 @@ namespace Aurora::Hashing
case EHashType::eRMD320:
DIGEST_CHECK(rmd320_process(&this->state_, buffer, len));
break;
case EHashType::eWhirlpool:
DIGEST_CHECK(whirlpool_process(&this->state_, buffer, len));
break;
case EHashType::eBlake2S_32:
case EHashType::eBlake2S_28:
case EHashType::eBlake2S_20:
case EHashType::eBlake2S_16:
DIGEST_CHECK(blake2s_process(&this->state_, buffer, len));
break;
case EHashType::eBlake2B_64:
case EHashType::eBlake2B_48:
case EHashType::eBlake2B_32:
case EHashType::eBlake2B_20:
DIGEST_CHECK(blake2b_process(&this->state_, buffer, len));
break;
}
}
@ -208,6 +223,87 @@ namespace Aurora::Hashing
}
return this->buffer_;
case EHashType::eWhirlpool:
length = 64;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(whirlpool_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2S_32:
length = 32;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2s_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2S_28:
length = 28;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2s_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2S_20:
length = 20;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2s_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2S_16:
length = 16;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2s_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2B_64:
length = 64;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2b_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2B_48:
length = 48;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2b_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2B_32:
length = 32;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2b_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
case EHashType::eBlake2B_20:
length = 20;
if (!AuExchange(this->bFinished_, true))
{
DIGEST_CHECK(blake2b_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
}
return this->buffer_;
}
return nullptr;
}
@ -248,6 +344,13 @@ namespace Aurora::Hashing
} \
return AuMemoryViewRead {this->state_.name.state, sizeof(this->state_.name.state)};
#define ADD_EXPORT_UNSAFE(name) \
if (this->state_.name.curlen) \
{ \
return {}; \
} \
return AuMemoryViewRead {&this->state_.name, sizeof(this->state_.name)};
switch (this->type_)
{
case EHashType::eMD4:
@ -294,6 +397,22 @@ namespace Aurora::Hashing
case EHashType::eRMD320:
ADD_EXPORT(rmd320);
case EHashType::eWhirlpool:
ADD_EXPORT(whirlpool);
case EHashType::eBlake2S_32:
case EHashType::eBlake2S_28:
case EHashType::eBlake2S_20:
case EHashType::eBlake2S_16:
ADD_EXPORT_UNSAFE(blake2s)
case EHashType::eBlake2B_64:
case EHashType::eBlake2B_48:
case EHashType::eBlake2B_32:
case EHashType::eBlake2B_20:
ADD_EXPORT_UNSAFE(blake2b)
default:
return {};
}
@ -314,6 +433,21 @@ namespace Aurora::Hashing
AuMemcpy(this->state_.name.state, view.ptr, sizeof(this->state_.name.state)); \
return true;
#define ADD_IMPORT_UNSAFE(name) \
if (sizeof(this->state_.name) != view.length) \
{ \
SysPushErrorCrypt("Invalid hash state length -> mixed ciphers?"); \
return false; \
} \
if (this->state_.name.outlen != ((decltype(this->state_.name) *)(view.ptr))->outlen) \
{ \
SysPushErrorCrypt("Invalid hash state length -> mixed ciphers?"); \
return false; \
} \
AuMemset(&this->state_, 0, sizeof(this->state_)); \
AuMemcpy(&this->state_.name, view.ptr, sizeof(this->state_.name)); \
return true;
switch (this->type_)
{
case EHashType::eMD4:
@ -367,6 +501,21 @@ namespace Aurora::Hashing
case EHashType::eRMD320:
ADD_IMPORT(rmd320);
case EHashType::eWhirlpool:
ADD_IMPORT(whirlpool);
case EHashType::eBlake2S_32:
case EHashType::eBlake2S_28:
case EHashType::eBlake2S_20:
case EHashType::eBlake2S_16:
ADD_IMPORT_UNSAFE(blake2s)
case EHashType::eBlake2B_64:
case EHashType::eBlake2B_48:
case EHashType::eBlake2B_32:
case EHashType::eBlake2B_20:
ADD_IMPORT_UNSAFE(blake2b)
default:
return false;
}
@ -431,9 +580,41 @@ namespace Aurora::Hashing
case EHashType::eRMD320:
DIGEST_CHECK(rmd320_init(&this->state_));
break;
case EHashType::eWhirlpool:
DIGEST_CHECK(whirlpool_init(&this->state_));
break;
case EHashType::eBlake2S_32:
DIGEST_CHECK(blake2s_256_init(&this->state_));
break;
case EHashType::eBlake2S_28:
DIGEST_CHECK(blake2s_224_init(&this->state_));
break;
case EHashType::eBlake2S_20:
DIGEST_CHECK(blake2s_160_init(&this->state_));
break;
case EHashType::eBlake2S_16:
DIGEST_CHECK(blake2s_128_init(&this->state_));
break;
case EHashType::eBlake2B_64:
DIGEST_CHECK(blake2b_512_init(&this->state_));
break;
case EHashType::eBlake2B_48:
DIGEST_CHECK(blake2b_384_init(&this->state_));
break;
case EHashType::eBlake2B_32:
DIGEST_CHECK(blake2b_256_init(&this->state_));
break;
case EHashType::eBlake2B_20:
DIGEST_CHECK(blake2b_160_init(&this->state_));
break;
}
}
EHashType HashStreamImpl::GetHashType()
{
return this->type_;
}
AUKN_SYM IHashStream *HashStreamNew(EHashType type)
{
if (!EHashTypeIsValid(type))

View File

@ -28,6 +28,8 @@ namespace Aurora::Hashing
void Reset() override;
EHashType GetHashType() override;
void Init();
private:
EHashType type_ {};