
Vinnie Falco wrote:
Sigh.. copy/paste typo.
/** Return a seeded HashAlgorithm */ template< class HashAlgorithm > HashAlgorithm make_seeded( unsigned char const* seed, std::size_t n ) { if constexpr(std::is_constructible
) return HashAlgorithm(seed, n); else { HashAlgorithm h; hash_append(h, seed, n);
You can in principle do something like that (except fix it to compile) but (much) better practices would be - hash.update( seed, n ) - encode `n` as 64 bit little endian in 8 bytes - hash.update these bytes - hash.update( "\x80", 1 ) - hash.update( "\x00", 1 ) - hash.update with as many zeroes as needed to reach a multiple of HashAlgorithm::block_size That's, incidentally, exactly what `update(p, n); result();` does. (What an amazing coincidence.) Note that reaching a multiple of block_size is important, because it ensures that the secret key you passed as the seed is not left in the internal buffer of the hash algorithm, visible in memory dumps. The test https://github.com/pdimov/hash2/blob/develop/test/plaintext_leak.cpp tries to catch these mistakes. That's why this line https://github.com/pdimov/hash2/blob/7a25f8518692b657e9272884519519fbaca2ec5... is needed, for example.
return h; } }
Thanks