ppad-censor 0.6.2 → 0.6.3
raw patch · 4 files changed
+61/−18 lines, 4 filesdep −ppad-randomPVP ok
version bump matches the API change (PVP)
Dependencies removed: ppad-random
API changes (from Hackage documentation)
Files
- CHANGELOG +7/−0
- lib/Censor/Rng.hs +40/−15
- ppad-censor.cabal +1/−2
- test/Main.hs +13/−1
CHANGELOG view
@@ -1,5 +1,12 @@ # Changelog +- 0.6.3 (2026-11-21)+ * censor no longer depends on ppad-random: Censor.Rng implements+ xoshiro256++ itself, drawing the same stream for a seed as 0.6.2.+ A harness depending on censor no longer carries ppad-random's+ ppad-chacha, which collided with a target pinning another+ ppad-chacha. A reseed no longer allocates.+ - 0.6.2 (2026-11-20) * Censor.Rng draws from ppad-random's xoshiro256++ (Crypto.PRNG), in place of splitmix64, so a seed's stream differs from 0.6.1's.
lib/Censor/Rng.hs view
@@ -7,7 +7,11 @@ -- License: MIT -- Maintainer: Jared Tobin <jared@ppad.tech> ----- A minimal PRNG for input samplers: ppad-random's xoshiro256++.+-- A minimal PRNG for input samplers: xoshiro256++, seeded from a+-- 64-bit seed via splitmix64. Its stream for a seed is that of+-- ppad-random's Crypto.PRNG; censor keeps its own copy so that it+-- adds nothing to a harness's dependency closure that a target might+-- also depend on (ppad-random depends on ppad-chacha). -- -- Samplers feeding 'Censor.runCT' want a pseudorandom source that is -- deterministic under a fixed seed, cheap, and light on allocation,@@ -34,45 +38,66 @@ , splitMix ) where -import qualified Crypto.PRNG as PRNG import qualified Data.Bits as B import qualified Data.ByteString as BS import qualified Data.ByteString.Internal as BI-import Data.IORef+import qualified Data.Primitive.PrimArray as PA import Data.Word (Word8, Word64) import GHC.Exts (RealWorld) import Foreign.Ptr (Ptr) import Foreign.Storable (pokeByteOff) --- | A xoshiro256++ generator, behind an 'IORef' so that it can be--- reseeded in place.-newtype Rng = Rng (IORef (PRNG.Gen RealWorld))+-- | A xoshiro256++ generator: its four words of state, mutable so+-- that it can be reseeded in place.+newtype Rng = Rng (PA.MutablePrimArray RealWorld Word64) -- | Create a generator from a seed. Equal seeds yield equal streams. mkRng :: Word64 -> IO Rng-mkRng s = PRNG.new s >>= fmap Rng . newIORef+mkRng s = do+ g <- Rng <$> PA.newPrimArray 4+ reseed g s+ pure g {-# INLINE mkRng #-} -- | Draw the next 'Word64' from the generator. nextWord :: Rng -> IO Word64-nextWord (Rng ref) = readIORef ref >>= PRNG.word64+nextWord (Rng a) = do+ !s0 <- PA.readPrimArray a 0+ !s1 <- PA.readPrimArray a 1+ !s2 <- PA.readPrimArray a 2+ !s3 <- PA.readPrimArray a 3+ let !t = s1 `B.shiftL` 17+ !a2 = s2 `B.xor` s0+ !a3 = s3 `B.xor` s1+ PA.writePrimArray a 0 (s0 `B.xor` a3)+ PA.writePrimArray a 1 (s1 `B.xor` a2)+ PA.writePrimArray a 2 (a2 `B.xor` t)+ PA.writePrimArray a 3 (a3 `B.rotateL` 45)+ pure $! ((s0 + s3) `B.rotateL` 23) + s0 {-# INLINE nextWord #-} -- | Reset a generator to a seed in place: after @reseed g s@ the -- generator draws exactly the stream of a fresh @'mkRng' s@. -- -- Lets one long-lived generator replay a pinned stream, or adopt--- a fresh one, allocating only the new generator's state — so the--- two classes of a fix-vs-random sampler can share a single--- generator object and differ only in the seed value written into--- it.+-- a fresh one, without allocating per use — so the two classes+-- of a fix-vs-random sampler can share a single generator object+-- and differ only in the seed value written into it. reseed :: Rng -> Word64 -> IO ()-reseed (Rng ref) s = PRNG.new s >>= writeIORef ref+reseed (Rng a) !x = do+ let !(x0, s0) = splitMix x+ !(x1, s1) = splitMix x0+ !(x2, s2) = splitMix x1+ !(_ , s3) = splitMix x2+ PA.writePrimArray a 0 s0+ PA.writePrimArray a 1 s1+ PA.writePrimArray a 2 s2+ PA.writePrimArray a 3 s3 {-# INLINE reseed #-} -- | The pure splitmix64 step: from a state, produce the successor--- state and an output word. "Censor" derives a run's seeds and--- its order bits with it; an 'Rng' doesn't use it.+-- state and an output word. An 'Rng' expands its seed with it,+-- and "Censor" derives a run's seeds and its order bits with it. splitMix :: Word64 -> (Word64, Word64) splitMix !s = let !s' = s + 0x9E3779B97F4A7C15
ppad-censor.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: ppad-censor-version: 0.6.2+version: 0.6.3 synopsis: Anytime-valid sequential constant-time testing. license: MIT license-file: LICENSE@@ -89,7 +89,6 @@ base >= 4.9 && < 5 , bytestring >= 0.9 && < 0.13 , ppad-eproc >= 0.5.3 && < 0.6- , ppad-random >= 0.1 && < 0.2 , primitive >= 0.8 && < 0.10 test-suite censor-tests
test/Main.hs view
@@ -864,7 +864,19 @@ rngTests :: TestTree rngTests = testGroup "Censor.Rng" [- testCase "equal seeds give equal streams" $ do+ -- xoshiro256++ seeded via splitmix64, as ppad-random's+ -- Crypto.PRNG draws it+ testCase "xoshiro256++ vectors" $ do+ g42 <- C.mkRng 42+ ws42 <- mapM (\_ -> C.nextWord g42) [1 .. 4 :: Int]+ ws42 @?= [ 0xd0764d4f4476689f, 0x519e4174576f3791+ , 0xfbe07cfb0c24ed8c, 0xb37d9f600cd835b8 ]+ g0 <- C.mkRng 0+ ws0 <- mapM (\_ -> C.nextWord g0) [1 .. 4 :: Int]+ ws0 @?= [ 0x53175d61490b23df, 0x61da6f3dc380d507+ , 0x5c0fdf91ec9a7bfc, 0x02eebf8c3bbe5e1a ]++ , testCase "equal seeds give equal streams" $ do g1 <- C.mkRng 0xFEEDFACE g2 <- C.mkRng 0xFEEDFACE ws1 <- mapM (\_ -> C.nextWord g1) [1 .. 16 :: Int]