diff --git a/test/Generators.hs b/test/Generators.hs index 18125c6b82b5e322e15489eb3e736f699d3d038e..a9823f666c7cc6521304fe5157cc44d2791979d2 100644 --- a/test/Generators.hs +++ b/test/Generators.hs @@ -245,11 +245,11 @@ applyShareBitFlips (CrypttextTreeLeafBitFlips hashFlips) = first (zipWith flipHa -- the same number of bytes back into a Digest, but hard to prove. digestFromByteStringPartial @a $ BA.xor mask leaf -{- | Generate lists of shares like the one given but with some bits in the - hashes needed to validate the merkle path to each share's "share root - hash" flipped. The generated lists will have the same length as the - input list with fewer than paramRequiredShares elements unmodified so - that they surely cannot be decoded. +{- | Generate instructions for making changes to the given list of shares so + that some bits in the hashes needed to validate the merkle path to each + share's "share root hash" are flipped. The modified list will have the + same length as the input list with fewer than paramRequiredShares + elements unmodified so that they surely cannot be decoded. -} shareTreeLeafBitFlipper :: MonadGen m => Parameters -> [Share] -> m (ShareBitFlips hash) shareTreeLeafBitFlipper Parameters{paramRequiredShares, paramTotalShares} shares' = do @@ -285,6 +285,12 @@ shareTreeLeafBitFlipper Parameters{paramRequiredShares, paramTotalShares} shares -- Filter out the mask with no bits set, which would result in no bit flips. nonZeroFlips = Gen.filterT (/= zeroMask) flips +{- | Generate instructions for making changes to the given list of shares so + that some bits in the "crypttext hash tree" leaves are flipped. The + modified list will have the same length as the input list with fewer than + paramRequiredShares elements unmodified so that they surely cannot be + decoded. +-} crypttextTreeLeafBitFlipper :: forall m. MonadGen m => Parameters -> [Share] -> m (ShareBitFlips SHA256d) crypttextTreeLeafBitFlipper Parameters{paramRequiredShares, paramTotalShares} shares' = do -- Pick the shares the crypttext hash trees of which will be modified. @@ -307,6 +313,9 @@ crypttextTreeLeafBitFlipper Parameters{paramRequiredShares, paramTotalShares} sh nonZeroDigest :: forall a. HashAlgorithm a => Digest' a -> m (Digest' a) nonZeroDigest _ = digestFromByteStringPartial <$> nonZeroBytes (Range.singleton (hashDigestSize @a undefined)) +{- | Make a @Digest'@ out of a @BS.ByteString@ of the right length. If the + length is wrong, error. +-} digestFromByteStringPartial :: HashAlgorithm hash => BS.ByteString -> Digest' hash digestFromByteStringPartial = maybe