botan-low-0.0.1.0: Low-level Botan bindings
Copyright(c) Leo D 2023
LicenseBSD-3-Clause
Maintainerleo@apotheca.io
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Botan.Low.Hash

Description

Hash functions are one-way functions, which map data of arbitrary size to a fixed output length. Most of the hash functions in Botan are designed to be cryptographically secure, which means that it is computationally infeasible to create a collision (finding two inputs with the same hash) or preimages (given a hash output, generating an arbitrary input with the same hash). But note that not all such hash functions meet their goals, in particular MD4 and MD5 are trivially broken. However they are still included due to their wide adoption in various protocols.

Using a hash function is typically split into three stages: initialization, update, and finalization (often referred to as a IUF interface). The initialization stage is implicit: after creating a hash function object, it is ready to process data. Then update is called one or more times. Calling update several times is equivalent to calling it once with all of the arguments concatenated. After completing a hash computation (eg using hashFinal), the internal state is reset to begin hashing a new message.

Synopsis

Hashing

A hash is deterministic, one-way function suitable for producing a deterministic, fixed-size digest from an arbitrarily-sized message, which is used to verify the integrity of the data.

Usage

Unless you need a specific hash, it is strongly recommended that you use the SHA3 algorithm.

import Botan.Low.Hash
hash <- hashInit SHA3
message = "Fee fi fo fum!"
hashUpdate hash message
digest <- hashFinal hash

You can verify a digest by hashing the message a second time, and comparing the two:

rehash <- hashInit SHA3
hashUpdate rehash message
redigest <- hashFinal rehash
digest == redigest -- True

You can clear a hash's state, leaving it ready for reuse:

hashClear hash
-- Process another message
hashUpdate hash anotherMessage
anotherDigest <- hashFinal hash

newtype Hash Source #

Constructors

MkHash 

Fields

withHash :: Hash -> (BotanHash -> IO a) -> IO a Source #

hashInit Source #

Arguments

:: HashName

hash_name: name of the hash function, e.g., "SHA-384"

-> IO Hash

hash: hash object

hashName Source #

Arguments

:: Hash

hash: the object to read

-> IO HashDigest

name: output buffer

hashBlockSize Source #

Arguments

:: Hash

hash: hash object

-> IO Int

block_size: output buffer to hold the hash function block size

hashOutputLength Source #

Arguments

:: Hash

hash: hash object

-> IO Int

block_size: output buffer to hold the hash function output length

hashCopyState Source #

Arguments

:: Hash

source: source hash object

-> IO Hash

dest: destination hash object

hashUpdate Source #

Arguments

:: Hash

hash: hash object

-> ByteString

in: input buffer

-> IO () 

hashFinal Source #

Arguments

:: Hash

hash: hash object

-> IO HashDigest

out[]: output buffer

hashClear Source #

Arguments

:: Hash

hash: hash object

-> IO () 

Hash algorithms

blake2b :: (Ord a, Num a, Show a) => a -> HashName Source #

keccak1600 :: (Eq a, Num a, Show a) => a -> HashName Source #

pattern MD4 :: HashName Source #

pattern MD5 :: HashName Source #

pattern SHA1 :: HashName Source #

pattern SHA224 :: HashName Source #

pattern SHA256 :: HashName Source #

pattern SHA384 :: HashName Source #

pattern SHA512 :: HashName Source #

pattern SHA3 :: HashName Source #

sha3 :: (Eq a, Num a, Show a) => a -> HashName Source #

pattern SM3 :: HashName Source #

pattern Comb4P :: HashName Source #

pattern CRC24 :: HashName Source #

pattern CRC32 :: HashName Source #

Convenience