|
Boost : |
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2024-12-09 18:00:19
On 12/9/24 19:43, Peter Dimov via Boost wrote:
>
> Note that this is not the only innovation that the proposed
> hash algorithm concept involves. All hash algorithms are
> required to support seeding from uint64_t and from an
> arbitrary sequence of bytes, which makes them effectively
> _keyed hash functions_ (or _message authentication codes_).
>
> Also note that the requirement that one can interleave calls
> to `update` and `result` arbitrarily makes it possible to
> implement byte sequence seeding (for algorithms that don't
> already support it) in the following manner:
>
> Hash::Hash( unsigned char const* p, size_t n ): Hash()
> {
> if( n != 0 )
> {
> update( p, n );
> result();
> }
> }
>
> Subsequent `update` calls now start from an initial internal
> state that has incorporated the contents of [p, p+n), and that
> has been "finalized" (scrambled thoroughly) such that the
> result is not equivalent to just prepending the seed to the
> message (as would have happened if the result() call has been
> omitted.)
Also, my understanding of HMAC[1] is that the key is prepended to the
subsequent data and then the whole data is hashed. This contradicts with
your code calling result() in the middle. Am I missing something?
[1]: https://datatracker.ietf.org/doc/html/rfc2104#section-2
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk