| License | BSD-style |
|---|---|
| Maintainer | Herbert Valerio Riedel <hvr@gnu.org> |
| Stability | stable |
| Portability | unknown |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Crypto.Hash.SHA512
Description
A module containing SHA-512 bindings
Synopsis
- newtype Ctx = Ctx ByteString
- init :: Ctx
- update :: Ctx -> ByteString -> Ctx
- updates :: Ctx -> [ByteString] -> Ctx
- finalize :: Ctx -> ByteString
- finalizeAndLength :: Ctx -> (ByteString, Word64)
- start :: ByteString -> Ctx
- startlazy :: ByteString -> Ctx
- hash :: ByteString -> ByteString
- hashlazy :: ByteString -> ByteString
- hashlazyAndLength :: ByteString -> (ByteString, Word64)
- hmac :: ByteString -> ByteString -> ByteString
- hmaclazy :: ByteString -> ByteString -> ByteString
- hmaclazyAndLength :: ByteString -> ByteString -> (ByteString, Word64)
Incremental API
This API is based on 4 different functions, similar to the lowlevel operations of a typical hash:
init: create a new hash contextupdate: update non-destructively a new hash context with a strict bytestringupdates: same as update, except that it takes a list of strict bytestringsfinalize: finalize the context and returns a digest bytestring.
all those operations are completely pure, and instead of changing the context as usual in others language, it re-allocates a new context each time.
Example:
import qualified Data.ByteString
import qualified Crypto.Hash.SHA512 as SHA512
main = print digest
where
digest = SHA512.finalize ctx
ctx = foldl SHA512.update ctx0 (map Data.ByteString.pack [ [1,2,3], [4,5,6] ])
ctx0 = SHA512.initSHA-512 Context
The context data is exactly 208 bytes long, however the data in the context is stored in host-endianness.
The context data is made up of
Constructors
| Ctx ByteString |
finalize :: Ctx -> ByteString Source #
finalize the context into a digest bytestring (64 bytes)
finalizeAndLength :: Ctx -> (ByteString, Word64) Source #
Variant of finalize also returning length of hashed content
Since: 0.11.101.0
start :: ByteString -> Ctx Source #
hash a strict bytestring into a Ctx
Since: 0.11.101.0
startlazy :: ByteString -> Ctx Source #
hash a lazy bytestring into a Ctx
Since: 0.11.101.0
Single Pass API
This API use the incremental API under the hood to provide
the common all-in-one operations to create digests out of a
ByteString and lazy ByteString.
hash: create a digest (init+update+finalize) from a strictByteStringhashlazy: create a digest (init+update+finalize) from a lazyByteString
Example:
import qualified Data.ByteString import qualified Crypto.Hash.SHA512 as SHA512 main = print $ SHA512.hash (Data.ByteString.pack [0..255])
NOTE: The returned digest is a binary ByteString. For
converting to a base16/hex encoded digest the
base16-bytestring
package is recommended.
hash :: ByteString -> ByteString Source #
hash a strict bytestring into a digest bytestring (64 bytes)
hashlazy :: ByteString -> ByteString Source #
hash a lazy bytestring into a digest bytestring (64 bytes)
hashlazyAndLength :: ByteString -> (ByteString, Word64) Source #
Variant of hashlazy which simultaneously computes the hash and length of a lazy bytestring.
Since: 0.11.101.0
HMAC-SHA-512
Arguments
| :: ByteString | secret |
| -> ByteString | message |
| -> ByteString |
Compute 64-byte RFC2104-compatible HMAC-SHA-512 digest for a strict bytestring message
Since: 0.11.100.0
Arguments
| :: ByteString | secret |
| -> ByteString | message |
| -> ByteString |
Compute 64-byte RFC2104-compatible HMAC-SHA-512 digest for a lazy bytestring message
Since: 0.11.100.0
Arguments
| :: ByteString | secret |
| -> ByteString | message |
| -> (ByteString, Word64) | digest (64 bytes) and length of message |
Variant of hmaclazy which also returns length of message
Since: 0.11.101.0