hwsl2-0.4.0.0: Hashing with SL2

LicenseMIT
MaintainerSam Rijs <srijs@airpost.net>
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Hash.SL2

Contents

Description

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.

Synopsis

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)).

Composition

unit :: Hash Source

O(1) The unit element for concatenation. Alias for mempty.

concat :: Hash -> Hash -> Hash Source

O(1) Concatenate two hashes. Alias for mappend.

concatAll :: [Hash] -> Hash Source

O(n) Concatenate a list of hashes. Alias for mconcat.

Parsing

parse :: String -> Maybe Hash Source

O(1) Parse the representation generated by show.

Validation

valid :: Hash -> Bool Source

O(1) Check a hash for bit-level validity.

validate :: Hash -> Maybe Hash Source

O(1) Validate a hash on the bit-level. From valid h == True follows validate h == Just h.

Packing

pack8 :: [Word8] -> Maybe Hash Source

O(1) Pack a list of 64 8-bit words.

pack16 :: [Word16] -> Maybe Hash Source

O(1) Pack a list of 32 16-bit words.

pack32 :: [Word32] -> Maybe Hash Source

O(1) Pack a list of 16 32-bit words.

pack64 :: [Word64] -> Maybe Hash Source

O(1) Pack a list of 8 64-bit words.

Unpacking

unpack8 :: Hash -> [Word8] Source

O(1) Unpack into list of 64 8-bit words.

unpack16 :: Hash -> [Word16] Source

O(1) Unpack into list of 32 16-bit words.

unpack32 :: Hash -> [Word32] Source

O(1) Unpack into list of 16 32-bit words.

unpack64 :: Hash -> [Word64] Source

O(1) Unpack into list of 8 64-bit words.