cryptohash-sha512-0.11.102.0: Fast, pure and practical SHA-512 implementation
LicenseBSD-style
MaintainerHerbert Valerio Riedel <hvr@gnu.org>
Stabilitystable
Portabilityunknown
Safe HaskellTrustworthy
LanguageHaskell2010

Crypto.Hash.SHA512t

Description

A module containing SHA-512/t bindings

Since: 0.11.102.0

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

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

data Ctx Source #

SHA-512/t Context

This extends the non-truncated SHA-512 Context (see Ctx) with the value of the t parameter which must be within the range [1..511] excluding the value 384 as per FIPS-180-4 section 5.3.6.

Constructors

Ctx !Int !Ctx 

Instances

Instances details
Eq Ctx Source # 
Instance details

Defined in Crypto.Hash.SHA512t

Methods

(==) :: Ctx -> Ctx -> Bool #

(/=) :: Ctx -> Ctx -> Bool #

init :: Int -> Ctx Source #

create a new hash context

update :: Ctx -> ByteString -> Ctx Source #

update a context with a bytestring

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

updates a context with multiple bytestrings

finalize :: Ctx -> ByteString Source #

finalize the context into a digest bytestring (t bits)

finalizeAndLength :: Ctx -> (ByteString, Word64) Source #

Variant of finalize also returning length of hashed content

start :: Int -> ByteString -> Ctx Source #

hash a strict bytestring into a Ctx

startlazy :: Int -> ByteString -> Ctx Source #

hash a lazy bytestring into a Ctx

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

main = print $ SHA512t.hash 224 (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 :: Int -> ByteString -> ByteString Source #

hash a strict bytestring into a digest bytestring (t bits)

hashlazy :: Int -> ByteString -> ByteString Source #

hash a lazy bytestring into a digest bytestring (t bits)

hashlazyAndLength :: Int -> ByteString -> (ByteString, Word64) Source #

Variant of hashlazy which simultaneously computes the hash and length of a lazy bytestring.

HMAC-SHA-512/t

RFC2104-compatible HMAC-SHA-512/t digests

hmac Source #

Arguments

:: Int

digest length t in bits

-> ByteString

secret

-> ByteString

message

-> ByteString 

Compute t-bit RFC2104-compatible HMAC-SHA-512/t digest for a strict bytestring message

hmaclazy Source #

Arguments

:: Int

digest length t in bits

-> ByteString

secret

-> ByteString

message

-> ByteString 

Compute4 t-bit RFC2104-compatible HMAC-SHA-512/t digest for a lazy bytestring message

hmaclazyAndLength Source #

Arguments

:: Int

digest length t in bits

-> ByteString

secret

-> ByteString

message

-> (ByteString, Word64)

digest (t bits) and length of message

Variant of hmaclazy which also returns length of message