Copyright | (c) Leo D 2023 |
---|---|
License | BSD-3-Clause |
Maintainer | leo@apotheca.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
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 BotanHashStruct
- newtype BotanHash = MkBotanHash {}
- botan_hash_destroy :: FinalizerPtr BotanHashStruct
- pattern BOTAN_HASH_BLAKE2B :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_KECCAK_1600 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_GOST_34_11 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_MD4 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_MD5 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_RIPEMD_160 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA1 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_224 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_256 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_384 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_512 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_512_256 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHA_3 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHAKE_128 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SHAKE_256 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SM3 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_SKEIN_512 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_STREEBOG_256 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_STREEBOG_512 :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_WHIRLPOOL :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_STRAT_PARALLEL :: (Eq a, IsString a) => a
- pattern BOTAN_HASH_STRAT_COMB4P :: (Eq a, IsString a) => a
- pattern BOTAN_CHECKSUM_ADLER32 :: (Eq a, IsString a) => a
- pattern BOTAN_CHECKSUM_CRC24 :: (Eq a, IsString a) => a
- pattern BOTAN_CHECKSUM_CRC32 :: (Eq a, IsString a) => a
- botan_hash_init :: Ptr BotanHash -> ConstPtr CChar -> Word32 -> IO CInt
- botan_hash_name :: BotanHash -> Ptr CChar -> Ptr CSize -> IO CInt
- botan_hash_copy_state :: Ptr BotanHash -> BotanHash -> IO CInt
- botan_hash_output_length :: BotanHash -> Ptr CSize -> IO CInt
- botan_hash_block_size :: BotanHash -> Ptr CSize -> IO CInt
- botan_hash_update :: BotanHash -> ConstPtr Word8 -> CSize -> IO CInt
- botan_hash_final :: BotanHash -> Ptr Word8 -> IO CInt
- botan_hash_clear :: BotanHash -> IO CInt
- botan_pkcs_hash_id :: ConstPtr CChar -> Ptr Word8 -> Ptr CSize -> IO CInt
Documentation
data BotanHashStruct Source #
Opaque Hash struct
Botan Hash object
Instances
Storable BotanHash Source # | |
Defined in Botan.Bindings.Hash | |
Eq BotanHash Source # | |
Ord BotanHash Source # | |
Defined in Botan.Bindings.Hash |
botan_hash_destroy :: FinalizerPtr BotanHashStruct Source #
Frees all resources of the hash object
pattern BOTAN_HASH_BLAKE2B :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_KECCAK_1600 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_GOST_34_11 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_MD4 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_MD5 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_RIPEMD_160 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA1 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_224 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_256 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_384 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_512 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_512_256 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHA_3 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHAKE_128 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SHAKE_256 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SM3 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_SKEIN_512 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_STREEBOG_256 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_STREEBOG_512 :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_WHIRLPOOL :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_STRAT_PARALLEL :: (Eq a, IsString a) => a Source #
pattern BOTAN_HASH_STRAT_COMB4P :: (Eq a, IsString a) => a Source #
pattern BOTAN_CHECKSUM_ADLER32 :: (Eq a, IsString a) => a Source #
pattern BOTAN_CHECKSUM_CRC24 :: (Eq a, IsString a) => a Source #
pattern BOTAN_CHECKSUM_CRC32 :: (Eq a, IsString a) => a Source #
:: Ptr BotanHash | hash: hash object |
-> ConstPtr CChar | hash_name: name of the hash function, e.g., "SHA-384" |
-> Word32 | flags: should be 0 in current API revision, all other uses are reserved and return BOTAN_FFI_ERROR_BAD_FLAG |
-> IO CInt |
Initialize a hash function object
:: BotanHash | hash: the object to read |
-> Ptr CChar | name: output buffer |
-> Ptr CSize | name_len: on input, the length of buffer, on success the number of bytes written |
-> IO CInt |
Get the name of this hash function
botan_hash_copy_state Source #
:: Ptr BotanHash | dest: destination hash object |
-> BotanHash | source: source hash object |
-> IO CInt | 0 on success, a negative value on failure |
Copy the state of a hash function object
botan_hash_output_length Source #
:: BotanHash | hash: hash object |
-> Ptr CSize | output_length: output buffer to hold the hash function output length |
-> IO CInt | 0 on success, a negative value on failure |
Writes the output length of the hash function to *output_length
botan_hash_block_size Source #
:: BotanHash | hash: hash object |
-> Ptr CSize | block_size: output buffer to hold the hash function block size |
-> IO CInt | 0 on success, a negative value on failure |
Writes the block size of the hash function to *block_size
:: BotanHash | hash: hash object |
-> ConstPtr Word8 | in: input buffer |
-> CSize | in_len: number of bytes to read from the input buffer |
-> IO CInt | 0 on success, a negative value on failure |
Send more input to the hash function
:: BotanHash | hash: hash object |
-> Ptr Word8 | out[]: output buffer |
-> IO CInt | 0 on success, a negative value on failure |
Finalizes the hash computation and writes the output to out[0:botan_hash_output_length()] then reinitializes for computing another digest as if botan_hash_clear had been called.
Reinitializes the state of the hash computation. A hash can be computed (with update/final) immediately.