0

I would like to evaluate a hash for a C++ data-structure, containing mainly double, and std::string. Boost proposes some functions to do so, with hash and sha1.

Boost hash is known to be platform dependent, since it returns a std::size_t. However, its API is very handy, thanks to its extensions that deal with stl containers.

For example, Boost hash allows to declare such a hash

#include <boost/functional/hash.hpp>
boost::hash<MyType> hash;
std::size_t seed = hash(MyType());

I would like to benefit from the same API using boost SHA1. Is there a higher API level for SHA1, than the process_bytes method?

Glorfindel
  • 20,880
  • 13
  • 75
  • 99
Guillaume Jacquenot
  • 10,118
  • 5
  • 41
  • 48
  • Cryptographic hashes like SHA-1 fundamentally work on a stream of bytes. So if you want to use one of those, the problem reduces to that of serializing your data structure in a platform-independent format. See if [Boost Serialization](http://www.boost.org/doc/libs/release/libs/serialization/) helps. – Igor Tandetnik Jun 02 '15 at 13:53
  • @IgorTandetnik I've demo-ed just that here: http://stackoverflow.com/questions/30097385/hash-an-arbitrary-precision-value-boostmultiprecisioncpp-int/30111778#30111778 – sehe Jun 02 '15 at 14:20

0 Answers0