src/lt256: include, build and install ltsha256 utility
commitb4157181bcf941e3578e58e2ba8cbb87252e76fe
authorKyle J. McKay <mackyle@gmail.com>
Mon, 29 Jun 2020 22:09:14 +0000 (29 15:09 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Mon, 29 Jun 2020 22:09:14 +0000 (29 15:09 -0700)
tree1af11ad6b26f64f53ce3d46eb88a48a416e4c4ee
parente6bdf888eb06c6a527c4e0696a0ce979128f0f24
src/lt256: include, build and install ltsha256 utility

It's tempting to use Git's `git hash-object --stdin` function to
generate hash "signature"s.  It's easy, it's already guaranteed
to be present and it appears to be reasonably fast.

But it has issues:

  1) The "git" executable is rather large and performs a bunch
     of unwanted setup that's irrelevant to computing a hash

  2) The `git hash-object --stdin` operation creates a Git "blob"
     which requires the total length of the data being hashed be
     known in advance since the length ends up embedded at the
     beginning of a Git "blob"

  3) The `--stdin` option to `git hash-object` causes the entire
     input from a pipe to first be collected in an ever-expanding
     memory buffer until EOF is reached at which point the length
     becomes known and the hash is finally computed.

  4) The sha-1 hash that Git uses has been outdated and "broken"
     for several years now.

At first glance, there doesn't seem to be an obvious alternative
without requiring yet another dependency for Girocco.

The LibTomCrypt code <https://www.libtom.net/LibTomCrypt/> has a
very liberal license that is fully compatible with GPLv2.

Include the extracted sha256 computation code from LibTomCrypt
and a simple utility to compute the hexadecimal sha256 hash of
the input stream using the LibTomCrypt sha256 code.

Test and install this utility during normal Girocco installation.

The `ltsha256` utility runs plenty fast enough, does no extra
unwanted setup and has extremely low memory use since it hashes
the input as it reads it (no need to know the length in advance).

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
install.sh
src/.gitignore
src/GNUmakefile
src/lt256-LICENSE.txt [new file with mode: 0644]
src/lt256.c [new file with mode: 0644]
src/lt256.h [new file with mode: 0644]
src/ltsha256-test.sh [new file with mode: 0755]
src/ltsha256.c [new file with mode: 0644]