Skip to content

Commit

Permalink
Add pkcs5_pbkdf2_hmac_sha1 to OpenSSL.EVP.Digest
Browse files Browse the repository at this point in the history
darcs-hash:20081005075451-4d968-0f1f903399624b6dc37dd56ec868741b15629cd4.gz
  • Loading branch information
taruti committed Oct 5, 2008
1 parent f99ad2b commit b820359
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion OpenSSL/EVP/Digest.hsc
Expand Up @@ -27,11 +27,12 @@ module OpenSSL.EVP.Digest
, digestLBS

, hmacBS
, pkcs5_pbkdf2_hmac_sha1
)
where

import Control.Monad
import Data.ByteString.Internal (createAndTrim)
import Data.ByteString.Internal (createAndTrim, create)
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8
Expand Down Expand Up @@ -204,3 +205,21 @@ hmacBS (Digest md) key input =
do _HMAC md keydata (fromIntegral keylen) inputdata (fromIntegral inputlen) bufPtr bufLenPtr
bufLen <- liftM fromIntegral $ peek bufLenPtr
B8.packCStringLen (bufPtr, bufLen)

pkcs5_pbkdf2_hmac_sha1 :: B8.ByteString -- ^ password
-> B8.ByteString -- ^ salt
-> Int -- ^ iterations
-> Int -- ^ destination key length
-> B8.ByteString -- ^ destination key
pkcs5_pbkdf2_hmac_sha1 pass salt iter dkeylen =
unsafePerformIO $
unsafeUseAsCStringLen pass $ \(passdata, passlen) ->
unsafeUseAsCStringLen salt $ \(saltdata, saltlen) ->
create dkeylen $ \dkeydata ->
do _PKCS5_PBKDF2_HMAC_SHA1 passdata (fromIntegral passlen) saltdata (fromIntegral saltlen) (fromIntegral iter) (fromIntegral dkeylen) (castPtr dkeydata)
return ()

foreign import ccall unsafe "PKCS5_PBKDF2_HMAC_SHA1" _PKCS5_PBKDF2_HMAC_SHA1 :: Ptr CChar -> CInt
-> Ptr CChar -> CInt
-> CInt -> CInt -> Ptr CChar
-> IO CInt

0 comments on commit b820359

Please sign in to comment.