Eigenstate : libcryptohash

Libcryptohash contains a set of implementations of common hash functions. It supports taking the hash of an entire string, as well as a streaming API.

API Reference

    pkg cryptohash =
            /* state types */
            type md5
            type sha1
            type sha256
            type sha224
            type sha512

            /* md5 funtions */
            const md5       : (data : byte[:] -> byte[16])
            const md5init   : (st : md5# -> void)
            const md5add    : (st : md5#, data : byte[:] -> void)
            const md5fin    : (st : md5# -> byte[16])

            /* sha1 functions */
            const sha1      : (data : byte[:] -> byte[20])
            const sha1init  : (st : sha1# -> void)
            const sha1add   : (st : sha1#, data : byte[:] -> void)
            const sha1fin   : (st : sha1# -> byte[20])

            /* sha256 functions */
            const sha256    : (data : byte[:] -> byte[32])
            const sha256init        : (st : sha256# -> void)
            const sha256add : (st : sha256#, data : byte[:] -> void)
            const sha256fin : (st : sha256# -> byte[32])

            /* sha224 functions */
            const sha224    : (data : byte[:] -> byte[28])
            const sha224init        : (st : sha224# -> void)
            const sha224add : (st : sha224#, data : byte[:] -> void)
            const sha224fin : (st : sha224# -> byte[28])

            /* sha512 functions */
            const sha512    : (data : byte[:] -> byte[64])
            const sha512init        : (st : sha512# -> void)
            const sha512add : (st : sha512#, data : byte[:] -> void)
            const sha512fin : (st : sha512# -> byte[64])

            /* sha384 functions */
            const sha384    : (data : byte[:] -> byte[48])
            const sha384init        : (st : sha384# -> void)
            const sha384add : (st : sha384#, data : byte[:] -> void)
            const sha384fin : (st : sha384# -> byte[48])
    ;;

The hashtype functions (eg, md5(), sha1(), etc) all compute and immediately return the hash of their argument.

The hashtypeinit() functions will initialize a hashing state of type hashtype, and prepare it to accept input.

The hashtypeadd() functions must be called on an initialized state, and will add data argument to the hashed value.

The hashtypefin() functions will return the hash value that was computed on the data added by hashtypeadd(). If hashtypeadd() was not called, the hash of 0 bytes of data will be returned.

Example: Simple hashing

Example: Streaming hash