aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2019-11-05 16:49:55 +0000
committerYann Herklotz <git@yannherklotz.com>2019-11-05 16:49:55 +0000
commit0fe2e068a834488c1b28f01bdddb67efdcb2d9ec (patch)
tree7c893ceac2cf56e2e482940351145b47ccd7f2cc
parent93db24ed012586f8a9a00432c2fd196b094952be (diff)
downloadverismith-fix/remove-DRBG.tar.gz
verismith-fix/remove-DRBG.zip
Remove DRBG from Fuzz.hsfix/remove-DRBG
-rw-r--r--src/Verismith/Fuzz.hs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/Verismith/Fuzz.hs b/src/Verismith/Fuzz.hs
index d14e74b..b7b2555 100644
--- a/src/Verismith/Fuzz.hs
+++ b/src/Verismith/Fuzz.hs
@@ -36,7 +36,6 @@ import Control.Monad.IO.Class
import Control.Monad.Reader
import Control.Monad.State.Strict
import Control.Monad.Trans.Control (MonadBaseControl)
-import qualified Crypto.Random.DRBG as C
import Data.ByteString (ByteString)
import Data.List (nubBy, sort)
import Data.Maybe (fromMaybe, isNothing)
@@ -291,7 +290,7 @@ simulation :: (MonadIO m, MonadSh m) => SourceInfo -> Fuzz m ()
simulation src = do
datadir <- fmap _fuzzDataDir askOpts
synth <- passedSynthesis
- vals <- liftIO $ generateByteString 20
+ vals <- liftIO $ generateByteString Nothing 32 20
ident <- liftSh $ equiv datadir vals defaultIdentitySynth
resTimes <- liftSh $ mapM (equiv datadir vals) synth
liftSh
@@ -309,18 +308,23 @@ simulation src = do
runSimIc datadir defaultIcarus a src b
where dir = fromText $ "simulation_" <> toText a
--- | Generate a specific number of random bytestrings of size 256.
-randomByteString :: C.CtrDRBG -> Int -> [ByteString] -> [ByteString]
-randomByteString gen n bytes
- | n == 0 = ranBytes : bytes
- | otherwise = randomByteString newGen (n - 1) $ ranBytes : bytes
- where Right (ranBytes, newGen) = C.genBytes 32 gen
-
-- | generates the specific number of bytestring with a random seed.
-generateByteString :: Int -> IO [ByteString]
-generateByteString n = do
- gen <- C.newGenIO :: IO C.CtrDRBG
- return $ randomByteString gen n []
+generateByteString' :: Int -> [Word8] -> (ByteString, [Word8])
+generateByteString' size words = (B.pack $ take size words, drop size words)
+
+generateByteString :: (Maybe Int) -> Int -> Int -> IO [ByteString]
+generateByteString mseed size n = do
+ gen <- case mseed of
+ Some seed' -> return $ mkStdGen seed'
+ Nothing -> newStdGen
+ randlist <- take (size * n) <$> randoms gen
+ return . fmap B.pack $ chunksOf size randlist
+ where
+ chunksOf i xs | i <= 0 = error $ "chunksOf, number must be positive, got " ++ show i
+ chunksOf i xs = repeatedly (splitAt i) xs
+ repeatedly f [] = []
+ repeatedly f as = b : repeatedly f as'
+ where (b, as') = f as
failEquivWithIdentity :: (MonadSh m) => Fuzz m [SynthResult]
failEquivWithIdentity = filter withIdentity . _fuzzSynthResults <$> get