AuroraRuntime/Source/Hashing/Digests.cpp
Reece d0c4d8cb33 Hash API polish
[+] Added IHashStream::Export
[+] Added IHashStream::Import
[+] Added IHashStream::Finalize (versus "deprecated" older api)
[+] Added EHashType eMD4, eRMD128, eRMD160, eRMD256, eRMD320
2022-05-14 21:06:46 +01:00

93 lines
2.9 KiB
C++

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