[number] add further gmp optional compat
This commit is contained in:
parent
ed8fbe8f69
commit
427541064d
@ -18,6 +18,9 @@ module Crypto.Number.Compat
|
|||||||
, gmpInverse
|
, gmpInverse
|
||||||
, gmpNextPrime
|
, gmpNextPrime
|
||||||
, gmpTestPrimeMillerRabin
|
, gmpTestPrimeMillerRabin
|
||||||
|
, gmpSizeInBytes
|
||||||
|
, gmpExportInteger
|
||||||
|
, gmpImportInteger
|
||||||
) where
|
) where
|
||||||
|
|
||||||
#ifndef MIN_VERSION_integer_gmp
|
#ifndef MIN_VERSION_integer_gmp
|
||||||
@ -29,6 +32,8 @@ import GHC.Integer.GMP.Internals
|
|||||||
import GHC.Base
|
import GHC.Base
|
||||||
import GHC.Integer.Logarithms (integerLog2#)
|
import GHC.Integer.Logarithms (integerLog2#)
|
||||||
#endif
|
#endif
|
||||||
|
import Data.Word
|
||||||
|
import GHC.Ptr (Ptr(..))
|
||||||
|
|
||||||
data GmpSupported a = GmpSupported a
|
data GmpSupported a = GmpSupported a
|
||||||
| GmpUnsupported
|
| GmpUnsupported
|
||||||
@ -94,3 +99,34 @@ gmpTestPrimeMillerRabin (I# tries) !n = GmpSupported $
|
|||||||
#else
|
#else
|
||||||
gmpTestPrimeMillerRabin _ _ = GmpUnsupported
|
gmpTestPrimeMillerRabin _ _ = GmpUnsupported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gmpSizeInBytes :: Integer -> GmpSupported Int
|
||||||
|
#if MIN_VERSION_integer_gmp(0,5,1)
|
||||||
|
gmpSizeInBytes n = GmpSupported (I# (word2Int# (sizeInBaseInteger n 256#)))
|
||||||
|
#else
|
||||||
|
gmpSizeInBytes _ = GmpUnsupported
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gmpExportInteger :: Integer -> Ptr Word8 -> GmpSupported (IO ())
|
||||||
|
#if __GLASGOW_HASKELL__ >= 710
|
||||||
|
gmpExportInteger n (Ptr addr) = GmpSupported $
|
||||||
|
_ <- exportIntegerToAddr n addr 1#
|
||||||
|
return ()
|
||||||
|
#elif MIN_VERSION_integer_gmp(0,5,1)
|
||||||
|
gmpExportInteger n (Ptr addr) = GmpSupported $ IO $ \s ->
|
||||||
|
case exportIntegerToAddr n addr 1# s of
|
||||||
|
(# s2, _ #) -> (# s2, () #)
|
||||||
|
#else
|
||||||
|
gmpExportInteger _ _ = GmpUnsupported
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gmpImportInteger :: Int -> Ptr Word8 -> GmpSupported (IO Integer)
|
||||||
|
#if __GLASGOW_HASKELL__ >= 710
|
||||||
|
gmpImportInteger n (Ptr addr) = GmpSupported $
|
||||||
|
importIntegerFromAddr addr (int2Word# n) 1#
|
||||||
|
#elif MIN_VERSION_integer_gmp(0,5,1)
|
||||||
|
gmpImportInteger n (Ptr addr) = GmpSupported $ IO $ \s ->
|
||||||
|
importIntegerFromAddr addr (int2Word# n) 1# s
|
||||||
|
#else
|
||||||
|
gmpImportInteger _ _ = GmpUnsupported
|
||||||
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user