Permalink
Browse files

Moved from Data.Crypto.* to Crypto.* module names. Renamed RandomGene…

…rator to CryptoRandomGen. Renamed OriginalGenClass to AsRandomGen.

Ignore-this: 51f60889e4a6dd9681f3fbfb93c0db47

darcs-hash:20100904161144-cef97-8ee02d55ded4d9c2028e486fced237549655a480.gz
  • Loading branch information...
1 parent e0d1162 commit da2010979e45f73cc056870c020f0f252884b8db @TomMD committed Sep 4, 2010
View
@@ -23,8 +23,8 @@ module Benchmark.Crypto
, benchmarkRNG
) where
-import Data.Crypto.Classes
-import Data.Crypto.Modes (ecb', unEcb')
+import Crypto.Classes
+import Crypto.Modes (ecb', unEcb')
import qualified Data.Serialize as Ser
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
@@ -1,5 +1,5 @@
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
-module Data.Crypto.Classes
+module Crypto.Classes
( Hash(..)
, BlockCipher(..)
, StreamCipher(..)
@@ -19,8 +19,8 @@ import qualified Data.ByteString as B
import qualified Data.ByteString.Internal as I
import Data.List (foldl')
import Data.Tagged
-import Data.Crypto.Types
-import Data.Crypto.Random
+import Crypto.Types
+import Crypto.Random
-- |The Hash class is intended as the generic interface
-- targeted by maintainers of Haskell digest implementations.
@@ -109,7 +109,7 @@ class (Binary k, Serialize k) => BlockCipher k where
keyLength :: k -> BitLength -- ^ keyLength may inspect its argument to return the length
class (Binary p, Serialize p) => AsymCipher p where
- buildKeyPair :: RandomGenerator g => g -> BitLength -> Maybe ((p,p),g)
+ buildKeyPair :: CryptoRandomGen g => g -> BitLength -> Maybe ((p,p),g)
encryptAsym :: p -> B.ByteString -> B.ByteString
decryptAsym :: p -> B.ByteString -> B.ByteString
asymKeyLength :: p -> BitLength
@@ -1,8 +1,8 @@
-module Data.Crypto.HMAC where
+module Crypto.HMAC where
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
-import Data.Crypto.Classes
+import Crypto.Classes
import Data.Serialize (encode)
import qualified Data.Binary as Bin
import Data.Bits (xor)
@@ -1,5 +1,5 @@
{-# LANGUAGE ScopedTypeVariables, MonoLocalBinds #-}
-module Data.Crypto.Modes
+module Crypto.Modes
( ecb, unEcb
, cbc, unCbc
, cfb, unCfb
@@ -25,8 +25,8 @@ import qualified Data.Binary.Get as BG
import qualified Data.Serialize.Put as SP
import qualified Data.Serialize.Get as SG
import Data.Bits (xor)
-import Data.Crypto.Classes
-import Data.Crypto.Random
+import Crypto.Classes
+import Crypto.Random
import System.Crypto.Random (getEntropy)
-- Initilization Vectors for key 'k' (IV k) are used
@@ -244,7 +244,7 @@ unfoldK f i =
let (as, iF) = unfoldK f i'
in (a:as, iF)
-getIV :: (BlockCipher k, RandomGenerator g) => g -> Either GenError (IV k, g)
+getIV :: (BlockCipher k, CryptoRandomGen g) => g -> Either GenError (IV k, g)
getIV g =
let bytes = ivBlockSizeBytes iv
gen = genBytes g bytes
@@ -1,14 +1,15 @@
{-# LANGUAGE ScopedTypeVariables, MonoLocalBinds #-}
-module Data.Crypto.Random
- ( OldRandomClass (..)
- , RandomGenerator(..)
+module Crypto.Random
+ ( AsRandomGen (..)
+ , CryptoRandomGen(..)
, genInteger
, GenError (..)
, newGenIO
) where
import System.Crypto.Random (getEntropy)
-import System.Random (RandomGen(..))
+import System.Random (RandomGen(next))
+import qualified System.Random as R
import Control.Monad (liftM)
import Data.Serialize
import qualified Data.ByteString as B
@@ -24,8 +25,8 @@ data GenError = -- Expected use:
| NotEnoughEntropy -- For instantiating new generators (or reseeding)
deriving (Eq, Ord, Show)
-instance (RandomGenerator g) => RandomGen (OldRandomClass g) where
- next (ORC g) =
+instance (SplitableGenerator g, CryptoRandomGen g) => RandomGen (AsRandomGen g) where
+ next (AsRG g) =
let (Right (bs, g')) = genBytes g (sizeOf res)
Right res = decode bs
in (res, ORC g')
@@ -36,18 +37,18 @@ instance (RandomGenerator g) => RandomGen (OldRandomClass g) where
Right new2 = newGen b
in (ORC new1, ORC new2)
--- |Any 'RandomGenerator' can be used where the 'RandomGen' class is needed
--- simply by wrapping with with the ORC constructor. Any failures
--- (Left results from genBytes or newGen bs | B.length bs == 512) result
+-- |Any 'CryptoRandomGen' can be used where the 'RandomGen' class is needed
+-- simply by wrapping with with the AsRG constructor. Any failures
+-- (Left results from genBytes or newGen) result
-- in a pattern match exception. Such failures were simply assumed
-- not possible by the RandomGen class, hence there is no non-exception
-- way to indicate a failure.
-data OldRandomClass a = ORC a
+data AsRandomGen a = AsRG a
deriving (Eq, Ord, Show)
-- |A class of random bit generators that allows for the possibility of failure,
-- reseeding, providing entropy at the same time as requesting bytes
-class RandomGenerator g where
+class CryptoRandomGen g where
-- |Instantiate a new random bit generator
newGen :: B.ByteString -> Either GenError g
@@ -78,8 +79,8 @@ class SplitableGenerator g where
split :: g -> Either GenError (g,g)
-- |Use System.Crypto.Random to obtain entropy for newGen.
--- Only buggy RandomGenerator instances should fail.
-newGenIO :: RandomGenerator g => IO (Either GenError g)
+-- Only buggy CryptoRandomGen instances should fail.
+newGenIO :: CryptoRandomGen g => IO (Either GenError g)
newGenIO = do
let r = Right undefined
l = genSeedLength `for` (fromRight r)
@@ -94,7 +95,7 @@ for t _ = unTagged t
-- |'genInteger g (low,high)' will generate an integer between [low, high] inclusivly.
-- This function has degraded (theoretically unbounded, probabilitically decent) performance
-- the closer your range size (high - low) is to 2^n+1 for large natural values of n.
-genInteger :: RandomGenerator g => g -> (Integer, Integer) -> Either GenError (Integer, g)
+genInteger :: CryptoRandomGen g => g -> (Integer, Integer) -> Either GenError (Integer, g)
genInteger g (low,high)
| high < low = genInteger g (high,low)
| high == low = Right (high, g)
@@ -1,4 +1,4 @@
-module Data.Crypto.Types where
+module Crypto.Types where
import Data.ByteString as B
import Data.ByteString.Lazy as L
View
@@ -11,7 +11,7 @@ import System.IO (openFile, hClose, IOMode(..), Handle)
import Control.Monad (liftM)
import Data.ByteString as B
import Data.ByteString.Lazy as L
-import Data.Crypto.Types
+import Crypto.Types
#if defined(_WIN32)
{- C example for windows rng - taken from a blog, can't recall which one but thank you!
View
@@ -37,8 +37,8 @@ module Test.Crypto
import Test.QuickCheck
import Test.ParseNistKATs
-import Data.Crypto.Classes
-import Data.Crypto.Modes
+import Crypto.Classes
+import Crypto.Modes
import qualified Data.ByteString.Lazy.Char8 as LC
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as B
View
@@ -12,7 +12,7 @@ description: A generic interface for cryptographic operations,
Maintainers of hash and cipher implementations are
encouraged to add instances for the classes defined
- in Data.Crypto.Classes. Crypto users are similarly
+ in Crypto.Classes. Crypto users are similarly
encoraged to use the interfaces defined in the Classes
module.
@@ -47,7 +47,7 @@ Library
filepath >= 1.1
ghc-options: -O2
hs-source-dirs:
- exposed-modules: Data.Crypto.Classes, Data.Crypto.Types, Data.Crypto.HMAC, Data.LargeWord, Data.Crypto.Modes, System.Crypto.Random, Data.Crypto.Random
+ exposed-modules: Crypto.Classes, Crypto.Types, Crypto.HMAC, Data.LargeWord, Crypto.Modes, System.Crypto.Random, Crypto.Random
if flag(alg-tests)
exposed-modules: Test.Crypto, Test.ParseNistKATs
build-depends: QuickCheck >= 2.0, parsec >= 3.1, directory >= 1.0.1.0

0 comments on commit da20109

Please sign in to comment.