Want to get started without worry about the details? Here's how.
Name | Digest Bits | HashAlgorithm Model (in boost::hash) | Reference | Design Type | Notes |
---|---|---|---|---|---|
Adler-h (h in {8, 16, 24, ..., 64}) | h | adler<h> | RFC 1950 | Checksum | Only supports octets as input values |
CRC-32/PNG | 32 | crc32_png | PNG Specification, Section 3.4 | Checksum | Also used by cksfv; Only supports bytes as input values |
CubeHash-h (h in {8, 16, 24, ..., 512}) | h | cubehash<h> | CubeHash NIST Submission | Cryptographic | SHA-3 candidate; Not yet mature. |
MD4 | 128 | md4 | RFC 1320 | Cryptographic | Practical attacks exist |
MD5 | 128 | md5 | RFC 1321 | ||
SHA | 160 | sha | FIPS 180 | Cryptographic | Collisions known; Repealed |
SHA-1 | 160 | sha1 | FIPS 180-3 | Some concern | |
SHA-224 | 224 | sha2<224> | As of 2010, considered secure by NIST | ||
SHA-256 | 256 | sha2<256> | |||
SHA-384 | 384 | sha2<384> | |||
SHA-512 | 512 | sha2<512> |
Here's a sample complete program, example/quickstart.cpp:
#include <boost/hash.hpp> #include <iostream> #include <string> int main() { std::string s = "Hello World!"; } int main() { using namespace boost::hash; std::string s = "Hello World!"; typedef boost::hash::sha2<256> HashAlgorithm; HashAlgorithm::digest_type digest = compute_digest<HashAlgorithm>(s); std::cout << digest << "\n"; }
The distribution also includes a "hash this file" example, example/hashsum.cpp, along the lines of the coreutils md5sum and sha1sum programs.
Previous: Introduction | Next: Functions |
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).