on master help sign in
Improved docs for Data.Hash
8430f90Sebastian de Bellefon
libs/base/Data/Hash.idr+12−2
@@ -3,15 +3,25 @@ module Data.Hash
3%access public
3%access public
4%default total
4%default total
5
5
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+
6||| A type that can be hashed
15||| A type that can be hashed
7class Hashable a where
16class Hashable a where
8 saltedHash64 : a -> Bits64 -> Bits64 -- value to hash, salt, hash
17 saltedHash64 : a -> Bits64 -> Bits64 -- value to hash, salt, hash
9
18
10−||| Computes a hash
19+||| Computes a non cryptographic hash
11hash : Hashable a => a -> Bits64
20hash : Hashable a => a -> Bits64
12hash x = saltedHash64 x 0x16fc397cf62f64d3
21hash x = saltedHash64 x 0x16fc397cf62f64d3
13
22
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.
15saltedHash : Hashable a => Bits64 -> a -> Bits64
25saltedHash : Hashable a => Bits64 -> a -> Bits64
16saltedHash salt x = saltedHash64 x salt
26saltedHash salt x = saltedHash64 x salt
17
27