
On Mon, 18 Apr 2016 07:03:03 -0400 Vinnie Falco <vinnie.falco@gmail.com> wrote:
On Mon, Apr 18, 2016 at 6:55 AM, Thijs van den Berg <thijs@sitmo.com> wrote:
Maybe it's a good idea to release you version using the std::hash (or boost:hash) interface, although a separte library of common predefined hash function would be a more natural place for it?
We've got a proposal winding its way through the C++ standard process which provides a new interface to computing hashes on objects suitable for use with unordered containers: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html
The problem is that while these interfaces are great for the purposes of generating 32-bit or 64-bit digests for hash tables, they are deficient for cryptographic purposes (i.e. producing a message authentication code). For example, regular std::hash doesn't deal with endiannes. But computing a cryptographic digest must yield the same results on all platforms, and therefore cares about endianness.
The hash function could return a machine independent value like `std::array<std::uint8_t, sha1_length>`. From the document listed above: template <class HashAlgorithm> struct uhash { using result_type = typename HashAlgorithm::result_type; template <class T> result_type operator()(T const& t) const noexcept { HashAlgorithm h; using std::hash_append; hash_append(h, t); return static_cast<result_type>(h); } }; Lee