From d035e3a3bc490f9da77f45c4de18c8383679ad20 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Mon, 11 May 2015 11:39:09 +0100 Subject: [PATCH] [number] properly handle gmp --- Crypto/Number/Compat.hs | 12 ++++++------ cryptonite.cabal | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Crypto/Number/Compat.hs b/Crypto/Number/Compat.hs index cbc1fcd..aa7c03f 100644 --- a/Crypto/Number/Compat.hs +++ b/Crypto/Number/Compat.hs @@ -28,7 +28,7 @@ module Crypto.Number.Compat #define MIN_VERSION_integer_gmp(a,b,c) 0 #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.Base import GHC.Integer.Logarithms (integerLog2#) @@ -55,7 +55,7 @@ gmpGcde _ _ = GmpUnsupported #endif gmpLog2 :: Integer -> GmpSupported Int -#ifdef VERSION_integer_gmp +#if MIN_VERSION_integer_gmp(0,5,1) gmpLog2 0 = GmpSupported 0 gmpLog2 x = GmpSupported (I# (integerLog2# x)) #else @@ -113,7 +113,7 @@ gmpSizeInBytes _ = GmpUnsupported #endif gmpExportInteger :: Integer -> Ptr Word8 -> GmpSupported (IO ()) -#if __GLASGOW_HASKELL__ >= 710 +#if MIN_VERSION_integer_gmp(1,0,0) gmpExportInteger n (Ptr addr) = GmpSupported $ do _ <- exportIntegerToAddr n addr 1# return () @@ -126,11 +126,11 @@ gmpExportInteger _ _ = GmpUnsupported #endif gmpImportInteger :: Int -> Ptr Word8 -> GmpSupported (IO Integer) -#if __GLASGOW_HASKELL__ >= 710 -gmpImportInteger n (Ptr addr) = GmpSupported $ +#if MIN_VERSION_integer_gmp(1,0,0) +gmpImportInteger (I# n) (Ptr addr) = GmpSupported $ importIntegerFromAddr addr (int2Word# n) 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 #else gmpImportInteger _ _ = GmpUnsupported diff --git a/cryptonite.cabal b/cryptonite.cabal index d34df28..8591d49 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -40,6 +40,11 @@ Flag builtin_memory Default: True Manual: True +Flag integer-gmp + Description: Whether or not to use GMP for some functions + Default: True + Manual: True + Library Exposed-modules: Crypto.Cipher.AES Crypto.Cipher.Blowfish @@ -208,6 +213,9 @@ Library else build-depends: memory + if impl(ghc) && flag(integer-gmp) + Build-depends: integer-gmp + Test-Suite test-cryptonite type: exitcode-stdio-1.0 hs-source-dirs: tests