diff --git a/Crypto/KDF/Scrypt.hs b/Crypto/KDF/Scrypt.hs new file mode 100644 index 0000000..693c1dd --- /dev/null +++ b/Crypto/KDF/Scrypt.hs @@ -0,0 +1,41 @@ +-- | +-- Module : Crypto.KDF.Scrypt +-- License : BSD-style +-- Maintainer : Vincent Hanquez +-- Stability : experimental +-- Portability : unknown +-- +-- Scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" . +-- +{-# LANGUAGE BangPatterns #-} +module Crypto.KDF.Scrypt + ( Parameters(..) + , generate + ) where + +import Data.Word +import Data.Bits +import Data.ByteString (ByteString) +import qualified Data.ByteString as B +import qualified Data.ByteString.Internal as B (unsafeCreate, memset) +import Data.Byteable +import Foreign.Storable +import Foreign.Ptr (Ptr, plusPtr) +import Control.Applicative +import Control.Monad (forM_, void) + +import qualified Crypto.KDF.PBKDF2 as PBKDF2 + +-- | Parameters for Scrypt +data Parameters = Parameters + { password :: ByteString -- ^ Password (bytes encoded) + , salt :: ByteString -- ^ Salt (bytes encoded) + , n :: Int -- ^ Cpu/Memory cost ratio. must be a power of 2 greater than 1 + , r :: Int -- ^ Must satisfy r * p < 2^30 + , p :: Int -- ^ Must satisfy r * p < 2^30 + , outputLength :: Int -- ^ the number of bytes to generate out of Scrypt + } + +-- | Generate the scrypt key derivation data +generate :: Parameters -> B.ByteString +generate params = undefined diff --git a/cryptonite.cabal b/cryptonite.cabal index 7066e1f..196e3b9 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -48,6 +48,7 @@ Library Other-modules: Crypto.Hash.Internal , Crypto.Hash.Utils , Crypto.Hash.Types + , Crypto.KDF.Scrypt , Crypto.Random.Entropy.Source Build-depends: base >= 4 && < 5 , bytestring