packages feed

secp256k1-haskell-3.1.1: src/Crypto/Secp256k1/Internal/EllSwiftOps.hs

-- | Foreign imports of the @ellswift@ module of libsecp256k1, which the
-- library has from version 0.4.0 on when it was built with it, as it is by
-- default. See "Crypto.Secp256k1.EllSwift". This module is only built when
-- the @ellswift@ flag of the package is on.
--
-- Like "Crypto.Secp256k1.Internal.BaseOps", it is hidden, because every
-- binding takes a context pointer and the package exposes nothing that makes,
-- takes or names a context.
module Crypto.Secp256k1.Internal.EllSwiftOps where

import Crypto.Secp256k1.Internal.ContextOps (LCtx)
import Crypto.Secp256k1.Internal.ForeignTypes
  ( EllSwift64,
    PubKey64,
    Ret,
    SecKey32,
    XdhHashFun,
  )
import Foreign (FunPtr, Ptr)
import Foreign.C (CInt (..), CUChar)

-- | Binding to @secp256k1_ellswift_encode@.
foreign import ccall safe "secp256k1_ellswift.h secp256k1_ellswift_encode"
  ellSwiftEncode ::
    Ptr LCtx ->
    Ptr EllSwift64 ->
    Ptr PubKey64 ->
    -- | 32 bytes of randomness
    Ptr CUChar ->
    IO Ret

-- | Binding to @secp256k1_ellswift_decode@.
foreign import ccall safe "secp256k1_ellswift.h secp256k1_ellswift_decode"
  ellSwiftDecode ::
    Ptr LCtx ->
    Ptr PubKey64 ->
    Ptr EllSwift64 ->
    IO Ret

-- | Binding to @secp256k1_ellswift_create@.
foreign import ccall safe "secp256k1_ellswift.h secp256k1_ellswift_create"
  ellSwiftCreate ::
    Ptr LCtx ->
    Ptr EllSwift64 ->
    Ptr SecKey32 ->
    -- | 32 bytes of auxiliary randomness, or null
    Ptr CUChar ->
    IO Ret

-- | Binding to @secp256k1_ellswift_xdh@.
foreign import ccall safe "secp256k1_ellswift.h secp256k1_ellswift_xdh"
  ellSwiftXdh ::
    Ptr LCtx ->
    -- | output, filled by the hash function
    Ptr CUChar ->
    -- | encoding of party A
    Ptr EllSwift64 ->
    -- | encoding of party B
    Ptr EllSwift64 ->
    Ptr SecKey32 ->
    -- | party: 0 for A, 1 for B
    CInt ->
    FunPtr (XdhHashFun a) ->
    -- | data passed to the hash function
    Ptr a ->
    IO Ret

-- | Address of @secp256k1_ellswift_xdh_hash_function_bip324@, a constant
-- that holds the hash function of BIP 324: the tagged hash with tag
-- @bip324_ellswift_xonly_ecdh@ of the encodings of A and B and the shared x
-- coordinate. It ignores its data argument.
foreign import ccall "secp256k1_ellswift.h &secp256k1_ellswift_xdh_hash_function_bip324"
  ellSwiftXdhHashFunctionBip324 :: Ptr (FunPtr (XdhHashFun a))