The cryptohash package

[Tags: bsd3, library]

A collection of crypto hashes, with a practical incremental and one-pass, pure APIs, with performance close to the fastest implementations available in other languages.

The implementations are made in C with a haskell FFI wrapper that hide the C implementation.

Simple examples using the unified API:

 import Crypto.Hash

 sha1 :: ByteString -> Digest SHA1
 sha1 = hash

 hexSha3_512 :: ByteString -> String
 hexSha3_512 bs = show (hash bs :: Digest SHA3_512)

Simple examples using the module API:

 import qualified Crypto.Hash.SHA1 as SHA1

 main = putStrLn $ show $ SHA1.hash (Data.ByteString.pack [0..255])
 import qualified Crypto.Hash.SHA3 as SHA3

 main = putStrLn $ show $ digest
   where digest = SHA3.finalize ctx
         ctx    = foldl' SHA3.update iCtx (map Data.ByteString.pack [ [1,2,3], [4,5,6] ]
         iCtx   = SHA3.init 224

[Skip to ReadMe]


Versions0.4, 0.4.1, 0.5, 0.5.1, 0.5.2, 0.5.3, 0.6, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7.5, 0.7.6, 0.7.7, 0.7.8, 0.7.9, 0.7.10, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.9.0, 0.9.1, 0.10.0, 0.11.0, 0.11.1, 0.11.2, 0.11.3, 0.11.4, 0.11.5, 0.11.6
Change logNone available
Dependenciesbase (>=4 && <6), byteable, bytestring, ghc-prim [details]
CopyrightVincent Hanquez <>
AuthorVincent Hanquez <>
MaintainerVincent Hanquez <>
CategoryData, Cryptography
Home page
Source repositoryhead: git clone git://
UploadedMon Sep 30 02:32:15 UTC 2013 by VincentHanquez
DistributionsDebian:0.11.6, Fedora:0.9.0, FreeBSD:0.11.6, LTSHaskell:0.11.6, NixOS:0.11.6, Stackage:0.11.6
Downloads120619 total (417 in last 30 days)
1 []
StatusDocs available [build log]
Successful builds reported [all 1 reports]




Maintainers' corner

For package maintainers and hackage trustees

Readme for cryptohash-0.11.0


hs-cryptohash provides lots of different secure digest algorithms, also called cryptohashes. It exposes every common hashes, but also some more exotic hashes, provides an extensive list of hashes available with a consistant API.

The general performance are comparable to the most optimised hashes available.

The complete list of supported hashes:

You can easily import any hash with the following:

import qualified Crypto.Hash.<HASH> as <Hash>

suggestion: it's easier to import qualified since there's a collision with the init symbol, but for only importing the hash or hashlazy function there's no such need.

Every hashes, exposes a very similar API.

Incremental API

it's based on 4 different functions, similar to the lowlevel operations of a typical hash:

all those operations are completely pure, and instead of changing the context as usual in others language, it re-allocates a new context each time.

One Pass API

The one pass API use the incremental API under the hood, but expose common operations to create digests out of a bytestring and lazy bytestring.

More Type safety

A more type safe API is also available from Crypto.Hash. The API provides all the supported hashes in the same namespace, through unified functions.

It introduces 2 new types, the Context type and the Digest type. Both those types are parametrized with the HashAlgorithm used.

The API is very similar to each single hash module, except the types are slightly different.

import Crypto.Hash

-- use the incremental API to hash the byte [1,2,3] with SHA1
-- and print the hexadecimal digest.
example1 = do
    let ctx = hashInit
        ctx' = hashUpdates ctx [ Data.ByteString.pack [1,2,3] ]
        dgt  = hashFinalize ctx' :: Digest SHA1
    putStrLn $ show dgt

-- use the one-pass API to hash the byte 1,2,3 with SHA3_512
-- and print the hexadecimal digest.
example2 = do
    let dgt  = hash (Data.ByteString.pack [1,2,3]) :: Digest SHA3_512
    putStrLn $ show dgt


Cryptohash uses C implementations to provide maximum performance. see the cbits directory for more information