cryptohash-sha1-0.11.7.1: Fast, pure and practical SHA-1 implementation

LicenseBSD-style
MaintainerHerbert Valerio Riedel <hvr@gnu.org>
Stabilitystable
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Crypto.Hash.SHA1

Contents

Description

A module containing SHA-1 bindings

Synopsis

Incremental API

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 bytestring
  • 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.SHA1 as SHA1

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

newtype Ctx Source

SHA-1 Context

Constructors

Ctx ByteString 

init :: Ctx Source

init a context

update :: Ctx -> ByteString -> Ctx Source

update a context with a bytestring

updates :: Ctx -> [ByteString] -> Ctx Source

updates a context with multiples bytestring

finalize :: Ctx -> ByteString Source

finalize the context into a digest bytestring

Single Pass API

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.SHA1 as SHA1

main = print $ SHA1.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.

hash :: ByteString -> ByteString Source

hash a strict bytestring into a digest bytestring

hashlazy :: ByteString -> ByteString Source

hash a lazy bytestring into a digest bytestring