Strict C89 LibRHash file checksum verification library with NO_DISCARD enum error percolation, Safe CRT support, and optional single-header STB-style amalgamation.
Originally the librhash implementation of libacquire's checksum API.
- Strict ISO C89 / ANSI C compatibility: Compiles cleanly with
-std=c89 -pedantic -Wall -Wextra -Werroron GCC/Clang and/W4 /WXon MSVC. - Explicit Error Percolation: Every function returns a
NO_DISCARDrhasheq_error_tstatus code (RHASHEQ_SUCCESS,RHASHEQ_INVALID_ARGUMENT,RHASHEQ_OUT_OF_MEMORY,RHASHEQ_INIT_ERROR,RHASHEQ_HASH_ERROR,RHASHEQ_FORMAT_ERROR) and writes verification results to an outputbool *. - Flexible Build Modes:
- Static library (
-DRHASHEQ_BUILD_STATIC=ON, default) - Shared library (
-DRHASHEQ_BUILD_SHARED=ON) - Header-only
INTERFACElibrary (-DRHASHEQ_HEADER_ONLY=ON) - Single-header STB-style amalgamation (
-DRHASHEQ_BUILD_AMALGAMATION=ON, generatesrhasheq_amalgamation.h; defineRHASHEQ_IMPLEMENTATIONbefore including in one translation unit)
- Static library (
- 31 Hash Algorithms Supported:
crc32,crc32c,md4,md5,sha1,sha224,sha256,sha384,sha512,sha3_224,sha3_256,sha3_384,sha3_512,tiger,tth,btih,ed2k,aich,whirlpool,ripemd160,gost94,gost94_cryptopro,has160,gost12_256,gost12_512,edonr256,edonr512,snefru128,snefru256,blake2s,blake2b.
- CMake (3.14 or later, including CMake 4.x)
- C compiler (any C89-compatible compiler supported by CMake)
- LibRHash (resolved automatically via system packages/vcpkg or fetched via CMake
FetchContent) - c89stringutils (resolved automatically via vcpkg/system packages or fetched via CMake
FetchContent)
cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure| Option | Default | Description |
|---|---|---|
RHASHEQ_BUILD_STATIC |
ON |
Build rhasheq as a static library |
RHASHEQ_BUILD_SHARED |
OFF |
Build rhasheq as a shared library |
RHASHEQ_HEADER_ONLY |
OFF |
Use rhasheq as a header-only INTERFACE library |
RHASHEQ_BUILD_AMALGAMATION |
ON |
Generate single-file rhasheq_amalgamation.h in the build directory |
RHASHEQ_BUILD_TESTING / BUILD_TESTING |
ON |
Build unit and amalgamation tests |
RHASHEQ_LTO |
OFF |
Enable Link-Time Optimization (IPO/LTO) |
RHASHEQ_CHARSET |
Unicode |
Character set (Unicode or ANSI) |
RHASHEQ_THREADING |
Multi-threaded |
Threading mode (Multi-threaded or Single-threaded) |
RHASHEQ_CRT_LINKAGE |
Shared |
MSVC CRT linkage (Shared or Static) |
#include <stdio.h>
#include <rhasheq.h>
int main(void) {
bool is_match = false;
rhasheq_error_t rc;
rc = sha256("path/to/file.txt",
"1292593d95c35eeccc89ffa1c91d6fe53b49f81cbf2c2b7758842b7f3186fcc2",
&is_match);
if (rc != RHASHEQ_SUCCESS) {
return (int)rc;
}
printf("SHA-256 matches: %s\n", is_match ? "true" : "false");
return 0;
}Define RHASHEQ_IMPLEMENTATION in one .c file before including rhasheq.h (or the generated rhasheq_amalgamation.h):
#define RHASHEQ_IMPLEMENTATION
#include "rhasheq_amalgamation.h"The code is distributed under BSD Zero Clause License.