-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Memory-hard password hash and proof-of-work function
--
-- Argon2 is the key derivation function (KDF) selected as the winner of
-- the Password Hashing Competition. The API exposed by this
-- bindings provide access to the 3 specified variants
--
--
-- - Argon2d (maximize resistance to GPU cracking
-- attacks),
-- - Argon2i (optimized to resist side-channel attacks),
-- and
-- - Argon2id (hybrid version combining Argon2d and
-- Argon2i)
--
--
-- and allows to control various parameters (time cost, memory cost,
-- parallelism) of the Argon2 function. Moreover, it is also supported to
-- generate and verify the deprecated version 1.0 hashes, as well as the
-- current version 1.3 hashes.
--
-- The Haskell API supports both raw binary hashes as well as the
-- ASCII-based PHC string format.
--
-- This version provides bindings to the "20171227" release of
-- the Argon2 reference implementation (libargon2) of the Argon2
-- password-hashing function.
--
-- Please refer to the Argon2 specification for more information.
@package argon2
@version 1.3.0.0
-- | This module provides low-level access to parts of the C API
--
-- Prefer the Crypto.Argon2 API when possible.
module Crypto.Argon2.FFI
-- | Compute Argon2 hash
--
--
-- int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
-- const uint32_t parallelism, const void *pwd,
-- const size_t pwdlen, const void *salt,
-- const size_t saltlen, void *hash,
-- const size_t hashlen, char *encoded,
-- const size_t encodedlen, argon2_type type,
-- const uint32_t version);
--
--
-- Parameters
--
--
-- - t_cost Number of iterations
-- - m_cost Sets memory usage to m_cost kibibytes
-- - parallelism Number of threads and compute lanes
-- - pwd Pointer to password
-- - pwdlen Password size in bytes
-- - salt Pointer to salt
-- - saltlen Salt size in bytes
-- - hash Buffer where to write the raw hash
-- - hashlen Desired length of the hash in bytes
-- - encoded Buffer where to write the encoded hash
-- - encodedlen Size of the buffer (thus max size of the encoded
-- hash)
-- - type Variant of Argon2 hash
-- - version Version of Argon2 specification
--
argon2_hash :: Word32 -> Word32 -> Word32 -> Ptr a -> CSize -> Ptr b -> CSize -> Ptr c -> CSize -> CString -> CSize -> Argon2_type -> Argon2_version -> IO CInt
-- | Verify encoded hash
--
--
-- int argon2_verify(const char *encoded, const void *pwd,
-- const size_t pwdlen, argon2_type type);
--
--
-- Parameters
--
--
-- - encoded Pointer to zero-terminated encoded hash
-- - pwd Pointer to password
-- - pwdlen Password size in bytes
-- - type Variant of Argon2 hash
--
argon2_verify :: CString -> Ptr a -> CSize -> Argon2_type -> IO CInt
-- | Compute size of encoded hash
--
--
-- size_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost, uint32_t parallelism,
-- uint32_t saltlen, uint32_t hashlen, argon2_type type);
--
--
-- Parameters
--
--
-- - t_cost Number of iterations
-- - m_cost Sets memory usage to m_cost kibibytes
-- - parallelism Number of threads and compute lanes
-- - salt Pointer to salt
-- - saltlen Salt size in bytes
-- - hashlen Desired length of the hash in bytes
-- - type Variant of Argon2 hash
--
argon2_encodedlen :: Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Argon2_type -> CSize
type Argon2_type = (Word32)
type Argon2_version = Word32
-- | Crypto.Argon2 provides bindings to the reference
-- implementation of Argon2, the password-hashing function that won
-- the Password Hashing Competition (PHC).
--
-- The main entry points to this module are hashEncoded, which
-- produces a crypt-like ASCII output; and hash which produces a
-- ByteString (a stream of bytes). Argon2 is a configurable hash
-- function, and can be configured by supplying a particular set of
-- HashOptions - defaultHashOptions should provide a good
-- starting point. See HashOptions for more documentation on the
-- particular parameters that can be adjusted.
--
-- For (unsafe) access directly to the C interface, see
-- Crypto.Argon2.FFI.
module Crypto.Argon2
-- | Encode a password with a given salt and HashOptions and produce
-- a binary stream of bytes (of size hashLength).
hash :: HashOptions -> ByteString -> ByteString -> Either Argon2Status ByteString
-- | Encode a password with a given salt and HashOptions and produce
-- a textual encoding according to the PHC string format of the
-- result.
--
-- Use verifyEncoded to verify.
hashEncoded :: HashOptions -> ByteString -> ByteString -> Either Argon2Status ShortText
-- | Verify that a given password could result in a given hash output.
-- Automatically determines the correct HashOptions based on the
-- encoded hash (using the PHC string format as produced by
-- hashEncoded).
--
-- Returns Argon2Ok on successful verification. If decoding is
-- successful but the password mismatches, Argon2VerifyMismatch is
-- returned; if decoding fails, the respective Argon2Status code
-- is returned.
verifyEncoded :: ShortText -> ByteString -> Argon2Status
-- | Parameters that can be adjusted to change the runtime performance of
-- the hashing. See also defaultHashOptions.
data HashOptions
HashOptions :: !Word32 -> !Word32 -> !Word32 -> !Argon2Variant -> !Argon2Version -> !Word32 -> HashOptions
-- | The time cost, which defines the amount of computation realized and
-- therefore the execution time, given in number of iterations.
--
-- ARGON2_MIN_TIME <= hashIterations <=
-- ARGON2_MAX_TIME
[hashIterations] :: HashOptions -> !Word32
-- | The memory cost, which defines the memory usage, given in
-- kibibytes.
--
-- max ARGON2_MIN_MEMORY (8 * hashParallelism) <=
-- hashMemory <= ARGON2_MAX_MEMORY
[hashMemory] :: HashOptions -> !Word32
-- | A parallelism degree, which defines the number of parallel threads.
--
-- ARGON2_MIN_LANES <= hashParallelism <=
-- ARGON2_MAX_LANES && ARGON_MIN_THREADS <=
-- hashParallelism <= ARGON2_MAX_THREADS
[hashParallelism] :: HashOptions -> !Word32
-- | Which variant of Argon2 to use.
[hashVariant] :: HashOptions -> !Argon2Variant
-- | Which version of Argon2 to use for generating hashes.
[hashVersion] :: HashOptions -> !Argon2Version
-- | Desired length of hash expressed in octets.
[hashLength] :: HashOptions -> !Word32
-- | Which variant of Argon2 to use. You should choose the variant that is
-- most applicable to your intention to hash inputs.
data Argon2Variant
-- | Argon2i uses data-independent memory access, which is preferred for
-- password hashing and password-based key derivation. Argon2i is slower
-- as it makes more passes over the memory to protect from tradeoff
-- attacks.
Argon2i :: Argon2Variant
-- | Argon2d is faster and uses data-depending memory access, which makes
-- it suitable for cryptocurrencies and applications with no threats from
-- side-channel timing attacks.
Argon2d :: Argon2Variant
-- | Argon2id works as Argon2i for the first half of the first iteration
-- over the memory, and as Argon2d for the rest, thus providing both
-- side-channel attack protection and brute-force cost savings due to
-- time-memory tradeoffs.
Argon2id :: Argon2Variant
-- | Version of the Argon2 algorithm.
data Argon2Version
-- | Version 1.0 (deprecated)
Argon2Version10 :: Argon2Version
-- | Version 1.3 (See this announcment for more details)
Argon2Version13 :: Argon2Version
-- | A set of default HashOptions, taken from the argon2
-- executable.
--
--
-- defaultHashOptions :: HashOptions
-- defaultHashOptions =
-- HashOptions { hashIterations = 3
-- , hashMemory = 2 ^ 12 -- 4 MiB
-- , hashParallelism = 1
-- , hashVariant = Argon2i
-- , hashVersion = Argon2Version13
-- , hashLength = 2 ^ 5 -- 32 bytes
-- }
--
--
-- For more information on how to select these parameters for your
-- application, see section 6.4 of the Argon2 specification.
defaultHashOptions :: HashOptions
-- | Returned status code for Argon2 functions.
--
-- Not all HashOptions can necessarily be used to compute hashes.
-- If you supply unsupported or invalid HashOptions (or hashing
-- otherwise fails) an Argon2Status value will be returned to
-- describe the failure.
--
-- Note that this enumeration contains some status codes which are not
-- expected to be returned by the operation provided by the Haskell API.
data Argon2Status
-- | OK (operation succeeded)
Argon2Ok :: Argon2Status
-- | Output pointer is NULL
Argon2OutputPtrNull :: Argon2Status
-- | Output is too short
Argon2OutputTooShort :: Argon2Status
-- | Output is too long
Argon2OutputTooLong :: Argon2Status
-- | Password is too short
Argon2PwdTooShort :: Argon2Status
-- | Password is too long
Argon2PwdTooLong :: Argon2Status
-- | Salt is too short
Argon2SaltTooShort :: Argon2Status
-- | Salt is too long
Argon2SaltTooLong :: Argon2Status
-- | Associated data is too short
Argon2AdTooShort :: Argon2Status
-- | Associated data is too long
Argon2AdTooLong :: Argon2Status
-- | Secret is too short
Argon2SecretTooShort :: Argon2Status
-- | Secret is too long
Argon2SecretTooLong :: Argon2Status
-- | Time cost is too small
Argon2TimeTooSmall :: Argon2Status
-- | Time cost is too large
Argon2TimeTooLarge :: Argon2Status
-- | Memory cost is too small
Argon2MemoryTooLittle :: Argon2Status
-- | Memory cost is too large
Argon2MemoryTooMuch :: Argon2Status
-- | Too few lanes
Argon2LanesTooFew :: Argon2Status
-- | Too many lanes
Argon2LanesTooMany :: Argon2Status
-- | Password pointer is NULL, but password length is not 0
Argon2PwdPtrMismatch :: Argon2Status
-- | Salt pointer is NULL, but salt length is not 0
Argon2SaltPtrMismatch :: Argon2Status
-- | Secret pointer is NULL, but secret length is not 0
Argon2SecretPtrMismatch :: Argon2Status
-- | Associated data pointer is NULL, but ad length is not 0
Argon2AdPtrMismatch :: Argon2Status
-- | Memory allocation error
Argon2MemoryAllocationError :: Argon2Status
-- | The free memory callback is NULL
Argon2FreeMemoryCbkNull :: Argon2Status
-- | The allocate memory callback is NULL
Argon2AllocateMemoryCbkNull :: Argon2Status
-- | Argon2_Context context is NULL
Argon2IncorrectParameter :: Argon2Status
-- | There is no such version of Argon2
Argon2IncorrectType :: Argon2Status
-- | Output pointer mismatch
Argon2OutPtrMismatch :: Argon2Status
-- | Not enough threads
Argon2ThreadsTooFew :: Argon2Status
-- | Too many threads
Argon2ThreadsTooMany :: Argon2Status
-- | Missing arguments
Argon2MissingArgs :: Argon2Status
-- | Encoding failed
Argon2EncodingFail :: Argon2Status
-- | Decoding failed
Argon2DecodingFail :: Argon2Status
-- | Threading failure
Argon2ThreadFail :: Argon2Status
-- | Some of encoded parameters are too long or too short
Argon2DecodingLengthFail :: Argon2Status
-- | The password does not match the supplied hash
Argon2VerifyMismatch :: Argon2Status
-- | Internal error or unrecognized status code
Argon2InternalError :: Argon2Status
instance GHC.Enum.Bounded Crypto.Argon2.Argon2Status
instance GHC.Enum.Enum Crypto.Argon2.Argon2Status
instance GHC.Show.Show Crypto.Argon2.Argon2Status
instance GHC.Read.Read Crypto.Argon2.Argon2Status
instance GHC.Classes.Ord Crypto.Argon2.Argon2Status
instance GHC.Classes.Eq Crypto.Argon2.Argon2Status
instance GHC.Generics.Generic Crypto.Argon2.HashOptions
instance GHC.Enum.Bounded Crypto.Argon2.HashOptions
instance GHC.Show.Show Crypto.Argon2.HashOptions
instance GHC.Read.Read Crypto.Argon2.HashOptions
instance GHC.Classes.Ord Crypto.Argon2.HashOptions
instance GHC.Classes.Eq Crypto.Argon2.HashOptions
instance GHC.Enum.Enum Crypto.Argon2.Argon2Version
instance GHC.Generics.Generic Crypto.Argon2.Argon2Version
instance GHC.Enum.Bounded Crypto.Argon2.Argon2Version
instance GHC.Show.Show Crypto.Argon2.Argon2Version
instance GHC.Read.Read Crypto.Argon2.Argon2Version
instance GHC.Classes.Ord Crypto.Argon2.Argon2Version
instance GHC.Classes.Eq Crypto.Argon2.Argon2Version
instance GHC.Enum.Enum Crypto.Argon2.Argon2Variant
instance GHC.Generics.Generic Crypto.Argon2.Argon2Variant
instance GHC.Enum.Bounded Crypto.Argon2.Argon2Variant
instance GHC.Show.Show Crypto.Argon2.Argon2Variant
instance GHC.Read.Read Crypto.Argon2.Argon2Variant
instance GHC.Classes.Ord Crypto.Argon2.Argon2Variant
instance GHC.Classes.Eq Crypto.Argon2.Argon2Variant
instance Control.DeepSeq.NFData Crypto.Argon2.Argon2Status
instance GHC.Exception.Exception Crypto.Argon2.Argon2Status
instance Control.DeepSeq.NFData Crypto.Argon2.HashOptions
instance Control.DeepSeq.NFData Crypto.Argon2.Argon2Version
instance Control.DeepSeq.NFData Crypto.Argon2.Argon2Variant