freehash is a single file library of common message hashing functions. This project is inspired by picohash but aims to include more common hash functions and to be more easily reproducable so as to stay up to date with the upstream source (libtomcrypt) as necessary.
Simply copy the source files (freehash.h/freehash.c) into your project.
You can use any of the hash functions straight away or call register_all_hashes()
and enumerate
them by looping through hash_descriptor[]
or by calling find_hash()
, etc.
for (int i = 0; hash_descriptor[i].name != NULL; i++) {
printf("%s\n", hash_descriptor[i].name);
}
The following hash fucntions are enabled by default:
md2
md4
md5
sha1
sha224
sha256
sha384
sha512
sha512-224
sha512-256
sha3-224
sha3-256
sha3-384
sha3-512
You can rebuild the source files by running make
. The Makefile will fetch the required upstream
sources using wget
and then amalgamate them with an unhealthy amount of sed
commands. (And if
you're really curious, you can run make VERBOSE=1
to see all of the commands it's using.)
Note: the Makefile is not required for building freehash. You can compile it right away:
gcc -o freehash.o -c freehash.c
make clean
- remove generated build filesmake distclean
- remove generated build files and downloaded upstream sourcesmake sources
- rebuildfreehash.h
andfreehash.c
(this is the defaultmake
target)make shared
- build the shared librarylibfreehash.so
orfreehash.dll
make static
- build the static libraryfreehash.a
make test
- build and run the shared and static test applications
VERBOSE=1
- enable verbose output to see all of thesed
andwget
commands
Running make test
will produce two test files: test-shared
which links to libfreehash.so
and
test-static
which links directly with freehash.o
. Running these should produce an "OK"
output
for each of the hash functions listed above.
As with libtomcrypt, this project is released as public domain under Unlicense.