Back to Index

The MaybeBoost Hash Library: Concepts

HashAlgorithm Concept

Models of the HashAlgorithm concept are policies to be provided as template arguments to other templates. They provide access to the set of types needed to generically compute and store digests with a particular algorithm. (For example, the compute_digest function templates are parametrized by a HashAlgorithm, as would a future HMAC-computing function template.)

A type T modelling the HashAlgorithm concept must support the following:

T::stream_hash<ValueBits>::type
must model the StreamHash<ValueBits> concept.
Not all possible values of ValueBits need be accepted. Typically, small powers of 2 (1, 2, 4, 8, 16, 32, 64) are accepted.
T::digest_type
an instantiation of the digest class template.
must match the digest_type of the StreamHash<ValueBits> policies mentioned above for any allowed choice of ValueBits.

Provided models:
Header Type digest_type
<boost/hash/adler.hpp> adler<h>, with h in {8, 16, 24, ..., 64} digest<h>
<boost/hash/crc.hpp> crc<h, ...>, with template arguments as for Boost.CRC's crc_optimal digest<h>
<boost/hash/cubehash.hpp> cubehash<h>, cubehash<r, b, h>, with h in {8, 16, 24, ..., 512}, r in {1, 2, 3, ...} (default 16), b in {4, 8, 12, ..., 128} (default 32) digest<h>
<boost/hash/md4.hpp> md4 digest<128>
<boost/hash/md5.hpp> md5 digest<128>
<boost/hash/sha.hpp> sha, sha0 digest<128>
<boost/hash/sha1.hpp> sha1 digest<160>
<boost/hash/sha2.hpp> sha2<h>, with h in {224, 256, 384, 512} digest<h>

StreamHash<ValueBits> Concept

A type T modelling the StreamHash<ValueBits> concept must be default-constructible, copy-constructible, and copy-assignable, as well as support the following (h is an object of type T, hc is an object of type T const):

T::digest_type
an instantiation of the digest class template.
T::value_type
an unsigned fundamental integral type that can hold least ValueBits bits
h.reset();
(equivalent to h = T();)
T::digest_type d = h.end_message();
returns the digest of all input provided since the last reset, then resets
(equivalent to digest_type d = h.digest(); h.reset();, though typically more efficient if the hash involves padding or finalization)
T::digest_type d = hc.digest();
returns the digest of all input provided since the last reset
(equivalent to digest_type d = T(hc).end_message();, though typically more efficient if the hash involves neither padding nor finalization)
value_type x; h.update_one(x);
Feeds the low ValueBits bits of x as input to the hash algorithm
InputIterator b, e; h.update(b, e);
Equivalent to for (InputIterator i = b; i != e; ++i) h.update_one(*i);
InputIterator b; size_t n; h.update_n(b, n);
Equivalent to { InputIterator i = b; for (size_t j = 0; j != n; ++j) h.update_one(*i++); }

Each HashAlgorithm model provides access to all its associated StreamHash models; Those StreamHash models are generally not accessible in other ways.

Previous: Functions Next: Performance


Copyright Scott McMurray 2010

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).