Sane C++ Libraries
C++ Platform Abstraction Libraries
sc_hashing.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#if !defined(SANE_CPP_LIBRARIES_HASHING)
4#define SANE_CPP_LIBRARIES_HASHING 1
5#include <stdbool.h> // bool
6#include <stddef.h> // size_t
7#include <stdint.h> // uint64_t
8
11
14
30
32
33#if _MSC_VER
34#define SANE_CPP_NO_DISCARD
35#else
36#define SANE_CPP_NO_DISCARD __attribute__((warn_unused_result))
37#endif
38// clang-format off
39#ifdef __cplusplus
40extern "C"
41{
42#endif
43
45typedef enum
46{
51
53typedef struct
54{
55 uint64_t opaque[14];
57
59typedef struct
60{
61 uint8_t hash[32];
62 size_t size;
64
66typedef struct
67{
68 const void* data;
69 size_t length;
71
73SANE_CPP_NO_DISCARD bool sc_hashing_init(sc_hashing_t* hashing, sc_hashing_type type);
74
77
79SANE_CPP_NO_DISCARD bool sc_hashing_add(sc_hashing_t* hashing, sc_hashing_span_t span);
80
82SANE_CPP_NO_DISCARD bool sc_hashing_get(sc_hashing_t* hashing, sc_hashing_result_t* result);
83
84#ifdef __cplusplus
85} // extern "C"
86#endif
87// clang-format on
88
89#undef SANE_CPP_NO_DISCARD
91
92#endif // SANE_CPP_LIBRARIES_HASHING
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition: PrimitiveTypes.h:36
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition: PrimitiveTypes.h:42
SANE_CPP_NO_DISCARD bool sc_hashing_get(sc_hashing_t *hashing, sc_hashing_result_t *result)
Obtain the actual hash of data added through sc_hashing_add.
sc_hashing_type
Type of hashing algorithm to use.
Definition: sc_hashing.h:46
void sc_hashing_close(sc_hashing_t *hashing)
Releases os resources allocated by sc_hashing_init.
SANE_CPP_NO_DISCARD bool sc_hashing_init(sc_hashing_t *hashing, sc_hashing_type type)
Initializes OS objects to compute hash (call sc_hashing_close when done).
SANE_CPP_NO_DISCARD bool sc_hashing_add(sc_hashing_t *hashing, sc_hashing_span_t span)
Add data to hash computation. Can be called multiple times to hash data iteratively.
@ SC_HASHING_TYPE_SHA1
Computes SHA1 Hash.
Definition: sc_hashing.h:48
@ SC_HASHING_TYPE_MD5
Computes MD5 Hash.
Definition: sc_hashing.h:47
@ SC_HASHING_TYPE_SHA256
Computes SHA256 Hash.
Definition: sc_hashing.h:49
Hash result.
Definition: sc_hashing.h:60
size_t size
Length of the computed hash.
Definition: sc_hashing.h:62
Just a generic data span.
Definition: sc_hashing.h:67
const void * data
Pointer to data.
Definition: sc_hashing.h:68
size_t length
Length of the data (in bytes)
Definition: sc_hashing.h:69
Opaque object holding state of hashing.
Definition: sc_hashing.h:54