HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulecryptohash-md5-0.11.101.0Haskell2010

Crypto.Hash.MD5

A module containing MD5 bindings

  • 1 type
  • 13 values

Incremental API

8 declarations

This API is based on 4 different functions, similar to the lowlevel operations of a typical hash:

  • init: create a new hash context

  • update: update non-destructively a new hash context with a strict bytestring

  • updates: same as update, except that it takes a list of strict bytestrings

  • finalize: finalize the context and returns a digest bytestring.

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.

Example:

import qualified Data.ByteString
import qualified Crypto.Hash.MD5 as MD5

main = print digest
  where
    digest = MD5.finalize ctx
    ctx    = foldl MD5.update ctx0 (map Data.ByteString.pack [ [1,2,3], [4,5,6] ])
    ctx0   = MD5.init
newtypenewtype Ctx
#

MD5 Context

The context data is exactly 88 bytes long, however the data in the context is stored in host-endianness.

The context data is made up of

  • a Word64 representing the number of bytes already feed to hash algorithm so far,

  • a 64-element Word8 buffer holding partial input-chunks, and finally

  • a 4-element Word32 array holding the current work-in-progress digest-value.

Consequently, a MD5 digest as produced by hash, hashlazy, or finalize is 16 bytes long.

Constructors

Instances1Eq
  • Eq CtxDefined in cryptohash-md5-0.11.101.0 · Crypto.Hash.MD5.FFI
valueinit :: Ctx
#

create a new hash context

Single Pass API

3 declarations

This API use the incremental API under the hood to provide the common all-in-one operations to create digests out of a ByteString and lazy ByteString.

Example:

import qualified Data.ByteString
import qualified Crypto.Hash.MD5 as MD5

main = print $ MD5.hash (Data.ByteString.pack [0..255])

NOTE: The returned digest is a binary ByteString. For converting to a base16/hex encoded digest the base16-bytestring package is recommended.

HMAC-MD5

RFC2104-compatible HMAC-MD5 digests