Skip to content

Commit

Permalink
Add getIVIO, export getIV* from Data.Crypto.Modes
Browse files Browse the repository at this point in the history
Ignore-this: 5b3a1855fdbe4ba3e6668ca5817ce568

darcs-hash:20100902212443-cef97-abcc43fc664a8923dddd96769781992bac83a890.gz
  • Loading branch information
TomMD committed Sep 2, 2010
1 parent 95cdc55 commit dcad9a5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Data/Crypto/Modes.hs
@@ -1,4 +1,4 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ScopedTypeVariables, MonoLocalBinds #-}
module Data.Crypto.Modes
( ecb, unEcb
, cbc, unCbc
Expand All @@ -9,6 +9,7 @@ module Data.Crypto.Modes
, cfb', unCfb'
, ofb', unOfb'
, IV
, getIV, getIVIO
-- , gmc
-- , xts
-- , ccm
Expand All @@ -26,6 +27,7 @@ import qualified Data.Serialize.Get as SG
import Data.Bits (xor)
import Data.Crypto.Classes
import Data.Crypto.Random
import System.Crypto.Random (getEntropy)

-- Initilization Vectors for key 'k' (IV k) are used
-- for various modes and guarrenteed to be blockSize
Expand Down Expand Up @@ -254,6 +256,13 @@ getIV g =
| B.length bs == bytes -> Right (iv, g')
| otherwise -> Left (GenErrorOther "Generator failed to provide requested number of bytes")

getIVIO :: (BlockCipher k) => IO (IV k)
getIVIO = do
let bytes = ivBlockSizeBytes p
p = undefined
bs <- getEntropy bytes
return (IV bs `asTypeOf` p)

ivBlockSizeBytes :: BlockCipher k => IV k -> Int
ivBlockSizeBytes iv = (blockSize `for` (keyForIV iv)) `div` 8
where
Expand Down

0 comments on commit dcad9a5

Please sign in to comment.