nano-cryptr-0.1.1.3: A threadsafe binding to glibc's crypt_r function

Safe HaskellNone

System.Gnu.CryptR

Description

This package wraps glibc's crypt_r function in a thread-safe manner.

 $ ghci -XOverloadedStrings
 GHCi, version 6.12.3: http:www.haskell.orgghc  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 Loading package ffi-1.0 ... linking ... done.
 Prelude> :m + System.Gnu.CryptR Data.ByteString.Char8
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptR "password" "l3"
 Loading package bytestring-0.9.1.7 ... linking ... done.
 Loading package nano-cryptr-0.1.1.1 ... linking ... done.
 "l3vmImyenGFYg"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptR "password1" "l3vmImyenGFYg"
 "l3vmImyenGFYg"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> x <- newCryptData
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x  "password1" "l3vmImyenGFYg"
 "l3vmImyenGFYg"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "xpassword" "l3vmImyenGFYg"
 "l3odRN01x86RU"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "password" "l3vmImyenGFYg"
 "l3vmImyenGFYg"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "password" "$1$grufal$"
 "$1$grufal$KyfLpXJJ32ZZw9EqqMSav1"
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "password1" "$1$grufal$"
 "$1$grufal$xi8N0nP2Fl22TxyW68uvV."
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "password1" "$1$grufal$KyfLpXJJ32ZZw9EqqMSav1"
 "$1$grufal$xi8N0nP2Fl22TxyW68uvV."
 Prelude System.Gnu.CryptR Data.ByteString.Char8> cryptRIO x "password" "$1$grufal$KyfLpXJJ32ZZw9EqqMSav1"
 "$1$grufal$KyfLpXJJ32ZZw9EqqMSav1"

Synopsis

Documentation

data CryptData Source

CryptData is an opaque wrapper around the state used by crypt_r.

Instances

newCryptData :: IO CryptDataSource

Create a new CryptData value. It uses ForeignPtr to free the underlying data structure properly when it is garbage collected.

cryptRIOSource

Arguments

:: CryptData

the CryptData to use as scratch space

-> ByteString

the key value as described by crypt_r

-> ByteString

the salt value as described by crypt_r

-> IO ByteString

the result of the call to crypt_r

This is a thread-safe interface to the functionality provided by glibc's crypt_r. It protects against concurrent use of the same CryptData value internally. This means that it's potentially a performance bottleneck, and you may wish to use multiple CryptData values if high concurrency is necessary.

This interface avoids initializing a new CryptData for each call, as is done by the cryptR call

cryptRSource

Arguments

:: ByteString

the key value as described in crypt_r

-> ByteString

the salt value as described in crypt_r

-> ByteString

the result of the call to crypt_r

This is a pure, thread-safe interface to the functionality provided by glibc's crypt_r. It uses crypt_r internally, allocating a single-use buffer for each call. Because the buffer is decently large and needs to be initialized for each call, this function has significantly more overhead on multiple calls than using newCryptData followed by multiple uses of cryptRIO. This is provided as a convenience function when the overhead is not as important as the simplicity of this interface.