cprng-aes 0.3.4 → 0.4.0
raw patch · 2 files changed
+6/−27 lines, 2 filesdep −crypto-apidep ~bytestringdep ~cipher-aesdep ~randomPVP ok
version bump matches the API change (PVP)
Dependencies removed: crypto-api
Dependency ranges changed: bytestring, cipher-aes, random
API changes (from Hackage documentation)
- Crypto.Random.AESCtr: instance CryptoRandomGen AESRNG
Files
- Crypto/Random/AESCtr.hs +4/−18
- cprng-aes.cabal +2/−9
Crypto/Random/AESCtr.hs view
@@ -22,9 +22,6 @@ import Control.Applicative ((<$>)) -#ifdef USE_CRYPTOAPI-import qualified Crypto.Random as CAPI-#endif import Crypto.Random.API import System.Random (RandomGen(..))@@ -60,7 +57,7 @@ {-# UNPACK #-} !Word128 {-# UNPACK #-} !Word128 {-# UNPACK #-} !Word64- {-# UNPACK #-} !AES.Key+ {-# UNPACK #-} !AES.AES data AESRNG = AESRNG { aesrngState :: RNG , aesrngCache :: ByteString }@@ -99,10 +96,10 @@ add64 :: Word128 -> Word128 add64 (Word128 a b) = if b >= (0xffffffffffffffff-63) then Word128 (a+1) (b+64) else Word128 a (b+64) -makeParams :: ByteString -> (AES.Key, ByteString, ByteString)+makeParams :: ByteString -> (AES.AES, ByteString, ByteString) makeParams b = (key, cnt, iv) where- key = AES.initKey $ B.take 32 left2+ key = AES.initAES $ B.take 32 left2 (cnt, left2) = B.splitAt 16 left1 (iv, left1) = B.splitAt 16 b @@ -126,7 +123,7 @@ genNextChunk (RNG iv counter sz key) = (chunk, newrng) where newrng = RNG (get128 chunk) (add64 counter) (sz+fromIntegral chunkSize) key- chunk = AES.genCTR key (AES.IV bytes) 1024+ chunk = AES.genCTR key bytes 1024 bytes = put128 (iv `xor128` counter) getRNGReseedLimit :: RNG -> Int@@ -166,17 +163,6 @@ reseedState b rng@(RNG _ cnt1 _ _) = RNG (get128 r16 `xor128` get128 iv2) (cnt1 `xor128` get128 cnt2) 0 key2 where (r16, _) = genNextChunk rng (key2, cnt2, iv2) = makeParams b--#ifdef USE_CRYPTOAPI--- going away in 0.4.0. use the CPRG instance.-instance CAPI.CryptoRandomGen AESRNG where- newGen b = maybe (Left CAPI.NotEnoughEntropy) Right $ make b- genSeedLength = 64- genBytes len rng = Right $ genRanBytes rng len- reseed b rng- | B.length b < 64 = Left CAPI.NotEnoughEntropy- | otherwise = Right $ rng { aesrngState = reseedState b (aesrngState rng) }-#endif instance CPRG AESRNG where cprgGenBytes len rng = genRanBytes rng len
cprng-aes.cabal view
@@ -1,5 +1,5 @@ Name: cprng-aes-Version: 0.3.4+Version: 0.4.0 Description: Simple crypto pseudo-random-number-generator with really good randomness property. .@@ -34,10 +34,6 @@ Description: Use cereal Default: False -Flag cryptoapi- Description: Use cryptoapi- Default: True- Library Build-Depends: base >= 3 && < 5 , bytestring@@ -47,13 +43,10 @@ Exposed-modules: Crypto.Random.AESCtr ghc-options: -Wall - Build-Depends: cipher-aes >= 0.1 && < 0.2+ Build-Depends: cipher-aes >= 0.2 && < 0.3 if flag(cereal) Build-Depends: cereal >= 0.3.0 && < 0.4.0 cpp-options: -DUSE_CEREAL- if flag(cryptoapi)- Build-Depends: crypto-api >= 0.8- cpp-options: -DUSE_CRYPTOAPI Benchmark bench-cprng-aes hs-source-dirs: Benchmarks