From c295cceb01c45e7530022b1edde970f5fbbb03c1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Aug 2016 22:19:30 -0400 Subject: round-tripping now working, except for guessing the puzzle --- Encryption.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Encryption.hs') diff --git a/Encryption.hs b/Encryption.hs index c712d98..8af25d4 100644 --- a/Encryption.hs +++ b/Encryption.hs @@ -119,15 +119,17 @@ sizePuzzleIV tunables = ceiling $ nbits / 8 -- Add one bit of entropy, because a brute-force attack will -- on average succeed half-way through the search space. nbits :: Double - nbits = logBase 2 (fromIntegral $ targetseconds * triespersecond) + 1 + nbits + | targetseconds < 1 = 0 + | otherwise = logBase 2 (fromIntegral $ targetseconds * triespersecond) + 1 mkPuzzleIV :: Raaz.IV -> Int -> PuzzleIV -mkPuzzleIV randomiv nbytes = PuzzleIV $ - fromMaybe (error "mkRandomIV fromByteString failed") $ - Raaz.fromByteString $ B.take nbytes b <> padding +mkPuzzleIV randomiv nrand = PuzzleIV $ + fromMaybe (error "mkPuzzleIV fromByteString failed") $ + Raaz.fromByteString $ B.take nrand b <> padding where b = Raaz.toByteString randomiv - padding = B.replicate (B.length b - nbytes) 0 + padding = B.replicate (B.length b - nrand) 0 genPuzzleIV :: Tunables -> IO PuzzleIV genPuzzleIV tunables = do -- cgit v1.2.3