Add test generation for RFC 6979 k value generation.

This commit is contained in:
2019-01-18 21:53:52 -08:00
parent f4e47154c2
commit c5e9d4be25
4 changed files with 158 additions and 3 deletions

View File

@@ -5,11 +5,12 @@ module Math(
, modulate, modulate'
, isqrt
, divmod
, showX, showB
, showX, showB, showBin
)
where
import Data.Bits(shiftL,shiftR)
import Data.Bits(shiftL,shiftR,(.&.))
import qualified Data.ByteString as S
import GHC.Integer.GMP.Internals(recipModInteger)
import Numeric(showHex)
@@ -106,6 +107,13 @@ showB :: Bool -> String
showB False = "0"
showB True = "1"
showBin :: S.ByteString -> String
showBin bstr =
case S.uncons bstr of
Nothing -> ""
Just (x,rest) ->
showX (x `shiftR` 4) ++ showX (x .&. 0xF) ++ showBin rest
isqrt :: Int -> Integer -> Integer
isqrt bits val = final
where