diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-11 22:19:30 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-11 22:19:30 -0400 |
commit | c295cceb01c45e7530022b1edde970f5fbbb03c1 (patch) | |
tree | c4060595adec4bdfc1f9cd882033e1935753eddd /Encryption.hs | |
parent | 7db612b232a0f8a98fa695da6f14853284def681 (diff) | |
download | keysafe-c295cceb01c45e7530022b1edde970f5fbbb03c1.tar.gz |
round-tripping now working, except for guessing the puzzle
Diffstat (limited to 'Encryption.hs')
-rw-r--r-- | Encryption.hs | 12 |
1 files changed, 7 insertions, 5 deletions
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 |