Copyright | (C) Hécate Moonlight 2022 |
---|---|
License | BSD-3-Clause |
Maintainer | The Haskell Cryptography Group |
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data PasswordHash
- hashByteString :: StrictByteString -> IO PasswordHash
- hashText :: Text -> IO PasswordHash
- verifyByteString :: PasswordHash -> StrictByteString -> Bool
- verifyText :: PasswordHash -> Text -> Bool
- hashByteStringWithParams :: Argon2Params -> Salt -> StrictByteString -> IO PasswordHash
- passwordHashToByteString :: PasswordHash -> StrictByteString
- passwordHashToText :: PasswordHash -> Text
- passwordHashToHexText :: PasswordHash -> Text
- passwordHashToHexByteString :: PasswordHash -> StrictByteString
- asciiTextToPasswordHash :: Text -> PasswordHash
- asciiByteStringToPasswordHash :: StrictByteString -> PasswordHash
- data Salt
- genSalt :: IO Salt
- saltToBinary :: Salt -> StrictByteString
- saltToHexText :: Salt -> Text
- saltToHexByteString :: Salt -> StrictByteString
- binaryToSalt :: StrictByteString -> Maybe Salt
- hexTextToSalt :: Text -> Maybe Salt
- hexByteStringToSalt :: StrictByteString -> Maybe Salt
- data Argon2Params = Argon2Params CULLong CSize
- defaultArgon2Params :: Argon2Params
Introduction
This API provides functions for password hashing, backed by the Argon2id algorithm.
If you need to deviate from the defaults enforced by this module, please use the underlying bindings at LibSodium.Bindings.PasswordHashing.
data PasswordHash Source #
A hashed password from the Argon2id algorithm.
Since: 0.0.1.0
Instances
Password Hashing and Verifying
hashByteString :: StrictByteString -> IO PasswordHash Source #
Hash the password with the Argon2id algorithm and a set of pre-defined parameters.
The hash is encoded in a human-readable format that includes:
- The result of a memory-hard, CPU-intensive hash function applied to the password;
- The automatically generated salt used for the previous computation;
- The other parameters required to verify the password, including the algorithm identifier, its version, opslimit, and memlimit.
Example output: $argon2id$v=19$m=262144,t=3,p=1$fpPdXj9mK7J4m…
Since: 0.0.1.0
hashText :: Text -> IO PasswordHash Source #
Hash a UTF8-encoded password with the Argon2id algorithm and a set of pre-defined parameters.
Since: 0.0.1.0
verifyByteString :: PasswordHash -> StrictByteString -> Bool Source #
Verify the password hash against a clear StrictByteString
password
This function purposefully takes some time to complete, in order to alleviate bruteforce attacks.
Since: 0.0.1.0
verifyText :: PasswordHash -> Text -> Bool Source #
Verify the password hash against a clear Text
password
This function purposefully takes some time to complete, in order to alleviate bruteforce attacks.
Since: 0.0.1.0
hashByteStringWithParams :: Argon2Params -> Salt -> StrictByteString -> IO PasswordHash Source #
Hash the password with the Argon2id algorithm.
The hash is not encoded in human-readable format.
Since: 0.0.1.0
Conversion
passwordHashToByteString :: PasswordHash -> StrictByteString Source #
Convert a PasswordHash
to a StrictByteString
.
Since: 0.0.1.0
passwordHashToText :: PasswordHash -> Text Source #
Convert a PasswordHash
to a strict Text
.
Since: 0.0.1.0
passwordHashToHexText :: PasswordHash -> Text Source #
Convert a PasswordHash
to a strict hexadecimal-encoded Text
.
It is recommended to use this one on a PasswordHash
produced by hashByteStringWithParams
.
Since: 0.0.1.0
passwordHashToHexByteString :: PasswordHash -> StrictByteString Source #
Convert a PasswordHash
to a hexadecimal-encoded StrictByteString
.
It is recommended to use this one on a PasswordHash
produced by hashByteStringWithParams
.
Since: 0.0.1.0
asciiTextToPasswordHash :: Text -> PasswordHash Source #
Convert an ascii-encoded password hash to a PasswordHash
This function does not perform ASCII validation.
Since: 0.0.1.0
asciiByteStringToPasswordHash :: StrictByteString -> PasswordHash Source #
Convert an ascii-encoded password hash to a PasswordHash
This function does not perform ASCII validation.
Since: 0.0.1.0
Salt
The Salt
is used in conjunction with hashByteStringWithParams
when you want to manually provide the piece of data that will
differentiate two fingerprints of the same password.
It is automatically taken care of for you when you use
hashByteString
or hashText
.
Use genSalt
to create a Salt
of size
equal to the constant cryptoPWHashSaltBytes
.
Since: 0.0.1.0
Conversion
saltToBinary :: Salt -> StrictByteString Source #
Convert Salt
to underlying StrictByteString
binary.
Since: 0.0.2.0
saltToHexText :: Salt -> Text Source #
saltToHexByteString :: Salt -> StrictByteString Source #
Convert Salt
to a hexadecimal-encoded StrictByteString
.
Since: 0.0.2.0
binaryToSalt :: StrictByteString -> Maybe Salt Source #
Convert StrictByteString
to Salt
.
The input salt must be of length cryptoPWHashSaltBytes
.
Since: 0.0.2.0
hexTextToSalt :: Text -> Maybe Salt Source #
Convert a strict hexadecimal-encoded Text
to a Salt
.
The input salt, once decoded from base16, must be of length cryptoPWHashSaltBytes
.
Since: 0.0.1.0
hexByteStringToSalt :: StrictByteString -> Maybe Salt Source #
Convert a hexadecimal-encoded StrictByteString
to a Salt
.
The input salt, once decoded from base16, must be of length cryptoPWHashSaltBytes
.
Since: 0.0.1.0
Argon2 Parameters
defaultArgon2Params :: Argon2Params Source #
These are the default parameters with which hashByteStringWithParams
can be invoked:
- opsLimit =
cryptoPWHashOpsLimitModerate
- memLimit =
cryptoPWHashMemLimitModerate
Since: 0.0.1.0