packages feed

scrypt 0.1.1 → 0.2.0

raw patch · 2 files changed

+28/−19 lines, 2 files

Files

Crypto/Scrypt.hs view
@@ -5,23 +5,23 @@ --  Percival. For more information see <http://www.tarsnap.com/scrypt.html>. module Crypto.Scrypt (      -- *Parameters to the @scrypt@ function-     ScryptParams, params, defaultParams+     ScryptParams, params     -- * The @scrypt@ key derivation function-    , scrypt, getSalt     , Pass(..), Salt(..), PassHash(..)+    , scrypt, scrypt', getSalt     ) where  import Control.Applicative ((<$>))-import Data.ByteString+import Data.ByteString (ByteString, useAsCStringLen, packCStringLen, hGet) import Data.Maybe import Foreign import Foreign.C import System.IO  -newtype Pass = Pass ByteString deriving (Show)-newtype Salt = Salt ByteString deriving (Show)-newtype PassHash = PassHash ByteString deriving (Show,Eq)+newtype Pass = Pass { unPass :: ByteString } deriving (Show)+newtype Salt = Salt { unSalt :: ByteString } deriving (Show)+newtype PassHash = PassHash { unHash :: ByteString } deriving (Show,Eq)  -- |Encapsulates the three tuning parameters to the 'scrypt' function: @N@, --  @r@ and @p@. The parameters affect running time and memory usage:@@ -40,6 +40,14 @@ -- data ScryptParams = Params { logN, r, p, bufLen :: Integer} +instance Show ScryptParams where+    show Params{..} = concat [ "ScryptParams "+        , "{ logN=", show logN+        , ", r="   , show r+        , ", p="   , show p+        , " }"+        ]+ -- |Constructor function for the 'ScryptParams' data type params :: Integer        -- ^ @log_2(N)@. Scrypt's @N@ parameter must be a power of two greater@@ -61,18 +69,6 @@                 , bufLen ps <= 2^(32 :: Int)-1 * 32                 ] --- |Default parameters as recommended in the scrypt paper:------  @   N = 2^14, r = 8, p = 1 @------  Equivalent to @'fromJust' ('params' 14 8 1)@.-defaultParams :: ScryptParams-defaultParams = fromJust (params 14 8 1)---- |Reads a 32-byte random salt from @\/dev\/urandom@.-getSalt :: IO Salt-getSalt = Salt <$> withBinaryFile "/dev/urandom" ReadMode (flip hGet 32)- -- |Calculates a 64-byte hash from the given password, salt and parameters. scrypt :: ScryptParams -> Salt -> Pass -> PassHash scrypt Params{..} (Salt salt) (Pass pass) =@@ -93,3 +89,16 @@     -> Word64 -> Word32 -> Word32 -- N, r, p     -> Ptr Word8 -> CSize         -- result buffer     -> IO CInt++-- |Note the prime symbol (\'). Calls 'scrypt' with default parameters as+--  recommended in the scrypt paper:+--+--  @   N = 2^14, r = 8, p = 1 @+--+--  Equivalent to @'scrypt' ('fromJust' ('params' 14 8 1))@.+scrypt' :: Salt -> Pass -> PassHash+scrypt' = scrypt $ fromJust (params 14 8 1)++-- |Reads a 32-byte random salt from @\/dev\/urandom@.+getSalt :: IO Salt+getSalt = Salt <$> withBinaryFile "/dev/urandom" ReadMode (flip hGet 32)
scrypt.cabal view
@@ -1,5 +1,5 @@ name:           scrypt-version:        0.1.1+version:        0.2.0 license:        BSD3 license-file:   LICENSE category:       Cryptography