sel-0.0.1.0: Cryptography for the casual user
Copyright(C) Hécate Moonlight 2022
LicenseBSD-3-Clause
MaintainerThe Haskell Cryptography Group
PortabilityGHC only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Sel.Hashing.SHA256

Description

 
Synopsis

Usage

The SHA-2 family of hashing functions is only provided for interoperability with other applications.

If you are looking for a generic hash function, do use Hashing.

If you are looking to hash passwords or deriving keys from passwords, do use Password, as the functions of the SHA-2 family are not suitable for this task.

Only import this module qualified like this:

>>> import qualified Sel.Hashing.SHA256 as SHA256

data Hash Source #

A hashed value from the SHA-256 algorithm.

Since: 0.0.1.0

Instances

Instances details
Storable Hash Source #

Since: 0.0.1.0

Instance details

Defined in Sel.Hashing.SHA256

Methods

sizeOf :: Hash -> Int #

alignment :: Hash -> Int #

peekElemOff :: Ptr Hash -> Int -> IO Hash #

pokeElemOff :: Ptr Hash -> Int -> Hash -> IO () #

peekByteOff :: Ptr b -> Int -> IO Hash #

pokeByteOff :: Ptr b -> Int -> Hash -> IO () #

peek :: Ptr Hash -> IO Hash #

poke :: Ptr Hash -> Hash -> IO () #

Show Hash Source #

Since: 0.0.1.0

Instance details

Defined in Sel.Hashing.SHA256

Methods

showsPrec :: Int -> Hash -> ShowS #

show :: Hash -> String #

showList :: [Hash] -> ShowS #

Eq Hash Source #

Since: 0.0.1.0

Instance details

Defined in Sel.Hashing.SHA256

Methods

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

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

Ord Hash Source #

Since: 0.0.1.0

Instance details

Defined in Sel.Hashing.SHA256

Methods

compare :: Hash -> Hash -> Ordering #

(<) :: Hash -> Hash -> Bool #

(<=) :: Hash -> Hash -> Bool #

(>) :: Hash -> Hash -> Bool #

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

max :: Hash -> Hash -> Hash #

min :: Hash -> Hash -> Hash #

Display Hash Source #

Since: 0.0.1.0

Instance details

Defined in Sel.Hashing.SHA256

Hashing a single message

hashByteString :: StrictByteString -> IO Hash Source #

Hash a StrictByteString with the SHA-256 algorithm.

Since: 0.0.1.0

hashText :: Text -> IO Hash Source #

Hash a UTF8-encoded strict Text with the SHA-256 algorithm.

Since: 0.0.1.0

Hashing a multi-part message

data Multipart s Source #

Multipart is a cryptographic context for streaming hashing. This API can be used when a message is too big to fit in memory or when the message is received in portions.

Use it like this:

>>> hash <- SHA256.withMultipart $ \multipartState -> do -- we are in MonadIO
...   message1 <- getMessage
...   SHA256.updateMultipart multipartState message1
...   message2 <- getMessage
...   SHA256.updateMultipart multipartState message2

Since: 0.0.1.0

withMultipart Source #

Arguments

:: forall (a :: Type) (m :: Type -> Type). MonadIO m 
=> (forall s. Multipart s -> m a)

Continuation that gives you access to a Multipart cryptographic context

-> m Hash 

Perform streaming hashing with a Multipart cryptographic context.

Use updateMultipart within the continuation.

The context is safely allocated first, then the continuation is run and then it is deallocated after that.

Since: 0.0.1.0

updateMultipart :: Multipart s -> StrictByteString -> IO () Source #

Add a message portion to be hashed.

This function should be used within withMultipart.

Since: 0.0.1.0

Displaying

hashToBinary :: Hash -> StrictByteString Source #

Convert a Hash to a binary StrictByteString.

Since: 0.0.1.0

hashToHexText :: Hash -> Text Source #

Convert a Hash to a strict hexadecimal Text.

Since: 0.0.1.0

hashToHexByteString :: Hash -> StrictByteString Source #

Convert a Hash to a strict, hexadecimal-encoded StrictByteString.

Since: 0.0.1.0