{-# LINE 1 "src/Data/Number/Flint/Fmpz/Mod/FFI.hsc" #-}
module Data.Number.Flint.Fmpz.Mod.FFI (
FmpzModCtx (..)
, CFmpzModCtx (..)
, newFmpzModCtx
, withFmpzModCtx
, withNewFmpzModCtx
, fmpz_mod_ctx_init
, fmpz_mod_ctx_clear
, fmpz_mod_ctx_set_modulus
, fmpz_mod_set_fmpz
, fmpz_mod_is_canonical
, fmpz_mod_is_one
, fmpz_mod_add
, fmpz_mod_add_fmpz
, fmpz_mod_sub
, fmpz_mod_sub_fmpz
, fmpz_mod_fmpz_sub
, fmpz_mod_neg
, fmpz_mod_mul
, fmpz_mod_inv
, fmpz_mod_divides
, fmpz_mod_pow_ui
, fmpz_mod_pow_fmpz
, fmpz_mod_discrete_log_pohlig_hellman_init
, fmpz_mod_discrete_log_pohlig_hellman_clear
, fmpz_mod_discrete_log_pohlig_hellman_precompute_prime
, fmpz_mod_discrete_log_pohlig_hellman_primitive_root
, fmpz_mod_discrete_log_pohlig_hellman_run
, fmpz_next_smooth_prime
) where
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, plusPtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
data FmpzModCtx = FmpzModCtx {-# UNPACK #-} !(ForeignPtr CFmpzModCtx)
type CFmpzModCtx = CFlint FmpzModCtx
instance Storable CFmpzModCtx where
{-# INLINE sizeOf #-}
sizeOf :: CFmpzModCtx -> Int
sizeOf CFmpzModCtx
_ = (Int
112)
{-# LINE 69 "src/Data/Number/Flint/Fmpz/Mod/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CFmpzModCtx -> Int
alignment CFmpzModCtx
_ = Int
8
{-# LINE 71 "src/Data/Number/Flint/Fmpz/Mod/FFI.hsc" #-}
peek = error "CFmpzModCtx.peek: Not defined"
poke :: Ptr CFmpzModCtx -> CFmpzModCtx -> IO ()
poke = forall a. HasCallStack => [Char] -> a
error [Char]
"CFmpzModCtx.poke: Not defined"
newFmpzModCtx :: Fmpz -> IO FmpzModCtx
newFmpzModCtx Fmpz
n = do
ForeignPtr CFmpzModCtx
p <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
n forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
n ->
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFmpzModCtx
p forall a b. (a -> b) -> a -> b
$ \Ptr CFmpzModCtx
p ->
Ptr CFmpzModCtx -> Ptr CFmpz -> IO ()
fmpz_mod_ctx_init Ptr CFmpzModCtx
p Ptr CFmpz
n
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CFmpzModCtx -> IO ())
p_fmpz_mod_ctx_clear ForeignPtr CFmpzModCtx
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CFmpzModCtx -> FmpzModCtx
FmpzModCtx ForeignPtr CFmpzModCtx
p
{-# INLINE withFmpzModCtx #-}
withFmpzModCtx :: FmpzModCtx -> (Ptr CFmpzModCtx -> IO a) -> IO (FmpzModCtx, a)
withFmpzModCtx (FmpzModCtx ForeignPtr CFmpzModCtx
p) Ptr CFmpzModCtx -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFmpzModCtx
p forall a b. (a -> b) -> a -> b
$ \Ptr CFmpzModCtx
fp -> Ptr CFmpzModCtx -> IO a
f Ptr CFmpzModCtx
fp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CFmpzModCtx -> FmpzModCtx
FmpzModCtx ForeignPtr CFmpzModCtx
p,)
{-# INLINE withNewFmpzModCtx #-}
withNewFmpzModCtx :: Fmpz -> (Ptr CFmpzModCtx -> IO a) -> IO (FmpzModCtx, a)
withNewFmpzModCtx Fmpz
n Ptr CFmpzModCtx -> IO a
f = Fmpz -> IO FmpzModCtx
newFmpzModCtx Fmpz
n forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> b -> a -> c
flip forall {a}.
FmpzModCtx -> (Ptr CFmpzModCtx -> IO a) -> IO (FmpzModCtx, a)
withFmpzModCtx Ptr CFmpzModCtx -> IO a
f
foreign import ccall "fmpz_mod.h fmpz_mod_ctx_init"
fmpz_mod_ctx_init :: Ptr CFmpzModCtx -> Ptr CFmpz -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_ctx_clear"
fmpz_mod_ctx_clear :: Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h &fmpz_mod_ctx_clear"
p_fmpz_mod_ctx_clear :: FunPtr (Ptr CFmpzModCtx -> IO ())
foreign import ccall "fmpz_mod.h fmpz_mod_ctx_set_modulus"
fmpz_mod_ctx_set_modulus :: Ptr CFmpzModCtx -> Ptr CFmpz -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_set_fmpz"
fmpz_mod_set_fmpz :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_is_canonical"
fmpz_mod_is_canonical :: Ptr CFmpz -> Ptr CFmpzModCtx -> IO CInt
foreign import ccall "fmpz_mod.h fmpz_mod_is_one"
fmpz_mod_is_one :: Ptr CFmpz -> Ptr CFmpzModCtx -> IO CInt
foreign import ccall "fmpz_mod.h fmpz_mod_add"
fmpz_mod_add :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_add_fmpz"
fmpz_mod_add_fmpz :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_sub"
fmpz_mod_sub :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_sub_fmpz"
fmpz_mod_sub_fmpz :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_fmpz_sub"
fmpz_mod_fmpz_sub :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_neg"
fmpz_mod_neg :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_mul"
fmpz_mod_mul :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_inv"
fmpz_mod_inv :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_divides"
fmpz_mod_divides :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO CInt
foreign import ccall "fmpz_mod.h fmpz_mod_pow_ui"
fmpz_mod_pow_ui :: Ptr CFmpz -> Ptr CFmpz -> CULong -> Ptr CFmpzModCtx -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_pow_fmpz"
fmpz_mod_pow_fmpz :: Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpz -> Ptr CFmpzModCtx -> IO CInt
data FmpzModDiscreteLogPohligHellmann = FmpzModDiscreteLogPohligHellmann {-# UNPACK #-} !(ForeignPtr CFmpzModDiscreteLogPohligHellmann)
type CFmpzModDiscreteLogPohligHellmann = CFlint FmpzModDiscreteLogPohligHellmann
instance Storable CFmpzModDiscreteLogPohligHellmann where
{-# INLINE sizeOf #-}
sizeOf :: CFmpzModDiscreteLogPohligHellmann -> Int
sizeOf CFmpzModDiscreteLogPohligHellmann
_ = (Int
152)
{-# LINE 227 "src/Data/Number/Flint/Fmpz/Mod/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CFmpzModDiscreteLogPohligHellmann -> Int
alignment CFmpzModDiscreteLogPohligHellmann
_ = Int
8
{-# LINE 229 "src/Data/Number/Flint/Fmpz/Mod/FFI.hsc" #-}
peek = error "CCFmpzModDiscreteLogPohligHellmann.peek: Not defined"
poke :: Ptr CFmpzModDiscreteLogPohligHellmann
-> CFmpzModDiscreteLogPohligHellmann -> IO ()
poke = forall a. HasCallStack => [Char] -> a
error [Char]
"CCFmpzModDiscreteLogPohligHellmann.poke: Not defined"
newCFmpzModDiscreteLogPohligHellmann :: IO FmpzModDiscreteLogPohligHellmann
newCFmpzModDiscreteLogPohligHellmann = do
ForeignPtr CFmpzModDiscreteLogPohligHellmann
p <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFmpzModDiscreteLogPohligHellmann
p Ptr CFmpzModDiscreteLogPohligHellmann -> IO ()
fmpz_mod_discrete_log_pohlig_hellman_init
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CFmpzModDiscreteLogPohligHellmann -> IO ())
p_fmpz_mod_discrete_log_pohlig_hellman_clear ForeignPtr CFmpzModDiscreteLogPohligHellmann
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CFmpzModDiscreteLogPohligHellmann
-> FmpzModDiscreteLogPohligHellmann
FmpzModDiscreteLogPohligHellmann ForeignPtr CFmpzModDiscreteLogPohligHellmann
p
foreign import ccall "fmpz_mod.h fmpz_mod_discrete_log_pohlig_hellman_init"
fmpz_mod_discrete_log_pohlig_hellman_init :: Ptr CFmpzModDiscreteLogPohligHellmann -> IO ()
foreign import ccall "fmpz_mod.h fmpz_mod_discrete_log_pohlig_hellman_clear"
fmpz_mod_discrete_log_pohlig_hellman_clear :: Ptr CFmpzModDiscreteLogPohligHellmann -> IO ()
foreign import ccall "fmpz_mod.h &fmpz_mod_discrete_log_pohlig_hellman_clear"
p_fmpz_mod_discrete_log_pohlig_hellman_clear :: FunPtr (Ptr CFmpzModDiscreteLogPohligHellmann -> IO ())
foreign import ccall "fmpz_mod.h fmpz_mod_discrete_log_pohlig_hellman_precompute_prime"
fmpz_mod_discrete_log_pohlig_hellman_precompute_prime :: Ptr CFmpzModDiscreteLogPohligHellmann -> Ptr CFmpz -> IO CDouble
foreign import ccall "fmpz_mod.h fmpz_mod_discrete_log_pohlig_hellman_primitive_root"
fmpz_mod_discrete_log_pohlig_hellman_primitive_root :: Ptr CFmpzModDiscreteLogPohligHellmann -> IO (Ptr CFmpz)
foreign import ccall "fmpz_mod.h fmpz_mod_discrete_log_pohlig_hellman_run"
fmpz_mod_discrete_log_pohlig_hellman_run :: Ptr CFmpz -> Ptr CFmpzModDiscreteLogPohligHellmann -> Ptr CFmpz -> IO ()
foreign import ccall "fmpz_mod.h fmpz_next_smooth_prime"
fmpz_next_smooth_prime :: Ptr CFmpz -> Ptr CFmpz -> IO CInt