move more compat things into Internal.Compat.
This commit is contained in:
parent
57aa7ce098
commit
969daf5af1
@ -11,9 +11,11 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
module Crypto.Internal.Compat
|
module Crypto.Internal.Compat
|
||||||
( unsafeDoIO
|
( unsafeDoIO
|
||||||
|
, popCount
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import System.IO.Unsafe
|
import System.IO.Unsafe
|
||||||
|
import Data.Bits (popCount)
|
||||||
|
|
||||||
-- | perform io for hashes that do allocation and ffi.
|
-- | perform io for hashes that do allocation and ffi.
|
||||||
-- unsafeDupablePerformIO is used when possible as the
|
-- unsafeDupablePerformIO is used when possible as the
|
||||||
@ -26,3 +28,10 @@ unsafeDoIO = unsafeDupablePerformIO
|
|||||||
#else
|
#else
|
||||||
unsafeDoIO = unsafePerformIO
|
unsafeDoIO = unsafePerformIO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !(MIN_VERSION_base(4,5,0))
|
||||||
|
popCount :: Word64 -> Int
|
||||||
|
popCount n = loop 0 n
|
||||||
|
where loop c 0 = c
|
||||||
|
loop c i = loop (c + if testBit c 0 then 1 else 0) (i `shiftR` 1)
|
||||||
|
#endif
|
||||||
|
|||||||
@ -16,7 +16,6 @@ module Crypto.KDF.Scrypt
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Word
|
import Data.Word
|
||||||
import Data.Bits
|
|
||||||
import Data.Byteable
|
import Data.Byteable
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
@ -30,6 +29,7 @@ import System.IO.Unsafe
|
|||||||
|
|
||||||
import Crypto.Hash (SHA256(..))
|
import Crypto.Hash (SHA256(..))
|
||||||
import qualified Crypto.KDF.PBKDF2 as PBKDF2
|
import qualified Crypto.KDF.PBKDF2 as PBKDF2
|
||||||
|
import Crypto.Internal.Compat (popCount)
|
||||||
|
|
||||||
-- | Parameters for Scrypt
|
-- | Parameters for Scrypt
|
||||||
data Parameters = Parameters
|
data Parameters = Parameters
|
||||||
@ -44,13 +44,6 @@ data Parameters = Parameters
|
|||||||
foreign import ccall "cryptonite_scrypt_smix"
|
foreign import ccall "cryptonite_scrypt_smix"
|
||||||
ccryptonite_scrypt_smix :: Ptr Word8 -> Word32 -> Word64 -> Ptr Word8 -> Ptr Word8 -> IO ()
|
ccryptonite_scrypt_smix :: Ptr Word8 -> Word32 -> Word64 -> Ptr Word8 -> Ptr Word8 -> IO ()
|
||||||
|
|
||||||
#if !(MIN_VERSION_base(4,5,0))
|
|
||||||
popCount :: Word64 -> Int
|
|
||||||
popCount n = loop 0 n
|
|
||||||
where loop c 0 = c
|
|
||||||
loop c i = loop (c + if testBit c 0 then 1 else 0) (i `shiftR` 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Generate the scrypt key derivation data
|
-- | Generate the scrypt key derivation data
|
||||||
generate :: Parameters -> B.ByteString
|
generate :: Parameters -> B.ByteString
|
||||||
generate params
|
generate params
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user