Skip to content

Commit

Permalink
Remove need for MonoLocalBinds
Browse files Browse the repository at this point in the history
Ignore-this: 83e93137e2d6926cd7a1c06acd51035a

darcs-hash:20101028180329-cef97-51d39a14f30c7a19259ef694da9652f63cb2172e.gz
  • Loading branch information
TomMD committed Oct 28, 2010
1 parent 49906b5 commit 53a30c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions Crypto/Modes.hs
@@ -1,4 +1,3 @@
{-# LANGUAGE MonoLocalBinds #-}
{-|
Maintainer: Thomas.DuBuisson@gmail.com
Stability: beta
Expand Down Expand Up @@ -35,6 +34,7 @@ import Data.Tagged
import Crypto.Classes
import Crypto.Random
import System.Crypto.Random (getEntropy)
import Control.Monad (liftM)

-- |Initilization Vectors for BlockCipher implementations (IV k) are used
-- for various modes and guarrenteed to be blockSize bits long.
Expand Down Expand Up @@ -266,10 +266,11 @@ getIV g =
-- | Obtain an `IV` using the system entropy (see "System.Crypto.Random")
getIVIO :: (BlockCipher k) => IO (IV k)
getIVIO = do
let bytes = proxy blockSize p `div` 8
p = Proxy
bs <- getEntropy bytes
return (IV bs `asProxyTypeOf` ivProxy p)
let p = Proxy
getTypedIV :: BlockCipher k => Proxy k -> IO (IV k)
getTypedIV pr = liftM IV (getEntropy (proxy blockSize pr `div` 8))
iv <- getTypedIV p
return (iv `asProxyTypeOf` ivProxy p)

ivProxy :: Proxy k -> Proxy (IV k)
ivProxy = reproxy
Expand All @@ -288,9 +289,10 @@ ivBlockSizeBytes iv =
instance (BlockCipher k) => Serialize (IV k) where
get = do
let p = Proxy
bytes = proxy blockSize p `div` 8
iv <- SG.getByteString bytes
return ((IV iv) `asProxyTypeOf` ivProxy p)
doGet :: BlockCipher k => Proxy k -> Get (IV k)
doGet pr = liftM IV (SG.getByteString (proxy blockSize pr `div` 8))
iv <- doGet p
return (iv `asProxyTypeOf` ivProxy p)
put (IV iv) = SP.putByteString iv

-- TODO: GCM, GMAC
Expand Down
2 changes: 1 addition & 1 deletion crypto-api.cabal
@@ -1,5 +1,5 @@
name: crypto-api
version: 0.1.2.4
version: 0.1.3.0
license: BSD3
license-file: LICENSE
copyright: Thomas DuBuisson <thomas.dubuisson@gmail.com>, Dominic Steinitz (see Data.LargeWord module)
Expand Down

0 comments on commit 53a30c1

Please sign in to comment.