[number] correct tweak function to mask things properly
This commit is contained in:
parent
e14d9cafc9
commit
0e048b77c4
@ -49,20 +49,18 @@ generateParams bits genTopPolicy generateOdd
|
|||||||
| otherwise = os2ip . tweak <$> getRandomBytes bytes
|
| otherwise = os2ip . tweak <$> getRandomBytes bytes
|
||||||
where
|
where
|
||||||
tweak :: ScrubbedBytes -> ScrubbedBytes
|
tweak :: ScrubbedBytes -> ScrubbedBytes
|
||||||
tweak orig =
|
tweak orig = B.copyAndFreeze orig $ \p0 -> do
|
||||||
case (genTopPolicy, generateOdd) of
|
let p1 = p0 `plusPtr` 1
|
||||||
(Nothing , False) -> orig
|
pEnd = p0 `plusPtr` (bytes - 1)
|
||||||
(Nothing , True ) -> B.copyAndFreeze orig $ \p -> (p `plusPtr` (bytes-1)) |= 0x1
|
case genTopPolicy of
|
||||||
(Just topPolicy, _ ) -> B.copyAndFreeze orig $ \p0 -> do
|
Nothing -> return ()
|
||||||
let p1 = p0 `plusPtr` 1
|
Just SetHighest -> p0 |= (1 `shiftL` bit)
|
||||||
pEnd = p0 `plusPtr` (bytes - 1)
|
Just SetTwoHighest
|
||||||
case topPolicy of
|
| bit == 0 -> do p0 $= 0x1
|
||||||
SetHighest -> p0 |= (1 `shiftL` bit)
|
p1 |= 0x80
|
||||||
SetTwoHighest | bit == 0 -> do p0 $= 0x1
|
| otherwise -> p0 |= (0x3 `shiftL` (bit - 1))
|
||||||
p1 |= 0x80
|
p0 &= (complement $ mask)
|
||||||
| otherwise -> p0 |= (0x3 `shiftL` (bit - 1))
|
when generateOdd (pEnd |= 0x1)
|
||||||
p0 &= (complement $ mask)
|
|
||||||
when generateOdd (pEnd |= 0x1)
|
|
||||||
|
|
||||||
($=) :: Ptr Word8 -> Word8 -> IO ()
|
($=) :: Ptr Word8 -> Word8 -> IO ()
|
||||||
($=) p w = poke p w
|
($=) p w = poke p w
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user