-- PBKDF2 hash output size, in octets

------------------------------------------------------------------------
-- Tuning parameters

guessIterCount :: Double -> IO Int
guessIterCount targetSecs = do
  salt <- getSalt
  let
    pass = fromString "Pass"
    loop !z = do
      t0 <- getCPUTime
      _  <- evaluate (kdf pass salt z)
      t1 <- getCPUTime
      if (fromIntegral (t1 - t0) * 1e-12) >= targetSecs
         then return z
         else loop (z + 1000)
  loop 0

------------------------------------------------------------------------
-- High-level interface

-- | Update passphrase and encryption parameters.
guessIterCount :: Double -> IO Int
guessIterCount targetSecs = do
  salt <- getSalt
  let
    pass = fromString "Pass"
    loop !z = do
      t0 <- getCPUTime
      _  <- evaluate (kdf pass salt z)
      t1 <- getCPUTime
      if (fromIntegral (t1 - t0) * 1e-12) >= targetSecs
         then return z
         else loop (z + 1000)
  loop 0

------------------------------------------------------------------------
-- High-level interface

-- | Update passphrase and encryption parameters.
guessIterCount targetSecs = do
  salt <- getSalt
  let
    pass = fromString "Pass"
    loop !z = do
      t0 <- getCPUTime
      _  <- evaluate (kdf pass salt z)
      t1 <- getCPUTime
      if (fromIntegral (t1 - t0) * 1e-12) >= targetSecs
         then return z
         else loop (z + 1000)
  loop 0

------------------------------------------------------------------------
-- High-level interface

-- | Update passphrase and encryption parameters.