TigerHash-0.2: TigerHash with C implementation




There comes some kind of description how to use this module.

Assume next import:

 import Data.Digest.TigerHash

Typical instant usage:

 instance TigerHashable k => TigerHashable (k, Message) where
     tigerHashUpdate ctx_ (key, Message {sender = data0, body = data1}) = do
         tigerHashUpdate ctx_ key
         tigerHashUpdate ctx_ data0
         tigerHashUpdate ctx_ data1

 signMessage :: TigerHashable k => k -> Message -> SignedMessage
 signMessage pkey msg = SignedMessage { message = msg, sign = tigerHash (pkey, msg) }

This is pretty useful when you need to send signed messages over public channel.

But using this in a such functional way have its drawbacks. Each time system requires calculation of hash it will issue prepearing of new context for each calculation instead of using the same context.

To solve that there is function for processing lazy list:

 hashMessageSenders :: [Message] -> [(TigerHash, Message)]
 hashMessageSenders msgs = zip (tigerHashList senders) msgs
     where senders = map sender msgs

This can be used for building hashed storage, which requires hash of each element.

Notice that while you expand each node of the list tigerHashList will calculate it's head for you. That's done with intention to loose overhead while hashing files for DC++ .



class TigerHashable a whereSource


tigerHashUpdate :: TigerContext (Ptr c) => Ptr c -> a -> IO ()Source

Each TigerHashable data should implement this using updateContext of TigerContext class from Data.Digest.TigerHash.Internal. But usually there is enough to just call tigerHashUpdate for data which already have instance for TigerHashable.

tigerHash :: a -> TigerHashSource

Instant caluculation of Tiger Hash with stack allocated context.

tigerTreeHash :: a -> TigerHashSource

Same as tgerHash, but with Tiger Tree hashing algorithm

tigerHashList :: [a] -> [TigerHash]Source

Calculate sequence of hashes where each next is calculated on-demand and only after previous one using one context for all calculations. Be sure to prepare sequence wich contains only required for hashing entries.

tigerTreeHashList :: [a] -> [TigerHash]Source

Same as tigerHashList, but with Tiger Tree hashing algorithm

hexTigerHash :: TigerHash -> StringSource

render TigerHash to String as hex-dump

b32TigerHash :: TigerHash -> StringSource

render TigerHash to String using Base32 encoding (as used in magnet-links and etc.)