{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Cardano.Crypto.Libsodium.C (
c_sodium_init,
c_sodium_memzero,
c_sodium_malloc,
c_sodium_free,
c_sodium_free_funptr,
c_sodium_mlock,
c_sodium_munlock,
c_crypto_hash_sha256,
c_crypto_hash_sha256_final,
c_crypto_hash_sha256_init,
c_crypto_hash_sha256_update,
c_crypto_generichash_blake2b,
c_crypto_generichash_blake2b_final,
c_crypto_generichash_blake2b_init,
c_crypto_generichash_blake2b_update,
c_crypto_sign_ed25519_seed_keypair,
c_crypto_sign_ed25519_sk_to_seed,
c_crypto_sign_ed25519_detached,
c_crypto_sign_ed25519_verify_detached,
c_crypto_sign_ed25519_sk_to_pk,
c_sodium_randombytes_buf,
c_sodium_compare,
CRYPTO_SHA256_BYTES,
CRYPTO_SHA512_BYTES,
CRYPTO_BLAKE2B_256_BYTES,
CRYPTO_SHA256_STATE_SIZE,
CRYPTO_SHA512_STATE_SIZE,
CRYPTO_BLAKE2B_256_STATE_SIZE,
CRYPTO_SIGN_ED25519_BYTES,
CRYPTO_SIGN_ED25519_SEEDBYTES,
CRYPTO_SIGN_ED25519_PUBLICKEYBYTES,
CRYPTO_SIGN_ED25519_SECRETKEYBYTES,
) where
import Foreign.C.Types
import Foreign.Ptr (FunPtr, Ptr)
import Cardano.Crypto.Libsodium.Constants
import Cardano.Foreign
foreign import capi "sodium.h sodium_init" c_sodium_init :: IO Int
foreign import capi unsafe "sodium.h sodium_memzero" c_sodium_memzero :: Ptr a -> CSize -> IO ()
foreign import capi unsafe "sodium.h sodium_malloc" c_sodium_malloc :: CSize -> IO (Ptr a)
foreign import capi unsafe "sodium.h sodium_free" c_sodium_free :: Ptr a -> IO ()
foreign import capi unsafe "sodium.h &sodium_free" c_sodium_free_funptr :: FunPtr (Ptr a -> IO ())
foreign import capi unsafe "sodium.h sodium_mlock" c_sodium_mlock :: Ptr a -> CSize -> IO CInt
foreign import capi unsafe "sodium.h sodium_munlock" c_sodium_munlock :: Ptr a -> CSize -> IO CInt
foreign import capi unsafe "sodium.h crypto_hash_sha256"
c_crypto_hash_sha256 :: SizedPtr CRYPTO_SHA256_BYTES -> Ptr CUChar -> CULLong -> IO Int
foreign import capi unsafe "sodium.h crypto_hash_sha256_init"
c_crypto_hash_sha256_init :: SizedPtr CRYPTO_SHA256_STATE_SIZE -> IO Int
foreign import capi unsafe "sodium.h crypto_hash_sha256_update"
c_crypto_hash_sha256_update :: SizedPtr CRYPTO_SHA256_STATE_SIZE -> Ptr CUChar -> CULLong -> IO Int
foreign import capi unsafe "sodium.h crypto_hash_sha256_final"
c_crypto_hash_sha256_final ::
SizedPtr CRYPTO_SHA256_STATE_SIZE -> SizedPtr CRYPTO_SHA256_BYTES -> IO Int
foreign import capi unsafe "sodium.h crypto_generichash_blake2b"
c_crypto_generichash_blake2b ::
Ptr out ->
CSize ->
Ptr CUChar ->
CULLong ->
Ptr key ->
CSize ->
IO Int
foreign import capi unsafe "sodium.h crypto_generichash_blake2b_init"
c_crypto_generichash_blake2b_init ::
SizedPtr CRYPTO_BLAKE2B_256_STATE_SIZE -> Ptr key -> CSize -> CSize -> IO Int
foreign import capi unsafe "sodium.h crypto_generichash_blake2b_update"
c_crypto_generichash_blake2b_update ::
SizedPtr CRYPTO_BLAKE2B_256_STATE_SIZE -> Ptr CUChar -> CULLong -> IO Int
foreign import capi unsafe "sodium.h crypto_generichash_blake2b_final"
c_crypto_generichash_blake2b_final ::
SizedPtr CRYPTO_BLAKE2B_256_STATE_SIZE -> Ptr out -> CSize -> IO Int
foreign import capi unsafe "sodium.h crypto_sign_ed25519_seed_keypair"
c_crypto_sign_ed25519_seed_keypair ::
SizedPtr CRYPTO_SIGN_ED25519_PUBLICKEYBYTES ->
SizedPtr CRYPTO_SIGN_ED25519_SECRETKEYBYTES ->
SizedPtr CRYPTO_SIGN_ED25519_SEEDBYTES ->
IO Int
foreign import capi unsafe "sodium.h crypto_sign_ed25519_sk_to_seed"
c_crypto_sign_ed25519_sk_to_seed ::
SizedPtr CRYPTO_SIGN_ED25519_SEEDBYTES ->
SizedPtr CRYPTO_SIGN_ED25519_SECRETKEYBYTES ->
IO Int
foreign import capi unsafe "sodium.h crypto_sign_ed25519_detached"
c_crypto_sign_ed25519_detached ::
SizedPtr CRYPTO_SIGN_ED25519_BYTES ->
Ptr CULLong ->
Ptr CUChar ->
CULLong ->
SizedPtr CRYPTO_SIGN_ED25519_SECRETKEYBYTES ->
IO Int
foreign import capi unsafe "sodium.h crypto_sign_ed25519_verify_detached"
c_crypto_sign_ed25519_verify_detached ::
SizedPtr CRYPTO_SIGN_ED25519_BYTES ->
Ptr CUChar ->
CULLong ->
SizedPtr CRYPTO_SIGN_ED25519_PUBLICKEYBYTES ->
IO Int
foreign import capi unsafe "sodium.h crypto_sign_ed25519_sk_to_pk"
c_crypto_sign_ed25519_sk_to_pk ::
SizedPtr CRYPTO_SIGN_ED25519_PUBLICKEYBYTES ->
SizedPtr CRYPTO_SIGN_ED25519_SECRETKEYBYTES ->
IO Int
foreign import capi unsafe "sodium.h sodium_compare"
c_sodium_compare :: Ptr a -> Ptr a -> CSize -> IO Int
foreign import capi unsafe "sodium/randombytes.h randombytes_buf"
c_sodium_randombytes_buf :: Ptr a -> CSize -> IO ()