Copyright | (C) Hécate Moonlight 2022 |
---|---|
License | BSD-3-Clause |
Maintainer | The Haskell Cryptography Group |
Stability | Stable |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Synopsis
- cryptoPWHash :: Ptr CUChar -> CLLong -> Ptr CChar -> CULLong -> Ptr CUChar -> CULLong -> CSize -> CInt -> IO CInt
- cryptoPWHashStr :: Ptr CChar -> Ptr CChar -> CULLong -> CULLong -> CSize -> IO CInt
- cryptoPWHashStrVerify :: Ptr CChar -> Ptr CChar -> CULLong -> IO CInt
- cryptoPWHashStrNeedsRehash :: Ptr CChar -> CULLong -> CSize -> IO CInt
- cryptoPWHashAlgDefault :: CInt
- cryptoPWHashAlgArgon2I13 :: CInt
- cryptoPWHashAlgArgon2ID13 :: CInt
- cryptoPWHashSaltBytes :: CSize
- cryptoPWHashPasswdMin :: CSize
- cryptoPWHashPasswdMax :: CSize
- cryptoPWHashOpsLimitInteractive :: CULLong
- cryptoPWHashOpsLimitSensitive :: CULLong
- cryptoPWHashOpsLimitModerate :: CULLong
- cryptoPWHashOpsLimitMin :: CULLong
- cryptoPWHashOpsLimitMax :: CULLong
- cryptoPWHashMemLimitModerate :: CSize
- cryptoPWHashMemLimitInteractive :: CSize
- cryptoPWHashMemLimitSensitive :: CSize
- cryptoPWHashMemLimitMin :: CSize
- cryptoPWHashMemLimitMax :: CSize
- cryptoPWHashBytesMax :: CULLong
- cryptoPWHashBytesMin :: CULLong
- cryptoPWHashStrBytes :: CSize
- cryptoPWHashStrPrefix :: Ptr CChar
Introduction
This modules provides an API that can be used both for key derivation using a low-entropy input and password storage.
Guidelines for choosing the parameters
Start by determining how much memory the function can use. What will be the highest number of threads/processes evaluating the function simultaneously (ideally, no more than 1 per CPU core)? How much physical memory is guaranteed to be available?
Set memlimit
to the amount of memory you want to reserve for password hashing.
Then set opslimit
to 3 and measure the time it takes to hash a password.
If this is way too long for your application, reduce memlimit
, but keep opslimit
set to 3.
If the function is so fast that you can afford it to be more computationally intensive without
any usability issues, then increase opslimit
.
For online use (e.g. logging in on a website), a 1 second computation is likely to be the acceptable maximum.
For interactive use (e.g. a desktop application), a 5 second pause after having entered a password is acceptable if the password doesn't need to be entered more than once per session.
For non-interactive and infrequent use (e.g. restoring an encrypted backup), an even slower computation can be an option.
However, the best defense against brute-force password cracking is to use strong passwords. Libraries such as passwdqc can help enforce this.
Operations
:: Ptr CUChar |
|
-> CLLong |
|
-> Ptr CChar |
|
-> CULLong |
|
-> Ptr CUChar |
|
-> CULLong |
|
-> CSize |
|
-> CInt |
|
-> IO CInt | The return code is 0 on success and -1 if the computation didn't complete, usually because the operating system refused to allocate the amount of requested memory. |
This functions derives a key from a password. The computed key is then stored in the out
parameter.
See: crypto_pwhash()
Since: 0.0.1.0
:: Ptr CChar |
|
-> Ptr CChar |
|
-> CULLong |
|
-> CULLong |
|
-> CSize |
|
-> IO CInt | The function returns 0 on success and -1 if it didn't complete successfully. |
This function is used for password storage, like an SQL database.
It stores an ASCII-encoded string into its out
parameter,
which includes:
- The result of a memory-hard, CPU-intensive hash function applied to the password passwd of length passwdlen;
- 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.
The out
parameter must be a dedicated storage area that's large enough to hold cryptoPWHashStrBytes
bytes,
but the actual output string may be shorter.
See: crypto_pwhash_str()
Since: 0.0.1.0
cryptoPWHashStrVerify Source #
:: Ptr CChar |
|
-> Ptr CChar |
|
-> CULLong |
|
-> IO CInt | It returns 0 if the verification succeeds and -1 on error. |
This function verifies that the str
parameter is a valid password verification string
(as generated by cryptoPWHashStr
), for a passwd
whose length is passwdlen
.
See: crypto_pwhash_str_verify()
Since: 0.0.1.0
cryptoPWHashStrNeedsRehash Source #
:: Ptr CChar |
|
-> CULLong |
|
-> CSize |
|
-> IO CInt | The function returns 0 if the parameters already match the given ones, and returns 1 on error. In particular, It will return 1 if the string appears to be correct but doesn't match the given parameters. In that situation, applications may want to compute a new hash using the current parameters the next time the user logs in. |
This functions checks if a password verification string str
matches the parameters opslimit
, memlimit
, and the current default algorithm.
See: crypto_pwhash_str_needs_rehash()
Since: 0.0.1.0
Constants
cryptoPWHashAlgDefault :: CInt Source #
Numeric indicator for the default algorithm, Argon2id v1.3.
See: crypto_pwhash_ALG_DEFAULT
Since: 0.0.1.0
cryptoPWHashOpsLimitInteractive :: CULLong Source #
Upper limit of operations in an interactive setting.
See: crypto_pwhash_OPSLIMIT_INTERACTIVE
Since: 0.0.1.0
cryptoPWHashOpsLimitSensitive :: CULLong Source #
Cryptographic perations done in a sensitive setting.
See: crypto_pwhash_OPSLIMIT_SENSITIVE
Since: 0.0.1.0
cryptoPWHashOpsLimitModerate :: CULLong Source #
Cryptographic operations in a moderately sensitive setting.
See: crypto_pwhash_OPSLIMIT_MODERATE
Since: 0.0.1.0
cryptoPWHashMemLimitModerate :: CSize Source #
Memory used in a moderately sensitive setting, in bytes.
See: crypto_pwhash_MEMLIMIT_MODERATE
Since: 0.0.1.0
cryptoPWHashMemLimitInteractive :: CSize Source #
Memory used in an interactive setting, in bytes.
See: crypto_pwhash_MEMLIMIT_INTERACTIVE
Since: 0.0.1.0
cryptoPWHashMemLimitMin :: CSize Source #
Minimum amount of memory that the caller can use, in bytes.
See: crypto_pwhash_MEMLIMIT_MIN
Since: 0.0.1.0
cryptoPWHashMemLimitMax :: CSize Source #
Maximum amount of memory that the caller can use, in bytes.
See: crypto_pwhash_MEMLIMIT_MAX @since 0.0.1.0
cryptoPWHashStrBytes :: CSize Source #
Expected size of a hash's textual representation, as generated by cryptoPWHashStr
.
Since: 0.0.1.0
cryptoPWHashStrPrefix :: Ptr CChar Source #
Prefix used in the hash's textual representation, as generated by cryptoPWHashStr
: "$argon2id$"
Since: 0.0.1.0