Copyright | (c) Leo D 2023 |
---|---|
License | BSD-3-Clause |
Maintainer | leo@apotheca.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
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
- data Hash
- = BLAKE2b BLAKE2bSize
- | GOST_34_11
- | Keccak1600_224
- | Keccak1600_256
- | Keccak1600_384
- | Keccak1600_512
- | MD4
- | MD5
- | RIPEMD160
- | SHA1
- | SHA224
- | SHA256
- | SHA384
- | SHA512
- | SHA512_256
- | SHA3_224
- | SHA3_256
- | SHA3_384
- | SHA3_512
- | SHAKE128 SHAKE128Size
- | SHAKE256 SHAKE256Size
- | SM3
- | Skein512 Skein512Size Skein512Salt
- | Streebog256
- | Streebog512
- | Whirlpool
- | Adler32
- | CRC24
- | CRC32
- newtype CryptoHash = MkCryptoHash {
- unCryptoHash :: Hash
- newtype Checksum = MkChecksum {
- unChecksum :: Hash
- hashes :: [Hash]
- cryptoHashes :: [CryptoHash]
- checksums :: [Checksum]
- type HashDigest = ByteString
- type BLAKE2bSize = Int
- type SHAKE128Size = Int
- type SHAKE256Size = Int
- type Skein512Size = Int
- type Skein512Salt = ByteString
- hashName :: Hash -> HashName
- hashBlockSize :: Hash -> Int
- hashDigestSize :: Hash -> Int
- hash :: Hash -> ByteString -> HashDigest
- hashChunks :: Hash -> [ByteString] -> HashDigest
- hashLazy :: Hash -> ByteString -> HashDigest
- hashFile :: MonadIO m => Hash -> FilePath -> m HashDigest
- hashFileLazy :: MonadIO m => Hash -> FilePath -> m HashDigest
- data MutableHash = MkMutableHash {
- mutableHashType :: Hash
- mutableHashCtx :: Hash
- destroyHash :: MonadIO m => MutableHash -> m ()
- newHash :: MonadIO m => Hash -> m MutableHash
- getHashName :: MonadIO m => MutableHash -> m HashName
- getHashBlockSize :: MonadIO m => MutableHash -> m Int
- getHashDigestSize :: MonadIO m => MutableHash -> m Int
- copyHashState :: MonadIO m => MutableHash -> m MutableHash
- clearHash :: MonadIO m => MutableHash -> m ()
- updateHash :: MonadIO m => MutableHash -> ByteString -> m ()
- updateHashChunks :: MonadIO m => MutableHash -> [ByteString] -> m ()
- finalizeHash :: MonadIO m => MutableHash -> m HashDigest
- updateFinalizeHash :: MonadIO m => MutableHash -> ByteString -> m HashDigest
- updateFinalizeClearHash :: MonadIO m => MutableHash -> ByteString -> m HashDigest
- blake2b :: Int -> Maybe Hash
- gost_34_11 :: Hash
- keccak1600_224 :: Hash
- keccak1600_256 :: Hash
- keccak1600_384 :: Hash
- keccak1600_512 :: Hash
- keccak1600 :: Int -> Maybe Hash
- md4 :: Hash
- md5 :: Hash
- ripemd160 :: Hash
- sha1 :: Hash
- sha2_224 :: Hash
- sha2_256 :: Hash
- sha2_384 :: Hash
- sha2_512 :: Hash
- sha2_512_256 :: Hash
- sha2 :: Int -> Maybe Hash
- sha3_224 :: Hash
- sha3_256 :: Hash
- sha3_384 :: Hash
- sha3_512 :: Hash
- sha3 :: Int -> Maybe Hash
- shake128 :: Int -> Maybe Hash
- shake256 :: Int -> Maybe Hash
- sm3 :: Hash
- skein512 :: Int -> ByteString -> Maybe Hash
- streebog256 :: Hash
- streebog512 :: Hash
- whirlpool :: Hash
- adler32 :: Hash
- crc24 :: Hash
- crc32 :: Hash
Hashes
Usage
Idiomatic interface
Data type
newtype CryptoHash Source #
Instances
Show CryptoHash Source # | |
Defined in Botan.Hash showsPrec :: Int -> CryptoHash -> ShowS # show :: CryptoHash -> String # showList :: [CryptoHash] -> ShowS # | |
Eq CryptoHash Source # | |
Defined in Botan.Hash (==) :: CryptoHash -> CryptoHash -> Bool # (/=) :: CryptoHash -> CryptoHash -> Bool # | |
Ord CryptoHash Source # | |
Defined in Botan.Hash compare :: CryptoHash -> CryptoHash -> Ordering # (<) :: CryptoHash -> CryptoHash -> Bool # (<=) :: CryptoHash -> CryptoHash -> Bool # (>) :: CryptoHash -> CryptoHash -> Bool # (>=) :: CryptoHash -> CryptoHash -> Bool # max :: CryptoHash -> CryptoHash -> CryptoHash # min :: CryptoHash -> CryptoHash -> CryptoHash # |
Enumerations
cryptoHashes :: [CryptoHash] Source #
Associated types
type HashDigest = ByteString Source #
type BLAKE2bSize = Int Source #
type SHAKE128Size = Int Source #
type SHAKE256Size = Int Source #
type Skein512Size = Int Source #
type Skein512Salt = ByteString Source #
Accessors
hashBlockSize :: Hash -> Int Source #
Warning: Unimplemented for: Adler32, CRC24, CRC32
hashDigestSize :: Hash -> Int Source #
Idiomatic algorithm
hash :: Hash -> ByteString -> HashDigest Source #
hashChunks :: Hash -> [ByteString] -> HashDigest Source #
hashLazy :: Hash -> ByteString -> HashDigest Source #
hashFileLazy :: MonadIO m => Hash -> FilePath -> m HashDigest Source #
Mutable interface
Tagged mutable context
data MutableHash Source #
MkMutableHash | |
|
Destructor
destroyHash :: MonadIO m => MutableHash -> m () Source #
Initializers
Accessors
getHashName :: MonadIO m => MutableHash -> m HashName Source #
getHashBlockSize :: MonadIO m => MutableHash -> m Int Source #
getHashDigestSize :: MonadIO m => MutableHash -> m Int Source #
Accessory functions
copyHashState :: MonadIO m => MutableHash -> m MutableHash Source #
clearHash :: MonadIO m => MutableHash -> m () Source #
Mutable algorithm
updateHash :: MonadIO m => MutableHash -> ByteString -> m () Source #
updateHashChunks :: MonadIO m => MutableHash -> [ByteString] -> m () Source #
finalizeHash :: MonadIO m => MutableHash -> m HashDigest Source #
updateFinalizeHash :: MonadIO m => MutableHash -> ByteString -> m HashDigest Source #
updateFinalizeClearHash :: MonadIO m => MutableHash -> ByteString -> m HashDigest Source #
gost_34_11 :: Hash Source #
sha2_512_256 :: Hash Source #
streebog256 :: Hash Source #
streebog512 :: Hash Source #