poulpy/spqlios/lib/test/testlib/test_hash.cpp
spqlios/lib/test/testlib/test_hash.cppRaw
1#include "sha3.h"
2#include "test_commons.h"
3
4/** @brief returns some pseudorandom hash of the content */
5thash test_hash(const void* data, uint64_t size) {
6 thash res;
7 sha3(data, size, &res, sizeof(res));
8 return res;
9}
10/** @brief class to return a pseudorandom hash of the content */
11test_hasher::test_hasher() {
12 md = malloc(sizeof(sha3_ctx_t));
13 sha3_init((sha3_ctx_t*)md, 16);
14}
15
16void test_hasher::update(const void* data, uint64_t size) { sha3_update((sha3_ctx_t*)md, data, size); }
17
18thash test_hasher::hash() {
19 thash res;
20 sha3_final(&res, (sha3_ctx_t*)md);
21 return res;
22}
23
24test_hasher::~test_hasher() { free(md); }