Senscape/Dagon

std::hash is unsuited for Dagon

bd339 opened this issue · 1 comments

bd339 commented

std::hash is only guaranteed to produce the same output for the same input for the duration of the program. See http://en.cppreference.com/w/cpp/utility/hash:

Hash functions are only required to produce the same result for the same input within a single execution of a program; this allows salted hashes that prevent collision DoS attacks. (since C++14)

Clearly we will need some other hashing algorithm. One that guarantees that the same input will always give the same output. We don't care about security but collisions should be highly unlikely and it should run fast, or we will considerably slow down Lua scripts that create new variables.

bd339 commented

I've heard good things about SipHash. It is a fast hash optimized for short input strings and it has better collision characteristics thanstd::hash so it seems ideal for our use case.