AuroraRuntime/Source/Hashing/AuDigests.cpp

135 lines
5.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuDigests.cpp
Date: 2021-6-12
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuDigests.hpp"
#include <tomcrypt.h>
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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()));
}
}