Copyright | (C) Hécate Moonlight 2022 |
---|---|
License | BSD-3-Clause |
Maintainer | The Haskell Cryptography Group |
Stability | Stable |
Portability | GHC only |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- cryptoHashSHA256 :: Ptr CUChar -> Ptr CUChar -> CULLong -> IO CInt
- data CryptoHashSHA256State
- withCryptoHashSHA256State :: (Ptr CryptoHashSHA256State -> IO a) -> IO a
- cryptoHashSHA256Init :: Ptr CryptoHashSHA256State -> IO CInt
- cryptoHashSHA256Update :: Ptr CryptoHashSHA256State -> Ptr CUChar -> CULLong -> IO CInt
- cryptoHashSHA256Final :: Ptr CryptoHashSHA256State -> Ptr CUChar -> IO CInt
- cryptoHashSHA256Bytes :: CSize
- cryptoHashSHA256StateBytes :: CSize
- cryptoAuthHMACSHA256 :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA256Verify :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA256Keygen :: Ptr CUChar -> IO ()
- data CryptoAuthHMACSHA256State
- withCryptoAuthHMACSHA256State :: (Ptr CryptoAuthHMACSHA256State -> IO a) -> IO a
- cryptoAuthHMACSHA256Init :: Ptr CryptoAuthHMACSHA256State -> Ptr CUChar -> CSize -> IO CInt
- cryptoAuthHMACSHA256Update :: Ptr CryptoAuthHMACSHA256State -> Ptr CUChar -> CULLong -> IO CInt
- cryptoAuthHMACSHA256Final :: Ptr CryptoAuthHMACSHA256State -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA256StateBytes :: CSize
- cryptoAuthHMACSHA256Bytes :: CSize
- cryptoAuthHMACSHA256KeyBytes :: CSize
- cryptoHashSHA512 :: Ptr CUChar -> Ptr CUChar -> CULLong -> IO CInt
- data CryptoHashSHA512State
- withCryptoHashSHA512State :: (Ptr CryptoHashSHA512State -> IO a) -> IO a
- cryptoHashSHA512Init :: Ptr CryptoHashSHA512State -> IO CInt
- cryptoHashSHA512Update :: Ptr CryptoHashSHA512State -> Ptr CUChar -> CULLong -> IO CInt
- cryptoHashSHA512Final :: Ptr CryptoHashSHA512State -> Ptr CUChar -> IO CInt
- cryptoHashSHA512Bytes :: CSize
- cryptoHashSHA512StateBytes :: CSize
- data CryptoAuthHMACSHA512State
- withCryptoAuthHMACSHA512State :: (Ptr CryptoAuthHMACSHA512State -> IO a) -> IO a
- cryptoAuthHMACSHA512 :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512Verify :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512Keygen :: Ptr CUChar -> IO ()
- cryptoAuthHMACSHA512Init :: Ptr CryptoAuthHMACSHA512State -> Ptr CUChar -> CSize -> IO CInt
- cryptoAuthHMACSHA512Update :: Ptr CryptoAuthHMACSHA512State -> Ptr CUChar -> CULLong -> IO CInt
- cryptoAuthHMACSHA512Final :: Ptr CryptoAuthHMACSHA512State -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512StateBytes :: CSize
- cryptoAuthHMACSHA512Bytes :: CSize
- cryptoAuthHMACSHA512KeyBytes :: CSize
- data CryptoAuthHMACSHA512256State
- withCryptoAuthHMACSHA512256State :: (Ptr CryptoAuthHMACSHA512256State -> IO a) -> IO a
- cryptoAuthHMACSHA512256 :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512256Verify :: Ptr CUChar -> Ptr CUChar -> CULLong -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512256Keygen :: Ptr CUChar -> IO ()
- cryptoAuthHMACSHA512256Init :: Ptr CryptoAuthHMACSHA512256State -> Ptr CUChar -> CSize -> IO CInt
- cryptoAuthHMACSHA512256Update :: Ptr CryptoAuthHMACSHA512256State -> Ptr CUChar -> CULLong -> IO CInt
- cryptoAuthHMACSHA512256Final :: Ptr CryptoAuthHMACSHA512256State -> Ptr CUChar -> IO CInt
- cryptoAuthHMACSHA512256StateBytes :: CSize
- cryptoAuthHMACSHA512256Bytes :: CSize
- cryptoAuthHMACSHA512256KeyBytes :: CSize
Introduction
The SHA-256 and SHA-512 functions are provided for interoperability with other applications. If you are
looking for a generic hash function and not specifically SHA-2, using
GenericHashing
(BLAKE2b) might be a better choice.
These functions are also not suitable for hashing passwords or deriving keys from passwords.
Use PasswordHashing
instead.
Only use these functions for interoperability with 3rd party services.
These functions are not keyed and are thus deterministic. In addition, the untruncated versions are vulnerable to length extension attacks. A message can be hashed in a single pass, but a streaming API is also available to process a message as a sequence of multiple chunks.
SHA-256
Single-part message
:: Ptr CUChar | A pointer to the hash of your data. |
-> Ptr CUChar | A pointer to the data you want to hash. |
-> CULLong | The length of the data you want to hash. |
-> IO CInt | Returns 0 on success, -1 on error. |
Hash the content of the second buffer and put the result in the first buffer.
See: crypto_hash_sha256()
Since: 0.0.1.0
Multi-part messages
data CryptoHashSHA256State Source #
This is the opaque state held and used by the SHA-256 functions.
Its size is cryptoHashSHA256StateBytes
.
Since: 0.0.1.0
withCryptoHashSHA256State :: (Ptr CryptoHashSHA256State -> IO a) -> IO a Source #
Perform an operation with a CryptoHashSHA256State
of size cryptoHashSHA256StateBytes
allocated and deallocated automatically.
⚠️ The return value of withCryptoHashSHA256State
MUST NOT leak the CryptoHashSHA256State
.
Please refer to the documentation of allocaBytes
for more operational details.
Since: 0.0.1.0
:: Ptr CryptoHashSHA256State | A pointer to an uninitialised hash state. Cannot be |
-> IO CInt | Returns 0 on success, -1 on error. |
This function initializes the CryptoHashSHA256State
state.
Call this function on a Ptr
CryptoHashSHA256State
before using it
as an argument in any other function in this module.
See: crypto_hash_sha256_init()
Since: 0.0.1.0
cryptoHashSHA256Update Source #
:: Ptr CryptoHashSHA256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the new message chunk to process. |
-> CULLong | The length in bytes of the chunk. |
-> IO CInt | Returns 0 on success, -1 on error. |
Add a new chunk to the message that will eventually be hashed.
After all parts have been supplied, cryptoHashSHA256Final
can be used to finalise the operation
and get the final hash.
See: crypto_hash_sha256_update()
Since: 0.0.1.0
cryptoHashSHA256Final Source #
:: Ptr CryptoHashSHA256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | The buffer in which the final hash is stored. |
-> IO CInt | Returns 0 on success, -1 on error. |
Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.
After this operation, the buffer containing the CryptoHashSHA256State
is emptied and
cannot be relied upon.
See: crypto_hash_sha256_final()
Since: 0.0.1.0
Constants
cryptoHashSHA256Bytes :: CSize Source #
The size of a SHA256-hashed message.
Since: 0.0.1.0
cryptoHashSHA256StateBytes :: CSize Source #
The size of a CryptoHashSHA256State
.
Since: 0.0.1.0
HMAC-SHA-256
Single-part message
:: Ptr CUChar | A pointer to the buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message to be authenticated. |
-> CULLong | The length of the message to be authenticated. |
-> Ptr CUChar | A pointer to the secret key used for authentication, of length |
-> IO CInt | Returns 0 on success, -1 on error. |
Authenticate a message given its size and a secret key, and produce an authenticator to be
validated with cryptoAuthHMACSHA256Verify
.
See: crypto_auth_hmacsha256().
Since: 0.0.1.0
cryptoAuthHMACSHA256Verify Source #
:: Ptr CUChar | A pointer to buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message that is being authenticated. |
-> CULLong | The length of the message that is being authenticated. |
-> Ptr CUChar | A pointer to the secret key, of size |
-> IO CInt | Returns 0 on success, -1 on failure. |
Verify that an authenticator provided by cryptoAuthHMACSHA256
is correct.
See: crypto_auth_hmacsha256_verify()
Since: 0.0.1.0
cryptoAuthHMACSHA256Keygen Source #
:: Ptr CUChar | A pointer to the buffer that will hold the secret key, of size |
-> IO () | Nothing is returned |
Multi-part messages
data CryptoAuthHMACSHA256State Source #
This is the opaque state held and used by the HMAC-SHA-256 functions.
Its size is cryptoAuthHMACSHA256StateBytes
bytes.
Please refer to the documentation of allocaBytes
for more operational details.
See: crypto_auth_hmacsha256_state
Since: 0.0.1.0
withCryptoAuthHMACSHA256State :: (Ptr CryptoAuthHMACSHA256State -> IO a) -> IO a Source #
Perform an operation with a CryptoAuthHMACSHA256State
of size cryptoAuthHMACSHA256StateBytes
allocated and deallocated automatically.
⚠️ The return value of withCryptoAuthHMACSHA256State
MUST NOT leak the CryptoAuthHMACSHA256State
.
Please refer to the documentation of allocaBytes
for more operational details.
Since: 0.0.1.0
cryptoAuthHMACSHA256Init Source #
:: Ptr CryptoAuthHMACSHA256State | A pointer to an uninitialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the secret key. |
-> CSize | The size of the key. |
-> IO CInt | Returns 0 on success, -1 on error. |
This function initializes the CryptoAuthHMACSHA256State
state.
Call this function on a Ptr
CryptoAuthHMACSHA256State
before using it
as an argument in any other function in this module.
See: crypto_auth_hmacsha256_init()
Since: 0.0.1.0
cryptoAuthHMACSHA256Update Source #
:: Ptr CryptoAuthHMACSHA256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the message to authenticate. |
-> CULLong | The size of the message to authenticate. |
-> IO CInt | Returns 0 on success, -1 on error. |
Add a new chunk to the message that will eventually be hashed.
After all parts have been supplied, cryptoAuthHMACSHA256Final
can be used to finalise the operation
and get the final hash.
See: crypto_auth_hmacsha256_update()
Since: 0.0.1.0
cryptoAuthHMACSHA256Final Source #
:: Ptr CryptoAuthHMACSHA256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the buffer that will hold the authenticator. |
-> IO CInt | Returns 0 on success, -1 on error. |
Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.
After this operation, the buffer containing the CryptoAuthHMACSHA256State
is emptied and
cannot be relied upon.
See: crypto_auth_hmacsha256_final()
Since: 0.0.1.0
Constants
cryptoAuthHMACSHA256StateBytes :: CSize Source #
The size of a CryptoAuthHMACSHA256State
.
Since: 0.0.1.0
cryptoAuthHMACSHA256Bytes :: CSize Source #
The size of a HMAC-SHA-256 hash
Since: 0.0.1.0
cryptoAuthHMACSHA256KeyBytes :: CSize Source #
The size of a HMAC-SHA-256 key
Since: 0.0.1.0
SHA-512
Single-part message
:: Ptr CUChar | A pointer to the hash of your data. |
-> Ptr CUChar | A pointer to the data you want to hash. |
-> CULLong | The length of the data you want to hash. |
-> IO CInt | Returns 0 on success, -1 on error. |
Hash the content of the second buffer and put the result in the first buffer.
See: crypto_hash_sha512()
Since: 0.0.1.0
Multi-part messages
data CryptoHashSHA512State Source #
This is the opaque state held and used by the SHA-512 functions.
Its size is cryptoHashSHA512StateBytes
.
Since: 0.0.1.0
withCryptoHashSHA512State :: (Ptr CryptoHashSHA512State -> IO a) -> IO a Source #
Perform an operation with a 'CryptoHashSHA512State of size cryptoHashSHA512StateBytes
allocated and deallocated automatically.
⚠️ The return value of withCryptoHashSHA512State
MUST NOT leak the CryptoHashSHA512State
.
Please refer to the documentation of allocaBytes
for more operational details.
Since: 0.0.1.0
:: Ptr CryptoHashSHA512State | A pointer to an initialised hash state. Cannot be |
-> IO CInt | Returns 0 on success, -1 on error. |
This function initializes the CryptoHashSHA512State
state.
Call this function on a 'Ptr CryptoHashSHA512State' before using it as an argument in any other function in this module.
See: crypto_hash_sha512_init()
Since: 0.0.1.0
cryptoHashSHA512Update Source #
:: Ptr CryptoHashSHA512State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the new message chunk to process. |
-> CULLong | The length in bytes of the chunk. |
-> IO CInt | Returns 0 on success, -1 on error. |
Add a new chunk to the message that will eventually be hashed.
After all parts have been supplied, cryptoHashSHA512Final
can be used to finalise the operation
and get the final hash.
See: crypto_hash_sha512_update()
Since: 0.0.1.0
cryptoHashSHA512Final Source #
:: Ptr CryptoHashSHA512State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | The buffer in which the final hash is stored. |
-> IO CInt | Returns 0 on success, -1 on error. |
Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.
After this operation, the buffer containing the CryptoHashSHA512State
is emptied and
cannot be relied upon.
See: crypto_hash_sha512_final()
Since: 0.0.1.0
Constants
cryptoHashSHA512Bytes :: CSize Source #
The size of a SHA512-hash message.
Since: 0.0.1.0
cryptoHashSHA512StateBytes :: CSize Source #
The size of a CryptoHashSHA512State
.
Since: 0.0.1.0
HMAC-SHA-512
Single-part message
data CryptoAuthHMACSHA512State Source #
This is the opaque state held and used by the HMAC-SHA-512 functions.
Its size is cryptoAuthHMACSHA512StateBytes
bytes.
Please refer to the documentation of allocaBytes
for more operational details.
See: crypto_auth_hmacsha512_state
Since: 0.0.1.0
withCryptoAuthHMACSHA512State :: (Ptr CryptoAuthHMACSHA512State -> IO a) -> IO a Source #
Perform an operation with a CryptoAuthHMACSHA512State
of size cryptoAuthHMACSHA512StateBytes
allocated and deallocated automatically.
⚠️ The return value of withCryptoAuthHMACSHA512State
MUST NOT leak the CryptoAuthHMACSHA512State
.
Please refer to the documentation of allocaBytes
for more operational details.
Since: 0.0.1.0
:: Ptr CUChar | A pointer to the buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message to be authenticated. |
-> CULLong | The length of the message to be authenticated. |
-> Ptr CUChar | A pointer to the secret key used for authentication, of length |
-> IO CInt | Returns 0 on success, -1 on error. |
Authenticate a message given its size and a secret key, and produce an authenticator to be
validated with cryptoAuthHMACSHA512Verify
.
See: crypto_auth_hmacsha512().
Since: 0.0.1.0
cryptoAuthHMACSHA512Verify Source #
:: Ptr CUChar | A pointer to buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message that is being authenticated. |
-> CULLong | The length of the message that is being authenticated. |
-> Ptr CUChar | A pointer to the secret key, of size |
-> IO CInt | Returns 0 on success, -1 on failure. |
Verify that an authenticator provided by cryptoAuthHMACSHA512
is correct.
See: crypto_auth_hmacsha512_verify()
Since: 0.0.1.0
cryptoAuthHMACSHA512Keygen Source #
:: Ptr CUChar | A pointer to the buffer that will hold the secret key, of size |
-> IO () | Nothing is returned |
Multi-part messages
cryptoAuthHMACSHA512Init Source #
:: Ptr CryptoAuthHMACSHA512State | A pointer to an uninitialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the secret key. |
-> CSize | The size of the key. |
-> IO CInt | Returns 0 on success, -1 on error. |
This function initializes the CryptoAuthHMACSHA512State
state.
Call this function on a 'Ptr CryptoAuthHMACSHA512State' before using it as an argument in any other function in this module.
See: crypto_auth_hmacsha512_init()
Since: 0.0.1.0
cryptoAuthHMACSHA512Update Source #
:: Ptr CryptoAuthHMACSHA512State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the message to authenticate. |
-> CULLong | The size of the message to authenticate. |
-> IO CInt | Returns 0 on success, -1 on error. |
Add a new chunk to the message that will eventually be hashed.
After all parts have been supplied, cryptoAuthHMACSHA512Final
can be used
to finalise the operation and get the final hash.
See: crypto_auth_hmacsha512_update()
Since: 0.0.1.0
cryptoAuthHMACSHA512Final Source #
:: Ptr CryptoAuthHMACSHA512State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the buffer that will hold the authenticator. |
-> IO CInt | Returns 0 on success, -1 on error. |
Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.
After this operation, the buffer containing the CryptoAuthHMACSHA512State
is emptied and
cannot be relied upon.
See: crypto_auth_hmacsha512_final()
Since: 0.0.1.0
Constants
cryptoAuthHMACSHA512StateBytes :: CSize Source #
The size of a CryptoAuthHMACSHA512State
.
Since: 0.0.1.0
cryptoAuthHMACSHA512Bytes :: CSize Source #
The size of a HMAC-SHA-512 hash
Since: 0.0.1.0
cryptoAuthHMACSHA512KeyBytes :: CSize Source #
The size of a HMAC-SHA-512 key
Since: 0.0.1.0
HMAC-SHA-512-256
HMAC-SHA-512-256 is implemented as HMAC-SHA-512 with the output truncated to 256 bits. This is slightly faster than HMAC-SHA-256. Note that this construction is not the same as HMAC-SHA-512/256, which is HMAC using the SHA-512/256 function.
Single-part message
data CryptoAuthHMACSHA512256State Source #
This is the opaque state held and used by the HMAC-SHA-512256 functions.
Its size is cryptoAuthHMACSHA512256StateBytes
bytes.
Please refer to the documentation of allocaBytes
for more operational details.
See: crypto_auth_hmacsha512256_state
Since: 0.0.1.0
withCryptoAuthHMACSHA512256State :: (Ptr CryptoAuthHMACSHA512256State -> IO a) -> IO a Source #
Perform an operation with a CryptoAuthHMACSHA512256State
of size cryptoAuthHMACSHA512256StateBytes
allocated and deallocated automatically.
⚠️ The return value of withCryptoAuthHMACSHA512256State
MUST NOT leak
the CryptoAuthHMACSHA512256State
.
Please refer to the documentation of allocaBytes
for more operational details.
Since: 0.0.1.0
cryptoAuthHMACSHA512256 Source #
:: Ptr CUChar | A pointer to the buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message to be authenticated. |
-> CULLong | The length of the message to be authenticated. |
-> Ptr CUChar | A pointer to the secret key used for authentication, of length |
-> IO CInt | Returns 0 on success, -1 on error. |
Authenticate a message given its size and a secret key, and produce an authenticator to be
validated with cryptoAuthHMACSHA512256Verify
.
See: crypto_auth_hmacsha512256().
Since: 0.0.1.0
cryptoAuthHMACSHA512256Verify Source #
:: Ptr CUChar | A pointer to buffer holding the authenticator. |
-> Ptr CUChar | A pointer to the message that is being authenticated. |
-> CULLong | The length of the message that is being authenticated. |
-> Ptr CUChar | A pointer to the secret key, of size |
-> IO CInt | Returns 0 on success, -1 on failure. |
Verify that an authenticator provided by cryptoAuthHMACSHA512256
is correct.
See: crypto_auth_hmacsha512256_verify()
Since: 0.0.1.0
cryptoAuthHMACSHA512256Keygen Source #
:: Ptr CUChar | A pointer to the buffer that will hold the secret key,
of size |
-> IO () | Nothing is returned |
Multi-part messages
cryptoAuthHMACSHA512256Init Source #
:: Ptr CryptoAuthHMACSHA512256State | A pointer to an uninitialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the secret key. |
-> CSize | The size of the key. |
-> IO CInt | Returns 0 on success, -1 on error. |
This function initializes the CryptoAuthHMACSHA512256State
state.
Call this function on a Ptr
CryptoAuthHMACSHA512256State
before using it
as an argument in any other function in this module.
See: crypto_auth_hmacsha512256_init()
Since: 0.0.1.0
cryptoAuthHMACSHA512256Update Source #
:: Ptr CryptoAuthHMACSHA512256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the message to authenticate. |
-> CULLong | The size of the message to authenticate. |
-> IO CInt | Returns 0 on success, -1 on error. |
Add a new chunk to the message that will eventually be hashed.
After all parts have been supplied, cryptoAuthHMACSHA512256Final
can be
used to finalise the operation and get the final hash.
See: crypto_auth_hmacsha512256_update()
Since: 0.0.1.0
cryptoAuthHMACSHA512256Final Source #
:: Ptr CryptoAuthHMACSHA512256State | A pointer to an initialised hash state. Cannot be |
-> Ptr CUChar | A pointer to the buffer that will hold the authenticator. |
-> IO CInt | Returns 0 on success, -1 on error. |
Finalise the hashing of a message. The final hash is padded with extra zeros if necessary, then put in a buffer.
After this operation, the buffer containing the CryptoAuthHMACSHA512256State
is emptied and
cannot be relied upon.
See: crypto_auth_hmacsha512256_final()
Since: 0.0.1.0
Constants
cryptoAuthHMACSHA512256StateBytes :: CSize Source #
The size of a CryptoAuthHMACSHA512256State
.
Since: 0.0.1.0
cryptoAuthHMACSHA512256Bytes :: CSize Source #
The size of a HMAC-SHA-512256 hash
Since: 0.0.1.0
cryptoAuthHMACSHA512256KeyBytes :: CSize Source #
The size of a HMAC-SHA-512256 key
Since: 0.0.1.0