/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuDigests.cpp Date: 2021-6-12 Author: Reece ***/ #include #include "AuDigests.hpp" #include namespace Aurora::Hashing { #define DIGEST_CHECK(n) SysAssert(n == CRYPT_OK) AUKN_SYM void MD4(const AuMemoryViewRead &read, AuArray &md4) { hash_state md; DIGEST_CHECK(md4_init(&md)); DIGEST_CHECK(md4_process(&md, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(md4_done(&md, md4.data())); } AUKN_SYM void MD5(const AuMemoryViewRead &read, AuArray &md5) { hash_state md; DIGEST_CHECK(md5_init(&md)); DIGEST_CHECK(md5_process(&md, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(md5_done(&md, md5.data())); } AUKN_SYM void SHA1(const AuMemoryViewRead &read, AuArray &sha1) { hash_state hs; DIGEST_CHECK(sha1_init(&hs)); DIGEST_CHECK(sha1_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha1_done(&hs, sha1.data())); } AUKN_SYM void Tiger(const AuMemoryViewRead &read, AuArray &tiger) { hash_state hs; DIGEST_CHECK(tiger_init(&hs)); DIGEST_CHECK(tiger_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(tiger_done(&hs, tiger.data())); } AUKN_SYM void SHA2(const AuMemoryViewRead &read, AuArray &sha2) { hash_state hs; DIGEST_CHECK(sha256_init(&hs)); DIGEST_CHECK(sha256_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha256_done(&hs, sha2.data())); } AUKN_SYM void SHA2_48(const AuMemoryViewRead &read, AuArray &sha2) { hash_state hs; DIGEST_CHECK(sha384_init(&hs)); DIGEST_CHECK(sha384_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha384_done(&hs, sha2.data())); } AUKN_SYM void SHA2_64(const AuMemoryViewRead &read, AuArray &sha2) { hash_state hs; DIGEST_CHECK(sha512_init(&hs)); DIGEST_CHECK(sha512_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha512_done(&hs, sha2.data())); } AUKN_SYM void SHA3_28(const AuMemoryViewRead &read, AuArray &sha3) { hash_state hs; DIGEST_CHECK(sha3_224_init(&hs)); DIGEST_CHECK(sha3_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha3_done(&hs, sha3.data())); } AUKN_SYM void SHA3_32(const AuMemoryViewRead &read, AuArray &sha3) { hash_state hs; DIGEST_CHECK(sha3_256_init(&hs)); DIGEST_CHECK(sha3_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha3_done(&hs, sha3.data())); } AUKN_SYM void SHA3_48(const AuMemoryViewRead &read, AuArray &sha3) { hash_state hs; DIGEST_CHECK(sha3_384_init(&hs)); DIGEST_CHECK(sha3_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha3_done(&hs, sha3.data())); } AUKN_SYM void SHA3_64(const AuMemoryViewRead &read, AuArray &sha3) { hash_state hs; DIGEST_CHECK(sha3_512_init(&hs)); DIGEST_CHECK(sha3_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(sha3_done(&hs, sha3.data())); } AUKN_SYM void RMD128(const AuMemoryViewRead &read, AuArray &rmd128) { hash_state hs; DIGEST_CHECK(rmd128_init(&hs)); DIGEST_CHECK(rmd128_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(rmd128_done(&hs, rmd128.data())); } AUKN_SYM void RMD160(const AuMemoryViewRead &read, AuArray &rmd160) { hash_state hs; DIGEST_CHECK(rmd160_init(&hs)); DIGEST_CHECK(rmd160_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(rmd160_done(&hs, rmd160.data())); } AUKN_SYM void RMD256(const AuMemoryViewRead &read, AuArray &rmd256) { hash_state hs; DIGEST_CHECK(rmd256_init(&hs)); DIGEST_CHECK(rmd256_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(rmd256_done(&hs, rmd256.data())); } AUKN_SYM void RMD320(const AuMemoryViewRead &read, AuArray &rmd320) { hash_state hs; DIGEST_CHECK(rmd320_init(&hs)); DIGEST_CHECK(rmd320_process(&hs, reinterpret_cast(read.ptr), read.length)); DIGEST_CHECK(rmd320_done(&hs, rmd320.data())); } }