{-# LINE 1 "src/Crypto/Argon2/FFI.hsc" #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE Unsafe #-} -- | -- Module : Crypto.Argon2.FFI -- License : BSD3 -- Maintainer : hvr@gnu.org -- -- This module provides low-level access to parts of the C API -- -- Prefer the "Crypto.Argon2" API when possible. module Crypto.Argon2.FFI where import Foreign import Foreign.C {-# LINE 24 "src/Crypto/Argon2/FFI.hsc" #-} -- * @libargon2@ functions -- | 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 -- foreign import ccall safe {-# LINE 57 "src/Crypto/Argon2/FFI.hsc" #-} "argon2.h hs_argon2__argon2_hash" {-# LINE 59 "src/Crypto/Argon2/FFI.hsc" #-} argon2_hash :: Word32 {- t_cost -} -> Word32 {- m_cost -} -> Word32 {- parallelism -} -> Ptr a -> CSize {- pwd + pwdlen -} -> Ptr b -> CSize {- salt + saltlen -} -> Ptr c -> CSize {- hash + hashlen -} -> CString -> CSize {- encoded + encodedlen -} -> 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 -- foreign import ccall safe {-# LINE 87 "src/Crypto/Argon2/FFI.hsc" #-} "argon2.h hs_argon2__argon2_verify" {-# LINE 89 "src/Crypto/Argon2/FFI.hsc" #-} 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 -- foreign import ccall unsafe {-# LINE 111 "src/Crypto/Argon2/FFI.hsc" #-} "argon2.h hs_argon2__argon2_encodedlen" {-# LINE 113 "src/Crypto/Argon2/FFI.hsc" #-} argon2_encodedlen :: Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Argon2_type -> CSize -- * @libargon2@ API typedefs -- ** @argon2_type@ type Argon2_type = (Word32) {-# LINE 121 "src/Crypto/Argon2/FFI.hsc" #-} pattern Argon2_d = (0) {-# LINE 122 "src/Crypto/Argon2/FFI.hsc" #-} pattern Argon2_i = (1) {-# LINE 123 "src/Crypto/Argon2/FFI.hsc" #-} pattern Argon2_id = (2) {-# LINE 124 "src/Crypto/Argon2/FFI.hsc" #-} -- ** @argon2_version@ type Argon2_version = Word32 -- NB, not (#type argon2_version) pattern ARGON2_VERSION_10 = (16) {-# LINE 129 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_VERSION_13 = (19) {-# LINE 130 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_VERSION_NUMBER = (19) {-# LINE 131 "src/Crypto/Argon2/FFI.hsc" #-} -- ** @argon2_error_codes@ -- argon2_error_codes pattern ARGON2_OK = (0) {-# LINE 136 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_OUTPUT_PTR_NULL = (-1) {-# LINE 137 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_OUTPUT_TOO_SHORT = (-2) {-# LINE 138 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_OUTPUT_TOO_LONG = (-3) {-# LINE 139 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_PWD_TOO_SHORT = (-4) {-# LINE 140 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_PWD_TOO_LONG = (-5) {-# LINE 141 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SALT_TOO_SHORT = (-6) {-# LINE 142 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SALT_TOO_LONG = (-7) {-# LINE 143 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_AD_TOO_SHORT = (-8) {-# LINE 144 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_AD_TOO_LONG = (-9) {-# LINE 145 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SECRET_TOO_SHORT = (-10) {-# LINE 146 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SECRET_TOO_LONG = (-11) {-# LINE 147 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_TIME_TOO_SMALL = (-12) {-# LINE 148 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_TIME_TOO_LARGE = (-13) {-# LINE 149 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MEMORY_TOO_LITTLE = (-14) {-# LINE 150 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MEMORY_TOO_MUCH = (-15) {-# LINE 151 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_LANES_TOO_FEW = (-16) {-# LINE 152 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_LANES_TOO_MANY = (-17) {-# LINE 153 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_PWD_PTR_MISMATCH = (-18) {-# LINE 154 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SALT_PTR_MISMATCH = (-19) {-# LINE 155 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SECRET_PTR_MISMATCH = (-20) {-# LINE 156 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_AD_PTR_MISMATCH = (-21) {-# LINE 157 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MEMORY_ALLOCATION_ERROR = (-22) {-# LINE 158 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_FREE_MEMORY_CBK_NULL = (-23) {-# LINE 159 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_ALLOCATE_MEMORY_CBK_NULL = (-24) {-# LINE 160 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_INCORRECT_PARAMETER = (-25) {-# LINE 161 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_INCORRECT_TYPE = (-26) {-# LINE 162 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_OUT_PTR_MISMATCH = (-27) {-# LINE 163 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_THREADS_TOO_FEW = (-28) {-# LINE 164 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_THREADS_TOO_MANY = (-29) {-# LINE 165 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MISSING_ARGS = (-30) {-# LINE 166 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_ENCODING_FAIL = (-31) {-# LINE 167 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_DECODING_FAIL = (-32) {-# LINE 168 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_THREAD_FAIL = (-33) {-# LINE 169 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_DECODING_LENGTH_FAIL = (-34) {-# LINE 170 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_VERIFY_MISMATCH = (-35) {-# LINE 171 "src/Crypto/Argon2/FFI.hsc" #-} -- * @libargon2@ limits & constants pattern ARGON2_MIN_LANES = (1) {-# LINE 175 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_LANES = (16777215) {-# LINE 176 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_THREADS = (1) {-# LINE 178 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_THREADS = (16777215) {-# LINE 179 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_SYNC_POINTS = (4) {-# LINE 181 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_OUTLEN = (4) {-# LINE 183 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_OUTLEN = (4294967295) {-# LINE 184 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_MEMORY = (8) {-# LINE 186 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_MEMORY_BITS = (32) {-# LINE 188 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_MEMORY = (4294967295) {-# LINE 189 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_TIME = (1) {-# LINE 191 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_TIME = (4294967295) {-# LINE 192 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_PWD_LENGTH = (0) {-# LINE 194 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_PWD_LENGTH = (4294967295) {-# LINE 195 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_AD_LENGTH = (0) {-# LINE 197 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_AD_LENGTH = (4294967295) {-# LINE 198 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_SALT_LENGTH = (8) {-# LINE 200 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_SALT_LENGTH = (4294967295) {-# LINE 201 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MIN_SECRET = (0) {-# LINE 203 "src/Crypto/Argon2/FFI.hsc" #-} pattern ARGON2_MAX_SECRET = (4294967295) {-# LINE 204 "src/Crypto/Argon2/FFI.hsc" #-} {- /* Global flag to determine if we are wiping internal memory buffers. This flag * is defined in core.c and deafults to 1 (wipe internal memory). */ extern int FLAG_clear_internal_memory; pattern ARGON2_FLAG_CLEAR_PASSWORD = (#const ARGON2_FLAG_CLEAR_PASSWORD) pattern ARGON2_FLAG_CLEAR_SECRET = (#const ARGON2_FLAG_CLEAR_SECRET) pattern ARGON2_DEFAULT_FLAGS = (#const ARGON2_DEFAULT_FLAGS) -}