@@ -3,15 +3,25 @@ module Data.Hash
33%access public
44%default total
55
6+{- A general purpose Hashing library (not cryptographic)
7+
8+ The core hash is djb2, which is very fast but does not have the best distribution
9+ Source: http://www.cse.yorku.ca/~oz/hash.html
10+
11+ The salted version and the magic salt are copied from Haskell's bloomfilter library
12+ Source: https://hackage.haskell.org/package/bloomfilter-2.0.0.0/docs/src/Data-BloomFilter-Hash.html#Hashable
13+-}
14+
615||| A type that can be hashed
716class Hashable a where
817 saltedHash64 : a -> Bits64 -> Bits64 -- value to hash, salt, hash
918
10−||| Computes a hash
19+||| Computes a non cryptographic hash
1120hash : Hashable a => a -> Bits64
1221hash x = saltedHash64 x 0x16fc397cf62f64d3
1322
14−||| Given a user provided salt, Computes a hash
23+||| Given a user provided salt, computes a non cryptographic hash.
24+||| This version is meant to mitigate hash-flooding DoS attacks.
1525saltedHash : Hashable a => Bits64 -> a -> Bits64
1626saltedHash salt x = saltedHash64 x salt
1727