Copyright | Copyright © 2021-2024 Lars Kuhtz <lakuhtz@gmail.com> |
---|---|
License | MIT |
Maintainer | Lars Kuhtz <lakuhtz@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Bindings for OpenSSL EVP Message Digest Routines.
Requires OpenSSL version >= 1.1.0
Synopsis
- newtype Algorithm a = Algorithm (ForeignPtr Void)
- newtype Ctx a = Ctx (ForeignPtr Void)
- newtype Digest a = Digest ShortByteString
- resetCtx :: Ctx a -> IO ()
- initCtx :: Algorithm a -> IO (Ctx a)
- updateCtx :: Ctx a -> Ptr Word8 -> Int -> IO ()
- finalCtx :: Ctx a -> IO (Digest a)
- fetchAlgorithm :: String -> IO (Algorithm a)
- class OpenSslDigest a where
- newtype OpenSslException = OpenSslException String
- newtype Sha2_224 = Sha2_224 ShortByteString
- newtype Sha2_256 = Sha2_256 ShortByteString
- newtype Sha2_384 = Sha2_384 ShortByteString
- newtype Sha2_512 = Sha2_512 ShortByteString
- newtype Sha2_512_224 = Sha2_512_224 ShortByteString
- newtype Sha2_512_256 = Sha2_512_256 ShortByteString
- newtype Sha3_224 = Sha3_224 ShortByteString
- newtype Sha3_256 = Sha3_256 ShortByteString
- newtype Sha3_384 = Sha3_384 ShortByteString
- newtype Sha3_512 = Sha3_512 ShortByteString
- newtype Shake128 (bits :: Natural) = Shake128 ShortByteString
- type Shake128_256 = Shake128 32
- newtype Shake256 (bits :: Natural) = Shake256 ShortByteString
- type Shake256_512 = Shake256 64
- newtype Keccak224 = Keccak224 ShortByteString
- newtype Keccak256 = Keccak256 ShortByteString
- newtype Keccak384 = Keccak384 ShortByteString
- newtype Keccak512 = Keccak512 ShortByteString
- finalizeKeccak256Ptr :: Ctx Keccak256 -> Ptr Word8 -> IO ()
- finalizeKeccak512Ptr :: Ctx Keccak512 -> Ptr Word8 -> IO ()
- newtype Blake2b512 = Blake2b512 ShortByteString
- newtype Blake2s256 = Blake2s256 ShortByteString
EVP digest routines
An algorithm implementation from an OpenSSL algorithm provider.
It must be freed after use. Internally, implementations are cached and reference counted. Re-initialization after the last reference is freed is somewhat expensive.
It is assumed that this always points to a valid algorithm implementation.
Generic OpenSSL message digest type.
This can be used with DerivingVia
to derive hash instances for concrete
message digest algorithms.
Instances
IsString (Digest a) Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Digest a # | |
Show (Digest a) Source # | |
Eq (Digest a) Source # | |
Ord (Digest a) Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
OpenSslDigest a => Hash (Digest a) Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash (Digest a) Source # | |
ResetableHash (Digest a) Source # | |
type Context (Digest a) Source # | |
Defined in Data.Hash.Internal.OpenSSL |
initCtx :: Algorithm a -> IO (Ctx a) Source #
Allocates and initializes a new context. The context may be reused by
calling resetCtx
on it.
fetchAlgorithm :: String -> IO (Algorithm a) Source #
Look up the Algorithm
with given identifier. This is a less efficient
legacy way to obtain algorithm implementations. The returned algorithms
do not need to be freed.
The result is guaranteed to be a valid algorithm. Otherwise an
OpenSslException
is thrown.
Algorithms
class OpenSslDigest a where Source #
Instances
newtype OpenSslException Source #
Instances
Exception OpenSslException Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Show OpenSslException Source # | |
Defined in Data.Hash.Internal.OpenSSL showsPrec :: Int -> OpenSslException -> ShowS # show :: OpenSslException -> String # showList :: [OpenSslException] -> ShowS # |
SHA2
SHA-2 (Secure Hash Algorithm 2) is a family of cryptographic hash functions standardized in NIST FIPS 180-4, first published in 2001. These functions conform to NIST FIPS 180-4.
The following hash functions from the SHA-2 family are supported in openssl-3.0 (cf. https://www.openssl.org/docs/man3.0/man3/EVP_sha224.html)
SHA2-224, SHA2-256, SHA2-512224, SHA2-512256, SHA2-384, SHA2-512
Instances
IsString Sha2_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha2_224 # | |
Show Sha2_224 Source # | |
Eq Sha2_224 Source # | |
Ord Sha2_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha2_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha2_224 Source # | |
ResetableHash Sha2_224 Source # | |
OpenSslDigest Sha2_224 Source # | |
type Context Sha2_224 Source # | |
Instances
IsString Sha2_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha2_256 # | |
Show Sha2_256 Source # | |
Eq Sha2_256 Source # | |
Ord Sha2_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha2_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha2_256 Source # | |
ResetableHash Sha2_256 Source # | |
OpenSslDigest Sha2_256 Source # | |
type Context Sha2_256 Source # | |
Instances
IsString Sha2_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha2_384 # | |
Show Sha2_384 Source # | |
Eq Sha2_384 Source # | |
Ord Sha2_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha2_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha2_384 Source # | |
ResetableHash Sha2_384 Source # | |
OpenSslDigest Sha2_384 Source # | |
type Context Sha2_384 Source # | |
Instances
IsString Sha2_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha2_512 # | |
Show Sha2_512 Source # | |
Eq Sha2_512 Source # | |
Ord Sha2_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha2_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha2_512 Source # | |
ResetableHash Sha2_512 Source # | |
OpenSslDigest Sha2_512 Source # | |
type Context Sha2_512 Source # | |
newtype Sha2_512_224 Source #
Instances
newtype Sha2_512_256 Source #
Instances
SHA3
SHA-3 (Secure Hash Algorithm 3) is a family of cryptographic hash functions standardized in NIST FIPS 202, first published in 2015. It is based on the Keccak algorithm. These functions conform to NIST FIPS 202.
The following hash functions from the SHA-3 family are supported in openssl-3.0 (cf. https://www.openssl.org/docs/man3.0/man3/EVP_sha3_224.html)
SHA3-3_224, SHA3-3_256, SHA3-3_384, SHA3-3_512, SHAKE128, SHAKE256
Instances
IsString Sha3_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha3_224 # | |
Show Sha3_224 Source # | |
Eq Sha3_224 Source # | |
Ord Sha3_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha3_224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha3_224 Source # | |
ResetableHash Sha3_224 Source # | |
OpenSslDigest Sha3_224 Source # | |
type Context Sha3_224 Source # | |
Instances
IsString Sha3_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha3_256 # | |
Show Sha3_256 Source # | |
Eq Sha3_256 Source # | |
Ord Sha3_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha3_256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha3_256 Source # | |
ResetableHash Sha3_256 Source # | |
OpenSslDigest Sha3_256 Source # | |
type Context Sha3_256 Source # | |
Instances
IsString Sha3_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha3_384 # | |
Show Sha3_384 Source # | |
Eq Sha3_384 Source # | |
Ord Sha3_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha3_384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha3_384 Source # | |
ResetableHash Sha3_384 Source # | |
OpenSslDigest Sha3_384 Source # | |
type Context Sha3_384 Source # | |
Instances
IsString Sha3_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Sha3_512 # | |
Show Sha3_512 Source # | |
Eq Sha3_512 Source # | |
Ord Sha3_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Sha3_512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Sha3_512 Source # | |
ResetableHash Sha3_512 Source # | |
OpenSslDigest Sha3_512 Source # | |
type Context Sha3_512 Source # | |
newtype Shake128 (bits :: Natural) Source #
Instances
IsString (Shake128 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Shake128 bits # | |
Show (Shake128 bits) Source # | |
Eq (Shake128 bits) Source # | |
Ord (Shake128 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL compare :: Shake128 bits -> Shake128 bits -> Ordering # (<) :: Shake128 bits -> Shake128 bits -> Bool # (<=) :: Shake128 bits -> Shake128 bits -> Bool # (>) :: Shake128 bits -> Shake128 bits -> Bool # (>=) :: Shake128 bits -> Shake128 bits -> Bool # | |
KnownNat bits => Hash (Shake128 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
KnownNat bits => IncrementalHash (Shake128 bits) Source # | |
KnownNat bits => ResetableHash (Shake128 bits) Source # | |
OpenSslDigest (Shake128 n) Source # | |
type Context (Shake128 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL |
type Shake128_256 = Shake128 32 Source #
newtype Shake256 (bits :: Natural) Source #
Instances
IsString (Shake256 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Shake256 bits # | |
Show (Shake256 bits) Source # | |
Eq (Shake256 bits) Source # | |
Ord (Shake256 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL compare :: Shake256 bits -> Shake256 bits -> Ordering # (<) :: Shake256 bits -> Shake256 bits -> Bool # (<=) :: Shake256 bits -> Shake256 bits -> Bool # (>) :: Shake256 bits -> Shake256 bits -> Bool # (>=) :: Shake256 bits -> Shake256 bits -> Bool # | |
KnownNat bits => Hash (Shake256 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
KnownNat bits => IncrementalHash (Shake256 bits) Source # | |
KnownNat bits => ResetableHash (Shake256 bits) Source # | |
OpenSslDigest (Shake256 n) Source # | |
type Context (Shake256 bits) Source # | |
Defined in Data.Hash.Internal.OpenSSL |
type Shake256_512 = Shake256 64 Source #
Keccak
This is the latest version of Keccak-256 hash function that was submitted to the SHA3 competition. It is different from the final NIST SHA3 hash.
The difference between NIST SHA3-256 and Keccak-256 is the use of a different padding character for the input message. The former uses '0x06' and the latter uses '0x01'.
This version of Keccak-256 is used by the Ethereum project.
The following hash functions from the SHA-3 family are supported in openssl-3.2 (cf. https://www.openssl.org/docs/man3.2/man7/EVP_MD-KECCAK.html)
KECCAK-224, KECCAK-256, KECCAK-384, KECCAK-512
Instances
IsString Keccak224 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Keccak224 # | |
Show Keccak224 Source # | |
Eq Keccak224 Source # | |
Ord Keccak224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Keccak224 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Keccak224 Source # | |
ResetableHash Keccak224 Source # | |
OpenSslDigest Keccak224 Source # | |
type Context Keccak224 Source # | |
Defined in Data.Hash.Internal.OpenSSL |
Instances
IsString Keccak256 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Keccak256 # | |
Show Keccak256 Source # | |
Eq Keccak256 Source # | |
Ord Keccak256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Keccak256 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Keccak256 Source # | |
ResetableHash Keccak256 Source # | |
OpenSslDigest Keccak256 Source # | |
type Context Keccak256 Source # | |
Defined in Data.Hash.Internal.OpenSSL |
Instances
IsString Keccak384 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Keccak384 # | |
Show Keccak384 Source # | |
Eq Keccak384 Source # | |
Ord Keccak384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Keccak384 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Keccak384 Source # | |
ResetableHash Keccak384 Source # | |
OpenSslDigest Keccak384 Source # | |
type Context Keccak384 Source # | |
Defined in Data.Hash.Internal.OpenSSL |
Instances
IsString Keccak512 Source # | |
Defined in Data.Hash.Internal.OpenSSL fromString :: String -> Keccak512 # | |
Show Keccak512 Source # | |
Eq Keccak512 Source # | |
Ord Keccak512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
Hash Keccak512 Source # | |
Defined in Data.Hash.Internal.OpenSSL | |
IncrementalHash Keccak512 Source # | |
ResetableHash Keccak512 Source # | |
OpenSslDigest Keccak512 Source # | |
type Context Keccak512 Source # | |
Defined in Data.Hash.Internal.OpenSSL |
Unsafe finalize functions
finalizeKeccak256Ptr :: Ctx Keccak256 -> Ptr Word8 -> IO () Source #
Low-Level function that writes the final digest directly into the provided pointer. The pointer must point to at least 64 bytes of allocated memory. This is not checked and a violation of this condition may result in a segmentation fault.
finalizeKeccak512Ptr :: Ctx Keccak512 -> Ptr Word8 -> IO () Source #
Low-Level function that writes the final digest directly into the provided pointer. The pointer must point to at least 64 bytes of allocated memory. This is not checked and a violation of this condition may result in a segmentation fault.
Blake2
BLAKE2 is an improved version of BLAKE, which was submitted to the NIST SHA-3 algorithm competition. The BLAKE2s and BLAKE2b algorithms are described in RFC 7693.
The following hash functions from the BLAKE2 family are supported in openssl-3.0 (cf. https://www.openssl.org/docs/man3.0/man3/EVP_blake2b512.html)
BLAKE2B-512, BLACKE2S-256
While the BLAKE2b and BLAKE2s algorithms supports a variable length digest, this implementation outputs a digest of a fixed length (the maximum length supported), which is 512-bits for BLAKE2b and 256-bits for BLAKE2s.
newtype Blake2b512 Source #
Instances
newtype Blake2s256 Source #