License | MIT |
---|---|
Maintainer | Sam Rijs <srijs@airpost.net> |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
An algebraic hash function, inspired by the paper Hashing with SL2 by Tillich and Zemor.
The hash function is based on matrix multiplication in the special linear group of degree 2, over a Galois field of order 2^127, with all computations modulo the polynomial x^127 + x^63 + 1.
This construction gives some nice properties, which traditional bit-scambling hash functions don't possess, including it being composable. It holds:
hash (m1 <> m2) == hash m1 <> hash m2
Following that, the hash function is also parallelisable. If a message m
can be divided
into a list of chunks cs
, the hash of the message can be calculated in parallel:
mconcat (parMap rpar hash cs) == hash m
All operations in this package are implemented in a very efficient manner using SSE instructions.
- data Hash
- hash :: ByteString -> Hash
- append :: Hash -> ByteString -> Hash
- prepend :: ByteString -> Hash -> Hash
- foldAppend :: Foldable t => Hash -> t ByteString -> Hash
- foldPrepend :: Foldable t => t ByteString -> Hash -> Hash
- unit :: Hash
- concat :: Hash -> Hash -> Hash
- concatAll :: [Hash] -> Hash
- parse :: String -> Maybe Hash
- valid :: Hash -> Bool
- validate :: Hash -> Maybe Hash
- pack8 :: [Word8] -> Maybe Hash
- pack16 :: [Word16] -> Maybe Hash
- pack32 :: [Word32] -> Maybe Hash
- pack64 :: [Word64] -> Maybe Hash
- unpack8 :: Hash -> [Word8]
- unpack16 :: Hash -> [Word16]
- unpack32 :: Hash -> [Word32]
- unpack64 :: Hash -> [Word64]
Documentation
Hashing
hash :: ByteString -> Hash Source
O(n) Calculate the hash of the ByteString
. Alias for (
.append
unit
)
append :: Hash -> ByteString -> Hash Source
O(n) Append the hash of the ByteString
to the existing Hash
.
A significantly faster equivalent of ((.
.hash
) . concat
)
prepend :: ByteString -> Hash -> Hash Source
O(n) Prepend the hash of the ByteString
to the existing Hash
.
A significantly faster equivalent of (
.concat
. hash
)
foldAppend :: Foldable t => Hash -> t ByteString -> Hash Source
O(n) Append the hash of every ByteString
to the existing Hash
, from left to right.
A significantly faster equivalent of (
.foldl
append
)
foldPrepend :: Foldable t => t ByteString -> Hash -> Hash Source
O(n) Prepend the hash of every ByteString
to the existing Hash
, from right to left.
A significantly faster equivalent of (
.flip
(foldr
prepend
))