[number] properly handle gmp
This commit is contained in:
parent
f84d60e69f
commit
d035e3a3bc
@ -28,7 +28,7 @@ module Crypto.Number.Compat
|
|||||||
#define MIN_VERSION_integer_gmp(a,b,c) 0
|
#define MIN_VERSION_integer_gmp(a,b,c) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __GLASGOW_HASKELL__ >= 710 || MIN_VERSION_integer_gmp(0,5,1)
|
#if MIN_VERSION_integer_gmp(0,5,1)
|
||||||
import GHC.Integer.GMP.Internals
|
import GHC.Integer.GMP.Internals
|
||||||
import GHC.Base
|
import GHC.Base
|
||||||
import GHC.Integer.Logarithms (integerLog2#)
|
import GHC.Integer.Logarithms (integerLog2#)
|
||||||
@ -55,7 +55,7 @@ gmpGcde _ _ = GmpUnsupported
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gmpLog2 :: Integer -> GmpSupported Int
|
gmpLog2 :: Integer -> GmpSupported Int
|
||||||
#ifdef VERSION_integer_gmp
|
#if MIN_VERSION_integer_gmp(0,5,1)
|
||||||
gmpLog2 0 = GmpSupported 0
|
gmpLog2 0 = GmpSupported 0
|
||||||
gmpLog2 x = GmpSupported (I# (integerLog2# x))
|
gmpLog2 x = GmpSupported (I# (integerLog2# x))
|
||||||
#else
|
#else
|
||||||
@ -113,7 +113,7 @@ gmpSizeInBytes _ = GmpUnsupported
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gmpExportInteger :: Integer -> Ptr Word8 -> GmpSupported (IO ())
|
gmpExportInteger :: Integer -> Ptr Word8 -> GmpSupported (IO ())
|
||||||
#if __GLASGOW_HASKELL__ >= 710
|
#if MIN_VERSION_integer_gmp(1,0,0)
|
||||||
gmpExportInteger n (Ptr addr) = GmpSupported $ do
|
gmpExportInteger n (Ptr addr) = GmpSupported $ do
|
||||||
_ <- exportIntegerToAddr n addr 1#
|
_ <- exportIntegerToAddr n addr 1#
|
||||||
return ()
|
return ()
|
||||||
@ -126,11 +126,11 @@ gmpExportInteger _ _ = GmpUnsupported
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
gmpImportInteger :: Int -> Ptr Word8 -> GmpSupported (IO Integer)
|
gmpImportInteger :: Int -> Ptr Word8 -> GmpSupported (IO Integer)
|
||||||
#if __GLASGOW_HASKELL__ >= 710
|
#if MIN_VERSION_integer_gmp(1,0,0)
|
||||||
gmpImportInteger n (Ptr addr) = GmpSupported $
|
gmpImportInteger (I# n) (Ptr addr) = GmpSupported $
|
||||||
importIntegerFromAddr addr (int2Word# n) 1#
|
importIntegerFromAddr addr (int2Word# n) 1#
|
||||||
#elif MIN_VERSION_integer_gmp(0,5,1)
|
#elif MIN_VERSION_integer_gmp(0,5,1)
|
||||||
gmpImportInteger n (Ptr addr) = GmpSupported $ IO $ \s ->
|
gmpImportInteger (I# n) (Ptr addr) = GmpSupported $ IO $ \s ->
|
||||||
importIntegerFromAddr addr (int2Word# n) 1# s
|
importIntegerFromAddr addr (int2Word# n) 1# s
|
||||||
#else
|
#else
|
||||||
gmpImportInteger _ _ = GmpUnsupported
|
gmpImportInteger _ _ = GmpUnsupported
|
||||||
|
|||||||
@ -40,6 +40,11 @@ Flag builtin_memory
|
|||||||
Default: True
|
Default: True
|
||||||
Manual: True
|
Manual: True
|
||||||
|
|
||||||
|
Flag integer-gmp
|
||||||
|
Description: Whether or not to use GMP for some functions
|
||||||
|
Default: True
|
||||||
|
Manual: True
|
||||||
|
|
||||||
Library
|
Library
|
||||||
Exposed-modules: Crypto.Cipher.AES
|
Exposed-modules: Crypto.Cipher.AES
|
||||||
Crypto.Cipher.Blowfish
|
Crypto.Cipher.Blowfish
|
||||||
@ -208,6 +213,9 @@ Library
|
|||||||
else
|
else
|
||||||
build-depends: memory
|
build-depends: memory
|
||||||
|
|
||||||
|
if impl(ghc) && flag(integer-gmp)
|
||||||
|
Build-depends: integer-gmp
|
||||||
|
|
||||||
Test-Suite test-cryptonite
|
Test-Suite test-cryptonite
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
hs-source-dirs: tests
|
hs-source-dirs: tests
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user