[+] Added asserts in Digests.cpp and HashStream.cpp for good measure
[*] Fix: eRMD320 was crossed with some other done function
This commit is contained in:
parent
50a3ee76f6
commit
c36f159f95
@ -11,123 +11,125 @@
|
||||
|
||||
namespace Aurora::Hashing
|
||||
{
|
||||
#define DIGEST_CHECK(n) SysAssert(n == CRYPT_OK)
|
||||
|
||||
AUKN_SYM void MD4(const AuMemoryViewRead &read, AuArray<AuUInt8, 16> &md4)
|
||||
{
|
||||
hash_state md;
|
||||
md4_init(&md);
|
||||
md4_process(&md, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
md4_done(&md, md4.data());
|
||||
DIGEST_CHECK(md4_init(&md));
|
||||
DIGEST_CHECK(md4_process(&md, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(md4_done(&md, md4.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void MD5(const AuMemoryViewRead &read, AuArray<AuUInt8, 16> &md5)
|
||||
{
|
||||
hash_state md;
|
||||
md5_init(&md);
|
||||
md5_process(&md, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
md5_done(&md, md5.data());
|
||||
DIGEST_CHECK(md5_init(&md));
|
||||
DIGEST_CHECK(md5_process(&md, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(md5_done(&md, md5.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA1(const AuMemoryViewRead &read, AuArray<AuUInt8, 20> &sha1)
|
||||
{
|
||||
hash_state hs;
|
||||
sha1_init(&hs);
|
||||
sha1_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha1_done(&hs, sha1.data());
|
||||
DIGEST_CHECK(sha1_init(&hs));
|
||||
DIGEST_CHECK(sha1_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha1_done(&hs, sha1.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void Tiger(const AuMemoryViewRead &read, AuArray<AuUInt8, 24> &tiger)
|
||||
{
|
||||
hash_state hs;
|
||||
tiger_init(&hs);
|
||||
tiger_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
tiger_done(&hs, tiger.data());
|
||||
DIGEST_CHECK(tiger_init(&hs));
|
||||
DIGEST_CHECK(tiger_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(tiger_done(&hs, tiger.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA2(const AuMemoryViewRead &read, AuArray<AuUInt8, 32> &sha2)
|
||||
{
|
||||
hash_state hs;
|
||||
sha256_init(&hs);
|
||||
sha256_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha256_done(&hs, sha2.data());
|
||||
DIGEST_CHECK(sha256_init(&hs));
|
||||
DIGEST_CHECK(sha256_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha256_done(&hs, sha2.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA2_48(const AuMemoryViewRead &read, AuArray<AuUInt8, 48> &sha2)
|
||||
{
|
||||
hash_state hs;
|
||||
sha384_init(&hs);
|
||||
sha384_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha384_done(&hs, sha2.data());
|
||||
DIGEST_CHECK(sha384_init(&hs));
|
||||
DIGEST_CHECK(sha384_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha384_done(&hs, sha2.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA2_64(const AuMemoryViewRead &read, AuArray<AuUInt8, 64> &sha2)
|
||||
{
|
||||
hash_state hs;
|
||||
sha512_init(&hs);
|
||||
sha512_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha512_done(&hs, sha2.data());
|
||||
DIGEST_CHECK(sha512_init(&hs));
|
||||
DIGEST_CHECK(sha512_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha512_done(&hs, sha2.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA3_28(const AuMemoryViewRead &read, AuArray<AuUInt8, 28> &sha3)
|
||||
{
|
||||
hash_state hs;
|
||||
sha3_224_init(&hs);
|
||||
sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha3_done(&hs, sha3.data());
|
||||
DIGEST_CHECK(sha3_224_init(&hs));
|
||||
DIGEST_CHECK(sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha3_done(&hs, sha3.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA3_32(const AuMemoryViewRead &read, AuArray<AuUInt8, 32> &sha3)
|
||||
{
|
||||
hash_state hs;
|
||||
sha3_256_init(&hs);
|
||||
sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha3_done(&hs, sha3.data());
|
||||
DIGEST_CHECK(sha3_256_init(&hs));
|
||||
DIGEST_CHECK(sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha3_done(&hs, sha3.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA3_48(const AuMemoryViewRead &read, AuArray<AuUInt8, 48> &sha3)
|
||||
{
|
||||
hash_state hs;
|
||||
sha3_384_init(&hs);
|
||||
sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha3_done(&hs, sha3.data());
|
||||
DIGEST_CHECK(sha3_384_init(&hs));
|
||||
DIGEST_CHECK(sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha3_done(&hs, sha3.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void SHA3_64(const AuMemoryViewRead &read, AuArray<AuUInt8, 64> &sha3)
|
||||
{
|
||||
hash_state hs;
|
||||
sha3_512_init(&hs);
|
||||
sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
sha3_done(&hs, sha3.data());
|
||||
DIGEST_CHECK(sha3_512_init(&hs));
|
||||
DIGEST_CHECK(sha3_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(sha3_done(&hs, sha3.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void RMD128(const AuMemoryViewRead &read, AuArray<AuUInt8, 16> &rmd128)
|
||||
{
|
||||
hash_state hs;
|
||||
rmd128_init(&hs);
|
||||
rmd128_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
rmd128_done(&hs, rmd128.data());
|
||||
DIGEST_CHECK(rmd128_init(&hs));
|
||||
DIGEST_CHECK(rmd128_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(rmd128_done(&hs, rmd128.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void RMD160(const AuMemoryViewRead &read, AuArray<AuUInt8, 20> &rmd160)
|
||||
{
|
||||
hash_state hs;
|
||||
rmd160_init(&hs);
|
||||
rmd160_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
rmd160_done(&hs, rmd160.data());
|
||||
DIGEST_CHECK(rmd160_init(&hs));
|
||||
DIGEST_CHECK(rmd160_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(rmd160_done(&hs, rmd160.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void RMD256(const AuMemoryViewRead &read, AuArray<AuUInt8, 32> &rmd256)
|
||||
{
|
||||
hash_state hs;
|
||||
rmd256_init(&hs);
|
||||
rmd256_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
rmd256_done(&hs, rmd256.data());
|
||||
DIGEST_CHECK(rmd256_init(&hs));
|
||||
DIGEST_CHECK(rmd256_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(rmd256_done(&hs, rmd256.data()));
|
||||
}
|
||||
|
||||
AUKN_SYM void RMD320(const AuMemoryViewRead &read, AuArray<AuUInt8, 40> &rmd320)
|
||||
{
|
||||
hash_state hs;
|
||||
rmd320_init(&hs);
|
||||
rmd320_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length);
|
||||
rmd320_done(&hs, rmd320.data());
|
||||
DIGEST_CHECK(rmd320_init(&hs));
|
||||
DIGEST_CHECK(rmd320_process(&hs, reinterpret_cast<const unsigned char *>(read.ptr), read.length));
|
||||
DIGEST_CHECK(rmd320_done(&hs, rmd320.data()));
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Aurora::Hashing
|
||||
{
|
||||
#define DIGEST_CHECK(n) SysAssert(n == CRYPT_OK)
|
||||
|
||||
HashStream::HashStream(EHashType type) : type_(type)
|
||||
{
|
||||
Init();
|
||||
@ -29,43 +31,43 @@ namespace Aurora::Hashing
|
||||
switch (this->type_)
|
||||
{
|
||||
case EHashType::eMD4:
|
||||
md4_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(md4_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eMD5:
|
||||
md5_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(md5_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eSHA1:
|
||||
sha1_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(sha1_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eSHA2_32:
|
||||
sha256_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(sha256_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eSHA2_48:
|
||||
sha384_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(sha384_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eSHA2_64:
|
||||
sha512_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(sha512_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eSHA3_28:
|
||||
case EHashType::eSHA3_48:
|
||||
case EHashType::eSHA3_32:
|
||||
case EHashType::eSHA3_64:
|
||||
sha3_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(sha3_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eTiger:
|
||||
tiger_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(tiger_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eRMD128:
|
||||
rmd128_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(rmd128_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eRMD160:
|
||||
rmd160_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(rmd160_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eRMD256:
|
||||
rmd256_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(rmd256_process(&this->state_, buffer, len));
|
||||
break;
|
||||
case EHashType::eRMD320:
|
||||
rmd320_process(&this->state_, buffer, len);
|
||||
DIGEST_CHECK(rmd320_process(&this->state_, buffer, len));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -78,7 +80,7 @@ namespace Aurora::Hashing
|
||||
length = 16;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
md4_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(md4_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -86,7 +88,7 @@ namespace Aurora::Hashing
|
||||
length = 16;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
md5_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(md5_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -94,7 +96,7 @@ namespace Aurora::Hashing
|
||||
length = 20;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha1_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha1_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -102,7 +104,7 @@ namespace Aurora::Hashing
|
||||
length = 48;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha384_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha384_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -110,7 +112,7 @@ namespace Aurora::Hashing
|
||||
length = 32;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha256_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha256_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -118,7 +120,7 @@ namespace Aurora::Hashing
|
||||
length = 64;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha512_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha512_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -126,7 +128,7 @@ namespace Aurora::Hashing
|
||||
length = 28;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -134,7 +136,7 @@ namespace Aurora::Hashing
|
||||
length = 48;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -142,7 +144,7 @@ namespace Aurora::Hashing
|
||||
length = 32;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -150,7 +152,7 @@ namespace Aurora::Hashing
|
||||
length = 64;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(sha3_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -158,7 +160,7 @@ namespace Aurora::Hashing
|
||||
length = 24;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
tiger_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(tiger_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -166,7 +168,7 @@ namespace Aurora::Hashing
|
||||
length = 16;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
rmd128_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(rmd128_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -174,7 +176,7 @@ namespace Aurora::Hashing
|
||||
length = 20;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
rmd160_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(rmd160_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -182,7 +184,7 @@ namespace Aurora::Hashing
|
||||
length = 32;
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
rmd256_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(rmd256_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -191,7 +193,7 @@ namespace Aurora::Hashing
|
||||
|
||||
if (!AuExchange(this->bFinished_, true))
|
||||
{
|
||||
rmd256_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_));
|
||||
DIGEST_CHECK(rmd320_done(&this->state_, reinterpret_cast<unsigned char *>(this->buffer_)));
|
||||
}
|
||||
return this->buffer_;
|
||||
|
||||
@ -374,49 +376,49 @@ namespace Aurora::Hashing
|
||||
switch (this->type_)
|
||||
{
|
||||
case EHashType::eMD4:
|
||||
md4_init(&this->state_);
|
||||
DIGEST_CHECK(md4_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eMD5:
|
||||
md5_init(&this->state_);
|
||||
DIGEST_CHECK(md5_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA1:
|
||||
sha1_init(&this->state_);
|
||||
DIGEST_CHECK(sha1_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA2_32:
|
||||
sha256_init(&this->state_);
|
||||
DIGEST_CHECK(sha256_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA2_48:
|
||||
sha384_init(&this->state_);
|
||||
DIGEST_CHECK(sha384_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA2_64:
|
||||
sha512_init(&this->state_);
|
||||
DIGEST_CHECK(sha512_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA3_28:
|
||||
sha3_224_init(&this->state_);
|
||||
DIGEST_CHECK(sha3_224_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA3_32:
|
||||
sha3_256_init(&this->state_);
|
||||
DIGEST_CHECK(sha3_256_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA3_48:
|
||||
sha3_384_init(&this->state_);
|
||||
DIGEST_CHECK(sha3_384_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eSHA3_64:
|
||||
sha3_512_init(&this->state_);
|
||||
DIGEST_CHECK(sha3_512_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eTiger:
|
||||
tiger_init(&this->state_);
|
||||
DIGEST_CHECK(tiger_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eRMD128:
|
||||
rmd128_init(&this->state_);
|
||||
DIGEST_CHECK(rmd128_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eRMD160:
|
||||
rmd160_init(&this->state_);
|
||||
DIGEST_CHECK(rmd160_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eRMD256:
|
||||
rmd256_init(&this->state_);
|
||||
DIGEST_CHECK(rmd256_init(&this->state_));
|
||||
break;
|
||||
case EHashType::eRMD320:
|
||||
rmd320_init(&this->state_);
|
||||
DIGEST_CHECK(rmd320_init(&this->state_));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user