cprng-aes 0.3.2 → 0.3.3
raw patch · 2 files changed
+3/−36 lines, 2 filesdep −cryptocipherdep ~basedep ~random
Dependencies removed: cryptocipher
Dependency ranges changed: base, random
Files
- Crypto/Random/AESCtr.hs +1/−26
- cprng-aes.cabal +2/−10
Crypto/Random/AESCtr.hs view
@@ -12,7 +12,7 @@ -- each block are generated the following way: -- aes (IV `xor` counter) -> 16 bytes output ---{-# LANGUAGE CPP, PackageImports #-}+{-# LANGUAGE CPP #-} module Crypto.Random.AESCtr ( AESRNG , make@@ -29,11 +29,7 @@ import System.Random (RandomGen(..)) import System.Entropy (getEntropy)-#ifdef CIPHER_AES import qualified "cipher-aes" Crypto.Cipher.AES as AES-#else-import qualified "cryptocipher" Crypto.Cipher.AES as AES-#endif import Data.ByteString (ByteString) import qualified Data.ByteString as B@@ -100,22 +96,13 @@ xor128 :: Word128 -> Word128 -> Word128 xor128 (Word128 a1 b1) (Word128 a2 b2) = Word128 (a1 `xor` a2) (b1 `xor` b2) -#ifdef CIPHER_AES add64 :: Word128 -> Word128 add64 (Word128 a b) = if b >= (0xffffffffffffffff-63) then Word128 (a+1) (b+64) else Word128 a (b+64)-#else-add1 :: Word128 -> Word128-add1 (Word128 a b) = if b == 0xffffffffffffffff then Word128 (a+1) 0 else Word128 a (b+1)-#endif makeParams :: ByteString -> (AES.Key, ByteString, ByteString) makeParams b = (key, cnt, iv) where-#ifdef CIPHER_AES key = AES.initKey $ B.take 32 left2-#else- (Right key) = AES.initKey256 $ B.take 32 left2-#endif (cnt, left2) = B.splitAt 16 left1 (iv, left1) = B.splitAt 16 b @@ -132,7 +119,6 @@ rng = RNG (get128 iv) (get128 cnt) 0 key (key, cnt, iv) = makeParams b -#ifdef CIPHER_AES chunkSize :: Int chunkSize = 1024 @@ -142,17 +128,6 @@ newrng = RNG (get128 chunk) (add64 counter) (sz+fromIntegral chunkSize) key chunk = AES.genCTR key (AES.IV bytes) 1024 bytes = put128 (iv `xor128` counter)-#else-chunkSize :: Int-chunkSize = 16--genNextChunk :: RNG -> (ByteString, RNG)-genNextChunk (RNG iv counter sz key) = (chunk, newrng)- where- newrng = RNG (get128 chunk) (add1 counter) (sz+fromIntegral chunkSize) key- chunk = AES.encrypt key bytes- bytes = put128 (iv `xor128` counter)-#endif getRNGReseedLimit :: RNG -> Int getRNGReseedLimit (RNG _ _ sz _)
cprng-aes.cabal view
@@ -1,5 +1,5 @@ Name: cprng-aes-Version: 0.3.2+Version: 0.3.3 Description: Simple crypto pseudo-random-number-generator with really good randomness property. .@@ -30,10 +30,6 @@ Homepage: http://github.com/vincenthz/hs-cprng-aes data-files: README.md -Flag fastaes- Description: Use fast AES if available- Default: True- Flag cereal Description: Use cereal Default: False@@ -51,11 +47,7 @@ Exposed-modules: Crypto.Random.AESCtr ghc-options: -Wall - if flag(fastaes) && (arch(i386) || arch(x86_64))- cpp-options: -DCIPHER_AES- Build-Depends: cipher-aes >= 0.1 && < 0.2- else- Build-Depends: cryptocipher+ Build-Depends: cipher-aes >= 0.1 && < 0.2 if flag(cereal) Build-Depends: cereal >= 0.3.0 && < 0.4.0 cpp-options: -DUSE_CEREAL