packages feed

crypto-api 0.9 → 0.10

raw patch · 5 files changed

+30/−6 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Crypto.Random: instance Exception GenError
+ Crypto.Random: instance Typeable GenError
+ Crypto.Random: throwLeft :: Exception e => Either e a -> a
- Crypto.Random: class CryptoRandomGen g where genBytesWithEntropy len entropy g = let res = genBytes len g in case res of { Left err -> Left err Right (bs, g') -> let entropy' = append entropy (replicate (len - length entropy) 0) in Right (zwp' entropy' bs, g') } newGenIO = go 0 where go 1000 = error $ "The generator instance requested by" ++ "newGenIO never instantiates (1000 tries). " ++ "It must be broken." go i = do { let p = Proxy getTypedGen :: CryptoRandomGen g => Proxy g -> IO (Either GenError g) getTypedGen pr = liftM newGen (getEntropy $ proxy genSeedLength pr); res <- getTypedGen p; case res of { Left _ -> go (i + 1) Right g -> return (g `asProxyTypeOf` p) } }
+ Crypto.Random: class CryptoRandomGen g where genBytesWithEntropy len entropy g = let res = genBytes len g in case res of { Left err -> Left err Right (bs, g') -> let entropy' = append entropy (replicate (len - length entropy) 0) in Right (zwp' entropy' bs, g') } newGenIO = go 0 where go 1000 = throw $ GenErrorOther $ "The generator instance requested by" ++ "newGenIO never instantiates (1000 tries). " ++ "It must be broken." go i = do { let p = Proxy getTypedGen :: CryptoRandomGen g => Proxy g -> IO (Either GenError g) getTypedGen pr = liftM newGen (getEntropy $ proxy genSeedLength pr); res <- getTypedGen p; case res of { Left _ -> go (i + 1) Right g -> return (g `asProxyTypeOf` p) } }

Files

Crypto/HMAC.hs view
@@ -16,6 +16,8 @@ import Data.Serialize (encode) import Data.Bits (xor) +-- | A key carrying phantom types @c@ and @d@, forcing the key data to only be used+-- by particular hash algorithms. newtype MacKey c d = MacKey B.ByteString deriving (Eq, Ord, Show)  -- |Message authentication code calculation for lazy bytestrings.
Crypto/Modes.hs view
@@ -139,10 +139,12 @@ 	in (c:cs, ivFinal) {-# INLINEABLE cbc' #-} +-- |Cipher block chaining message authentication cbcMac' :: BlockCipher k => k -> B.ByteString -> B.ByteString cbcMac' k pt = encode $ snd $ cbc' k zeroIV pt {-# INLINEABLE cbcMac' #-} +-- |Cipher block chaining message authentication cbcMac :: BlockCipher k => k -> L.ByteString -> L.ByteString cbcMac k pt = L.fromChunks [encode $ snd $ cbc k zeroIV pt] {-# INLINEABLE cbcMac #-}@@ -444,25 +446,28 @@   where bytes = ivBlockSizeBytes iv         iv  = IV $ B.replicate  bytes 0 -+-- |Cook book mode - not really a mode at all.  If you don't know what you're doing, don't use this mode^H^H^H^H library. ecb :: BlockCipher k => k -> L.ByteString -> L.ByteString ecb k msg = 	let chunks = chunkFor k msg 	in L.fromChunks $ map (encryptBlock k) chunks {-# INLINEABLE ecb #-} +-- |ECB decrypt, complementary to `ecb`. unEcb :: BlockCipher k => k -> L.ByteString -> L.ByteString unEcb k msg = 	let chunks = chunkFor k msg 	in L.fromChunks $ map (decryptBlock k) chunks {-# INLINEABLE unEcb #-} +-- | Like `ecb` but for strict bytestrings ecb' :: BlockCipher k => k -> B.ByteString -> B.ByteString ecb' k msg = 	let chunks = chunkFor' k msg 	in B.concat $ map (encryptBlock k) chunks {-# INLINEABLE ecb' #-} +-- |Decryption complement to `ecb'` unEcb' :: BlockCipher k => k -> B.ByteString -> B.ByteString unEcb' k ct = 	let chunks = chunkFor' k ct
Crypto/Random.hs view
@@ -1,11 +1,11 @@-{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, CPP #-}+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, DeriveDataTypeable, CPP #-} {-|  Maintainer: Thomas.DuBuisson@gmail.com  Stability: beta  Portability: portable   - This module is for instantiating cryptographically strong+ This module is for instantiating cryptographicly strong determinitic random bit generators (DRBGs, aka PRNGs) For the simple use case of using the system random number generator ('System.Crypto.Random') to seed the DRBG:@@ -27,15 +27,18 @@        , GenError (..)          -- * Helper functions and expanded interface        , splitGen+       , throwLeft          -- * Instances        , SystemRandom        ) where  import Control.Monad (liftM)+import Control.Exception import Crypto.Types import Data.Bits (xor, setBit, shiftR, shiftL, (.&.)) import Data.List (foldl') import Data.Tagged+import Data.Typeable import System.Entropy import System.IO.Unsafe(unsafeInterleaveIO) import qualified Data.ByteString as B@@ -47,6 +50,10 @@ #endif  -- |Generator failures should always return the appropriate GenError.+-- Note 'GenError' in an instance of exception but wether or not an+-- exception is thrown depends on if the selected generator (read:+-- if you don't want execptions from code that uses 'throw' then+-- pass in a generator that never has an error for the used functions) data GenError = 	  GenErrorOther String	-- ^ Misc 	| RequestedTooManyBytes	-- ^ Requested more bytes than a@@ -64,8 +71,10 @@ 	| NeedsInfiniteSeed	-- ^ This generator can not be                                 -- instantiated or reseeded with a                                 -- finite seed (ex: 'SystemRandom')-  deriving (Eq, Ord, Show)+  deriving (Eq, Ord, Show, Typeable) +instance Exception GenError+ -- |A class of random bit generators that allows for the possibility -- of failure, reseeding, providing entropy at the same time as -- requesting bytes@@ -138,7 +147,8 @@ 	newGenIO :: IO g 	newGenIO = go 0 	  where-	  go 1000 = error $ "The generator instance requested by" +++	  go 1000 = throw $ GenErrorOther $ +                          "The generator instance requested by" ++                           "newGenIO never instantiates (1000 tries). " ++                           "It must be broken." 	  go i = do@@ -203,6 +213,12 @@        case newGen ent of 		Right new -> Right (g',new) 		Left e -> Left e++-- | Useful utility to extract the result of a generator operation+-- and translate error results to exceptions.+throwLeft :: Exception e => Either e a -> a+throwLeft (Left e)  = throw e+throwLeft (Right a) = a  -- |Obtain a tagged value for a particular instantiated type. for :: Tagged a b -> a -> b
Crypto/Util.hs view
@@ -1,3 +1,4 @@+-- |A small selection of utilities that might be of use to others working with bytestring/number combinations. module Crypto.Util where import qualified Data.ByteString as B import Data.ByteString.Unsafe (unsafeIndex)
crypto-api.cabal view
@@ -1,5 +1,5 @@ name:           crypto-api-version:        0.9+version:        0.10 license:        BSD3 license-file:   LICENSE copyright:      Thomas DuBuisson <thomas.dubuisson@gmail.com>, Francisco Blas Izquierdo Riera (klondike) (see AUTHORS)